mirror of
https://github.com/simonw/datasette.git
synced 2026-09-02 14:44:07 +02:00
Show the dismiss X for facets applied as ?column__exact=value
This commit is contained in:
parent
e889403d3b
commit
cad1c345fa
2 changed files with 52 additions and 0 deletions
|
|
@ -264,6 +264,10 @@ class ColumnFacet(Facet):
|
|||
column_qs = column
|
||||
if column.startswith("_"):
|
||||
column_qs = f"{column}__exact"
|
||||
# ?column=x and ?column__exact=x are equivalent filters,
|
||||
# so check for both, https://github.com/simonw/datasette/issues/2011
|
||||
if (f"{column}__exact", str(row["value"])) in qs_pairs:
|
||||
column_qs = f"{column}__exact"
|
||||
selected = (column_qs, str(row["value"])) in qs_pairs
|
||||
if selected:
|
||||
toggle_path = path_with_removed_args(
|
||||
|
|
|
|||
|
|
@ -151,6 +151,54 @@ async def test_column_facet_results(ds_client):
|
|||
] == buckets
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_column_facet_results_selected_by_exact_filter(ds_client):
|
||||
# The filter form produces ?column__exact=x rather than ?column=x -
|
||||
# both should mark the matching facet value as selected
|
||||
# https://github.com/simonw/datasette/issues/2011
|
||||
facet = ColumnFacet(
|
||||
ds_client.ds,
|
||||
Request.fake("/?_facet=state&state__exact=MI"),
|
||||
database="fixtures",
|
||||
sql="select * from facetable",
|
||||
table="facetable",
|
||||
)
|
||||
buckets, timed_out = await facet.facet_results()
|
||||
assert [] == timed_out
|
||||
assert buckets == [
|
||||
{
|
||||
"name": "state",
|
||||
"type": "column",
|
||||
"hideable": True,
|
||||
"toggle_url": "/?state__exact=MI",
|
||||
"results": [
|
||||
{
|
||||
"value": "CA",
|
||||
"label": "CA",
|
||||
"count": 10,
|
||||
"toggle_url": "http://localhost/?_facet=state&state__exact=MI&state=CA",
|
||||
"selected": False,
|
||||
},
|
||||
{
|
||||
"value": "MI",
|
||||
"label": "MI",
|
||||
"count": 4,
|
||||
"toggle_url": "http://localhost/?_facet=state",
|
||||
"selected": True,
|
||||
},
|
||||
{
|
||||
"value": "MC",
|
||||
"label": "MC",
|
||||
"count": 1,
|
||||
"toggle_url": "http://localhost/?_facet=state&state__exact=MI&state=MC",
|
||||
"selected": False,
|
||||
},
|
||||
],
|
||||
"truncated": False,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_column_facet_results_column_starts_with_underscore(ds_client):
|
||||
facet = ColumnFacet(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue