mirror of
https://github.com/supabase/supabase.git
synced 2026-09-09 03:19:36 +08:00
Hides the "Multigres" term from user-facing surfaces — it's the tech powering High Availability projects, but "High Availability" is the only term users should see for now (per Slack discussion with Saxon/Ivan). **Changed:** - High Availability badge hover card (project overview) no longer says "Driven by Multigres" - Project creation HA toggle description drops the Multigres name + multigres.com link, keeps the informational copy - All schema dropdowns now hide the `multigres` schema on HA projects, by wiring in the previously-unused `filterSchemasForHighAvailability` helper: - `SchemaSelector` (shared — Table Editor, Functions, Indexes, Triggers, Schema Visualizer, etc.) - `ExposedSchemaSelector` (API settings → exposed schemas) - `EnableExtensionModal`, `CreateIndexSidePanel`, `ForeignKeySelector`, `WrapperTableEditor`, Integrations install sheet `AdvancedSettings` - SQL editor schema autocomplete (`useAddDefinitions`) - Schema list computations in the touched components are now memoized (incl. stabilizing `SchemaSelector`'s `excludedSchemas` default so the memo actually holds) **Added:** - Unit tests for `filterSchemasForHighAvailability` / `resolveHighAvailability` - MSW component test for `SchemaSelector` asserting `multigres` is hidden on HA projects and still shown on non-HA projects The filter is HA-gated on purpose: a self-hosted/non-HA user with their own schema named `multigres` still sees it. The flag-gated Multigres option in Logs is intentionally untouched — that exposure is kept for the Multigres team's debugging (separate track). ## To test - On an HA project (`high_availability: true`): hover the High Availability badge on project overview — no "Multigres" mention; open schema dropdowns in Table Editor / Database pages / SQL editor autocomplete — no `multigres` schema - Project creation with HA entitlement: toggle description has no Multigres wording/link - On a non-HA project: schema dropdowns behave as before <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Improvements** * Made schema dropdowns and related selectors high-availability aware across extensions, indexes, integrations, SQL editing, API exposed schemas, and relationship editors. * Updated project high-availability UI text and badge hover description to remove outdated branding and clarify horizontally scalable Postgres architecture. * **Tests** * Added coverage to ensure the schema “multigres” option is hidden/shown correctly based on high availability, and validated high-availability value handling. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
207 lines
7.4 KiB
TypeScript
207 lines
7.4 KiB
TypeScript
import { Check, ChevronsUpDown } from 'lucide-react'
|
|
import { useMemo, useState } from 'react'
|
|
import {
|
|
Button,
|
|
cn,
|
|
Command,
|
|
CommandEmpty,
|
|
CommandGroup,
|
|
CommandInput,
|
|
CommandItem,
|
|
CommandList,
|
|
Popover,
|
|
PopoverContent,
|
|
PopoverTrigger,
|
|
ScrollArea,
|
|
} from 'ui'
|
|
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { getExposedSchemaCounts } from './ExposedSchemaSelector.utils'
|
|
import { useSchemasQuery } from '@/data/database/schemas-query'
|
|
import {
|
|
MULTIGRES_SCHEMA_NAME,
|
|
useHighAvailability,
|
|
useSchemasFilteredForHighAvailability,
|
|
} from '@/hooks/misc/useHighAvailability'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { INTERNAL_SCHEMAS } from '@/hooks/useProtectedSchemas'
|
|
import { pluralize } from '@/lib/helpers'
|
|
|
|
/**
|
|
* [Joshen] This would only affect graphql_public and pgmq_public, given that they're intended
|
|
* to be public, we can let users expose them via the API, but not let them adjust the schema via the dashboard
|
|
* */
|
|
export const internalSchemasCannotExpose = new Set(
|
|
INTERNAL_SCHEMAS.filter((x) => !x.endsWith('_public'))
|
|
)
|
|
|
|
interface ExposedSchemaSelectorProps {
|
|
/**
|
|
* When true the dropdown can still be opened to inspect which schemas are exposed (e.g.
|
|
* self-hosted, where schemas are managed via PGRST_DB_SCHEMAS), but schemas can't be toggled.
|
|
*/
|
|
readOnly?: boolean
|
|
selectedSchemas: string[]
|
|
onToggleSchema: (schema: string) => void
|
|
}
|
|
|
|
export const ExposedSchemaSelector = ({
|
|
readOnly = false,
|
|
selectedSchemas,
|
|
onToggleSchema,
|
|
}: ExposedSchemaSelectorProps) => {
|
|
const [open, setOpen] = useState(false)
|
|
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const { isHighAvailability } = useHighAvailability()
|
|
|
|
const {
|
|
data: allSchemas,
|
|
isPending,
|
|
isError,
|
|
isSuccess,
|
|
} = useSchemasQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
})
|
|
|
|
const visibleSchemas = useSchemasFilteredForHighAvailability(allSchemas)
|
|
const schemas = useMemo(
|
|
() =>
|
|
visibleSchemas
|
|
.filter((s) => !internalSchemasCannotExpose.has(s.name))
|
|
.sort((a, b) => a.name.localeCompare(b.name)),
|
|
[visibleSchemas]
|
|
)
|
|
|
|
// Persisted selections go through the same HA filtering as the schema list, so a
|
|
// multigres schema exposed in the config doesn't render as a "missing" schema row.
|
|
const visibleSelectedSchemas = useMemo(
|
|
() =>
|
|
isHighAvailability
|
|
? selectedSchemas.filter((schema) => schema !== MULTIGRES_SCHEMA_NAME)
|
|
: selectedSchemas,
|
|
[selectedSchemas, isHighAvailability]
|
|
)
|
|
|
|
const missingExposedSchema = useMemo(
|
|
() => visibleSelectedSchemas.filter((schema) => !schemas.some((s) => s.name === schema)),
|
|
[schemas, visibleSelectedSchemas]
|
|
)
|
|
|
|
const selectedSet = useMemo(() => new Set(visibleSelectedSchemas), [visibleSelectedSchemas])
|
|
const { selectedCount, totalCount } = getExposedSchemaCounts({
|
|
visibleSchemas: schemas.map((s) => s.name),
|
|
selectedSchemas: visibleSelectedSchemas,
|
|
protectedSchemas: internalSchemasCannotExpose,
|
|
})
|
|
|
|
return (
|
|
<Popover open={open} onOpenChange={setOpen} modal={false}>
|
|
<PopoverTrigger asChild>
|
|
<Button
|
|
size="small"
|
|
variant="default"
|
|
className="w-full [&>span]:w-full pr-1! space-x-1"
|
|
iconRight={<ChevronsUpDown className="text-foreground-muted" strokeWidth={2} size={14} />}
|
|
>
|
|
<div className="w-full flex gap-1">
|
|
<p className="text-foreground-lighter">
|
|
{isSuccess
|
|
? `${selectedCount} of ${totalCount} ${pluralize(totalCount, 'schema')} exposed`
|
|
: 'Loading schemas...'}
|
|
</p>
|
|
</div>
|
|
</Button>
|
|
</PopoverTrigger>
|
|
<PopoverContent
|
|
className="p-0 min-w-[200px] pointer-events-auto"
|
|
side="bottom"
|
|
align="start"
|
|
sameWidthAsTrigger
|
|
>
|
|
<Command>
|
|
<CommandInput className="text-xs" placeholder="Find schema..." />
|
|
<CommandList>
|
|
<CommandGroup>
|
|
{isPending ? (
|
|
<>
|
|
<div className="px-2 py-1">
|
|
<ShimmeringLoader className="py-2" />
|
|
</div>
|
|
<div className="px-2 py-1 w-4/5">
|
|
<ShimmeringLoader className="py-2" />
|
|
</div>
|
|
</>
|
|
) : isError ? (
|
|
<div className="flex items-center py-3 justify-center">
|
|
<p className="text-xs text-foreground-lighter">Failed to retrieve schemas</p>
|
|
</div>
|
|
) : (
|
|
<>
|
|
<CommandEmpty>
|
|
<p className="text-xs text-center text-foreground-lighter py-3">
|
|
No schemas found
|
|
</p>
|
|
</CommandEmpty>
|
|
<ScrollArea className={schemas.length > 7 ? 'h-[210px]' : ''}>
|
|
{missingExposedSchema.map((schema) => (
|
|
<CommandItem
|
|
key={schema}
|
|
value={schema}
|
|
className={cn('w-full', readOnly ? 'cursor-default' : 'cursor-pointer')}
|
|
onSelect={() => {
|
|
if (readOnly) return
|
|
onToggleSchema(schema)
|
|
}}
|
|
>
|
|
<div className="w-full flex flex-col">
|
|
<div className="w-full flex items-center gap-x-2">
|
|
<Check size={16} className="text-brand shrink-0" />
|
|
<span className="truncate">{schema}</span>
|
|
</div>
|
|
{internalSchemasCannotExpose.has(schema) ? (
|
|
<span className="pl-6 text-warning text-xs tracking-tight">
|
|
This schema is protected and should not be exposed
|
|
</span>
|
|
) : (
|
|
<span className="pl-6 text-foreground-lighter text-xs tracking-tight">
|
|
This schema does not exist and can be safely removed
|
|
</span>
|
|
)}
|
|
</div>
|
|
</CommandItem>
|
|
))}
|
|
{schemas.map((schema) => {
|
|
const isExposed = selectedSet.has(schema.name)
|
|
|
|
return (
|
|
<CommandItem
|
|
key={schema.id}
|
|
value={schema.name}
|
|
className={cn('w-full', readOnly ? 'cursor-default' : 'cursor-pointer')}
|
|
onSelect={() => {
|
|
if (readOnly) return
|
|
onToggleSchema(schema.name)
|
|
}}
|
|
>
|
|
<div
|
|
className={cn('w-full flex items-center gap-x-2', !isExposed && 'ml-6')}
|
|
>
|
|
{isExposed && <Check size={16} className="text-brand shrink-0" />}
|
|
<span className="truncate">{schema.name}</span>
|
|
</div>
|
|
</CommandItem>
|
|
)
|
|
})}
|
|
</ScrollArea>
|
|
</>
|
|
)}
|
|
</CommandGroup>
|
|
</CommandList>
|
|
</Command>
|
|
</PopoverContent>
|
|
</Popover>
|
|
)
|
|
}
|