@@ -15,8 +15,9 @@ import {
1515} from '@sim/emcn'
1616import { Check, Pencil, Plus, Trash } from '@sim/emcn/icons'
1717import type { TableViewWire } from '@/lib/api/contracts/tables'
18+ import { resolveTableViewSelection } from '@/app/workspace/[workspaceId]/tables/[tableId]/view-state'
1819
19- /** Label for the built-in unfiltered state. Not a stored row — `null` view id . */
20+ /** Legacy label for tables that do not yet have a persisted default view. */
2021export const ALL_ROWS_VIEW_LABEL = 'All'
2122
2223/** Matches the breadcrumb location popover's hover-intent grace period. */
@@ -29,7 +30,7 @@ const VIEW_ACTION_SLOT_PX = 22
2930
3031interface ViewsMenuProps {
3132 views: TableViewWire[]
32- /** `null` selects the built-in "All" state. */
33+ /** `null` selects the legacy "All" state while a table awaits backfill . */
3334 activeViewId: string | null
3435 onSelect: (viewId: string | null) => void
3536 onRename: (viewId: string) => void
@@ -41,8 +42,8 @@ interface ViewsMenuProps {
4142}
4243
4344/**
44- * View switcher for the table options bar. Reads "View" until one is selected,
45- * then carries the active view's name .
45+ * View switcher for the table options bar. Carries the active view's name, or
46+ * resolves an absent selection to the persisted default while the URL catches up .
4647 *
4748 * Opens on hover-intent like the header's breadcrumb location popover, so the
4849 * list of views is discoverable without a click.
@@ -59,8 +60,9 @@ export const ViewsMenu = memo(function ViewsMenu({
5960 const [open, setOpen] = useState(false)
6061 const closeTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
6162
62- const activeView = activeViewId ? views.find((view) => view.id === activeViewId) : undefined
63- const label = activeView?.name ?? 'View'
63+ const { activeView, defaultView } = resolveTableViewSelection(views, activeViewId)
64+ const hasDefaultView = defaultView !== null
65+ const label = activeView?.name ?? ALL_ROWS_VIEW_LABEL
6466
6567 const cancelScheduledClose = () => {
6668 if (closeTimeoutRef.current) {
@@ -132,11 +134,13 @@ export const ViewsMenu = memo(function ViewsMenu({
132134 Views
133135 </PopoverSection>
134136 <div className='flex flex-col gap-0.5'>
135- <ViewRow
136- label={ALL_ROWS_VIEW_LABEL}
137- isActive={activeViewId === null}
138- onSelect={() => runAndClose(() => onSelect(null))}
139- />
137+ {!hasDefaultView && (
138+ <ViewRow
139+ label={ALL_ROWS_VIEW_LABEL}
140+ isActive={activeViewId === null}
141+ onSelect={() => runAndClose(() => onSelect(null))}
142+ />
143+ )}
140144 {views.map((view) => (
141145 <ViewRow
142146 key={view.id}
0 commit comments