Files
supabase/apps/studio/components/ui/DataTable/DataTableResetButton.tsx
kemal.earth 53f2bb416d feat(studio): saved views in sidebar (#53630)
## Problem

Unified Logs had saved views behind a dropdown in the toolbar. The
dropdown couldn't show more than a name per row, had no room for
grouping, and gave new projects nothing to start from — an empty list
until you built and saved a filter combination yourself.

## Solution

Moved saved views into the filter sidebar as a second level, following
the Explorer notebooks/chats pattern: a Saved views button in the
sidebar header swaps the filters out for a Views panel, with a
breadcrumb back to Logs.

Key choices:

- **`FilterSideBar` stays generic.** It takes `section`, `headerAction`
and `onReset` slots; all saved-views specifics live in `LogsViewsPanel`.
- **Presets are virtual, not seeded.** Three built-in views (Errors,
Failed requests, Database health) render from a constant with `preset:`
ids. No per-project write, so they work for read-only members and can't
be deleted into oblivion. They can be duplicated into a real saved view,
but not renamed, edited or deleted.
- **One dialog for naming.** `ViewNameDialog` backs create, rename and
duplicate.
- **Clicking a modified view opens the update prompt** instead of
re-applying it, which previously discarded unsaved filter edits with no
warning.

Also fixed two pre-existing alignment issues in the sidebar: filter
options sat 4px left of their section heading, and the User filter — a
hand-copied clone of the filter row markup — had drifted from the shared
one.

## Review instructions

1. Enable the Unified Logs feature preview and the `logsSavedViews`
flag, then open **Logs**.
2. Click the layers button in the sidebar header. The filters swap for
the Views panel, with **Preset views** above **Saved views**.
3. Click **Errors**. The filter applies and the row highlights; the
layers icon turns green.
4. Change a filter. The row reads **Modified** and the update prompt
appears. Go back to Logs and return — the prompt is still available.
5. Open the ⋮ menu on a preset: only **Duplicate** is offered. Duplicate
it and confirm it lands under Saved views with rename/delete available.
6. Click **+** in the Views header to save the current filters, then
rename and delete it.
7. Hit the reset button in the header and confirm the active view clears
along with the
   filters.
2026-11-20 15:28:59 +00:00

42 lines
1.2 KiB
TypeScript

import { RotateCwIcon } from 'lucide-react'
import { Button } from 'ui'
import { useDataTable } from './providers/DataTableProvider'
import { ShortcutTooltip } from '@/components/ui/ShortcutTooltip'
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
import { useShortcut } from '@/state/shortcuts/useShortcut'
export interface DataTableResetButtonProps {
/** Called alongside `table.resetColumnFilters()` — for filters that live outside TanStack Table's columnFilters state (e.g. a cross-cutting URL param). */
onReset?: () => void
}
export function DataTableResetButton({ onReset }: DataTableResetButtonProps) {
const { table } = useDataTable()
const reset = () => {
table.resetColumnFilters()
onReset?.()
}
useShortcut(SHORTCUT_IDS.DATA_TABLE_RESET_FILTERS, reset, {
registerInCommandMenu: true,
})
return (
<ShortcutTooltip
shortcutId={SHORTCUT_IDS.DATA_TABLE_RESET_FILTERS}
label="Reset filters and views"
side="bottom"
>
<Button
size="tiny"
variant="outline"
className="size-7 shrink-0 px-0"
onClick={reset}
aria-label="Reset filters and views"
icon={<RotateCwIcon />}
/>
</ShortcutTooltip>
)
}