Show count of facet values if ?_facet_size=max, closes #1423

pull/1444/head
Simon Willison 2021-08-16 11:56:32 -07:00
rodzic 2883098770
commit adb5b70de5
4 zmienionych plików z 30 dodań i 2 usunięć

Wyświetl plik

@ -633,6 +633,11 @@ form button[type=button] {
width: 250px;
margin-right: 15px;
}
.facet-info-total {
font-size: 0.8em;
color: #666;
padding-right: 0.25em;
}
.facet-info li,
.facet-info ul {
margin: 0;

Wyświetl plik

@ -156,7 +156,9 @@
{% for facet_info in sorted_facet_results %}
<div class="facet-info facet-{{ database|to_css_class }}-{{ table|to_css_class }}-{{ facet_info.name|to_css_class }}" id="facet-{{ facet_info.name|to_css_class }}">
<p class="facet-info-name">
<strong>{{ facet_info.name }}{% if facet_info.type != "column" %} ({{ facet_info.type }}){% endif %}</strong>
<strong>{{ facet_info.name }}{% if facet_info.type != "column" %} ({{ facet_info.type }}){% endif %}
{% if show_facet_counts %} <span class="facet-info-total">{% if facet_info.truncated %}&gt;{% endif %}{{ facet_info.results|length }}</span>{% endif %}
</strong>
{% if facet_info.hideable %}
<a href="{{ facet_info.toggle_url }}" class="cross">&#x2716;</a>
{% endif %}

Wyświetl plik

@ -928,6 +928,7 @@ class TableView(RowTableShared):
key=lambda f: (len(f["results"]), f["name"]),
reverse=True,
),
"show_facet_counts": special_args.get("_facet_size") == "max",
"extra_wheres_for_ui": extra_wheres_for_ui,
"form_hidden_args": form_hidden_args,
"is_sortable": any(c["sortable"] for c in display_columns),

Wyświetl plik

@ -479,7 +479,7 @@ def test_facet_display(app_client):
for div in divs:
actual.append(
{
"name": div.find("strong").text,
"name": div.find("strong").text.split()[0],
"items": [
{
"name": a.text,
@ -1797,3 +1797,23 @@ def test_column_metadata(app_client):
soup.select("th[data-column=address]")[0]["data-column-description"]
== "The street address for the attraction"
)
@pytest.mark.parametrize("use_facet_size_max", (True, False))
def test_facet_total_shown_if_facet_max_size(use_facet_size_max):
# https://github.com/simonw/datasette/issues/1423
with make_app_client(settings={"max_returned_rows": 100}) as client:
path = "/fixtures/sortable?_facet=content&_facet=pk1"
if use_facet_size_max:
path += "&_facet_size=max"
response = client.get(path)
assert response.status == 200
fragments = (
'<span class="facet-info-total">&gt;100</span>',
'<span class="facet-info-total">8</span>',
)
for fragment in fragments:
if use_facet_size_max:
assert fragment in response.text
else:
assert fragment not in response.text