From e088abdb463836b4165782d20cdfbd3cd2fef65e Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Tue, 12 Mar 2024 16:34:00 -0700 Subject: [PATCH] Refactored action menus to a shared include, closes #2301 --- datasette/templates/_action_menu.html | 28 +++++++++++++++++++++++ datasette/templates/database.html | 32 ++------------------------ datasette/templates/index.html | 32 ++------------------------ datasette/templates/query.html | 33 ++------------------------- datasette/templates/row.html | 32 ++------------------------ datasette/templates/table.html | 32 ++------------------------ 6 files changed, 38 insertions(+), 151 deletions(-) create mode 100644 datasette/templates/_action_menu.html diff --git a/datasette/templates/_action_menu.html b/datasette/templates/_action_menu.html new file mode 100644 index 00000000..7d1d4a55 --- /dev/null +++ b/datasette/templates/_action_menu.html @@ -0,0 +1,28 @@ +{% if action_links %} +
+ +
+{% endif %} \ No newline at end of file diff --git a/datasette/templates/database.html b/datasette/templates/database.html index b5a0edc4..4a4a05cb 100644 --- a/datasette/templates/database.html +++ b/datasette/templates/database.html @@ -13,36 +13,8 @@ -{% set links = database_actions() %}{% if links %} -
- -
-{% endif %} +{% set action_links, action_title = database_actions(), "Database actions" %} +{% include "_action_menu.html" %} {{ top_database() }} diff --git a/datasette/templates/index.html b/datasette/templates/index.html index d08cdb10..6e95126d 100644 --- a/datasette/templates/index.html +++ b/datasette/templates/index.html @@ -7,36 +7,8 @@ {% block content %}

{{ metadata.title or "Datasette" }}{% if private %} 🔒{% endif %}

-{% set links = homepage_actions %}{% if links %} -
- -
-{% endif %} +{% set action_links, action_title = homepage_actions, "Homepage actions" %} +{% include "_action_menu.html" %} {{ top_homepage() }} diff --git a/datasette/templates/query.html b/datasette/templates/query.html index 09a29118..f7c8d0a3 100644 --- a/datasette/templates/query.html +++ b/datasette/templates/query.html @@ -29,37 +29,8 @@ {% endif %}

{{ metadata.title or database }}{% if canned_query and not metadata.title %}: {{ canned_query }}{% endif %}{% if private %} 🔒{% endif %}

-{% set links = query_actions() %}{% if links %} -
- -
-{% endif %} - +{% set action_links, action_title = query_actions(), "Query actions" %} +{% include "_action_menu.html" %} {% if canned_query %}{{ top_canned_query() }}{% else %}{{ top_query() }}{% endif %} diff --git a/datasette/templates/row.html b/datasette/templates/row.html index c3e6bed7..db43e71a 100644 --- a/datasette/templates/row.html +++ b/datasette/templates/row.html @@ -22,36 +22,8 @@ {% block content %}

{{ table }}: {{ ', '.join(primary_key_values) }}{% if private %} 🔒{% endif %}

-{% set links = row_actions %}{% if links %} -
- -
-{% endif %} +{% set action_links, action_title = row_actions, "Row actions" %} +{% include "_action_menu.html" %} {{ top_row() }} diff --git a/datasette/templates/table.html b/datasette/templates/table.html index 505335d6..35e0b9c1 100644 --- a/datasette/templates/table.html +++ b/datasette/templates/table.html @@ -24,36 +24,8 @@ -{% set links = actions() %}{% if links %} -
- -
-{% endif %} +{% set action_links, action_title = actions(), "View actions" if is_view else "Table actions" %} +{% include "_action_menu.html" %} {{ top_table() }}