Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/static/builder/command-builder.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions app/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,12 @@ button.seg:hover { filter: brightness(1.25); }
.st-search input { min-width: 0; width: 100%; padding: 0; border: 0; background: transparent; color: var(--text); font: 13px var(--sans); }
.st-search input:focus-visible { outline: none; }
.st-search:focus-within { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
/* the toolkit's one clear control; the browser's own is hidden */
.st-search [data-search]::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.st-search-clear { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; margin: -2px -4px -2px 0; padding: 0; border: 0; border-radius: 5px; background: transparent; color: var(--text-faint); cursor: pointer; }
.st-search-clear .ic { width: 14px; height: 14px; }
.st-search-clear:hover { color: var(--text); background: var(--surface); }
.st-search-clear:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.menu-wrap { position: relative; }
.btn.sm { font-size: .8rem; padding: .42rem .75rem; }
.menu {
Expand Down
15 changes: 10 additions & 5 deletions app/static/tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,22 @@ window.NulliusTable = {
/* A controls row's search box and filters (the controls macro), under
`tools`; each optional. Search keeps the rows (or cards) whose
data-search holds every word of the query, in any order and case;
Escape clears it. A column narrows when it does not show every value;
its clear button, shown while it holds text, or Escape empties it as
typing would and leaves the focus in it. A column narrows when it does not show every value;
the Filter button or a dropdown holding such a column is marked
.narrowed and counts: the Filter button the columns it narrows, a
dropdown the values chosen (after None, 0), or the one chosen by name. Clear filters clears every
column. `changed` runs after any of them. Returns passes(row). */
narrow(tools, changed) {
const [fbtn, fmenu] = [tools.querySelector('[data-tools-btn="filter"]'), tools.querySelector('[data-tools="filter"]')];
const q = tools.querySelector('[data-search]');
const q = tools.querySelector('[data-search]'), x = tools.querySelector('[data-search-clear]');
const shown = () => { if (x) x.hidden = !q.value; };
const clear = () => { q.value = ''; q.dispatchEvent(new Event('input', {bubbles: true})); q.focus(); };
if (q) {
q.addEventListener('input', changed);
q.addEventListener('keydown', e => { if (e.key === 'Escape' && q.value) { e.preventDefault(); q.value = ''; changed(); } });
q.addEventListener('input', () => { shown(); changed(); });
q.addEventListener('keydown', e => { if (e.key === 'Escape' && q.value) { e.preventDefault(); clear(); } });
x?.addEventListener('click', clear);
shown(); // a value the browser restored
}
const found = row => !q || this.matches(row.dataset.search, q.value);
const menus = [...(fmenu ? [[fbtn, fmenu, () => 1]] : []),
Expand All @@ -176,7 +181,7 @@ window.NulliusTable = {
count.textContent = sets.length === 1 ? n(sets[0]) : sets.length ? sets.reduce((sum, set) => sum + n(set), 0) : '';
count.hidden = !sets.length;
});
const narrowed = () => { mark(); changed(); };
const narrowed = () => { mark(); if (q) shown(); changed(); }; // a page that empties the box itself, then filters
const f = this.filters(tools, narrowed);
mark();
menus.forEach(([btn, menu]) => this.menu(btn, menu));
Expand Down
2 changes: 1 addition & 1 deletion app/templates/_tables.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
{% macro controls(id, cols, search='', columns=false, choices={}, only={}, views=none, actions=none, sort=true, layout=none, default='table') %}
{%- set by = {'button': [], 'dropdown': [], 'pills': []} %}{% for c in cols if c.key in choices %}{% for f in ([c.filter] if c.filter is string else c.filter or ['button']) %}{% set _ = by[f].append(c) %}{% endfor %}{% endfor %}
<div class="table-tools table-controls" id="{{ id }}-tools">
{% if search %}<label class="st-search"><svg class="ic" aria-hidden="true"><use href="#i-search"/></svg><input type="search" data-search placeholder="{{ search }}" aria-label="{{ search }}" autocomplete="off" spellcheck="false"></label>{% endif %}
{% if search %}<label class="st-search"><svg class="ic" aria-hidden="true"><use href="#i-search"/></svg><input type="search" data-search placeholder="{{ search }}" aria-label="{{ search }}" autocomplete="off" spellcheck="false"><button class="st-search-clear" type="button" data-search-clear aria-label="Clear search" hidden><svg class="ic" aria-hidden="true"><use href="#i-x"/></svg></button></label>{% endif %}
{% if columns or by.dropdown or by.button or sort or views or actions or layout %}<div class="table-buttons">
{{ slot('views', views) }}
{% if columns %}<div class="menu-wrap">{{ columns_button() }}{{ columns_menu(cols) }}</div>{% endif %}
Expand Down
7 changes: 7 additions & 0 deletions app/ui_tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ def get_ok(self, path, **kwargs):
self.assertEqual(response.status_code, 200, path)
return response

def test_the_toolkit_search_carries_its_clear_button_hidden(self):
for path in ("/runs", "/benchmarks", "/agents", "/kits", "/workspaces"):
with self.subTest(path=path):
html = self.get_ok(path).get_data(as_text=True)
self.assertIn('<button class="st-search-clear" type="button" data-search-clear aria-label="Clear search" hidden>'
'<svg class="ic" aria-hidden="true"><use href="#i-x"/></svg></button>', html)

def test_home_opens_runs_with_or_without_active_workspace(self):
for active in (self.active, None):
with self.subTest(active=bool(active)):
Expand Down
23 changes: 21 additions & 2 deletions app/ui_tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class El {
for (let e = this; e && !ev.stopped; e = e.parentNode) (e.on[type] || []).forEach(f => f(ev));
return ev;
}
dispatchEvent(ev) { return this.dispatch(ev.type); }
click() {
if (this.tagName === 'INPUT' && this.getAttribute('type') === 'checkbox') this.checked = !this.checked;
if (this.tagName === 'INPUT' && this.getAttribute('type') === 'radio') {
Expand Down Expand Up @@ -94,6 +95,7 @@ class El {
document.getElementById = id => document.querySelector(`[id="${id}"]`);
document.createElement = tag => new El(tag);
global.window = global;
global.Event = class { constructor(type) { this.type = type; } };
const on = {};
global.addEventListener = (t, f) => (on[t] ||= []).push(f);
global.scrollY = 0;
Expand Down Expand Up @@ -133,7 +135,7 @@ class El {
const radio = (k, v) => el('label', {}, el('input', {type: 'radio', name: `${id}-sort-${k}`, [`data-sort-${k}`]: '', value: v}), ' ' + v);
const button = !filter ? [] : typeof filter[0] === 'string' ? [filter] : filter;
const tools = el('div', {id: id + '-tools'},
...(search ? [el('label', {}, el('input', {type: 'search', 'data-search': ''}))] : []),
...(search ? [el('label', {}, el('input', {type: 'search', 'data-search': ''}), el('button', {type: 'button', 'data-search-clear': '', hidden: true}))] : []),
...dropdowns.map(c => dropdownOf(c, only)),
...(button.length ? [el('button', {'data-tools-btn': 'filter'}, 'Filter', el('span', {class: 'tools-count', hidden: true})),
el('div', {'data-tools': 'filter', hidden: true}, el('button', {'data-clear': ''}), ...button.map(c => fieldOf(c, only)))] : []),
Expand Down Expand Up @@ -220,6 +222,23 @@ def test_a_screen_reader_hears_a_change_once_typing_pauses(self):
self.assertNotIn('role="status"', html)


def test_the_clear_button_empties_the_box_as_typing_would(self):
got = node(LAUNCHES + r'''
const box = t.tools.querySelector('[data-search]'), x = t.tools.querySelector('[data-search-clear]');
let heard = 0; box.addEventListener('input', () => heard++); // a page's own listener
const out = {start: x.hidden};
t.type('gamma'); out.typed = [x.hidden, t.note()];
document.activeElement = null; x.click();
out.clicked = [box.value, t.note(), x.hidden, document.activeElement === box, heard];
t.type('delta'); document.activeElement = null; box.dispatch('keydown', {key: 'Escape'});
out.escaped = [box.value, t.note(), x.hidden, document.activeElement === box, heard];
process.stdout.write(JSON.stringify(out));
''')
self.assertEqual(got["start"], True) # hidden while empty
self.assertEqual(got["typed"], [False, "1–15 of 15"])
self.assertEqual(got["clicked"], ["", "1–25 of 30", True, True, 2]) # every row back, focus in the box
self.assertEqual(got["escaped"], ["", "1–25 of 30", True, True, 4])

# Thirty rows of a state and a kind; the kind in pills, a dropdown and the Filter menu, the state in the Filter menu.
FORMS = r'''
const kinds = ['a', 'b', 'c'];
Expand Down Expand Up @@ -458,7 +477,7 @@ def test_a_controls_row_places_its_slots_around_the_buttons(self):
f"{{% call(r, c) table('t', {cols}, [], none, search='Find', columns=true, choices={{'x': [('a', 'A')]}}, views=views, actions=actions) %}}{{% endcall %}}"):
with self.subTest(call=call[:12]):
html = self.slotted(call)
self.assertEqual(re.findall(r'data-search|data-slot="(\w+)"|data-tools-btn="(\w+)"|<button>(\w+)</button>', html),
self.assertEqual(re.findall(r'data-search(?!-)|data-slot="(\w+)"|data-tools-btn="(\w+)"|<button>(\w+)</button>', html),
[("", "", ""), ("views", "", ""), ("", "", "v1"), ("", "", "v2"), ("", "columns", ""), ("", "filter", ""),
("", "sort", ""), ("actions", "", ""), ("", "", "a1"), ("", "", "a2")])
self.assertEqual(html.count('class="table-slot"'), 2) # each slot one group, spaced as the buttons
Expand Down
Loading