Filter from a value
A list already shows the values people want to filter by. Let them select one. Select shared in a row, and the field gets is:shared. Select it again, and the filter goes away. The field shows every filter that runs, so the person can read it and edit it like typed text.
How it works
toggleFacet from @ngrok/mantle/query-filter does the edit. It is a pure function of the grammar, the query, and one qualifier:
- When the query doesn't have the qualifier, it adds it at the end, quoted when the value needs quotes.
- When the query has it, it takes it out. Aliases count, so
is:personalmatchesis:private. - The opposite qualifier gives way:
-is:sharedbecomesis:shared. - An
ORorANDbeside a removed qualifier goes with it, so no operator dangles. - A comma list such as
is:shared,privatestays as written, because the person wrote it on purpose.
A few rules keep the table honest:
- Each value is a real
<button>witharia-pressed, so a screen reader hears whether the filter is on. - Pass a function to
setQuery, so two quick selections never lose an edit. - When no row matches,
queryUsesQualifierspicks the advice: a filtered query needs a filter removed, and a text query needs a spelling check.
Link to a filtered list
To filter a list on another page, build the link with formatFacet. It writes the canonical spelling and quotes a value that has spaces:
Read the param on the other page with the Query from the URL hook.