From 69cfd16fcf62696b9c7beb87cec367f74ba7fd90 Mon Sep 17 00:00:00 2001 From: Daniel Shafer Date: Tue, 6 Oct 2026 14:30:08 +0000 Subject: [PATCH] Offer "Facet by this" for the first column of a view The column menu skipped the facet option for whichever column came first, which was meant to skip the special link column on tables. Views have no link column, so their first real column lost the option. Check data-is-link-column instead. Closes #1785 --- datasette/static/table.js | 4 ++-- tests/test_playwright.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/datasette/static/table.js b/datasette/static/table.js index aef694b5..e2f4c2d5 100644 --- a/datasette/static/table.js +++ b/datasette/static/table.js @@ -370,7 +370,7 @@ function buildColumnActionItems(manager, th, options) { var column = th.dataset.column; var columnActions = []; var isSortable = !!th.querySelector("a"); - var isFirstColumn = th.parentElement.querySelector("th:first-of-type") === th; + var isLinkColumn = th.dataset.isLinkColumn === "1"; var isSinglePk = th.dataset.isPk === "1" && document.querySelectorAll('th[data-is-pk="1"]').length === 1; @@ -394,7 +394,7 @@ function buildColumnActionItems(manager, th, options) { if ( DATASETTE_ALLOW_FACET && - !isFirstColumn && + !isLinkColumn && !getDisplayedFacets().includes(column) && !isSinglePk ) { diff --git a/tests/test_playwright.py b/tests/test_playwright.py index 665ed32a..f124ce9f 100644 --- a/tests/test_playwright.py +++ b/tests/test_playwright.py @@ -2301,3 +2301,16 @@ def test_menu_long_plugin_content_and_no_popover_fallback(page, datasette_server assert panel.evaluate("node => node.scrollTop > 0") page.keyboard.press("Escape") expect(panel).not_to_be_visible() + + +@pytest.mark.playwright +def test_column_menu_facet_by_first_column_of_view(page, datasette_server): + # https://github.com/simonw/datasette/issues/1785 + from playwright.sync_api import expect + + panel = page.locator("#column-actions-menu") + page.goto(datasette_server + "fixtures/paginated_view") + page.locator('th[data-column="content"] .column-menu-trigger').click() + expect( + panel.get_by_role("menuitem", name="Facet by this", exact=True) + ).to_be_visible()