The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Update UI for disabling FDW
Joshen Lim85cc1a964e80
diff --git a/studio/components/interfaces/Database/Wrappers/WrapperRow.tsx b/studio/components/interfaces/Database/Wrappers/WrapperRow.tsxindex 15519e74d76..0f4304d4fb0 100644--- a/studio/components/interfaces/Database/Wrappers/WrapperRow.tsx+++ b/studio/components/interfaces/Database/Wrappers/WrapperRow.tsx@@ -11,14 +11,18 @@ import {IconTrash,IconEye,IconEyeOff,+ IconCheckCircle,} from 'ui'import { useStore } from 'hooks'import { Wrapper } from './Wrappers.types'import { makeValidateRequired } from './Wrappers.utils'import { useFDWCreateMutation } from 'data/fdw/fdw-create-mutation'+import { useFDWDeleteMutation } from 'data/fdw/fdw-delete-mutation'import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'import WrapperTableEditor from './WrapperTableEditor'+import InformationBox from 'components/ui/InformationBox'+import { confirmAlert } from 'components/to-be-cleaned/ModalsDeprecated/ConfirmModal'interface Props {wrapper: Wrapper@@ -36,6 +40,7 @@ const WrapperRow: FC<Props> = ({ wrapper, isEnabled, isOpen, onOpen }) => {const { ui } = useStore()const { project } = useProjectContext()const { mutateAsync: createFDW } = useFDWCreateMutation()+ const { mutateAsync: deleteFDW } = useFDWDeleteMutation()const [isSubmitting, setIsSubmitting] = useState(false)const [isEditingTable, setIsEditingTable] = useState(false)@@ -65,7 +70,7 @@ const WrapperRow: FC<Props> = ({ wrapper, isEnabled, isOpen, onOpen }) => {setSelectedTableToEdit(undefined)}- const onSubmit = async () => {+ const onSaveWrapper = async () => {const validate = makeValidateRequired(wrapper.server.options)const errors: any = validate(formState)if (!isEmpty(errors)) {@@ -98,6 +103,28 @@ const WrapperRow: FC<Props> = ({ wrapper, isEnabled, isOpen, onOpen }) => {}}+ const onDeleteWrapper = () => {+ confirmAlert({+ title: `Confirm to disable ${wrapper.label} wrapper`,+ message: `Are you sure you want to disable the ${wrapper.label} wrapper? This will also remove all tables created with this wrapper.`,+ onAsyncConfirm: async () => {+ try {+ await deleteFDW({+ projectRef: project?.ref,+ connectionString: project?.connectionString,+ name: wrapper.name,+ })+ } catch (error: any) {+ ui.setNotification({+ error,+ category: 'error',+ message: `Disabling ${wrapper.name} failed: ${error.message}`,+ })+ }+ },+ })+ }+return (<><Collapsible@@ -152,112 +179,144 @@ const WrapperRow: FC<Props> = ({ wrapper, isEnabled, isOpen, onOpen }) => {</div></button></Collapsible.Trigger>- <Collapsible.Content>- <div className="group border-t border-scale-500 bg-scale-100 py-6 px-6 text-scale-1200 dark:bg-scale-300">- <div className="max-w-lg mx-auto space-y-6 my-6">- {wrapper.server.options.map((option) => {- const [showHidden, setShowHidden] = useState(option.hidden)- return (- <Input- key={option.name}- id={option.name}- name={option.name}- label={option.label}- defaultValue={option.defaultValue ?? ''}- required={option.required ?? false}- value={formState[option.name]}- onChange={(e) => {- setFormState((prev) => ({ ...prev, [option.name]: e.target.value }))- setFormErrors((prev) => ({ ...prev, [option.name]: '' }))- }}- error={formErrors[option.name]}- className="input-mono"- type={!option.hidden ? 'text' : showHidden ? 'text' : 'password'}- actions={- option.hidden ? (- <div className="mr-1 flex items-center justify-center">- <Button- type="default"- icon={showHidden ? <IconEye /> : <IconEyeOff />}- onClick={() => setShowHidden(!showHidden)}- />- </div>- ) : null- }- />- )- })}- <div className="space-y-4">- <div className="space-y-1">- <div className="flex items-center justify-between">- <p>Foreign Tables</p>- <Button type="default" onClick={() => setIsEditingTable(true)}>- Add table+ {isEnabled ? (+ <Collapsible.Content>+ <div className="group border-t border-scale-500 bg-scale-100 py-6 px-6 text-scale-1200 dark:bg-scale-300">+ <div className="max-w-lg mx-auto space-y-6 my-6">+ <InformationBox+ hideCollapse+ defaultVisibility+ icon={<IconCheckCircle strokeWidth={1.5} className="text-brand-900" />}+ title={`${wrapper.label} foreign data wrapper is currently enabled`}+ description="If you'd like to edit this wrapper, you'll need to disable the wrapper first and create it again with any updated configuration."+ />+ <div className="flex items-center justify-end !mt-8">+ <div className="flex items-center space-x-3">+ <Button+ type="default"+ loading={isSubmitting}+ disabled={noChanges}+ onClick={() => onDeleteWrapper()}+ >+ Disable wrapper</Button></div></div>+ </div>+ </div>+ </Collapsible.Content>+ ) : (+ <Collapsible.Content>+ <div className="group border-t border-scale-500 bg-scale-100 py-6 px-6 text-scale-1200 dark:bg-scale-300">+ <div className="max-w-lg mx-auto space-y-6 my-6">+ {wrapper.server.options.map((option) => {+ const [showHidden, setShowHidden] = useState(option.hidden)+ return (+ <Input+ key={option.name}+ id={option.name}+ name={option.name}+ label={option.label}+ defaultValue={option.defaultValue ?? ''}+ required={option.required ?? false}+ value={formState[option.name]}+ onChange={(e) => {+ setFormState((prev) => ({ ...prev, [option.name]: e.target.value }))+ setFormErrors((prev) => ({ ...prev, [option.name]: '' }))+ }}+ error={formErrors[option.name]}+ className="input-mono"+ type={!option.hidden ? 'text' : showHidden ? 'text' : 'password'}+ actions={+ option.hidden ? (+ <div className="mr-1 flex items-center justify-center">+ <Button+ type="default"+ icon={showHidden ? <IconEye /> : <IconEyeOff />}+ onClick={() => setShowHidden(!showHidden)}+ />+ </div>+ ) : null+ }+ />+ )+ })}<div className="space-y-2">- {newTables.length === 0 && (- <div className="border border-scale-600 px-4 py-4 rounded-md flex items-center justify-center">- <p className="text-sm text-scale-1000">- Add foreign tables to query from after the wrapper is enabled- </p>+ <div className="space-y-1">+ <div className="flex items-center justify-between">+ <p className="text-sm text-scale-1100">Foreign Tables</p>+ <Button type="default" onClick={() => setIsEditingTable(true)}>+ Add table+ </Button></div>- )}- {newTables.map((table, i) => (- <div className="border border-scale-600 px-4 py-2 rounded-md space-y-1 flex items-center justify-between">- <div>- <p>{table.table_name}</p>- <p className="text-sm text-scale-1100">- {wrapper.tables[table.index].label}: {table.columns.join(', ')}+ </div>+ <div className="space-y-2">+ {newTables.length === 0 && (+ <div className="border border-scale-600 px-4 py-4 rounded-md flex items-center justify-center">+ <p className="text-sm text-scale-1000">+ Add foreign tables to query from after the wrapper is enabled</p></div>- <div className="flex items-center space-x-2">- <Button- type="default"- className="px-1"- icon={<IconEdit />}- onClick={() => {- setIsEditingTable(true)- setSelectedTableToEdit({ ...table, tableIndex: i })- }}- />- <Button- type="default"- className="px-1"- icon={<IconTrash />}- onClick={() => {- setNewTables((prev) => prev.filter((_, j) => j !== i))- }}- />+ )}+ {newTables.map((table, i) => (+ <div className="border border-scale-600 px-4 py-2 rounded-md space-y-1 flex items-center justify-between">+ <div>+ <p className="text-sm">{table.table_name}</p>+ <p className="text-sm text-scale-1000">+ {wrapper.tables[table.index].label}: {table.columns.join(', ')}+ </p>+ </div>+ <div className="flex items-center space-x-2">+ <Button+ type="default"+ className="px-1"+ icon={<IconEdit />}+ onClick={() => {+ setIsEditingTable(true)+ setSelectedTableToEdit({ ...table, tableIndex: i })+ }}+ />+ <Button+ type="default"+ className="px-1"+ icon={<IconTrash />}+ onClick={() => {+ setNewTables((prev) => prev.filter((_, j) => j !== i))+ }}+ />+ </div></div>+ ))}+ </div>+ <div className="flex items-center justify-end !mt-8">+ {/* [Joshen] Thinking if we need to add a disclaimer here that users cannot edit wrappers */}+ <div className="flex items-center space-x-3">+ <Button+ type="default"+ htmlType="reset"+ onClick={() => {+ onOpen('')+ setNewTables([])+ setFormState(getInitialFormState)+ }}+ disabled={isSubmitting}+ >+ Cancel+ </Button>+ <Button+ loading={isSubmitting}+ disabled={noChanges}+ onClick={() => onSaveWrapper()}+ >+ Save+ </Button></div>- ))}- </div>- <div className="flex items-center justify-end !mt-8">- {/* [Joshen] Thinking if we need to add a disclaimer here that users cannot edit wrappers */}- <div className="flex items-center space-x-3">- <Button- type="default"- htmlType="reset"- onClick={() => {- onOpen('')- setNewTables([])- setFormState(getInitialFormState)- }}- disabled={isSubmitting}- >- Cancel- </Button>- <Button loading={isSubmitting} disabled={noChanges} onClick={() => onSubmit()}>- Save- </Button></div></div></div></div>- </div>- </Collapsible.Content>+ </Collapsible.Content>+ )}</Collapsible><WrapperTableEditorvisible={isEditingTable}diff --git a/studio/components/interfaces/Database/Wrappers/WrapperTableEditor.tsx b/studio/components/interfaces/Database/Wrappers/WrapperTableEditor.tsxindex c3f9a6f7561..6c33cb7a71a 100644--- a/studio/components/interfaces/Database/Wrappers/WrapperTableEditor.tsx+++ b/studio/components/interfaces/Database/Wrappers/WrapperTableEditor.tsx@@ -1,9 +1,9 @@-import ActionBar from 'components/interfaces/TableGridEditor/SidePanelEditor/ActionBar'-import MultiSelect from 'components/ui/MultiSelect'import { useEffect, useState } from 'react'import { Form, Input, Listbox, SidePanel } from 'ui'import { Table, TableOption } from './Wrappers.types'import { makeValidateRequired } from './Wrappers.utils'+import MultiSelect from 'components/ui/MultiSelect'+import ActionBar from 'components/interfaces/TableGridEditor/SidePanelEditor/ActionBar'export type WrapperTableEditorProps = {visible: booleandiff --git a/studio/components/interfaces/Database/Wrappers/Wrappers.tsx b/studio/components/interfaces/Database/Wrappers/Wrappers.tsxindex 704efdadc11..cc2cf11e939 100644--- a/studio/components/interfaces/Database/Wrappers/Wrappers.tsx+++ b/studio/components/interfaces/Database/Wrappers/Wrappers.tsx@@ -1,12 +1,10 @@-import { partition } from 'lodash'-import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'-import { FormHeader } from 'components/ui/Forms'+import { useState } from 'react'+import { useFDWsQuery } from 'data/fdw/fdws-query'import { wrappers } from './Wrappers.constants'-import WrapperCard from './WrapperCard'import WrapperRow from './WrapperRow'-import { useState } from 'react'-import { Wrapper } from './Wrappers.types'+import { FormHeader } from 'components/ui/Forms'+import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'const Wrappers = () => {const { project } = useProjectContext()@@ -16,11 +14,9 @@ const Wrappers = () => {})const [open, setOpen] = useState<string>('')+ console.log('useFDWQuery', { data })+const enabledWrapperNamesSet = new Set(data?.result.map((fdw) => fdw.name))- // const enabledWrapperNamesSet = new Set(['stripe_server'])- const [enabledWrappers, disabledWrappers] = partition(wrappers, (wrapper: Wrapper) =>- enabledWrapperNamesSet.has(wrapper.server.name)- )return (<div>@@ -46,7 +42,7 @@ const Wrappers = () => {</div>{/* [Joshen TODO] Once above is working, can remove below */}- <div className="space-y-4 mt-20">+ {/* <div className="space-y-4 mt-20"><div className="w-full space-y-12">{enabledWrappers.length > 0 && (<div className="space-y-4">@@ -70,7 +66,7 @@ const Wrappers = () => {</div>)}</div>- </div>+ </div> */}</div>)}diff --git a/studio/data/fdw/fdw-create-mutation.ts b/studio/data/fdw/fdw-create-mutation.tsindex 4c6000dccef..e55553cf8c8 100644--- a/studio/data/fdw/fdw-create-mutation.ts+++ b/studio/data/fdw/fdw-create-mutation.ts@@ -101,6 +101,8 @@ export function getFDWCreateSql({const sql = /* SQL */ `begin;+ create extension if not exists wrappers;+${createWrapperSql}${createEncryptedKeysSql}