Make all table search live and only write the URL on close

Add a live filter override to useTableQueryState: setFilter updates the filter
immediately (so every table's search filters as you type) without touching the
URL, and commitFilter writes it to the URL when the filter dropdown closes.
useColumnSearch and useUserFilter now filter live via setFilter and commit on
close, so the Users table no longer rewrites the URL on every keystroke and the
other tables gain live search.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 4.8 committed 2026-07-02 00:14:32 +00:00
1 parent 1f2730a64f
commit bb4c82ea5a
10 files changed
+95 -31

No files matched your search

+27 -9
View File
@@ -3,34 +3,50 @@ import { Input, InputRef } from "antd";
import { SearchOutlined } from "@ant-design/icons";
import type { FilterDropdownProps } from "antd/es/table/interface";
import type { TableQueryState } from "./useTableQueryState";
/**
* Column props for a free-text search filter rendered in the column header
* dropdown (the same style as the Users table). Spread the result onto a
* column; the search value is persisted through the table's filter state by
* {@link useTableQueryState}.
* dropdown (the same style as the Users table). Spread the result onto a column
* whose `filteredValue` is `tableState.filteredValue(columnKey)`.
*
* Filtering is live: the table updates as you type via {@link TableQueryState.setFilter},
* and the value is only written to the URL when the dropdown closes (via
* {@link TableQueryState.commitFilter}).
*
* @param tableState The table's query state.
* @param columnKey Key of the column this search filters (matches its filteredValue key).
* @param getText Returns the searchable text for a row.
* @param placeholder Placeholder shown in the search box.
*/
export default function useColumnSearch<T>(getText: (record: T) => string, placeholder = "Search") {
export default function useColumnSearch<T>(
tableState: TableQueryState<T>,
columnKey: string,
getText: (record: T) => string,
placeholder = "Search",
) {
const searchInput = useRef<InputRef>(null);
return {
filterIcon: (filtered: boolean) => (
<SearchOutlined style={{ color: filtered ? "#1677ff" : undefined }} />
),
filterDropdown: ({ selectedKeys, setSelectedKeys, confirm, clearFilters }: FilterDropdownProps) => (
filterDropdown: ({ selectedKeys, setSelectedKeys, close }: FilterDropdownProps) => (
<div style={{ padding: 8, width: 240 }} onKeyDown={e => e.stopPropagation()}>
<Input.Search
ref={searchInput}
placeholder={placeholder}
value={selectedKeys[0] as string | undefined}
allowClear
onChange={e => setSelectedKeys(e.target.value ? [e.target.value] : [])}
onSearch={() => confirm({ closeDropdown: true })}
onChange={e => {
const values = e.target.value ? [e.target.value] : [];
setSelectedKeys(values);
tableState.setFilter(columnKey, values.length ? values : null);
}}
onSearch={() => close()}
onClear={() => {
clearFilters?.({ closeDropdown: false });
confirm({ closeDropdown: true });
setSelectedKeys([]);
tableState.setFilter(columnKey, null);
}}
/>
</div>
@@ -39,6 +55,8 @@ export default function useColumnSearch<T>(getText: (record: T) => string, place
onOpenChange: (open: boolean) => {
if (open) {
setTimeout(() => searchInput.current?.select(), 100);
} else {
tableState.commitFilter(columnKey);
}
},
},