UI for selecting and re-ordering columns on the table page (#2662)

New Web Component on table/view page with a dialog for selecting and re-ordering columns.

Closes #2661
Refs #1298
This commit is contained in:
Simon Willison 2026-03-09 17:45:24 -07:00 committed by GitHub
commit e2c1e81ec9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 882 additions and 7 deletions

View file

@ -730,6 +730,69 @@ async def test_table_html_filter_form_still_shows_nocol_columns(ds_client):
]
@pytest.mark.asyncio
async def test_column_chooser_present(ds_client):
response = await ds_client.get("/fixtures/facetable")
assert response.status_code == 200
soup = Soup(response.text, "html.parser")
# Web component should be present
chooser = soup.find("column-chooser")
assert chooser is not None
# Script block should contain column data as JSON
scripts = soup.find_all("script")
chooser_script = [s for s in scripts if "_columnChooserData" in (s.string or "")]
assert len(chooser_script) == 1
script_text = chooser_script[0].string
# Extract the JSON data
assert "allColumns" in script_text
assert "selectedColumns" in script_text
assert "primaryKeys" in script_text
@pytest.mark.asyncio
async def test_column_chooser_data_reflects_col_filtering(ds_client):
response = await ds_client.get("/fixtures/facetable?_col=state&_col=created")
assert response.status_code == 200
import json
import re
soup = Soup(response.text, "html.parser")
chooser = soup.find("column-chooser")
assert chooser is not None
scripts = soup.find_all("script")
chooser_script = [s for s in scripts if "_columnChooserData" in (s.string or "")]
script_text = chooser_script[0].string
# Parse the JSON object from the script
match = re.search(
r"window\._columnChooserData\s*=\s*({.*?});", script_text, re.DOTALL
)
data = json.loads(match.group(1))
# All non-PK columns should still be listed in allColumns
assert "state" in data["allColumns"]
assert "created" in data["allColumns"]
assert "planet_int" in data["allColumns"]
# Only state and created should be in selectedColumns (plus pk)
non_pk_selected = [
c for c in data["selectedColumns"] if c not in data["primaryKeys"]
]
assert "state" in non_pk_selected
assert "created" in non_pk_selected
assert "planet_int" not in non_pk_selected
@pytest.mark.asyncio
async def test_column_chooser_shown_for_views(ds_client):
response = await ds_client.get("/fixtures/simple_view")
assert response.status_code == 200
soup = Soup(response.text, "html.parser")
chooser = soup.find("column-chooser")
assert chooser is not None
scripts = soup.find_all("script")
chooser_script = [s for s in scripts if "_columnChooserData" in (s.string or "")]
assert len(chooser_script) == 1
@pytest.mark.asyncio
async def test_compound_primary_key_with_foreign_key_references(ds_client):
# e.g. a many-to-many table with a compound primary key on the two columns