The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat(studio): make the Connect framework and client selectors searchable (#50072)
Danny White30ab816ff4ef
diff --git a/apps/studio/components/interfaces/ConnectSheet/Connect.types.ts b/apps/studio/components/interfaces/ConnectSheet/Connect.types.tsindex fc5bf7712ec..851aca8eeac 100644--- a/apps/studio/components/interfaces/ConnectSheet/Connect.types.ts+++ b/apps/studio/components/interfaces/ConnectSheet/Connect.types.ts@@ -73,7 +73,7 @@ export interface ModeDefinition {// Schema Types - Fields// ============================================================================-type FieldType = 'select' | 'radio-grid' | 'radio-list' | 'switch' | 'multi-select'+type FieldType = 'select' | 'combobox' | 'radio-grid' | 'radio-list' | 'switch' | 'multi-select'export interface FieldOption {value: string@@ -87,6 +87,12 @@ interface FieldDefinition {type: FieldTypelabel: stringdescription?: string+ // Copy for `combobox` fields, which need their own trigger, search and empty-state text+ combobox?: {+ placeholder: string+ searchPlaceholder: string+ emptyMessage: string+ }// Options can be static, or reference a data source, or be conditionaloptions?: FieldOption[] | { source: string } | ConditionalValue<FieldOption[]>// Only show this field when these state conditions are metdiff --git a/apps/studio/components/interfaces/ConnectSheet/ConnectConfigSection.test.tsx b/apps/studio/components/interfaces/ConnectSheet/ConnectConfigSection.test.tsxnew file mode 100644index 00000000000..bad879d0812--- /dev/null+++ b/apps/studio/components/interfaces/ConnectSheet/ConnectConfigSection.test.tsx@@ -0,0 +1,141 @@+import { screen } from '@testing-library/react'+import userEvent from '@testing-library/user-event'+import { mockAnimationsApi } from 'jsdom-testing-mocks'+import { describe, expect, test, vi } from 'vitest'++import type { ResolvedField } from './Connect.types'+import { ConnectConfigSection } from './ConnectConfigSection'+import { customRender } from '@/tests/lib/custom-render'++mockAnimationsApi()++const frameworkField: ResolvedField = {+ id: 'framework',+ type: 'combobox',+ label: 'Framework',+ combobox: {+ placeholder: 'Select framework',+ searchPlaceholder: 'Search frameworks...',+ emptyMessage: 'No frameworks found',+ },+ resolvedOptions: [],+}++const frameworkOptions = [+ { value: 'nextjs', label: 'Next.js' },+ { value: 'react', label: 'React' },+ { value: 'react-native', label: 'React Native' },+]++const manyFrameworkOptions = Array.from({ length: 20 }, (_, index) => ({+ value: `framework-${index}`,+ label: `Framework ${index}`,+}))++describe('ConnectConfigSection', () => {+ test('filters frameworks and selects the matching option', async () => {+ const user = userEvent.setup()+ const onFieldChange = vi.fn()++ customRender(+ <ConnectConfigSection+ activeFields={[frameworkField]}+ state={{ framework: 'nextjs' }}+ onFieldChange={onFieldChange}+ getFieldOptions={() => frameworkOptions}+ />+ )++ await user.click(screen.getByRole('combobox'))+ await user.type(screen.getByPlaceholderText('Search frameworks...'), 'native')++ expect(screen.getByRole('option', { name: 'React Native' })).toBeInTheDocument()+ expect(screen.queryByRole('option', { name: 'Next.js' })).not.toBeInTheDocument()++ await user.click(screen.getByRole('option', { name: 'React Native' }))++ expect(onFieldChange).toHaveBeenCalledWith('framework', 'react-native')+ })++ test('matches frameworks by key without announcing the empty state', async () => {+ const user = userEvent.setup()++ customRender(+ <ConnectConfigSection+ activeFields={[frameworkField]}+ state={{ framework: 'nextjs' }}+ onFieldChange={vi.fn()}+ getFieldOptions={() => frameworkOptions}+ />+ )++ await user.click(screen.getByRole('combobox'))+ await user.type(screen.getByPlaceholderText('Search frameworks...'), 'nextjs')++ expect(screen.getByRole('option', { name: 'Next.js' })).toBeInTheDocument()+ expect(screen.getByRole('status')).toBeEmptyDOMElement()+ })++ test('announces when no frameworks match the search', async () => {+ const user = userEvent.setup()++ customRender(+ <ConnectConfigSection+ activeFields={[frameworkField]}+ state={{ framework: 'nextjs' }}+ onFieldChange={vi.fn()}+ getFieldOptions={() => frameworkOptions}+ />+ )++ await user.click(screen.getByRole('combobox'))+ await user.type(screen.getByPlaceholderText('Search frameworks...'), 'missing')++ expect(screen.getByRole('status')).toHaveTextContent('No frameworks found')+ })++ test('clears the search when the combobox closes after selecting an option', async () => {+ const user = userEvent.setup()++ customRender(+ <ConnectConfigSection+ activeFields={[frameworkField]}+ state={{ framework: 'nextjs' }}+ onFieldChange={vi.fn()}+ getFieldOptions={() => frameworkOptions}+ />+ )++ await user.click(screen.getByRole('combobox'))+ const searchInput = screen.getByPlaceholderText('Search frameworks...')+ await user.type(searchInput, 'native')+ await user.click(screen.getByRole('option', { name: 'React Native' }))+ await user.click(screen.getByRole('combobox'))++ expect(screen.getByPlaceholderText('Search frameworks...')).toHaveValue('')+ })++ test('uses a bounded scroll area for long framework lists', async () => {+ const user = userEvent.setup()++ customRender(+ <ConnectConfigSection+ activeFields={[frameworkField]}+ state={{ framework: 'framework-0' }}+ onFieldChange={vi.fn()}+ getFieldOptions={() => manyFrameworkOptions}+ />+ )++ const combobox = document.getElementById('connect-framework')+ expect(combobox).toBeTruthy()++ await user.click(combobox!)++ const listbox = screen.getByRole('listbox')+ expect(combobox!.getAttribute('aria-controls')).toBe(listbox.id)++ expect(listbox).toHaveClass('max-h-72', 'overscroll-contain')+ expect(screen.getAllByRole('option')).toHaveLength(20)+ })+})diff --git a/apps/studio/components/interfaces/ConnectSheet/ConnectConfigSection.tsx b/apps/studio/components/interfaces/ConnectSheet/ConnectConfigSection.tsxindex 9f96b39af66..740f39e6e9f 100644--- a/apps/studio/components/interfaces/ConnectSheet/ConnectConfigSection.tsx+++ b/apps/studio/components/interfaces/ConnectSheet/ConnectConfigSection.tsx@@ -1,5 +1,17 @@+import { Check, ChevronsUpDown } from 'lucide-react'+import { useState } from 'react'import {+ Button,cn,+ Command,+ CommandEmpty,+ CommandGroup,+ CommandInput,+ CommandItem,+ CommandList,+ Popover,+ PopoverContent,+ PopoverTrigger,RadioGroupStacked,RadioGroupStackedItem,Select,@@ -19,6 +31,7 @@ import {} from 'ui-patterns/multi-select'import type { ConnectMode, FieldOption, ResolvedField } from './Connect.types'+import { getOptionMatchScore } from './ConnectConfigSection.utils'import { ConnectionIcon } from './ConnectionIcon'import {ConnectModeButton,@@ -55,6 +68,33 @@ export function ConnectConfigSection({}switch (field.type) {+ case 'combobox':+ return (+ <FormItemLayout+ key={field.id}+ isReactForm={false}+ layout="horizontal"+ label={field.label}+ description={field.description}+ name={`connect-${field.id}`}+ >+ <ConnectCombobox+ id={`connect-${field.id}`}+ options={options}+ value={String(value ?? '')}+ onValueChange={(v) => onFieldChange(field.id, v)}+ placeholder={field.combobox?.placeholder ?? 'Select option'}+ searchPlaceholder={field.combobox?.searchPlaceholder ?? 'Search...'}+ emptyMessage={field.combobox?.emptyMessage ?? 'No results found'}+ /*+ [Joshen] Omitting MCP icons for now as the images are not optimized (large)+ and is causing noticeably latency issues on the browser (even with the existing Connect UI)+ */+ showIcons={field.id === 'framework'}+ />+ </FormItemLayout>+ )+case 'radio-grid':return (<FormItemLayout@@ -233,6 +273,109 @@ export function ConnectConfigSection({)}+interface ConnectComboboxProps {+ id: string+ options: FieldOption[]+ value: string+ onValueChange: (value: string) => void+ placeholder: string+ searchPlaceholder: string+ emptyMessage: string+ showIcons: boolean+}++function ConnectCombobox({+ id,+ options,+ value,+ onValueChange,+ placeholder,+ searchPlaceholder,+ emptyMessage,+ showIcons,+}: ConnectComboboxProps) {+ const [isOpen, setIsOpen] = useState(false)+ const [search, setSearch] = useState('')+ const [listboxElementId, setListboxElementId] = useState<string>()+ const selectedOption = options.find((option) => option.value === value)+ const showEmptyStatus =+ search.trim().length > 0 &&+ !options.some((option) => getOptionMatchScore(option.label, search, [option.value]) > 0)+ const handleOpenChange = (open: boolean) => {+ setIsOpen(open)+ if (!open) setSearch('')+ }++ return (+ <Popover open={isOpen} onOpenChange={handleOpenChange} modal={false}>+ <PopoverTrigger asChild>+ <Button+ id={id}+ variant="default"+ size="small"+ role="combobox"+ aria-expanded={isOpen}+ aria-controls={listboxElementId}+ className={cn('w-full justify-between', !selectedOption && 'text-foreground-muted')}+ iconRight={<ChevronsUpDown className="h-4 w-4 shrink-0 opacity-50" strokeWidth={1} />}+ >+ <span className="flex min-w-0 items-center gap-x-2">+ {showIcons && selectedOption?.icon && (+ <span aria-hidden="true" className="flex shrink-0">+ <ConnectionIcon icon={selectedOption.icon} />+ </span>+ )}+ <span className="truncate">{selectedOption?.label ?? placeholder}</span>+ </span>+ </Button>+ </PopoverTrigger>+ <PopoverContent align="start" className="p-0" sameWidthAsTrigger>+ <Command filter={getOptionMatchScore}>+ <CommandInput placeholder={searchPlaceholder} value={search} onValueChange={setSearch} />+ <p className="sr-only" role="status" aria-live="polite">+ {showEmptyStatus ? emptyMessage : ''}+ </p>+ <CommandList+ className="max-h-72 overscroll-contain"+ ref={(node) => {+ if (node?.id) setListboxElementId(node.id)+ }}+ >+ <CommandEmpty>{emptyMessage}</CommandEmpty>+ <CommandGroup>+ {options.map((option) => (+ <CommandItem+ key={option.value}+ value={option.label}+ keywords={[option.value]}+ onSelect={() => {+ onValueChange(option.value)+ handleOpenChange(false)+ }}+ className="gap-x-2"+ >+ <Check+ className={cn(+ 'h-4 w-4 shrink-0',+ option.value === value ? 'opacity-100' : 'opacity-0'+ )}+ />+ {showIcons && option.icon && (+ <span aria-hidden="true" className="flex shrink-0">+ <ConnectionIcon icon={option.icon} />+ </span>+ )}+ <span className="truncate">{option.label}</span>+ </CommandItem>+ ))}+ </CommandGroup>+ </CommandList>+ </Command>+ </PopoverContent>+ </Popover>+ )+}+interface ModeSelectorProps {modes: Array<{ id: ConnectMode; label: string; description: string }>selected: ConnectModediff --git a/apps/studio/components/interfaces/ConnectSheet/ConnectConfigSection.utils.ts b/apps/studio/components/interfaces/ConnectSheet/ConnectConfigSection.utils.tsnew file mode 100644index 00000000000..7c20d3f6aa9--- /dev/null+++ b/apps/studio/components/interfaces/ConnectSheet/ConnectConfigSection.utils.ts@@ -0,0 +1,15 @@+/**+ * cmdk filter for the Connect comboboxes, matching a plain substring against the option label and+ * its key (passed through as a cmdk keyword) so `nextjs` finds `Next.js`.+ *+ * Also used to decide whether a combobox announces its empty state, so the announcement cannot+ * disagree with what the list actually filtered out.+ */+export function getOptionMatchScore(value: string, search: string, keywords?: string[]) {+ const normalizedSearch = search.trim().toLowerCase()+ if (normalizedSearch.length === 0) return 1++ const searchableValues = [value, ...(keywords ?? [])]++ return searchableValues.some((item) => item.toLowerCase().includes(normalizedSearch)) ? 1 : 0+}diff --git a/apps/studio/components/interfaces/ConnectSheet/__tests__/connect.schema.test.ts b/apps/studio/components/interfaces/ConnectSheet/__tests__/connect.schema.test.tsindex f3b08063f56..3582a1a4d44 100644--- a/apps/studio/components/interfaces/ConnectSheet/__tests__/connect.schema.test.ts+++ b/apps/studio/components/interfaces/ConnectSheet/__tests__/connect.schema.test.ts@@ -73,7 +73,7 @@ describe('connect.schema:structure', () => {describe('connect.schema:fields', () => {test('framework field should have correct type', () => {const field = connectSchema.fields.framework- expect(field.type).toBe('select')+ expect(field.type).toBe('combobox')expect(field.options).toEqual({ source: 'frameworks' })expect(field.defaultValue).toBe('nextjs')})@@ -112,9 +112,9 @@ describe('connect.schema:fields', () => {expect(field.defaultValue).toBe('prisma')})- test('mcpClient field should have select type', () => {+ test('mcpClient field should have combobox type', () => {const field = connectSchema.fields.mcpClient- expect(field.type).toBe('select')+ expect(field.type).toBe('combobox')expect(field.options).toEqual({ source: 'mcpClients' })expect(field.defaultValue).toBe('claude-code')})diff --git a/apps/studio/components/interfaces/ConnectSheet/connect.schema.ts b/apps/studio/components/interfaces/ConnectSheet/connect.schema.tsindex fb141fe0c8f..07ae4cee27c 100644--- a/apps/studio/components/interfaces/ConnectSheet/connect.schema.ts+++ b/apps/studio/components/interfaces/ConnectSheet/connect.schema.ts@@ -303,8 +303,13 @@ export const connectSchema: ConnectSchema = {// Framework fieldsframework: {id: 'framework',- type: 'select',+ type: 'combobox',label: 'Framework',+ combobox: {+ placeholder: 'Select framework',+ searchPlaceholder: 'Search frameworks...',+ emptyMessage: 'No frameworks found',+ },options: { source: 'frameworks' },defaultValue: 'nextjs',},@@ -376,9 +381,14 @@ export const connectSchema: ConnectSchema = {// MCP fieldsmcpClient: {id: 'mcpClient',- type: 'select',+ type: 'combobox',label: 'Client',description: 'The MCP client you are using.',+ combobox: {+ placeholder: 'Select client',+ searchPlaceholder: 'Search clients...',+ emptyMessage: 'No clients found',+ },options: { source: 'mcpClients' },defaultValue: 'claude-code',},diff --git a/apps/studio/tests/components/interfaces/ConnectSheet/ConnectConfigSection.utils.test.ts b/apps/studio/tests/components/interfaces/ConnectSheet/ConnectConfigSection.utils.test.tsnew file mode 100644index 00000000000..30202d96e8a--- /dev/null+++ b/apps/studio/tests/components/interfaces/ConnectSheet/ConnectConfigSection.utils.test.ts@@ -0,0 +1,29 @@+import { describe, expect, test } from 'vitest'++import { getOptionMatchScore } from '@/components/interfaces/ConnectSheet/ConnectConfigSection.utils'++describe('ConnectConfigSection utils: getOptionMatchScore', () => {+ test.each(['', ' '])('matches a blank search (%j)', (search) => {+ expect(getOptionMatchScore('Next.js', search, ['nextjs'])).toBe(1)+ })++ test('matches a substring of the option label', () => {+ expect(getOptionMatchScore('Next.js', 'xt.j')).toBe(1)+ })++ test('matches a substring of an option keyword', () => {+ expect(getOptionMatchScore('Next.js', 'nextjs', ['nextjs'])).toBe(1)+ })++ test('matches case-insensitively and ignores surrounding search whitespace', () => {+ expect(getOptionMatchScore('React Native', ' NATIVE ')).toBe(1)+ })++ test('does not match when the search is absent from the label and keywords', () => {+ expect(getOptionMatchScore('Next.js', 'flutter', ['nextjs'])).toBe(0)+ })++ test('does not require keywords', () => {+ expect(getOptionMatchScore('Next.js', 'nextjs')).toBe(0)+ })+})