Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore: update filters with new animations based on feedback (#42704)

Ali Waseem765f95ce9fe8
diff --git a/apps/studio/components/grid/components/header/filter/FilterPopoverNew.tsx b/apps/studio/components/grid/components/header/filter/FilterPopoverNew.tsx
index b4323dde9d5..9a731fc4edf 100644
--- a/apps/studio/components/grid/components/header/filter/FilterPopoverNew.tsx
+++ b/apps/studio/components/grid/components/header/filter/FilterPopoverNew.tsx
@@ -5,15 +5,15 @@ import { format } from 'date-fns'
import { Loader2 } from 'lucide-react'
import { useCallback, useMemo, useState } from 'react'
import { useTableEditorTableStateSnapshot } from 'state/table-editor-table'
-import { Button, Calendar } from 'ui'
+import { AiIconAnimation, Button, Calendar } from 'ui'
import {
CustomOptionProps,
FilterBar,
FilterGroup,
FilterOption,
FilterProperty,
- SerializableFilterProperty,
isGroup,
+ SerializableFilterProperty,
updateGroupAtPath,
} from 'ui-patterns'
@@ -190,7 +190,9 @@ export const FilterPopoverNew = ({ isRefetching = false }: FilterPopoverProps) =
[generateFilters, serializableFilterProperties, handleFilterChange, setFreeformText]
)
- const icon = isRefetching ? (
+ const icon = isGenerating ? (
+ <AiIconAnimation size={16} loading />
+ ) : isRefetching ? (
<Loader2 className="animate-spin text-brand h-4 w-4 shrink-0" aria-label="Loading table data" />
) : null
diff --git a/packages/ui-patterns/src/FilterBar/CommandListItem.tsx b/packages/ui-patterns/src/FilterBar/CommandListItem.tsx
index 8c05ebb985b..d5f42c4a5bd 100644
--- a/packages/ui-patterns/src/FilterBar/CommandListItem.tsx
+++ b/packages/ui-patterns/src/FilterBar/CommandListItem.tsx
@@ -2,6 +2,7 @@ import { cn } from 'ui'
import { OperatorSymbolBadge } from './OperatorSymbolBadge'
import { MenuItem } from './types'
+import { getActionItemLabel } from './utils'
export type CommandListItemProps = {
item: MenuItem
@@ -31,7 +32,7 @@ export function CommandListItem({
>
<span className="flex items-center gap-2">
{includeIcon && item.icon}
- {item.label}
+ {getActionItemLabel(item)}
</span>
{item.operatorSymbol && <OperatorSymbolBadge symbol={item.operatorSymbol} />}
</div>
diff --git a/packages/ui-patterns/src/FilterBar/FilterBar.test.tsx b/packages/ui-patterns/src/FilterBar/FilterBar.test.tsx
index 0c1841e919e..5504c209f52 100644
--- a/packages/ui-patterns/src/FilterBar/FilterBar.test.tsx
+++ b/packages/ui-patterns/src/FilterBar/FilterBar.test.tsx
@@ -51,11 +51,7 @@ describe('FilterBar', () => {
/>
)
- expect(
- screen.getByPlaceholderText(
- 'Ask AI for help (e.g. Find all users with name John) or filter...'
- )
- ).toBeInTheDocument()
+ expect(screen.getByPlaceholderText('Filter by Name, Status, Count')).toBeInTheDocument()
})
it('renders with search input', () => {
@@ -69,9 +65,7 @@ describe('FilterBar', () => {
/>
)
- const input = screen.getByPlaceholderText(
- 'Ask AI for help (e.g. Find all users with name John) or filter...'
- )
+ const input = screen.getByPlaceholderText('Filter by Name, Status, Count')
expect(input).toBeInTheDocument()
})
@@ -92,9 +86,7 @@ describe('FilterBar', () => {
/>
)
- const freeform = screen.getByPlaceholderText(
- 'Ask AI for help (e.g. Find all users with name John) or filter...'
- )
+ const freeform = screen.getByPlaceholderText('Filter by Name, Status, Count')
freeform.focus()
await user.click(freeform)
@@ -144,9 +136,7 @@ describe('FilterBar', () => {
/>
)
- const freeform = screen.getByPlaceholderText(
- 'Ask AI for help (e.g. Find all users with name John) or filter...'
- )
+ const freeform = screen.getByPlaceholderText('Filter by Name, Status, Count')
await user.click(freeform)
await user.click(screen.getByText('Status'))
@@ -236,9 +226,7 @@ describe('FilterBar', () => {
/>
)
- const freeform = screen.getByPlaceholderText(
- 'Ask AI for help (e.g. Find all users with name John) or filter...'
- )
+ const freeform = screen.getByPlaceholderText('Filter by Name, Status, Count...')
await user.click(freeform)
await user.click(screen.getByText('Tag'))
@@ -300,9 +288,7 @@ describe('FilterBar', () => {
/>
)
- const freeform = screen.getByPlaceholderText(
- 'Ask AI for help (e.g. Find all users with name John) or filter...'
- )
+ const freeform = screen.getByPlaceholderText('Filter by Name, Status, Count')
await user.click(freeform)
expect(await screen.findByText('Name')).toBeInTheDocument()
diff --git a/packages/ui-patterns/src/FilterBar/FilterGroup.tsx b/packages/ui-patterns/src/FilterBar/FilterGroup.tsx
index dca2232a6fd..310708e9627 100644
--- a/packages/ui-patterns/src/FilterBar/FilterGroup.tsx
+++ b/packages/ui-patterns/src/FilterBar/FilterGroup.tsx
@@ -15,7 +15,7 @@ import { FilterCondition } from './FilterCondition'
import { useDeferredBlur, useHighlightNavigation } from './hooks'
import { buildPropertyItems } from './menuItems'
import { FilterGroup as FilterGroupType } from './types'
-import { pathsEqual } from './utils'
+import { buildFilterPlaceholder, pathsEqual } from './utils'
export type FilterGroupProps = {
group: FilterGroupType
@@ -100,6 +100,14 @@ export function FilterGroup({ group, path }: FilterGroupProps) {
[filterProperties, isActive, freeformText, localFreeformValue, actions, supportsOperators]
)
+ const emptyPlaceholder = useMemo(
+ () =>
+ buildFilterPlaceholder(filterProperties, {
+ hasActions: actions && actions.length > 0,
+ }),
+ [filterProperties, actions]
+ )
+
// Only the root group should expand to fill available space
const isRootGroup = path.length === 0
@@ -184,9 +192,7 @@ export function FilterGroup({ group, path }: FilterGroupProps) {
onKeyDown={handleFreeformKeyDown}
className="border-none bg-transparent text-xs focus:outline-none focus:ring-0 focus:shadow-none focus-visible:ring-0 focus-visible:ring-offset-0 w-full flex-1 h-auto min-w-0 px-2 py-0"
placeholder={
- group.conditions.length === 0
- ? 'Ask AI for help (e.g. Find all users with name John) or filter...'
- : 'Add more filters...'
+ group.conditions.length === 0 ? emptyPlaceholder : 'Add more filters...'
}
disabled={isLoading}
/>
diff --git a/packages/ui-patterns/src/FilterBar/utils.test.ts b/packages/ui-patterns/src/FilterBar/utils.test.ts
index 92395eb5638..c3a2d8f7251 100644
--- a/packages/ui-patterns/src/FilterBar/utils.test.ts
+++ b/packages/ui-patterns/src/FilterBar/utils.test.ts
@@ -5,14 +5,17 @@ import { FilterGroup, FilterProperty, MenuItem } from './types'
import {
addFilterToGroup,
addGroupToGroup,
+ buildFilterPlaceholder,
findConditionByPath,
findGroupByPath,
+ getActionItemLabel,
groupMenuItemsByOperator,
isAsyncOptionsFunction,
isCustomOptionObject,
isFilterOptionObject,
isSyncOptionsFunction,
removeFromGroup,
+ truncateText,
updateNestedLogicalOperator,
updateNestedOperator,
updateNestedValue,
@@ -335,4 +338,121 @@ describe('FilterBar Utils', () => {
expect(result[0].items).toHaveLength(2)
})
})
+
+ describe('truncateText', () => {
+ it('returns text unchanged if under max length', () => {
+ expect(truncateText('hello', 10)).toBe('hello')
+ })
+
+ it('returns text unchanged if exactly max length', () => {
+ expect(truncateText('hello', 5)).toBe('hello')
+ })
+
+ it('truncates text and adds ellipsis if over max length', () => {
+ expect(truncateText('hello world', 5)).toBe('hello...')
+ })
+
+ it('handles empty string', () => {
+ expect(truncateText('', 10)).toBe('')
+ })
+ })
+
+ describe('getActionItemLabel', () => {
+ it('returns original label for non-action items', () => {
+ const item: MenuItem = { value: 'test', label: 'Test Label' }
+ expect(getActionItemLabel(item)).toBe('Test Label')
+ })
+
+ it('returns original label for action items without input value', () => {
+ const item: MenuItem = { value: 'ai', label: 'Filter by AI', isAction: true }
+ expect(getActionItemLabel(item)).toBe('Filter by AI')
+ })
+
+ it('returns formatted label for action items with input value', () => {
+ const item: MenuItem = {
+ value: 'ai',
+ label: 'Filter by AI',
+ isAction: true,
+ actionInputValue: 'Find users',
+ }
+ expect(getActionItemLabel(item)).toBe('Ask AI: "Find users"')
+ })
+
+ it('truncates long input values at 30 characters', () => {
+ const item: MenuItem = {
+ value: 'ai',
+ label: 'Filter by AI',
+ isAction: true,
+ actionInputValue: 'Find all users who registered in the last 30 days',
+ }
+ expect(getActionItemLabel(item)).toBe('Ask AI: "Find all users who registered ..."')
+ })
+ })
+
+ describe('buildFilterPlaceholder', () => {
+ it('returns default message for empty properties without actions', () => {
+ expect(buildFilterPlaceholder([])).toBe('Add filters...')
+ })
+
+ it('returns default message with AI mention when actions exist', () => {
+ expect(buildFilterPlaceholder([], { hasActions: true })).toBe('Add filters or ask AI...')
+ })
+
+ it('shows single property name without actions', () => {
+ const props = [{ label: 'Name', name: 'name', type: 'string' as const }]
+ expect(buildFilterPlaceholder(props)).toBe('Filter by Name')
+ })
+
+ it('shows single property name with AI suffix when actions exist', () => {
+ const props = [{ label: 'Name', name: 'name', type: 'string' as const }]
+ expect(buildFilterPlaceholder(props, { hasActions: true })).toBe('Filter by Name or ask AI')
+ })
+
+ it('shows multiple property names up to max', () => {
+ const props = [
+ { label: 'Name', name: 'name', type: 'string' as const },
+ { label: 'Status', name: 'status', type: 'string' as const },
+ { label: 'Created At', name: 'created_at', type: 'date' as const },
+ ]
+ expect(buildFilterPlaceholder(props)).toBe('Filter by Name, Status, Created At')
+ })
+
+ it('truncates with ellipsis when more than max properties', () => {
+ const props = [
+ { label: 'Name', name: 'name', type: 'string' as const },
+ { label: 'Status', name: 'status', type: 'string' as const },
+ { label: 'Created At', name: 'created_at', type: 'date' as const },
+ { label: 'Updated At', name: 'updated_at', type: 'date' as const },
+ ]
+ expect(buildFilterPlaceholder(props)).toBe('Filter by Name, Status, Created At...')
+ })
+
+ it('truncates with ellipsis and AI suffix when actions exist', () => {
+ const props = [
+ { label: 'Name', name: 'name', type: 'string' as const },
+ { label: 'Status', name: 'status', type: 'string' as const },
+ { label: 'Created At', name: 'created_at', type: 'date' as const },
+ { label: 'Updated At', name: 'updated_at', type: 'date' as const },
+ ]
+ expect(buildFilterPlaceholder(props, { hasActions: true })).toBe(
+ 'Filter by Name, Status, Created At... or ask AI'
+ )
+ })
+
+ it('respects custom maxProperties parameter', () => {
+ const props = [
+ { label: 'Name', name: 'name', type: 'string' as const },
+ { label: 'Status', name: 'status', type: 'string' as const },
+ ]
+ expect(buildFilterPlaceholder(props, { maxProperties: 1 })).toBe('Filter by Name...')
+ })
+
+ it('does not add ellipsis when properties equal maxProperties', () => {
+ const props = [
+ { label: 'Name', name: 'name', type: 'string' as const },
+ { label: 'Status', name: 'status', type: 'string' as const },
+ ]
+ expect(buildFilterPlaceholder(props, { maxProperties: 2 })).toBe('Filter by Name, Status')
+ })
+ })
})
diff --git a/packages/ui-patterns/src/FilterBar/utils.ts b/packages/ui-patterns/src/FilterBar/utils.ts
index 3fc143c58f3..719ececa866 100644
--- a/packages/ui-patterns/src/FilterBar/utils.ts
+++ b/packages/ui-patterns/src/FilterBar/utils.ts
@@ -276,3 +276,36 @@ export function groupMenuItemsByOperator(items: MenuItem[]): MenuItemGroup[] {
items: grouped.get(groupKey) ?? [],
}))
}
+
+export function truncateText(text: string, maxLength: number): string {
+ if (text.length <= maxLength) return text
+ return text.slice(0, maxLength) + '...'
+}
+
+export function getActionItemLabel(item: MenuItem): string {
+ if (item.isAction && item.actionInputValue) {
+ return `Ask AI: "${truncateText(item.actionInputValue, 30)}"`
+ }
+ return item.label
+}
+
+export function buildFilterPlaceholder(
+ filterProperties: FilterProperty[],
+ options: { maxProperties?: number; hasActions?: boolean } = {}
+): string {
+ const { maxProperties = 3, hasActions = false } = options
+
+ if (filterProperties.length === 0) {
+ return hasActions ? 'Add filters or ask AI...' : 'Add filters...'
+ }
+
+ const propertyNames = filterProperties
+ .slice(0, maxProperties)
+ .map((prop) => prop.label)
+ .join(', ')
+
+ const suffix = filterProperties.length > maxProperties ? '...' : ''
+ const aiSuffix = hasActions ? ' or ask AI' : ''
+
+ return `Filter by ${propertyNames}${suffix}${aiSuffix}`
+}