mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
## What kind of change does this PR introduce? Refactor. Follow-up to #49871. ## What is the current behavior? Branded (green) text still uses the `text-brand` classname while the colour comes from `--primary`. ## What is the new behavior? **Rename-only:** `text-brand` → `text-primary` across callsites and docs. Leftover `bg-brand` / `border-brand` alias to `brand-default`. No intentional colour changes in this PR. This better matches how we treat our green in other components and props, like `variant="primary"` for green buttons. ## To test On light mode: smoke-test that branded text still looks like #49871 (readable green, not the bright fill). - [Homepage](https://zone-www-dot-com-git-dnywh-depr-316-text-brand-de2380-supabase.vercel.app/): “Scale to millions” uses `text-primary` - [Docs homepage](https://docs-git-dnywh-depr-316-text-brand-to-primary-supabase.vercel.app/docs): branded links like “More on self-hosting” are still readable - [Typography docs](https://design-system-git-dnywh-depr-316-text-brand-to-primary-supabase.vercel.app/design-system/docs/typography): documents `text-primary` - [Colour usage](https://design-system-git-dnywh-depr-316-text-brand-to-primary-supabase.vercel.app/design-system/docs/color-usage): `text-primary` is visibly darker than `bg-brand-default` _on light mode_ - [Studio auth providers](https://studio-staging-git-dnywh-depr-316-text-brand-to-60fa6c-supabase.vercel.app/dashboard/project/_/auth/providers): enabled provider badge text readable; status dot stays bright green <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Style** * Updated branded text, link hover states, icons, badges, indicators, and highlighted content across the Design System, Docs, Studio, Learn, UI Library, and marketing experiences to use the primary theme color. * Updated syntax highlighting and table-of-contents styling for consistent primary-color presentation. * Refined brand color fallback behavior for bright fills and borders. * **Documentation** * Updated color-usage and typography guidance to recommend the primary text utility. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
177 lines
5.5 KiB
TypeScript
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-primary" 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
|