diff --git a/apps/sim/app/workspace/[workspaceId]/components/resource/components/resource-options/resource-options.test.tsx b/apps/sim/app/workspace/[workspaceId]/components/resource/components/resource-options/resource-options.test.tsx index 7a8e6682153..db10cad80a4 100644 --- a/apps/sim/app/workspace/[workspaceId]/components/resource/components/resource-options/resource-options.test.tsx +++ b/apps/sim/app/workspace/[workspaceId]/components/resource/components/resource-options/resource-options.test.tsx @@ -67,4 +67,60 @@ describe('SortDropdown', () => { expect(item?.querySelector('[data-testid="column-icon"]')).not.toBeNull() expect(item?.querySelectorAll('svg')).toHaveLength(2) }) + + it('keeps the popup open while changing or clearing the sort', () => { + const onOpenChange = vi.fn() + const onSort = vi.fn() + const onClear = vi.fn() + act(() => { + root.render( + + ) + }) + + const items = document.body.querySelectorAll('[role="menuitem"]') + expect(items).toHaveLength(2) + + act(() => items[1]?.click()) + expect(onSort).toHaveBeenCalledWith('name', 'desc') + + act(() => items[0]?.click()) + expect(onClear).toHaveBeenCalledOnce() + expect(onOpenChange).not.toHaveBeenCalledWith(false) + expect(document.body.querySelectorAll('[role="menuitem"]')).toHaveLength(2) + }) + + it('keeps the legacy close-on-select behavior by default', () => { + const onOpenChange = vi.fn() + const onSort = vi.fn() + act(() => { + root.render( + + ) + }) + + const item = document.body.querySelector('[role="menuitem"]') + act(() => item?.click()) + + expect(onSort).toHaveBeenCalledWith('name', 'desc') + expect(onOpenChange).toHaveBeenCalledWith(false) + }) }) diff --git a/apps/sim/app/workspace/[workspaceId]/components/resource/components/resource-options/resource-options.tsx b/apps/sim/app/workspace/[workspaceId]/components/resource/components/resource-options/resource-options.tsx index e8dc0876874..6f30372b129 100644 --- a/apps/sim/app/workspace/[workspaceId]/components/resource/components/resource-options/resource-options.tsx +++ b/apps/sim/app/workspace/[workspaceId]/components/resource/components/resource-options/resource-options.tsx @@ -48,6 +48,7 @@ export interface SortConfig { active: { column: string; direction: SortDirection } | null onSort: (column: string, direction: SortDirection) => void onClear?: () => void + keepOpenOnSelect?: boolean } export interface FilterTag { @@ -283,7 +284,7 @@ export const SortDropdown = memo(function SortDropdown({ open, onOpenChange, }: SortDropdownProps) { - const { options, active, onSort, onClear } = config + const { options, active, onSort, onClear, keepOpenOnSelect = false } = config return ( @@ -299,7 +300,12 @@ export const SortDropdown = memo(function SortDropdown({ > {active && onClear && ( <> - + { + if (keepOpenOnSelect) event.preventDefault() + onClear() + }} + > Clear sort @@ -314,7 +320,8 @@ export const SortDropdown = memo(function SortDropdown({ return ( { + onSelect={(event) => { + if (keepOpenOnSelect) event.preventDefault() if (isActive) { onSort(option.id, active.direction === 'asc' ? 'desc' : 'asc') } else { diff --git a/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/columns-menu/columns-menu.test.tsx b/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/columns-menu/columns-menu.test.tsx new file mode 100644 index 00000000000..3c812909631 --- /dev/null +++ b/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/columns-menu/columns-menu.test.tsx @@ -0,0 +1,69 @@ +/** + * @vitest-environment jsdom + */ +import { act, useState } from 'react' +import { createRoot, type Root } from 'react-dom/client' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { ColumnsMenu } from '@/app/workspace/[workspaceId]/tables/[tableId]/components/columns-menu/columns-menu' + +let container: HTMLDivElement +let root: Root + +function ColumnsMenuHarness({ onChange }: { onChange: (hiddenColumns: string[]) => void }) { + const [hiddenColumns, setHiddenColumns] = useState([]) + + return ( + { + setHiddenColumns(nextHiddenColumns) + onChange(nextHiddenColumns) + }} + /> + ) +} + +beforeEach(() => { + globalThis.IS_REACT_ACT_ENVIRONMENT = true + container = document.createElement('div') + document.body.appendChild(container) + root = createRoot(container) +}) + +afterEach(() => { + act(() => root.unmount()) + container.remove() +}) + +describe('ColumnsMenu', () => { + it('uses the app menu styling and stays open across column changes', () => { + const onChange = vi.fn() + act(() => { + root.render() + }) + act(() => { + container + .querySelector('button') + ?.dispatchEvent(new MouseEvent('pointerdown', { bubbles: true, button: 0 })) + }) + + const items = document.body.querySelectorAll('[role="menuitem"]') + expect(items).toHaveLength(3) + expect(items[0]).toHaveClass('text-small') + expect(items[0]?.querySelector('svg')).toHaveClass('size-[14px]') + + act(() => items[0]?.click()) + expect(onChange).toHaveBeenCalledWith(['col-name']) + + const remainingItems = document.body.querySelectorAll('[role="menuitem"]') + expect(remainingItems).toHaveLength(3) + act(() => remainingItems[1]?.click()) + expect(onChange).toHaveBeenLastCalledWith(['col-name', 'col-email']) + }) +}) diff --git a/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/columns-menu/columns-menu.tsx b/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/columns-menu/columns-menu.tsx index 0409ee2cf6a..a7bbb0f9f95 100644 --- a/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/columns-menu/columns-menu.tsx +++ b/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/columns-menu/columns-menu.tsx @@ -4,12 +4,10 @@ import { memo, useMemo, useState } from 'react' import { Chip, cn, - POPOVER_ANIMATION_CLASSES, - Popover, - PopoverContent, - PopoverItem, - PopoverSection, - PopoverTrigger, + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, } from '@sim/emcn' import { Columns3, Eye, EyeOff } from '@sim/emcn/icons' import type { ColumnDefinition, WorkflowGroup } from '@/lib/table' @@ -78,30 +76,18 @@ export const ColumnsMenu = memo(function ColumnsMenu({ const hiddenCount = hiddenColumns.length return ( - - + + {/* `active` alone signals that something is hidden — the label stays fixed so the bar doesn't reflow as columns are toggled. */} 0} leftIcon={Columns3}> Columns - - + - - Columns -
{plain.map((col) => { const id = getColumnId(col) @@ -144,8 +130,8 @@ export const ColumnsMenu = memo(function ColumnsMenu({ ) })}
-
-
+ +
) }) @@ -164,14 +150,17 @@ function ColumnToggleRow({ label, visible, partial, indented, onToggle }: Column const showing = visible || partial const Icon = showing ? Eye : EyeOff return ( - onToggle(!visible)} - className={cn('h-7 items-center gap-1.5 px-1.5 py-0 text-xs', indented && 'pl-5')} + { + event.preventDefault() + onToggle(!visible) + }} + className={cn(indented && 'pl-7')} > {label} - + ) } diff --git a/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-filter/table-filter.test.tsx b/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-filter/table-filter.test.tsx new file mode 100644 index 00000000000..e14dc0ef75e --- /dev/null +++ b/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-filter/table-filter.test.tsx @@ -0,0 +1,333 @@ +/** + * @vitest-environment jsdom + */ +import { act } from 'react' +import { createRoot, type Root } from 'react-dom/client' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import type { ColumnDefinition, TablePredicate } from '@/lib/table' +import { TableFilter } from '@/app/workspace/[workspaceId]/tables/[tableId]/components/table-filter/table-filter' + +const COLUMNS: ColumnDefinition[] = [{ id: 'col-name', name: 'Name', type: 'string' }] + +let container: HTMLDivElement +let root: Root + +beforeEach(() => { + globalThis.IS_REACT_ACT_ENVIRONMENT = true + container = document.createElement('div') + document.body.appendChild(container) + root = createRoot(container) +}) + +afterEach(() => { + act(() => root.unmount()) + container.remove() +}) + +function renderFilter( + onChange: (filter: TablePredicate | null) => void, + filter: TablePredicate | null = null, + autoApply = true, + onClose: () => void = vi.fn() +) { + act(() => { + root.render( + + ) + }) +} + +function valueInput(): HTMLInputElement | null { + return container.querySelector('input[placeholder="Enter a value"]') +} + +function typeInto(input: HTMLInputElement | null, value: string) { + if (!input) return + Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set?.call(input, value) + input.dispatchEvent(new Event('input', { bubbles: true })) +} + +describe('TableFilter', () => { + it('commits a typed value on blur, not per keystroke', () => { + const onChange = vi.fn() + renderFilter(onChange) + const input = valueInput() + expect(input).not.toBeNull() + + act(() => typeInto(input, 'Ada')) + expect(onChange).not.toHaveBeenCalled() + + act(() => input?.dispatchEvent(new FocusEvent('focusout', { bubbles: true }))) + expect(onChange).toHaveBeenCalledTimes(1) + expect(onChange).toHaveBeenCalledWith({ + all: [{ field: 'col-name', op: 'eq', value: 'Ada' }], + }) + }) + + it('commits a typed value on Enter', () => { + const onChange = vi.fn() + renderFilter(onChange) + const input = valueInput() + + act(() => typeInto(input, 'Grace')) + act(() => input?.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }))) + + expect(onChange).toHaveBeenCalledTimes(1) + expect(onChange).toHaveBeenCalledWith({ + all: [{ field: 'col-name', op: 'eq', value: 'Grace' }], + }) + }) + + it('does not re-commit an unchanged value on blur after Enter', () => { + const onChange = vi.fn() + renderFilter(onChange) + const input = valueInput() + + act(() => typeInto(input, 'Ada')) + act(() => input?.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }))) + act(() => input?.dispatchEvent(new FocusEvent('focusout', { bubbles: true }))) + + expect(onChange).toHaveBeenCalledTimes(1) + }) + + it('offers a toggleable conjunction without apply or clear actions', () => { + renderFilter(vi.fn()) + const addFilter = Array.from(container.querySelectorAll('button')).find((button) => + button.textContent?.includes('Add filter') + ) + + act(() => addFilter?.click()) + + const conjunction = Array.from(container.querySelectorAll('button')).find( + (button) => button.textContent?.trim() === 'and' + ) + expect(conjunction).toBeDefined() + + act(() => conjunction?.click()) + expect(conjunction?.textContent?.trim()).toBe('or') + + expect(container.textContent).not.toContain('Apply filter') + expect(container.textContent).not.toContain('Clear filters') + }) + + it('keeps the legacy Apply flow while automatic view saves are disabled', () => { + const onChange = vi.fn() + renderFilter(onChange, null, false) + const input = valueInput() + + act(() => typeInto(input, 'Ada')) + act(() => input?.dispatchEvent(new FocusEvent('focusout', { bubbles: true }))) + + expect(onChange).not.toHaveBeenCalled() + const applyButton = Array.from(container.querySelectorAll('button')).find( + (button) => button.textContent?.trim() === 'Apply filter' + ) + act(() => applyButton?.click()) + + expect(onChange).toHaveBeenCalledWith({ + all: [{ field: 'col-name', op: 'eq', value: 'Ada' }], + }) + }) + + it('clears the active filter as soon as its last rule is removed', () => { + const onChange = vi.fn() + renderFilter(onChange, { + all: [{ field: 'col-name', op: 'eq', value: 'Ada' }], + }) + + const removeButton = container.querySelector( + 'button[aria-label="Remove filter"]' + ) + act(() => removeButton?.click()) + + expect(onChange).toHaveBeenCalledWith(null) + expect(valueInput()?.value).toBe('') + }) + + it('preserves saved isNull conditions instead of dropping them', () => { + const onChange = vi.fn() + renderFilter(onChange, { all: [{ field: 'col-name', op: 'isNull' }] }) + + expect(onChange).not.toHaveBeenCalled() + }) + + it('keeps a saved valueless filter until its replacement value is committed', () => { + const onChange = vi.fn() + renderFilter(onChange, { all: [{ field: 'col-name', op: 'isEmpty' }] }) + + const operatorTrigger = Array.from(container.querySelectorAll('button')).find( + (button) => button.textContent?.trim() === 'is empty' + ) + act(() => { + operatorTrigger?.dispatchEvent(new MouseEvent('pointerdown', { bubbles: true, button: 0 })) + }) + const equalsOption = Array.from( + document.querySelectorAll('[role="menuitem"]') + ).find((item) => item.textContent?.trim() === 'equals') + act(() => equalsOption?.click()) + + expect(valueInput()).not.toBeNull() + expect(onChange).not.toHaveBeenCalled() + + act(() => typeInto(valueInput(), 'Ada')) + act(() => valueInput()?.dispatchEvent(new FocusEvent('focusout', { bubbles: true }))) + + expect(onChange).toHaveBeenCalledTimes(1) + expect(onChange).toHaveBeenCalledWith({ + all: [{ field: 'col-name', op: 'eq', value: 'Ada' }], + }) + }) + + it('keeps a deferred condition applied while another rule is removed', () => { + const onChange = vi.fn() + renderFilter(onChange, { + any: [ + { all: [{ field: 'col-name', op: 'eq', value: 'Ada' }] }, + { + all: [ + { field: 'col-name', op: 'isEmpty' }, + { field: 'col-name', op: 'eq', value: 'Linus' }, + ], + }, + ], + }) + + const operatorTrigger = Array.from(container.querySelectorAll('button')).find( + (button) => button.textContent?.trim() === 'is empty' + ) + act(() => { + operatorTrigger?.dispatchEvent(new MouseEvent('pointerdown', { bubbles: true, button: 0 })) + }) + const equalsOption = Array.from( + document.querySelectorAll('[role="menuitem"]') + ).find((item) => item.textContent?.trim() === 'equals') + act(() => equalsOption?.click()) + + expect(onChange).not.toHaveBeenCalled() + + const removeButtons = container.querySelectorAll( + 'button[aria-label="Remove filter"]' + ) + act(() => removeButtons[2]?.click()) + + expect(onChange).toHaveBeenCalledWith({ + any: [ + { all: [{ field: 'col-name', op: 'eq', value: 'Ada' }] }, + { all: [{ field: 'col-name', op: 'isEmpty' }] }, + ], + }) + }) + + it('loads a saved OR filter verbatim without an unsolicited autosave', () => { + const onChange = vi.fn() + renderFilter(onChange, { + any: [ + { all: [{ field: 'col-name', op: 'eq', value: 'Ada' }] }, + { all: [{ field: 'col-name', op: 'eq', value: 'Grace' }] }, + ], + }) + + const orToggle = Array.from(container.querySelectorAll('button')).find( + (button) => button.textContent?.trim() === 'or' + ) + expect(orToggle).toBeDefined() + expect(onChange).not.toHaveBeenCalled() + }) + + it('does not autosave when columns refresh without a user edit', () => { + const onChange = vi.fn() + act(() => { + root.render() + }) + act(() => { + root.render( + + ) + }) + + expect(onChange).not.toHaveBeenCalled() + }) + + it('merges the OR groups as soon as the conjunction is toggled back to and', () => { + const onChange = vi.fn() + renderFilter(onChange, { + any: [ + { all: [{ field: 'col-name', op: 'eq', value: 'Ada' }] }, + { all: [{ field: 'col-name', op: 'eq', value: 'Grace' }] }, + ], + }) + + const orToggle = Array.from(container.querySelectorAll('button')).find( + (button) => button.textContent?.trim() === 'or' + ) + act(() => orToggle?.click()) + + expect(onChange).toHaveBeenCalledWith({ + all: [ + { field: 'col-name', op: 'eq', value: 'Ada' }, + { field: 'col-name', op: 'eq', value: 'Grace' }, + ], + }) + }) + + it('preserves an OR boundary when its first rule is cleared', () => { + const onChange = vi.fn() + renderFilter(onChange, { + any: [ + { all: [{ field: 'col-name', op: 'eq', value: 'Ada' }] }, + { + all: [ + { field: 'col-name', op: 'eq', value: 'Grace' }, + { field: 'col-name', op: 'eq', value: 'Linus' }, + ], + }, + ], + }) + + const inputs = container.querySelectorAll( + 'input[placeholder="Enter a value"]' + ) + act(() => typeInto(inputs[1], '')) + act(() => inputs[1]?.dispatchEvent(new FocusEvent('focusout', { bubbles: true }))) + + expect(onChange).toHaveBeenCalledWith({ + any: [ + { all: [{ field: 'col-name', op: 'eq', value: 'Ada' }] }, + { all: [{ field: 'col-name', op: 'eq', value: 'Linus' }] }, + ], + }) + }) + + it('preserves an OR boundary when its first rule is removed', () => { + const onChange = vi.fn() + renderFilter(onChange, { + any: [ + { all: [{ field: 'col-name', op: 'eq', value: 'Ada' }] }, + { + all: [ + { field: 'col-name', op: 'eq', value: 'Grace' }, + { field: 'col-name', op: 'eq', value: 'Linus' }, + ], + }, + ], + }) + + const removeButtons = container.querySelectorAll( + 'button[aria-label="Remove filter"]' + ) + act(() => removeButtons[1]?.click()) + + expect(onChange).toHaveBeenCalledWith({ + any: [ + { all: [{ field: 'col-name', op: 'eq', value: 'Ada' }] }, + { all: [{ field: 'col-name', op: 'eq', value: 'Linus' }] }, + ], + }) + }) +}) diff --git a/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-filter/table-filter.tsx b/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-filter/table-filter.tsx index 7ce7cc200f3..3f7430c6e7c 100644 --- a/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-filter/table-filter.tsx +++ b/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-filter/table-filter.tsx @@ -1,7 +1,7 @@ 'use client' import { memo, useCallback, useMemo, useRef, useState } from 'react' -import { Button, ChipDropdown, ChipInput } from '@sim/emcn' +import { Button, ChipDropdown, ChipInput, cn } from '@sim/emcn' import { Plus, X } from '@sim/emcn/icons' import { generateShortId } from '@sim/utils/id' import type { ColumnDefinition, FilterRule, TablePredicate } from '@/lib/table' @@ -10,11 +10,11 @@ import { COMPARISON_OPERATORS, MULTI_SELECT_FILTER_OPERATORS, SINGLE_SELECT_FILTER_OPERATORS, - VALUELESS_OPERATORS, } from '@/lib/table/query-builder/constants' import { filterRulesToPredicate, predicateToFilterRules, + VALUELESS_OPS, } from '@/lib/table/query-builder/converters' const SINGLE_SELECT_COMPARISON_OPERATORS = COMPARISON_OPERATORS.filter((o) => @@ -28,21 +28,94 @@ function selectFilterOperators(column: ColumnDefinition | undefined): Set (isCompleteRule(rule) ? rule : { ...rule, column: '' })) + : rules.filter(isCompleteRule) + return filterRulesToPredicate(validRules, columns) +} + +function isCompleteRule(rule: FilterRule): boolean { + return Boolean(rule.column && (rule.value || VALUELESS_OPS.has(rule.operator))) +} + interface TableFilterProps { columns: ColumnDefinition[] filter: TablePredicate | null - onApply: (filter: TablePredicate | null) => void - onClose: () => void + autoApply?: boolean + onChange: (filter: TablePredicate | null) => void + onClose?: () => void } -export function TableFilter({ columns, filter, onApply, onClose }: TableFilterProps) { +export function TableFilter({ + columns, + filter, + autoApply = false, + onChange, + onClose, +}: TableFilterProps) { + const lastAppliedFilterRef = useRef(undefined) + const deferredAppliedRulesRef = useRef>(new Map()) const [rules, setRules] = useState(() => { const fromFilter = predicateToFilterRules(filter) return fromFilter.length > 0 ? fromFilter : [createRule(columns)] }) - const rulesRef = useRef(rules) rulesRef.current = rules + // Seed the "already applied" signature from the rules the panel actually + // renders, not the raw prop: a saved tree the flat builder cannot express + // (deeply nested groups, wire key order) round-trips differently, and seeding + // from the prop would fire an unedited autosave of that lossy form the + // moment the panel opens. The normalized form persists only once the user + // really edits a rule. + lastAppliedFilterRef.current ??= JSON.stringify(toAppliedPredicate(rules, columns)) + + const applyRules = useCallback( + (update: (current: FilterRule[]) => FilterRule[], deferIncompleteRuleId?: string) => { + const currentRules = rulesRef.current + const nextRules = update(currentRules) + rulesRef.current = nextRules + setRules(nextRules) + if (!autoApply) return + + const deferredRule = nextRules.find((rule) => rule.id === deferIncompleteRuleId) + if (deferredRule && !isCompleteRule(deferredRule)) { + const previouslyAppliedRule = currentRules.find((rule) => rule.id === deferredRule.id) + if (previouslyAppliedRule && isCompleteRule(previouslyAppliedRule)) { + const deferredRules = deferredAppliedRulesRef.current + if (!deferredRules.has(deferredRule.id)) { + deferredRules.set(deferredRule.id, previouslyAppliedRule) + } + } + } + + const nextRulesById = new Map(nextRules.map((rule) => [rule.id, rule])) + for (const [id] of deferredAppliedRulesRef.current) { + const nextRule = nextRulesById.get(id) + if (!nextRule || isCompleteRule(nextRule)) { + deferredAppliedRulesRef.current.delete(id) + } + } + + const appliedRules = nextRules.map((rule) => { + const deferredRule = deferredAppliedRulesRef.current.get(rule.id) + return deferredRule && !isCompleteRule(rule) + ? { ...deferredRule, logicalOperator: rule.logicalOperator } + : rule + }) + + const nextFilter = toAppliedPredicate(appliedRules, columns, true) + const signature = JSON.stringify(nextFilter) + if (signature === lastAppliedFilterRef.current) return + lastAppliedFilterRef.current = signature + onChange(nextFilter) + }, + [autoApply, columns, onChange] + ) // `value` is the filter field key (column id); `label` is what the user sees. const columnOptions = useMemo( @@ -56,26 +129,60 @@ export function TableFilter({ columns, filter, onApply, onClose }: TableFilterPr ) const handleAdd = useCallback(() => { - setRules((prev) => [...prev, createRule(columns)]) - }, [columns]) + applyRules((current) => [...current, createRule(columns)]) + }, [applyRules, columns]) const handleRemove = useCallback( (id: string) => { - const next = rulesRef.current.filter((r) => r.id !== id) - if (next.length === 0) { - onApply(null) - onClose() - setRules([createRule(columns)]) - } else { - setRules(next) + if (!autoApply) { + const nextRules = rulesRef.current.filter((rule) => rule.id !== id) + if (nextRules.length > 0) { + rulesRef.current = nextRules + setRules(nextRules) + return + } + const resetRules = [createRule(columns)] + rulesRef.current = resetRules + setRules(resetRules) + onChange(null) + onClose?.() + return } + applyRules((current) => { + const removedIndex = current.findIndex((rule) => rule.id === id) + const removedRule = current[removedIndex] + const next = current.filter((rule) => rule.id !== id) + if (removedRule?.logicalOperator === 'or' && removedIndex < next.length) { + next[removedIndex] = { ...next[removedIndex], logicalOperator: 'or' } + } + return next.length > 0 ? next : [createRule(columns)] + }) + }, + [applyRules, autoApply, columns, onChange, onClose] + ) + + const handleUpdate = useCallback( + (id: string, field: keyof FilterRule, value: string) => { + applyRules( + (current) => current.map((rule) => (rule.id === id ? { ...rule, [field]: value } : rule)), + field === 'operator' ? id : undefined + ) }, - [columns, onApply, onClose] + [applyRules] ) - const handleUpdate = useCallback((id: string, field: keyof FilterRule, value: string) => { - setRules((prev) => prev.map((r) => (r.id === id ? { ...r, [field]: value } : r))) - }, []) + const handleToggleLogical = useCallback( + (id: string) => { + applyRules((current) => + current.map((rule) => + rule.id === id + ? { ...rule, logicalOperator: rule.logicalOperator === 'and' ? 'or' : 'and' } + : rule + ) + ) + }, + [applyRules] + ) // Switching a rule's column across the select boundary changes what values and // operators are valid, so clear the value and coerce an unsupported operator @@ -83,45 +190,38 @@ export function TableFilter({ columns, filter, onApply, onClose }: TableFilterPr // apply against a select column and be rejected server-side. const handleColumnChange = useCallback( (id: string, columnId: string) => { - setRules((prev) => - prev.map((r) => { - if (r.id !== id) return r - const previous = columnById.get(r.column) - const next = columnById.get(columnId) - const wasSelect = previous?.type === 'select' - const isSelect = next?.type === 'select' - if (!wasSelect && !isSelect) return { ...r, column: columnId } - // Single- and multi-select take different operators, so a switch - // between them has to fall back too, not just select ↔ non-select. - const allowed = selectFilterOperators(next) - const fallback = next?.multiple ? 'contains' : 'eq' - const operator = isSelect && !allowed.has(r.operator) ? fallback : r.operator - return { ...r, column: columnId, operator, value: '' } - }) + applyRules( + (current) => + current.map((rule) => { + if (rule.id !== id) return rule + const previous = columnById.get(rule.column) + const next = columnById.get(columnId) + const wasSelect = previous?.type === 'select' + const isSelect = next?.type === 'select' + if (!wasSelect && !isSelect) return { ...rule, column: columnId } + // Single- and multi-select take different operators, so a switch + // between them has to fall back too, not just select ↔ non-select. + const allowed = selectFilterOperators(next) + const fallback = next?.multiple ? 'contains' : 'eq' + const operator = isSelect && !allowed.has(rule.operator) ? fallback : rule.operator + return { ...rule, column: columnId, operator, value: '' } + }), + id ) }, - [columnById] + [applyRules, columnById] ) - const handleToggleLogical = useCallback((id: string) => { - setRules((prev) => - prev.map((r) => - r.id === id ? { ...r, logicalOperator: r.logicalOperator === 'and' ? 'or' : 'and' } : r - ) - ) - }, []) - const handleApply = useCallback(() => { - const validRules = rulesRef.current.filter( - (r) => r.column && (r.value || VALUELESS_OPERATORS.has(r.operator)) - ) - onApply(filterRulesToPredicate(validRules, columns)) - }, [columns, onApply]) + onChange(toAppliedPredicate(rulesRef.current, columns)) + }, [columns, onChange]) - const handleClear = useCallback(() => { - setRules([createRule(columns)]) - onApply(null) - }, [columns, onApply]) + const handleClear = () => { + const resetRules = [createRule(columns)] + rulesRef.current = resetRules + setRules(resetRules) + onChange(null) + } return (
@@ -136,12 +236,13 @@ export function TableFilter({ columns, filter, onApply, onClose }: TableFilterPr onUpdate={handleUpdate} onColumnChange={handleColumnChange} onRemove={handleRemove} + autoApply={autoApply} onApply={handleApply} onToggleLogical={handleToggleLogical} /> ))} -
+
-
- {filter !== null && ( - + )} + - )} - -
+
+ )}
@@ -180,6 +283,7 @@ interface FilterRuleRowProps { onUpdate: (id: string, field: keyof FilterRule, value: string) => void onColumnChange: (id: string, columnId: string) => void onRemove: (id: string) => void + autoApply: boolean onApply: () => void onToggleLogical: (id: string) => void } @@ -192,6 +296,7 @@ const FilterRuleRow = memo(function FilterRuleRow({ onUpdate, onColumnChange, onRemove, + autoApply, onApply, onToggleLogical, }: FilterRuleRowProps) { @@ -254,7 +359,7 @@ const FilterRuleRow = memo(function FilterRuleRow({ className='min-w-[90px]' /> - {VALUELESS_OPERATORS.has(rule.operator) ? ( + {VALUELESS_OPS.has(rule.operator) ? (
) : isSelect ? ( + ) : autoApply ? ( + onUpdate(rule.id, 'value', value)} + /> ) : ( onUpdate(rule.id, 'value', e.target.value)} - onKeyDown={(e) => { - if (e.key === 'Enter') onApply() + onChange={(event) => onUpdate(rule.id, 'value', event.target.value)} + onKeyDown={(event) => { + if (event.key === 'Enter') onApply() }} placeholder='Enter a value' className='flex-1' @@ -291,6 +401,43 @@ const FilterRuleRow = memo(function FilterRuleRow({ ) }) +interface FilterValueInputProps { + value: string + onCommit: (value: string) => void +} + +/** + * Locally buffered value field: keystrokes stay in the field until Enter or + * blur commits them — the spreadsheet-cell contract. Every click-driven exit + * from the panel (closing it, switching views, navigating away) blurs the + * field first, so finishing-by-leaving commits without any imperative + * coordination. An external reseed (column switch clearing the value, a view + * replacement remount) adopts the incoming value over the draft. + */ +function FilterValueInput({ value, onCommit }: FilterValueInputProps) { + const [draft, setDraft] = useState(value) + const [prevValue, setPrevValue] = useState(value) + if (prevValue !== value) { + setPrevValue(value) + setDraft(value) + } + + return ( + setDraft(e.target.value)} + onBlur={() => { + if (draft !== value) onCommit(draft) + }} + onKeyDown={(e) => { + if (e.key === 'Enter' && draft !== value) onCommit(draft) + }} + placeholder='Enter a value' + className='flex-1' + /> + ) +} + function createRule(columns: ColumnDefinition[]): FilterRule { const first = columns[0] return { diff --git a/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/views-menu/views-menu.test.tsx b/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/views-menu/views-menu.test.tsx index fc9507426b5..c993a467e14 100644 --- a/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/views-menu/views-menu.test.tsx +++ b/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/views-menu/views-menu.test.tsx @@ -4,7 +4,7 @@ import { act } from 'react' import { createRoot } from 'react-dom/client' import { renderToStaticMarkup } from 'react-dom/server' -import { describe, expect, it, vi } from 'vitest' +import { afterEach, describe, expect, it, vi } from 'vitest' import type { TableViewWire } from '@/lib/api/contracts/tables' import { ViewsMenu } from '@/app/workspace/[workspaceId]/tables/[tableId]/components/views-menu/views-menu' @@ -19,13 +19,22 @@ const DEFAULT_VIEW: TableViewWire = { updatedAt: new Date('2026-08-15T01:00:00.000Z'), } -const SAVED_VIEW: TableViewWire = { +const SECOND_VIEW: TableViewWire = { ...DEFAULT_VIEW, - id: 'view-saved', - name: 'Saved', + id: 'view-second', + name: 'Second view', isDefault: false, } +const PRIMARY_VIEW: TableViewWire = { + ...DEFAULT_VIEW, + name: 'Primary view', +} + +afterEach(() => { + vi.useRealTimers() +}) + function renderMenu(views: TableViewWire[], activeViewId: string | null): string { return renderToStaticMarkup( { expect(markup).not.toContain('>View<') }) - it('only offers deletion for non-default views', () => { + it('shows filled and outline pins without a Default badge and keeps the menu open', () => { const container = document.createElement('div') document.body.appendChild(container) const root = createRoot(container) + const onSetDefault = vi.fn() act(() => { root.render( { act(() => container.querySelector('button[aria-label="Views"]')?.click()) expect(document.body.querySelectorAll('button[aria-label="Delete"]')).toHaveLength(1) + const defaultPin = document.body.querySelector( + 'button[aria-label="Current default view"]' + ) + const setDefaultPin = document.body.querySelector( + 'button[aria-label="Set as default"]' + ) + + expect(defaultPin?.querySelector('svg')).toHaveClass('fill-current') + expect(setDefaultPin?.querySelector('svg')).not.toHaveClass('fill-current') + expect(document.body).not.toHaveTextContent('Default') + + act(() => setDefaultPin?.click()) + expect(onSetDefault).toHaveBeenCalledWith(SECOND_VIEW.id) + expect(document.body).toHaveTextContent('New view') + + expect(defaultPin).toBeDisabled() + act(() => defaultPin?.click()) + expect(onSetDefault).toHaveBeenCalledTimes(1) + + act(() => root.unmount()) + container.remove() + }) + + it('keeps the menu open when keyboard focus moves from the trigger to the default pin', () => { + vi.useFakeTimers() + const container = document.createElement('div') + document.body.appendChild(container) + const root = createRoot(container) + + act(() => { + root.render( + + ) + }) + + const trigger = container.querySelector('button[aria-label="Views"]') + act(() => trigger?.focus()) + + const setDefaultPin = document.body.querySelector( + 'button[aria-label="Set as default"]' + ) + expect(setDefaultPin).not.toBeNull() + act(() => { + setDefaultPin?.focus() + vi.advanceTimersByTime(121) + }) + + expect(document.activeElement).toBe(setDefaultPin) + expect(document.body).toHaveTextContent('New view') + expect(document.body.querySelector('[data-native-surface-overlay]')).not.toBeNull() + + act(() => root.unmount()) + container.remove() + }) + + it('shows disabled pins without closing the menu for read-only members', () => { + const container = document.createElement('div') + document.body.appendChild(container) + const root = createRoot(container) + const onSetDefault = vi.fn() + + act(() => { + root.render( + + ) + }) + act(() => container.querySelector('button[aria-label="Views"]')?.click()) + + const defaultPin = document.body.querySelector( + 'button[aria-label="Current default view"]' + ) + const setDefaultPin = document.body.querySelector( + 'button[aria-label="Set as default"]' + ) + + expect(defaultPin?.querySelector('svg')).toHaveClass('fill-current') + expect(setDefaultPin?.querySelector('svg')).not.toHaveClass('fill-current') + expect(setDefaultPin).toBeDisabled() + + act(() => setDefaultPin?.click()) + + expect(onSetDefault).not.toHaveBeenCalled() + expect(document.body.querySelector('[data-native-surface-overlay]')).not.toBeNull() act(() => root.unmount()) container.remove() diff --git a/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/views-menu/views-menu.tsx b/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/views-menu/views-menu.tsx index 14b833f8108..96359e2556c 100644 --- a/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/views-menu/views-menu.tsx +++ b/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/views-menu/views-menu.tsx @@ -2,6 +2,7 @@ import { memo, useEffect, useRef, useState } from 'react' import { + Button, ChipChevronDown, chipContentLabelClass, chipVariants, @@ -13,7 +14,7 @@ import { PopoverItem, PopoverSection, } from '@sim/emcn' -import { Check, Pencil, Plus, Trash } from '@sim/emcn/icons' +import { Check, Pencil, Pin, Plus, Trash } from '@sim/emcn/icons' import type { TableViewWire } from '@/lib/api/contracts/tables' import { resolveTableViewSelection } from '@/app/workspace/[workspaceId]/tables/[tableId]/view-state' @@ -24,7 +25,7 @@ export const ALL_ROWS_VIEW_LABEL = 'All' const POPOVER_CLOSE_DELAY_MS = 120 /** Rendered width of one action button (`p-1` + `size-3` glyph) plus its `gap-0.5`. - * The row reserves `actions.length` of these, so keep it in step with the button + * The row reserves `actionCount` of these, so keep it in step with the button * classes below — the overlay is absolutely positioned and can't size the spacer. */ const VIEW_ACTION_SLOT_PX = 22 @@ -34,6 +35,7 @@ interface ViewsMenuProps { activeViewId: string | null onSelect: (viewId: string | null) => void onRename: (viewId: string) => void + onSetDefault: (viewId: string) => void onDelete: (viewId: string) => void /** Starts a blank view — named first, configured after. */ onNewView: () => void @@ -53,6 +55,7 @@ export const ViewsMenu = memo(function ViewsMenu({ activeViewId, onSelect, onRename, + onSetDefault, onDelete, onNewView, canEdit, @@ -129,6 +132,7 @@ export const ViewsMenu = memo(function ViewsMenu({ )} onMouseEnter={openPopover} onMouseLeave={scheduleClose} + onFocusCapture={cancelScheduledClose} > Views @@ -146,8 +150,17 @@ export const ViewsMenu = memo(function ViewsMenu({ key={view.id} label={view.name} isActive={view.id === activeViewId} - isDefault={view.isDefault} onSelect={() => runAndClose(() => onSelect(view.id))} + defaultState={{ + isDefault: view.isDefault, + onSetDefault: + canEdit && !view.isDefault + ? () => { + cancelScheduledClose() + onSetDefault(view.id) + } + : undefined, + }} actions={ canEdit ? [ @@ -196,11 +209,16 @@ interface ViewRowAction { onClick: () => void } +interface ViewRowDefaultState { + isDefault: boolean + onSetDefault?: () => void +} + interface ViewRowProps { label: string isActive: boolean - isDefault?: boolean onSelect: () => void + defaultState?: ViewRowDefaultState actions?: ViewRowAction[] } @@ -210,7 +228,9 @@ interface ViewRowProps { * on hover via opacity, not `display`) so the name never reflows or sits * underneath them. */ -function ViewRow({ label, isActive, isDefault, onSelect, actions }: ViewRowProps) { +function ViewRow({ label, isActive, onSelect, defaultState, actions }: ViewRowProps) { + const actionCount = (actions?.length ?? 0) + (defaultState ? 1 : 0) + return (
} {label} - {isDefault && ( - - Default - - )} - {actions && ( + {actionCount > 0 && ( )} - {actions && ( -
- {actions.map((action) => ( - + ))} + {defaultState && ( + + )}
)}
diff --git a/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/table.tsx b/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/table.tsx index f368f06908d..b94138e4385 100644 --- a/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/table.tsx +++ b/apps/sim/app/workspace/[workspaceId]/tables/[tableId]/table.tsx @@ -121,8 +121,8 @@ interface TableProps { tableLocksEnabled?: boolean /** * Resolved `table-views` flag. Server-only to resolve for the same reason. - * Defaults to `false` so the embedded mothership table — which has no server - * context to resolve it — stays on today's Filter/Sort bar. + * Defaults to `false` so any caller that has not resolved the flag stays on + * today's Filter/Sort behavior. */ viewsEnabled?: boolean } @@ -735,6 +735,15 @@ export function Table({ setViewModal({ mode: 'rename', viewId }) }, []) + const handleSetDefaultView = useCallback((viewId: string) => { + updateViewMutation.mutate( + { viewId, isDefault: true }, + { + onError: (error) => toast.error(getErrorMessage(error, 'Failed to set default view')), + } + ) + }, []) + const handleNewView = useCallback(() => { setViewModal({ mode: 'new' }) }, []) @@ -1175,25 +1184,34 @@ export function Table({ active: sortColumn ? { column: sortColumn, direction: sortDirection } : null, onSort: handleSortColumn, onClear: handleClearSort, + keepOpenOnSelect: viewsEnabled, }), - [columnOptions, sortColumn, sortDirection, handleSortColumn, handleClearSort] + [columnOptions, sortColumn, sortDirection, handleSortColumn, handleClearSort, viewsEnabled] ) - const handleFilterApply = (next: TablePredicate | null) => { - setFilter(next) - persistActiveViewConfig({ filter: next }) - } + const handleFilterChange = useCallback( + (next: TablePredicate | null) => { + setFilter(next) + persistActiveViewConfig({ filter: next }) + }, + [persistActiveViewConfig] + ) - const handleHiddenColumnsChange = (next: string[]) => { - setHiddenColumns(next) - persistActiveViewConfig({ hiddenColumns: next }) - } + const handleHiddenColumnsChange = useCallback( + (next: string[]) => { + setHiddenColumns(next) + persistActiveViewConfig({ hiddenColumns: next }) + }, + [persistActiveViewConfig] + ) /** * "Filter by cell value" from the grid's cell context menu. Narrows the * PRUNED filter, so a condition the current schema already invalidated is not * resurrected, and opens the panel — a silently narrowed table would leave the - * user no way to see what was applied. + * user no way to see what was applied. Persists explicitly: the reseeded + * panel starts signature-matched to this filter, so its gesture handlers will + * not emit it again. */ const handleFilterByCellValue = (conditions: readonly Predicate[]) => { const next = withCellValueFilter(effectiveFilter, conditions) @@ -1496,6 +1514,7 @@ export function Table({ activeViewId={activeView?.id ?? null} onSelect={handleSelectView} onRename={handleRenameView} + onSetDefault={handleSetDefaultView} onDelete={handleDeleteView} onNewView={handleNewView} canEdit={userPermissions.canEdit} @@ -1519,7 +1538,8 @@ export function Table({ key={filterSeed} columns={columns} filter={effectiveFilter} - onApply={handleFilterApply} + autoApply={viewsEnabled} + onChange={handleFilterChange} onClose={() => setFilterOpen(false)} /> )} diff --git a/apps/sim/hooks/queries/tables.test.ts b/apps/sim/hooks/queries/tables.test.ts index 2d4f6eb0b0d..0f81a28108f 100644 --- a/apps/sim/hooks/queries/tables.test.ts +++ b/apps/sim/hooks/queries/tables.test.ts @@ -57,6 +57,7 @@ vi.mock('@sim/emcn', () => ({ toast: { error: vi.fn(), success: vi.fn() }, })) +import type { TableViewWire } from '@/lib/api/contracts/tables' import { tableRowsInfiniteOptions, tableRowsParamsKey, @@ -105,6 +106,75 @@ describe('useUpdateTableView autosave ordering', () => { queryKey: tableKeys.views(TABLE_ID), }) }) + + it('optimistically demotes the previous default when a view is promoted', () => { + const previousDefault: TableViewWire = { + id: 'view-default', + tableId: TABLE_ID, + name: 'Default', + config: {}, + isDefault: true, + createdBy: 'user-1', + createdAt: new Date('2026-08-15T01:00:00.000Z'), + updatedAt: new Date('2026-08-15T01:00:00.000Z'), + } + const promoted: TableViewWire = { + ...previousDefault, + id: 'view-promoted', + name: 'My view', + updatedAt: new Date('2026-08-15T02:00:00.000Z'), + } + setCache(tableKeys.views(TABLE_ID), [ + previousDefault, + { ...promoted, isDefault: false, updatedAt: previousDefault.updatedAt }, + ]) + + const hook = useUpdateTableView({ workspaceId: WORKSPACE_ID, tableId: TABLE_ID }) + hook.onSuccess?.(promoted, { viewId: promoted.id, isDefault: true }, undefined, undefined) + + expect(getCache(tableKeys.views(TABLE_ID))).toEqual([ + { ...previousDefault, isDefault: false }, + promoted, + ]) + }) + + it('ignores a stale promotion response instead of demoting the newer default', () => { + const newerDefault: TableViewWire = { + id: 'view-newer-default', + tableId: TABLE_ID, + name: 'Newer default', + config: {}, + isDefault: true, + createdBy: 'user-1', + createdAt: new Date('2026-08-15T01:00:00.000Z'), + updatedAt: new Date('2026-08-15T03:00:00.000Z'), + } + const stalePromotion: TableViewWire = { + ...newerDefault, + id: 'view-stale', + name: 'Stale view', + updatedAt: new Date('2026-08-15T02:00:00.000Z'), + } + const cachedStaleRow: TableViewWire = { + ...stalePromotion, + isDefault: false, + updatedAt: new Date('2026-08-15T01:00:00.000Z'), + } + setCache(tableKeys.views(TABLE_ID), [newerDefault, cachedStaleRow]) + + const hook = useUpdateTableView({ workspaceId: WORKSPACE_ID, tableId: TABLE_ID }) + hook.onSuccess?.( + stalePromotion, + { viewId: stalePromotion.id, isDefault: true }, + undefined, + undefined + ) + + expect(getCache(tableKeys.views(TABLE_ID))).toEqual([ + newerDefault, + cachedStaleRow, + ]) + }) }) describe('useDeleteColumn optimistic update', () => { diff --git a/apps/sim/hooks/queries/tables.ts b/apps/sim/hooks/queries/tables.ts index fbe80d0abda..4d54cfb8bb8 100644 --- a/apps/sim/hooks/queries/tables.ts +++ b/apps/sim/hooks/queries/tables.ts @@ -1579,16 +1579,33 @@ export function useUpdateTableView({ workspaceId, tableId }: RowMutationContext) // Keep the active view's server baseline current immediately; the refetch // remains the authoritative reconciliation for concurrent collaborators. onSuccess: (view) => { - queryClient.setQueryData(tableKeys.views(tableId), (prev) => - prev?.map((existing) => { - if (existing.id !== view.id) return existing - // Layout and view controls auto-save concurrently, and their - // responses can arrive out of order. The DB merge is authoritative, so - // only let a row at least as new as the cached one win — otherwise a - // slower response rewinds the cache until the refetch lands. - return new Date(view.updatedAt) >= new Date(existing.updatedAt) ? view : existing + queryClient.setQueryData(tableKeys.views(tableId), (prev) => { + if (!prev) return prev + // Layout and view controls auto-save concurrently, and their + // responses can arrive out of order. The DB merge is authoritative, so + // only let a response at least as new as the cached row win — for + // installing the row AND for demoting the previous default. A stale + // response applies nothing; otherwise it would rewind the cache (or + // strip isDefault from a newer default, leaving none) until the + // refetch lands. + const cached = prev.find((existing) => existing.id === view.id) + const currentDefault = view.isDefault + ? prev.find((existing) => existing.id !== view.id && existing.isDefault) + : undefined + const responseTime = new Date(view.updatedAt) + if ( + (cached && responseTime < new Date(cached.updatedAt)) || + (currentDefault && responseTime < new Date(currentDefault.updatedAt)) + ) { + return prev + } + return prev.map((existing) => { + if (view.isDefault && existing.id !== view.id && existing.isDefault) { + return { ...existing, isDefault: false } + } + return existing.id === view.id ? view : existing }) - ) + }) }, onSettled: () => { // A scoped mutation only needs the database write ahead of the next diff --git a/apps/sim/lib/core/config/feature-flags.ts b/apps/sim/lib/core/config/feature-flags.ts index c068326a648..3a19f2ee368 100644 --- a/apps/sim/lib/core/config/feature-flags.ts +++ b/apps/sim/lib/core/config/feature-flags.ts @@ -136,11 +136,10 @@ const FEATURE_FLAGS = { 'table-views': { description: 'Saved table views (named filter/sort/column-visibility presets) plus the column show/hide ' + - 'menu, in the table-detail options bar. UI-only gate: resolved in the table page (server) ' + - "and passed down, so the table falls back to today's Filter/Sort bar when off. The routes " + - 'and the table_views table ship ungated — they are inert with no UI to call them, and a view ' + - 'saved during a rollout must survive the flag being toggled back off. Embedded (mothership) ' + - 'tables render without views regardless, since no server context resolves the flag there. ' + + 'menu. UI-only gate: resolved server-side for table-detail and embedded tables, then passed ' + + "down so both surfaces fall back to today's Filter/Sort behavior when off. The routes and " + + 'the table_views table ship ungated, and new or forked tables still seed their view data, so ' + + 'a saved view survives the flag being toggled off and can be restored when it is re-enabled. ' + 'Off-AppConfig falls back to TABLE_VIEWS.', fallback: 'TABLE_VIEWS', }, diff --git a/apps/sim/lib/table/query-builder/converters.ts b/apps/sim/lib/table/query-builder/converters.ts index 981d62294c8..4063bf53b19 100644 --- a/apps/sim/lib/table/query-builder/converters.ts +++ b/apps/sim/lib/table/query-builder/converters.ts @@ -308,7 +308,16 @@ function formatValueForBuilder(value: JsonValue): string { /* ----------------------------- v2 grammar ----------------------------- */ -const VALUELESS_OPS = new Set(['isEmpty', 'isNotEmpty', 'isNull', 'isNotNull']) +/** Operators that carry no value — the full v2 set, a superset of the legacy + * `VALUELESS_OPERATORS` in constants.ts (which the `$`-grammar serializer + * still reads and must not grow). Widened to `ReadonlySet` so UI rule + * operators can be tested without a cast. */ +export const VALUELESS_OPS: ReadonlySet = new Set([ + 'isEmpty', + 'isNotEmpty', + 'isNull', + 'isNotNull', +]) function ruleToPredicate(rule: FilterRule, keepAsText = false): Predicate { const op = rule.operator as FilterOp