The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore(studio): update data api form pattern (#41306)
Francesco Sansalvadore2c5b71aeee26
diff --git a/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx b/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsxindex cbc8668829d..1d88dcdf0d5 100644--- a/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx+++ b/apps/studio/components/interfaces/Settings/API/PostgrestConfig.tsx@@ -34,6 +34,7 @@ import {FormItem_Shadcn_,Form_Shadcn_,Input_Shadcn_,+ PrePostTab,Separator,Skeleton,Switch,@@ -201,23 +202,26 @@ export const PostgrestConfig = () => {</Button></div></CardHeader>- <CardContent className={cn(!isLoading ? 'p-0' : '')}>- <Form_Shadcn_ {...form}>- <form id={formId} onSubmit={form.handleSubmit(onSubmit)}>- {isLoading ? (+ <Form_Shadcn_ {...form}>+ <form id={formId} onSubmit={form.handleSubmit(onSubmit)}>+ {isLoading ? (+ <CardContent><GenericSkeletonLoader />- ) : isError ? (+ </CardContent>+ ) : isError ? (+ <CardContent><Admonition type="destructive" title="Failed to retrieve API settings" />- ) : (- <>+ </CardContent>+ ) : (+ <>+ <CardContent><FormField_Shadcn_control={form.control}name="enableDataApi"render={({ field }) => (- <FormItem_Shadcn_ className="w-full">+ <FormItem_Shadcn_ className="space-y-4"><FormItemLayout- className="w-full px-[var(--card-padding-x)] py-4"- layout="flex"+ layout="flex-row-reverse"label="Enable Data API"description="When enabled you will be able to use any Supabase client library and PostgREST endpoints with any schema configured below.">@@ -241,45 +245,38 @@ export const PostgrestConfig = () => {</FormItemLayout>{!field.value && (- <>- <Separator />- <Alert_Shadcn_- variant="warning"- className="mb-0 border-none rounded-none"- >- <WarningIcon className="!left-[2rem]" />- <AlertTitle_Shadcn_ className="!pl-[3.5rem] !left-[6rem]">- No schemas can be queried- </AlertTitle_Shadcn_>- <AlertDescription_Shadcn_ className="!pl-[3.5rem]">- <p>- With this setting disabled, you will not be able to query any- schemas via the Data API.- </p>- <p>- You will see errors from the Postgrest endpoint- <code className="text-code-inline">/rest/v1/</code>.- </p>- </AlertDescription_Shadcn_>- </Alert_Shadcn_>- </>+ <Alert_Shadcn_ variant="warning">+ <WarningIcon />+ <AlertTitle_Shadcn_>No schemas can be queried</AlertTitle_Shadcn_>+ <AlertDescription_Shadcn_>+ <p>+ With this setting disabled, you will not be able to query any schemas+ via the Data API.+ </p>+ <p>+ You will see errors from the Postgrest endpoint+ <code className="text-code-inline">/rest/v1/</code>.+ </p>+ </AlertDescription_Shadcn_>+ </Alert_Shadcn_>)}</FormItem_Shadcn_>)}/>- <Collapsible_Shadcn_ open={form.getValues('enableDataApi')}>- <CollapsibleContent_Shadcn_ className="border-t divide-y transition-all data-[state=closed]:animate-collapsible-up data-[state=open]:animate-collapsible-down">+ </CardContent>+ <Collapsible_Shadcn_ open={form.getValues('enableDataApi')}>+ <CollapsibleContent_Shadcn_ className="transition-all data-[state=closed]:animate-collapsible-up data-[state=open]:animate-collapsible-down">+ <CardContent><FormField_Shadcn_control={form.control}name="dbSchema"render={({ field }) => (- <FormItem_Shadcn_ className="w-full">+ <FormItem_Shadcn_><FormItemLayoutlabel="Exposed schemas"description="The schemas to expose in your API. Tables, views and stored procedures inthese schemas will get API endpoints."- layout="horizontal"- className="px-[var(--card-padding-x)] py-4"+ layout="flex-row-reverse">{isLoadingSchemas ? (<div className="col-span-12 flex flex-col gap-2 lg:col-span-7">@@ -294,7 +291,7 @@ export const PostgrestConfig = () => {><MultiSelectorTriggermode="inline-combobox"- label="Select schemas for Data API..."+ label="Select schemas..."badgeLimit="wrap"showIcon={false}deletableBadge@@ -351,15 +348,15 @@ export const PostgrestConfig = () => {</FormItem_Shadcn_>)}/>-+ </CardContent>+ <CardContent><FormField_Shadcn_control={form.control}name="dbExtraSearchPath"render={({ field }) => (- <FormItem_Shadcn_ className="w-full">+ <FormItem_Shadcn_><FormItemLayout- className="w-full px-[var(--card-padding-x)] py-4"- layout="horizontal"+ layout="flex-row-reverse"label="Extra search path"description="Extra schemas to add to the search path of every request.">@@ -376,7 +373,7 @@ export const PostgrestConfig = () => {><MultiSelectorTriggermode="inline-combobox"- label="Select schemas to add to search path..."+ label="Select schemas..."badgeLimit="wrap"showIcon={false}deletableBadge@@ -402,72 +399,74 @@ export const PostgrestConfig = () => {</FormItem_Shadcn_>)}/>-+ </CardContent>+ <CardContent><FormField_Shadcn_control={form.control}name="maxRows"render={({ field }) => (- <FormItem_Shadcn_ className="w-full">+ <FormItem_Shadcn_><FormItemLayout- className="w-full px-[var(--card-padding-x)] py-4"- layout="horizontal"+ layout="flex-row-reverse"label="Max rows"description="The maximum number of rows returned from a view, table, or stored procedure. Limits payload size for accidental or malicious requests."><FormControl_Shadcn_>- <Input_Shadcn_- size="small"- disabled={!canUpdatePostgrestConfig || !isDataApiEnabledInForm}- {...field}- type="number"- {...form.register('maxRows', {- valueAsNumber: true, // Ensure the value is handled as a number- })}- />+ <PrePostTab postTab="rows">+ <Input_Shadcn_+ size="small"+ disabled={!canUpdatePostgrestConfig || !isDataApiEnabledInForm}+ {...field}+ type="number"+ onChange={(e) => field.onChange(Number(e.target.value))}+ />+ </PrePostTab></FormControl_Shadcn_></FormItemLayout></FormItem_Shadcn_>)}/>-+ </CardContent>+ <CardContent><FormField_Shadcn_control={form.control}name="dbPool"render={({ field }) => (- <FormItem_Shadcn_ className="w-full">+ <FormItem_Shadcn_><FormItemLayout- className="w-full px-[var(--card-padding-x)] py-4"- layout="horizontal"+ layout="flex-row-reverse"label="Pool size"description="Number of maximum connections to keep open in the Data API server's database pool. Unset to let it be configured automatically based on compute size."><FormControl_Shadcn_>- <Input_Shadcn_- size="small"- disabled={!canUpdatePostgrestConfig || !isDataApiEnabledInForm}- {...field}- type="number"- placeholder="Configured automatically based on compute size"- onChange={(e) =>- field.onChange(- e.target.value === '' ? null : Number(e.target.value)- )- }- value={field.value === null ? '' : field.value}- />+ <PrePostTab postTab="connections">+ <Input_Shadcn_+ size="small"+ disabled={!canUpdatePostgrestConfig || !isDataApiEnabledInForm}+ {...field}+ type="number"+ placeholder="Configured automatically"+ onChange={(e) =>+ field.onChange(+ e.target.value === '' ? null : Number(e.target.value)+ )+ }+ value={field.value === null ? '' : field.value}+ />+ </PrePostTab></FormControl_Shadcn_></FormItemLayout></FormItem_Shadcn_>)}/>- </CollapsibleContent_Shadcn_>- </Collapsible_Shadcn_>- </>- )}- </form>- </Form_Shadcn_>- </CardContent>- <CardFooter>+ </CardContent>+ </CollapsibleContent_Shadcn_>+ </Collapsible_Shadcn_>+ </>+ )}+ </form>+ </Form_Shadcn_>+ <CardFooter className="border-t"><FormActionsform={formId}isSubmitting={isUpdating}diff --git a/apps/studio/components/interfaces/Settings/API/ServiceList.tsx b/apps/studio/components/interfaces/Settings/API/ServiceList.tsxindex 453eec2fff6..e4c4d00f502 100644--- a/apps/studio/components/interfaces/Settings/API/ServiceList.tsx+++ b/apps/studio/components/interfaces/Settings/API/ServiceList.tsx@@ -89,7 +89,7 @@ export const ServiceList = () => {</Alert_Shadcn_>) : (<FormLayout- layout="horizontal"+ layout="flex-row-reverse"label={isCustomDomainActive ? (<div className="flex items-center space-x-2">@@ -107,6 +107,7 @@ export const ServiceList = () => {? 'RESTful endpoint for querying your read replica': 'RESTful endpoint for querying and managing your database'}+ className="[&>div]:xl:w-1/2 [&>div>div]:w-full"><Input copy readOnly className="font-mono" value={endpoint} /></FormLayout>