Files
Danny White fce9d475ee chore(studio): migrate combobox triggers (#50157)
## What kind of change does this PR introduce?

Studio UI consistency refactor.

## What is the current behaviour?

Several Studio comboboxes still build their triggers from `Button` and
supply their own double-chevron icon. This duplicates trigger styling
and allows these controls to drift from selects and other comboboxes.

## What is the new behaviour?

- Migrates the PITR timezone, AWS region, and account timezone controls
to `ComboboxTrigger`
- Migrates the shared `SchemaSelector` and `FunctionSelector`, updating
their Studio callsites together
- Preserves the globe icon in both timezone controls
- Exposes the correct combobox role and open state through the shared
trigger
- Tightens the tiny schema selector end padding so its chevron aligns
with adjacent controls
- Leaves organisation and project context switchers unchanged

| Before | After |
| --- | --- |
| <img width="504" height="490" alt="CleanShot 2026-09-09 at 13 56
56@2x"
src="https://github.com/user-attachments/assets/117a9169-88bf-4f9e-8302-9df9b911a307"
/> | <img width="496" height="512" alt="CleanShot 2026-09-09 at 11 31
26@2x"
src="https://github.com/user-attachments/assets/bc98cded-2723-4d20-9d8c-49630ea018af"
/> |
| <img width="1250" height="394" alt="CleanShot 2026-09-09 at 13 58
34@2x"
src="https://github.com/user-attachments/assets/9106f924-88fd-40d4-88e3-8d0ddbb61d12"
/> | <img width="1246" height="376" alt="CleanShot 2026-09-09 at 13 58
09@2x"
src="https://github.com/user-attachments/assets/7894a254-f6f9-40bb-a312-9f1a5079f096"
/> |

## To test

On the [Studio
preview](https://studio-staging-git-dnywh-choremigrate-combobox-680102-supabase.vercel.app):

1. Open **Database > Tables** and use the schema selector above the
table. It should use a single down chevron, open normally, and update
the selected schema.
2. Open **Authentication > Hooks > Add hook**, then select **Postgres**
as the hook type. The **Postgres schema** and **Postgres function**
selectors should use a single down chevron and continue to open and
select normally.

The PITR, AWS region, and account timezone callsites require the
relevant plan, integration, or feature flag. When available, their
triggers should use the same single down chevron, and both timezone
controls should retain the globe icon.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **UI Improvements**
* Standardized timezone, AWS region, database backup, function, and
schema selectors with a consistent combobox interface.
  * Added clear visual feedback for open and closed selector states.
* Preserved contextual icons and labels, including globe icons for
timezone selections.
* Improved accessibility with appropriate combobox semantics, accessible
names, and state information.
* Timezone settings are now available without an optional feature flag.
* **Tests**
  * Updated end-to-end coverage for the standardized combobox controls.
* Added coverage confirming schema selectors expose the selected schema
as an accessible name.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-09-09 15:36:35 +08:00

177 lines
5.5 KiB
TypeScript

import { useParams } from 'common'
import { uniqBy } from 'lodash'
import { Check, Plus } from 'lucide-react'
import { useState } from 'react'
import {
Alert,
AlertDescription,
AlertTitle,
Button,
ComboboxTrigger,
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandSeparator,
Popover,
PopoverContent,
PopoverTrigger,
ScrollArea,
} from 'ui'
import { CommandItemLink } from '@/components/ui/CommandItemLink'
import {
DatabaseFunctionsData,
useDatabaseFunctionsQuery,
} from '@/data/database-functions/database-functions-query'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
type DatabaseFunction = DatabaseFunctionsData[number]
interface FunctionSelectorProps {
className?: string
size?: 'tiny' | 'small'
showError?: boolean
schema?: string
value: string
onChange: (value: string) => void
disabled?: boolean
// used to filter the functions by a criteria
filterFunction?: (func: DatabaseFunction) => boolean
noResultsLabel?: React.ReactNode
}
const FunctionSelector = ({
className,
size = 'tiny',
showError = true,
disabled = false,
schema,
value,
onChange,
filterFunction = () => true,
noResultsLabel = <span>No functions found in this schema.</span>,
}: FunctionSelectorProps) => {
const { ref } = useParams()
const { data: project } = useSelectedProjectQuery()
const [open, setOpen] = useState(false)
const {
data,
error,
isPending: isLoading,
isError,
isSuccess,
refetch,
} = useDatabaseFunctionsQuery({
projectRef: project?.ref,
connectionString: project?.connectionString,
})
const filteredFunctions = (data ?? [])
.filter((func) => schema && func.schema === schema)
.filter(filterFunction)
const functions = uniqBy(filteredFunctions, (func) => func.name)
return (
<div className={className}>
{isLoading && (
<Button variant="default" className="justify-start" block size={size} loading>
Loading functions...
</Button>
)}
{showError && isError && (
<Alert variant="warning" className="px-3! py-3!">
<AlertTitle className="text-xs text-amber-900">Failed to load functions</AlertTitle>
<AlertDescription className="text-xs mb-2">Error: {error.message}</AlertDescription>
<Button variant="default" size="tiny" onClick={() => refetch()}>
Reload functions
</Button>
</Alert>
)}
{isSuccess && (
<Popover open={open} onOpenChange={setOpen} modal={false}>
<PopoverTrigger asChild>
<ComboboxTrigger
size={size}
disabled={!!disabled}
aria-expanded={open}
data-state={open ? 'open' : 'closed'}
className={size === 'small' ? 'py-1.5' : undefined}
>
{value ? (
<span className="flex w-full gap-1">
<span className="text-foreground-lighter">function:</span>
<span className="text-foreground">{value}</span>
</span>
) : (
<span className="flex w-full gap-1 text-foreground-lighter">Select a function</span>
)}
</ComboboxTrigger>
</PopoverTrigger>
<PopoverContent className="p-0" side="bottom" align="start" sameWidthAsTrigger>
<Command>
<CommandInput placeholder="Search functions..." />
<CommandList>
<CommandEmpty>No functions found</CommandEmpty>
<CommandGroup>
<ScrollArea className={(functions || []).length > 7 ? 'h-[210px]' : ''}>
{!functions.length && (
<CommandItem
key="no-function-found"
disabled={true}
className="flex items-center justify-between space-x-2 w-full"
>
{noResultsLabel}
</CommandItem>
)}
{functions.map((func) => (
<CommandItem
key={func.id}
value={func.name.replaceAll('"', '')}
className="cursor-pointer flex items-center justify-between space-x-2 w-full"
onSelect={() => {
onChange(func.name)
setOpen(false)
}}
onClick={() => {
onChange(func.name)
setOpen(false)
}}
>
<span>{func.name}</span>
{value === func.name && (
<Check className="text-brand" size={14} strokeWidth={2} />
)}
</CommandItem>
))}
</ScrollArea>
</CommandGroup>
<CommandSeparator />
<CommandGroup>
<CommandItemLink
href={`/project/${ref}/database/functions`}
className="cursor-pointer w-full gap-2"
onSelect={() => setOpen(false)}
>
<Plus size={14} strokeWidth={1.5} />
<p>New function</p>
</CommandItemLink>
</CommandGroup>
</CommandList>
</Command>
</PopoverContent>
</Popover>
)}
</div>
)
}
export default FunctionSelector