web/src/components/table/table-view-presets/README.md
This module provides a flexible and robust way to manage and persist table states across sessions. Users can save, load, and share specific table configurations including column visibility, ordering, filters, and search queries.
Users can now:
The table view presets system is designed to gracefully handle changes to table structure:
Validation context is optional, and the system will apply table view presets even if validation parameters aren't provided, allowing for gradual adoption.
The system prioritizes keeping the application functional even when views are problematic:
When a view's state can't be fully applied:
If a user navigates to a permalink for a deleted view:
The permalink functionality allows users to share specific table configurations:
// Generate and copy permalink
generatePermalinkMutation.mutate({
viewId: view.id,
projectId,
tableName,
baseUrl: window.location.origin,
});
When a user visits a permalink:
viewId parameterweb/src/components/table/table-view-presets/
├── components/
│ ├── data-table-table-view-presets-drawer.tsx # Main UI component for table view presets
├── hooks/
│ ├── useTableViewManager.ts # Core hook for managing view state
│ ├── useViewData.ts # Hook for retrieving table view presets
│ └── useViewMutations.ts # Hook for mutation operations (create, update, delete)
Additional related files:
packages/shared/src/domain/table-view-presets.ts # Type definitions
packages/shared/src/server/services/TableViewService/ # Server-side handling
The implementation uses a combination of:
By focusing on robustness and graceful degradation, the table view presets feature provides a reliable experience even as tables evolve over time.
// 1. In your table component, set up the view manager
const {
isLoading: isViewLoading,
applyViewState,
handleSetViewId,
selectedViewId
} = useTableViewManager({
tableName: TableViewPresetTableName.Traces,
projectId,
stateUpdaters: {
setOrderBy,
setFilters,
setColumnOrder,
setColumnVisibility,
setSearchQuery,
},
validationContext: {
columns: columns,
filterColumnDefinition: filterColumnDefinition,
},
});
// 2. Pass the view configuration to the DataTableToolbar
<DataTableToolbar
viewConfig={{
tableName: TableViewPresetTableName.Traces,
projectId,
controllers: {
selectedViewId,
handleSetViewId,
applyViewState,
},
}}
// Other props...
/>
// 3. Add loading state to DataTable
<DataTable
data={
isLoading || isViewLoading
? { rows: [], rowCount: 0 }
: { rows: data, rowCount: totalCount }
}
// Other props...
/>