apps/studio/components/grid/hooks/README.md
The table filtering and sorting system uses a URL-based state persistence pattern combined with custom hooks that abstract the implementation details from consuming components. This architecture provides several benefits:
useTableFilter// Returns: { filters, urlFilters, onApplyFilters }
The useTableFilter hook manages filter state with these responsibilities:
saveFiltersAndTriggerSideEffectsKey design aspects:
useTableSort// Returns: { sorts, urlSorts, onApplySorts }
The useTableSort hook manages sort state with these responsibilities:
saveSortsAndTriggerSideEffectsKey design aspects:
These components follow a "draft and apply" pattern:
Components using these hooks should follow this pattern:
function TableComponent() {
// Get filter data and callbacks
const { filters, onApplyFilters } = useTableFilter()
// Get sort data and callbacks
const { sorts, onApplySorts } = useTableSort()
return (
<>
<FilterPopoverPrimitive filters={filters} onApplyFilters={onApplyFilters} />
<SortPopoverPrimitive sorts={sorts} onApplySorts={onApplySorts} />
</>
)
}
formatFilterURLParams, formatSortURLParams, etc.) handle translation between URL strings and typed objects