mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
## Context For database extensions, previously dashboard would fire a separate call just to retrieve the "default schema" for an extension via `useDatabaseExtensionDefaultSchemaQuery` from the `pg_available_extension_versions` table (the `schema` from this table implies where the extension will be installed in) ## Changes involved Am updating the `useDatabaseExtensionsQuery` to use a custom studio SQL that will fetch this data in one request via a `LEFT JOIN`, so dashboard no longer needs to fire a request to `pg_available_extension_versions` each time we open the `EnableExtensionModal` since all the info we need is loaded up front. Have also validated that the cost of the custom studio SQL is low (6.8, via explain analyze) so performance wise on the project's DB should be okay. This will then also allow us to correctly render the "default schema" of the extensions in the new Install Integration Sheet now that we have that information up front. ## Misc fix Also fixed a small issue on the database extensions page whereby if you searched for an extension that's hidden (e.g pg_tle), there's no "No results" UI state showing up <img width="1112" height="319" alt="image" src="https://github.com/user-attachments/assets/eb488117-2a24-4317-ad73-1d636f9b1bc8" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Per-extension default schema detection surfaced across install flows; default schema options added to selectors when applicable. * **Bug Fixes** * Hidden extensions filtered out earlier so they no longer appear in lists. * Install button now correctly disables when required extensions are missing. * **Refactor** * Consolidated extensions metadata retrieval and simplified schema selection/validation logic; UI text formatting standardized. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
132 lines
4.7 KiB
TypeScript
132 lines
4.7 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { useParams } from 'common'
|
|
import { isNull, partition } from 'lodash'
|
|
import { AlertCircle, Search } from 'lucide-react'
|
|
import { useEffect, useState } from 'react'
|
|
import {
|
|
Card,
|
|
Input,
|
|
ShadowScrollArea,
|
|
Table,
|
|
TableBody,
|
|
TableCell,
|
|
TableHead,
|
|
TableHeader,
|
|
TableRow,
|
|
} from 'ui'
|
|
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { ExtensionRow } from './ExtensionRow'
|
|
import { HIDDEN_EXTENSIONS, SEARCH_TERMS } from './Extensions.constants'
|
|
import InformationBox from '@/components/ui/InformationBox'
|
|
import { NoSearchResults } from '@/components/ui/NoSearchResults'
|
|
import { useDatabaseExtensionsQuery } from '@/data/database-extensions/database-extensions-query'
|
|
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
|
|
export const Extensions = () => {
|
|
const { filter } = useParams()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const [filterString, setFilterString] = useState<string>('')
|
|
|
|
const { data = [], isPending: isLoading } = useDatabaseExtensionsQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
})
|
|
|
|
const visibleExtensions = data.filter((ext) => !HIDDEN_EXTENSIONS.includes(ext.name))
|
|
const extensions =
|
|
filterString.length === 0
|
|
? visibleExtensions
|
|
: visibleExtensions.filter((ext) => {
|
|
const nameMatchesSearch = ext.name.toLowerCase().includes(filterString.toLowerCase())
|
|
const searchTermsMatchesSearch = (SEARCH_TERMS[ext.name] || []).some((x) =>
|
|
x.includes(filterString.toLowerCase())
|
|
)
|
|
return nameMatchesSearch || searchTermsMatchesSearch
|
|
})
|
|
const [enabledExtensions, disabledExtensions] = partition(
|
|
extensions,
|
|
(ext) => !isNull(ext.installed_version)
|
|
)
|
|
|
|
const { can: canUpdateExtensions, isSuccess: isPermissionsLoaded } = useAsyncCheckPermissions(
|
|
PermissionAction.TENANT_SQL_ADMIN_WRITE,
|
|
'extensions'
|
|
)
|
|
|
|
useEffect(() => {
|
|
if (filter !== undefined) setFilterString(filter as string)
|
|
}, [filter])
|
|
|
|
return (
|
|
<>
|
|
<div className="mb-4">
|
|
<Input
|
|
size="tiny"
|
|
placeholder="Search for an extension"
|
|
value={filterString}
|
|
onChange={(e) => setFilterString(e.target.value)}
|
|
className="w-52"
|
|
icon={<Search />}
|
|
/>
|
|
</div>
|
|
|
|
{isPermissionsLoaded && !canUpdateExtensions && (
|
|
<InformationBox
|
|
icon={<AlertCircle className="text-foreground-light" size={18} strokeWidth={2} />}
|
|
title="You need additional permissions to update database extensions"
|
|
/>
|
|
)}
|
|
|
|
{isLoading ? (
|
|
<GenericSkeletonLoader />
|
|
) : (
|
|
<Card>
|
|
<ShadowScrollArea stickyLastColumn>
|
|
<Table>
|
|
<TableHeader>
|
|
<TableRow>
|
|
<TableHead key="name">Name</TableHead>
|
|
<TableHead key="version">Version</TableHead>
|
|
<TableHead key="schema">Schema</TableHead>
|
|
<TableHead key="description">Description</TableHead>
|
|
<TableHead key="used-by">Used by</TableHead>
|
|
<TableHead key="links">Links</TableHead>
|
|
{/*
|
|
[Joshen] All these classes are just to make the last column sticky
|
|
I reckon we can pull these out into the Table component where we can declare
|
|
sticky columns via props, but we can do that if we start to have more tables
|
|
in the dashboard with sticky columns
|
|
*/}
|
|
<TableHead key="enabled" className="px-0">
|
|
<div className="!bg-200 px-4 w-full h-full flex items-center border-l">
|
|
Enabled
|
|
</div>
|
|
</TableHead>
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{[...enabledExtensions, ...disabledExtensions].map((extension) => (
|
|
<ExtensionRow key={extension.name} extension={extension} />
|
|
))}
|
|
{extensions.length === 0 && (
|
|
<TableRow>
|
|
<TableCell colSpan={7}>
|
|
<NoSearchResults
|
|
className="border-none !p-0 bg-transparent"
|
|
searchString={filterString}
|
|
onResetFilter={() => setFilterString('')}
|
|
/>
|
|
</TableCell>
|
|
</TableRow>
|
|
)}
|
|
</TableBody>
|
|
</Table>
|
|
</ShadowScrollArea>
|
|
</Card>
|
|
)}
|
|
</>
|
|
)
|
|
}
|