The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: Updates to the create Iceberg FDW sheet (#36918)
Ivan Vasilovf7c43fb4500f
diff --git a/apps/studio/components/interfaces/Integrations/Wrappers/CreateIcebergWrapperSheet.tsx b/apps/studio/components/interfaces/Integrations/Wrappers/CreateIcebergWrapperSheet.tsxnew file mode 100644index 00000000000..745b0b27886--- /dev/null+++ b/apps/studio/components/interfaces/Integrations/Wrappers/CreateIcebergWrapperSheet.tsx@@ -0,0 +1,343 @@+import { isEmpty } from 'lodash'+import { useMemo, useState } from 'react'+import { toast } from 'sonner'++import SchemaEditor from 'components/interfaces/TableGridEditor/SidePanelEditor/SchemaEditor'+import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'+import { FormSection, FormSectionContent, FormSectionLabel } from 'components/ui/Forms/FormSection'+import SchemaSelector from 'components/ui/SchemaSelector'+import { useSchemasQuery } from 'data/database/schemas-query'+import { useFDWCreateMutation } from 'data/fdw/fdw-create-mutation'+import {+ Button,+ Form,+ Input,+ Label_Shadcn_,+ RadioGroupStacked,+ RadioGroupStackedItem,+ Separator,+ SheetFooter,+ SheetHeader,+ SheetTitle,+} from 'ui'+import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'+import { CreateWrapperSheetProps } from './CreateWrapperSheet'+import InputField from './InputField'+import { makeValidateRequired } from './Wrappers.utils'++const FORM_ID = 'create-wrapper-form'++const requiredFields: Record<Target, { name: string; required: boolean }[]> = {+ S3Tables: [+ { name: 'vault_aws_access_key_id', required: true },+ { name: 'vault_aws_secret_access_key', required: true },+ { name: 'region_name', required: true },+ { name: 'vault_aws_s3table_bucket_arn', required: true },+ ],+ R2Catalog: [+ { name: 'vault_aws_access_key_id', required: true },+ { name: 'vault_aws_secret_access_key', required: true },+ { name: 'vault_token', required: true },+ { name: 'warehouse', required: true },+ { name: 's3.endpoint', required: true },+ { name: 'catalog_uri', required: true },+ ],+ IcebergRestCatalog: [+ { name: 'vault_aws_access_key_id', required: false },+ { name: 'vault_aws_secret_access_key', required: false },+ { name: 'region_name', required: false },+ { name: 'vault_aws_s3table_bucket_arn', required: false },+ { name: 'vault_token', required: false },+ { name: 'warehouse', required: false },+ { name: 's3.endpoint', required: false },+ { name: 'catalog_uri', required: false },+ ],+} as const++type Target = 'S3Tables' | 'R2Catalog' | 'IcebergRestCatalog'++export const CreateIcebergWrapperSheet = ({+ wrapperMeta: wrapperMetaOriginal,+ isClosing,+ setIsClosing,+ onClose,+}: CreateWrapperSheetProps) => {+ const { project } = useProjectContext()++ const [createSchemaSheetOpen, setCreateSchemaSheetOpen] = useState(false)+ const [selectedTarget, setSelectedTarget] = useState<Target>('S3Tables')++ const [formErrors, setFormErrors] = useState<{ [k: string]: string }>({})++ const { mutate: createFDW, isLoading: isCreating } = useFDWCreateMutation({+ onSuccess: () => {+ toast.success(`Successfully created ${wrapperMeta?.label} foreign data wrapper`)+ onClose()+ },+ })++ const wrapperMeta = useMemo(() => {+ const fields = requiredFields[selectedTarget]++ return {+ ...wrapperMetaOriginal,+ server: {+ options: wrapperMetaOriginal.server.options+ // when the target changes, change the wrapperMeta field+ .filter((option) => fields.find((field) => field.name === option.name))+ .map((option) => {+ const field = fields.find((field) => field.name === option.name)+ return {+ ...option,+ required: field?.required ?? false,+ }+ }),+ },+ }+ }, [wrapperMetaOriginal, selectedTarget])++ // prefetch schemas to make sure the schema selector is populated+ useSchemasQuery({ projectRef: project?.ref, connectionString: project?.connectionString })++ const initialValues = {+ wrapper_name: '',+ server_name: '',+ source_schema: wrapperMeta.sourceSchemaOption?.defaultValue ?? '',+ target_schema: 'public',+ ...Object.fromEntries(+ wrapperMeta.server.options.map((option) => [option.name, option.defaultValue ?? ''])+ ),+ }++ const onSubmit = async (values: any) => {+ const validate = makeValidateRequired(wrapperMeta.server.options)+ const errors: any = validate(values)++ if (values.source_schema.length === 0) {+ errors.source_schema = 'Please provide a source schema'+ }+ if (values.wrapper_name.length === 0) {+ errors.wrapper_name = 'Please provide a name for your wrapper'+ }+ if (!isEmpty(errors)) return setFormErrors(errors)++ createFDW({+ projectRef: project?.ref,+ connectionString: project?.connectionString,+ wrapperMeta,+ formState: { ...values, server_name: `${values.wrapper_name}_server` },+ mode: 'schema',+ tables: [],+ sourceSchema: values.source_schema,+ targetSchema: values.target_schema,+ })+ }++ return (+ <>+ <div className="h-full" tabIndex={-1}>+ <Form+ id={FORM_ID}+ initialValues={initialValues}+ onSubmit={onSubmit}+ className="flex-grow flex flex-col h-full"+ >+ {({ values, initialValues, setFieldValue }: any) => {+ const hasChanges = JSON.stringify(values) !== JSON.stringify(initialValues)++ const onClosePanel = () => {+ if (hasChanges) {+ setIsClosing(true)+ } else {+ onClose()+ }+ }++ // if the form hasn't been touched and the user clicked esc or the backdrop, close the sheet+ if (!hasChanges && isClosing) {+ onClose()+ }++ return (+ <>+ <SheetHeader>+ <SheetTitle>Create a {wrapperMeta.label} wrapper</SheetTitle>+ </SheetHeader>+ <div className="flex-grow overflow-y-auto">+ <FormSection header={<FormSectionLabel>Wrapper Configuration</FormSectionLabel>}>+ <FormSectionContent loading={false}>+ <Input+ id="wrapper_name"+ label="Wrapper Name"+ error={formErrors.wrapper_name}+ descriptionText={+ (values?.wrapper_name ?? '').length > 0 ? (+ <>+ Your wrapper's server name will be{' '}+ <code className="text-xs">{values.wrapper_name}_server</code>+ </>+ ) : (+ ''+ )+ }+ />+ </FormSectionContent>+ </FormSection>+ <Separator />+ <FormSection header={<FormSectionLabel>Data target</FormSectionLabel>}>+ <FormSectionContent loading={false} className="text-sm">+ <RadioGroupStacked+ value={selectedTarget}+ onValueChange={(value) => setSelectedTarget(value as Target)}+ >+ <RadioGroupStackedItem+ key="S3Tables"+ value="S3Tables"+ label="AWS S3 Tables"+ showIndicator={false}+ >+ <div className="flex gap-x-5">+ <div className="flex flex-col">+ <p className="text-foreground-light text-left">+ AWS S3 storage that's optimized for analytics workloads.+ </p>+ </div>+ </div>+ </RadioGroupStackedItem>+ <RadioGroupStackedItem+ key="R2Catalog"+ value="R2Catalog"+ label="Cloudflare R2 Catalog"+ showIndicator={false}+ >+ <div className="flex gap-x-5">+ <div className="flex flex-col">+ <p className="text-foreground-light text-left">+ Managed Apache Iceberg built directly into your R2 bucket.+ </p>+ </div>+ </div>+ </RadioGroupStackedItem>+ <RadioGroupStackedItem+ key="IcebergRestCatalog"+ value="IcebergRestCatalog"+ label="Iceberg REST Catalog"+ showIndicator={false}+ >+ <div className="flex gap-x-5">+ <div className="flex flex-col">+ <p className="text-foreground-light text-left">+ Can be used with any S3-compatible storage.+ </p>+ </div>+ </div>+ </RadioGroupStackedItem>+ </RadioGroupStacked>+ </FormSectionContent>+ </FormSection>+ <FormSection+ header={<FormSectionLabel>{wrapperMeta.label} Configuration</FormSectionLabel>}+ >+ <FormSectionContent loading={false}>+ {wrapperMeta.server.options+ .filter((option) => !option.hidden)+ .map((option) => (+ <InputField+ key={option.name}+ option={option}+ loading={false}+ error={formErrors[option.name]}+ />+ ))}+ </FormSectionContent>+ </FormSection>+ <Separator />+ <FormSection+ header={+ <FormSectionLabel>+ <p>Foreign Schema</p>+ <p className="text-foreground-light mt-2 w-[90%]">+ All wrapper tables will be created in the specified target schema.+ </p>+ </FormSectionLabel>+ }+ >+ <FormSectionContent loading={false}>+ {wrapperMeta.sourceSchemaOption && (+ <div>+ <InputField+ key="source_schema"+ option={wrapperMeta.sourceSchemaOption}+ loading={false}+ error={formErrors['source_schema']}+ />+ <p className="text-foreground-lighter text-sm">+ {wrapperMeta.sourceSchemaOption.description}+ </p>+ </div>+ )}+ <div className="flex flex-col gap-2">+ <Label_Shadcn_ className="text-foreground-light">+ Target Schema+ </Label_Shadcn_>+ <SchemaSelector+ portal={false}+ size="small"+ selectedSchemaName={values.target_schema}+ onSelectSchema={(schema) => setFieldValue('target_schema', schema)}+ onSelectCreateSchema={() => setCreateSchemaSheetOpen(true)}+ />+ </div>+ </FormSectionContent>+ </FormSection>+ </div>++ <SheetFooter>+ <Button+ size="tiny"+ type="default"+ htmlType="button"+ onClick={onClosePanel}+ disabled={isCreating}+ >+ Cancel+ </Button>+ <Button+ size="tiny"+ type="primary"+ form={FORM_ID}+ htmlType="submit"+ disabled={isCreating}+ loading={isCreating}+ >+ Create wrapper+ </Button>+ </SheetFooter>+ <SchemaEditor+ visible={createSchemaSheetOpen}+ closePanel={() => setCreateSchemaSheetOpen(false)}+ onSuccess={(schema) => {+ setFieldValue('target_schema', schema)+ setCreateSchemaSheetOpen(false)+ }}+ />+ </>+ )+ }}+ </Form>+ </div>+ <ConfirmationModal+ visible={isClosing}+ title="Discard changes"+ confirmLabel="Discard"+ onCancel={() => setIsClosing(false)}+ onConfirm={() => onClose()}+ >+ <p className="text-sm text-foreground-light">+ There are unsaved changes. Are you sure you want to close the panel? Your changes will be+ lost.+ </p>+ </ConfirmationModal>+ </>+ )+}diff --git a/apps/studio/components/interfaces/Integrations/Wrappers/CreateWrapperSheet.tsx b/apps/studio/components/interfaces/Integrations/Wrappers/CreateWrapperSheet.tsxindex e2957799175..a8901afa481 100644--- a/apps/studio/components/interfaces/Integrations/Wrappers/CreateWrapperSheet.tsx+++ b/apps/studio/components/interfaces/Integrations/Wrappers/CreateWrapperSheet.tsx@@ -114,18 +114,22 @@ export const CreateWrapperSheet = ({const validate = makeValidateRequired(wrapperMeta.server.options)const errors: any = validate(values)- const { wrapper_name } = values- if (wrapper_name.length === 0) errors.name = 'Please provide a name for your wrapper'+ if (values.wrapper_name.length === 0) {+ errors.wrapper_name = 'Please provide a name for your wrapper'+ }if (selectedMode === 'tables' && newTables.length === 0) {errors.tables = 'Please add at least one table'}+ if (selectedMode === 'schema' && values.source_schema.length === 0) {+ errors.source_schema = 'Please provide a source schema'+ }if (!isEmpty(errors)) return setFormErrors(errors)createFDW({projectRef: project?.ref,connectionString: project?.connectionString,wrapperMeta,- formState: { ...values, server_name: `${wrapper_name}_server` },+ formState: { ...values, server_name: `${values.wrapper_name}_server` },mode: selectedMode,tables: newTables,sourceSchema: values.source_schema,diff --git a/apps/studio/components/interfaces/Integrations/Wrappers/EditWrapperSheet.tsx b/apps/studio/components/interfaces/Integrations/Wrappers/EditWrapperSheet.tsxindex 378a1395345..87703801cc5 100644--- a/apps/studio/components/interfaces/Integrations/Wrappers/EditWrapperSheet.tsx+++ b/apps/studio/components/interfaces/Integrations/Wrappers/EditWrapperSheet.tsx@@ -17,6 +17,7 @@ import InputField from './InputField'import { WrapperMeta } from './Wrappers.types'import {convertKVStringArrayToJson,+ FormattedWrapperTable,formatWrapperTables,makeValidateRequired,} from './Wrappers.utils'@@ -57,11 +58,11 @@ export const EditWrapperSheet = ({},})- const [wrapperTables, setWrapperTables] = useState<any[]>(- formatWrapperTables(wrapper, wrapperMeta)- )+ const [wrapperTables, setWrapperTables] = useState(formatWrapperTables(wrapper, wrapperMeta))const [isEditingTable, setIsEditingTable] = useState(false)- const [selectedTableToEdit, setSelectedTableToEdit] = useState()+ const [selectedTableToEdit, setSelectedTableToEdit] = useState<FormattedWrapperTable | undefined>(+ undefined+ )const [formErrors, setFormErrors] = useState<{ [k: string]: string }>({})const initialValues = {@@ -273,15 +274,18 @@ export const EditWrapperSheet = ({</p></div><div className="flex items-center space-x-2">- <Button- type="default"- className="px-1"- icon={<Edit />}- onClick={() => {- setIsEditingTable(true)- setSelectedTableToEdit({ ...table, tableIndex: i })- }}- />+ {/* Wrappers which import foreign schema don't have tables and their tables can't be edited */}+ {wrapperMeta.tables.length !== 0 && (+ <Button+ type="default"+ className="px-1"+ icon={<Edit />}+ onClick={() => {+ setIsEditingTable(true)+ setSelectedTableToEdit({ ...table, tableIndex: i })+ }}+ />+ )}<Buttontype="default"className="px-1"diff --git a/apps/studio/components/interfaces/Integrations/Wrappers/InputField.tsx b/apps/studio/components/interfaces/Integrations/Wrappers/InputField.tsxindex c44a54369a4..213aaccd1d2 100644--- a/apps/studio/components/interfaces/Integrations/Wrappers/InputField.tsx+++ b/apps/studio/components/interfaces/Integrations/Wrappers/InputField.tsx@@ -66,6 +66,7 @@ const InputField = ({ option, loading, error }: InputFieldProps) => {)}</div>}+ labelOptional={option.required ? undefined : 'Optional'}defaultValue={option.defaultValue ?? ''}error={error}value={loading ? 'Fetching value from Vault...' : undefined}diff --git a/apps/studio/components/interfaces/Integrations/Wrappers/OverviewTab.tsx b/apps/studio/components/interfaces/Integrations/Wrappers/OverviewTab.tsxindex 3dd175b146d..0e7cc5fe4df 100644--- a/apps/studio/components/interfaces/Integrations/Wrappers/OverviewTab.tsx+++ b/apps/studio/components/interfaces/Integrations/Wrappers/OverviewTab.tsx@@ -49,6 +49,8 @@ export const WrapperOverviewTab = () => {const databaseNeedsUpgrading =wrappersExtension?.installed_version === wrappersExtension?.default_version+ const CreateWrapperSheetComponent = wrapperMeta.createComponent || CreateWrapperSheet+return (<IntegrationOverviewTabactions={@@ -113,9 +115,10 @@ export const WrapperOverviewTab = () => {<WrapperTable /></div><Separator />+<Sheet open={!!createWrapperShown} onOpenChange={() => setisClosingCreateWrapper(true)}><SheetContent size="lg" tabIndex={undefined}>- <CreateWrapperSheet+ <CreateWrapperSheetComponentwrapperMeta={wrapperMeta}onClose={() => {setCreateWrapperShown(false)diff --git a/apps/studio/components/interfaces/Integrations/Wrappers/Wrappers.constants.ts b/apps/studio/components/interfaces/Integrations/Wrappers/Wrappers.constants.tsindex c7d5734a490..4055a4423c3 100644--- a/apps/studio/components/interfaces/Integrations/Wrappers/Wrappers.constants.ts+++ b/apps/studio/components/interfaces/Integrations/Wrappers/Wrappers.constants.ts@@ -1,4 +1,5 @@import { BASE_PATH } from 'lib/constants'+import { CreateIcebergWrapperSheet } from './CreateIcebergWrapperSheet'import type { WrapperMeta } from './Wrappers.types'export const WRAPPER_HANDLERS = {@@ -2162,19 +2163,22 @@ export const WRAPPERS: WrapperMeta[] = [label: 'Iceberg',docsUrl: 'https://supabase.com/docs/guides/database/extensions/wrappers/iceberg',minimumExtensionVersion: '0.5.3',+ createComponent: CreateIcebergWrapperSheet,server: {+ // The fields are intentionally not required. The required flag is enforced in the create iceberg wrapper sheet.+ // In the edit wrapper sheet, all fields are shown and not required.options: [{name: 'vault_aws_access_key_id',label: 'AWS Access Key ID',- required: true,+ required: false,encrypted: true,secureEntry: true,},{name: 'vault_aws_secret_access_key',label: 'AWS Secret Access Key',- required: true,+ required: false,encrypted: true,secureEntry: true,},@@ -2202,21 +2206,21 @@ export const WRAPPERS: WrapperMeta[] = [{name: 'warehouse',label: 'Warehouse',- required: true,+ required: false,encrypted: false,secureEntry: false,},{name: 's3.endpoint',label: 'S3 Endpoint',- required: true,+ required: false,encrypted: false,secureEntry: false,},{name: 'catalog_uri',label: 'Catalog URI',- required: true,+ required: false,encrypted: false,secureEntry: false,},diff --git a/apps/studio/components/interfaces/Integrations/Wrappers/Wrappers.types.ts b/apps/studio/components/interfaces/Integrations/Wrappers/Wrappers.types.tsindex a47f73479e4..923a37e7977 100644--- a/apps/studio/components/interfaces/Integrations/Wrappers/Wrappers.types.ts+++ b/apps/studio/components/interfaces/Integrations/Wrappers/Wrappers.types.ts@@ -1,3 +1,5 @@+import { CreateWrapperSheetProps } from './CreateWrapperSheet'+export type WrapperMeta = {name: stringhandlerName: string@@ -10,6 +12,7 @@ export type WrapperMeta = {server: ServerdocsUrl: stringminimumExtensionVersion?: string+ createComponent?: React.ComponentType<CreateWrapperSheetProps>// If true, the wrapper can target a schema which will be populated with tables specified by the wrapper..canTargetSchema?: booleansourceSchemaOption?: ServerOptiondiff --git a/apps/studio/components/interfaces/Integrations/Wrappers/Wrappers.utils.ts b/apps/studio/components/interfaces/Integrations/Wrappers/Wrappers.utils.tsindex 3298e6d5b21..92f2101a570 100644--- a/apps/studio/components/interfaces/Integrations/Wrappers/Wrappers.utils.ts+++ b/apps/studio/components/interfaces/Integrations/Wrappers/Wrappers.utils.ts@@ -50,7 +50,7 @@ export const makeValidateRequired = (options: { name: string; required: boolean}}-interface FormattedWrapperTable {+export interface FormattedWrapperTable {index: numbercolumns: { name: string }[]is_new_schema: boolean