Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Use MultiSelectV2 component for Data API settings -> extra search path (#39283)

Joshen Lim3df618c0e6f6
diff --git a/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx b/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx
index 33fddb3c71e..7b59187c6d7 100644
--- a/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx
+++ b/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx
@@ -55,7 +55,7 @@ import { HardenAPIModal } from './HardenAPIModal'
const formSchema = z
.object({
dbSchema: z.array(z.string()),
- dbExtraSearchPath: z.string(),
+ dbExtraSearchPath: z.array(z.string()),
maxRows: z.number().max(1000000, "Can't be more than 1,000,000"),
dbPool: z
.number()
@@ -84,15 +84,26 @@ export const PostgrestConfig = () => {
const [showModal, setShowModal] = useState(false)
- const { data: config, isError, isLoading } = useProjectPostgrestConfigQuery({ projectRef })
+ const {
+ data: config,
+ isError,
+ isLoading: isLoadingConfig,
+ } = useProjectPostgrestConfigQuery({ projectRef })
const { data: extensions } = useDatabaseExtensionsQuery({
projectRef: project?.ref,
connectionString: project?.connectionString,
})
- const { data: schemas, isLoading: isLoadingSchemas } = useSchemasQuery({
+ const {
+ data: allSchemas = [],
+ isLoading: isLoadingSchemas,
+ isSuccess: isSuccessSchemas,
+ } = useSchemasQuery({
projectRef: project?.ref,
connectionString: project?.connectionString,
})
+
+ const isLoading = isLoadingConfig || isLoadingSchemas
+
const { mutate: updatePostgrestConfig, isLoading: isUpdating } =
useProjectPostgrestConfigUpdateMutation({
onSuccess: () => {
@@ -112,7 +123,10 @@ export const PostgrestConfig = () => {
const defaultValues = {
dbSchema,
maxRows: config?.max_rows,
- dbExtraSearchPath: config?.db_extra_search_path,
+ dbExtraSearchPath: (config?.db_extra_search_path ?? '')
+ .split(',')
+ .map((x) => x.trim())
+ .filter((x) => x.length > 0 && allSchemas.find((y) => y.name === x)),
dbPool: config?.db_pool,
}
@@ -122,9 +136,9 @@ export const PostgrestConfig = () => {
defaultValues,
})
- const schema =
- schemas
- ?.filter((x) => {
+ const schemas =
+ allSchemas
+ .filter((x) => {
const find = indexOf(hiddenSchema, x.name)
if (find < 0) return x
})
@@ -149,20 +163,20 @@ export const PostgrestConfig = () => {
projectRef,
dbSchema: values.dbSchema.join(', '),
maxRows: values.maxRows,
- dbExtraSearchPath: values.dbExtraSearchPath,
+ dbExtraSearchPath: values.dbExtraSearchPath.join(','),
dbPool: values.dbPool ? values.dbPool : null,
})
}
useEffect(() => {
- if (config) {
+ if (config && isSuccessSchemas) {
/**
* Checks if enableDataApi should be enabled or disabled
* based on the db_schema value being empty string
*/
resetForm()
}
- }, [config])
+ }, [config, isSuccessSchemas])
const isDataApiEnabledInForm = form.getValues('enableDataApi')
@@ -277,21 +291,16 @@ export const PostgrestConfig = () => {
/>
<MultiSelectorContent>
<MultiSelectorList>
- {schema.length <= 0 ? (
+ {schemas.length <= 0 ? (
<MultiSelectorItem key="empty" value="no">
no
</MultiSelectorItem>
) : (
- <>
- {schema.map((x) => (
- <MultiSelectorItem
- key={x.id + '-' + x.name}
- value={x.name}
- >
- {x.name}
- </MultiSelectorItem>
- ))}
- </>
+ schemas.map((x) => (
+ <MultiSelectorItem key={x.id + '-' + x.name} value={x.name}>
+ {x.name}
+ </MultiSelectorItem>
+ ))
)}
</MultiSelectorList>
</MultiSelectorContent>
@@ -341,15 +350,43 @@ export const PostgrestConfig = () => {
className="w-full px-8 py-8"
layout="horizontal"
label="Extra search path"
- description="Extra schemas to add to the search path of every request. Multiple schemas must be comma-separated."
+ description="Extra schemas to add to the search path of every request."
>
- <FormControl_Shadcn_>
- <Input_Shadcn_
+ {isLoadingSchemas ? (
+ <div className="col-span-12 flex flex-col gap-2 lg:col-span-7">
+ <Skeleton className="w-full h-[38px]" />
+ </div>
+ ) : (
+ <MultiSelector
+ onValuesChange={field.onChange}
+ values={field.value}
size="small"
disabled={!canUpdatePostgrestConfig || !isDataApiEnabledInForm}
- {...field}
- />
- </FormControl_Shadcn_>
+ >
+ <MultiSelectorTrigger
+ mode="inline-combobox"
+ label="Select schemas to add to search path..."
+ badgeLimit="wrap"
+ showIcon={false}
+ deletableBadge
+ />
+ <MultiSelectorContent>
+ <MultiSelectorList>
+ {allSchemas.length <= 0 ? (
+ <MultiSelectorItem key="empty" value="no">
+ no
+ </MultiSelectorItem>
+ ) : (
+ allSchemas.map((x) => (
+ <MultiSelectorItem key={x.id + '-' + x.name} value={x.name}>
+ {x.name}
+ </MultiSelectorItem>
+ ))
+ )}
+ </MultiSelectorList>
+ </MultiSelectorContent>
+ </MultiSelector>
+ )}
</FormItemLayout>
</FormItem_Shadcn_>
)}
diff --git a/apps/studio/components/interfaces/Settings/API/ServiceList.tsx b/apps/studio/components/interfaces/Settings/API/ServiceList.tsx
index 34145807e93..2b16008778b 100644
--- a/apps/studio/components/interfaces/Settings/API/ServiceList.tsx
+++ b/apps/studio/components/interfaces/Settings/API/ServiceList.tsx
@@ -3,7 +3,6 @@ import { AlertCircle } from 'lucide-react'
import { useParams } from 'common'
import { ScaffoldSection } from 'components/layouts/Scaffold'
import DatabaseSelector from 'components/ui/DatabaseSelector'
-import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { useCustomDomainsQuery } from 'data/custom-domains/custom-domains-query'
import { useLoadBalancersQuery } from 'data/read-replicas/load-balancers-query'
import { useReadReplicasQuery } from 'data/read-replicas/replicas-query'
@@ -13,6 +12,7 @@ import { useDatabaseSelectorStateSnapshot } from 'state/database-selector'
import { Alert_Shadcn_, AlertTitle_Shadcn_, Badge, Card, CardContent, CardHeader } from 'ui'
import { Input } from 'ui-patterns/DataInputs/Input'
import { FormLayout } from 'ui-patterns/form/Layout/FormLayout'
+import ShimmeringLoader from 'ui-patterns/ShimmeringLoader'
import { PostgrestConfig } from './PostgrestConfig'
export const ServiceList = () => {
@@ -65,7 +65,10 @@ export const ServiceList = () => {
</CardHeader>
<CardContent>
{isLoading || isLoadingDatabases ? (
- <GenericSkeletonLoader />
+ <div className="space-y-2">
+ <ShimmeringLoader className="py-3.5" />
+ <ShimmeringLoader className="py-3.5 w-3/4" delayIndex={1} />
+ </div>
) : isError ? (
<Alert_Shadcn_ variant="destructive">
<AlertCircle size={16} />