The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat: add create more toggle (#43009)
Jordi Enric9918711b7108
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ActionBar.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ActionBar.tsxindex 11cc0dd2a64..6ee65372ddf 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ActionBar.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ActionBar.tsx@@ -70,39 +70,46 @@ export const ActionBar = ({useHotKey(handleSave, 'Enter', { enabled: visible })return (- <div className="flex w-full justify-end space-x-3 border-t border-default px-3 py-4">- <Button type="default" htmlType="button" onClick={closePanel} disabled={isRunning || loading}>- {backButtonLabel}- </Button>-+ <div className="flex w-full items-center gap-3 border-t border-default px-3 py-4">{children}- {applyFunction !== undefined ? (- // Old solution, necessary when loading is handled by this component itself+ <div className="flex items-center gap-3 ml-auto"><Button- onClick={onSelectApply}- disabled={disableApply || isRunning || loading}- loading={isRunning || loading}+ type="default"+ htmlType="button"+ onClick={closePanel}+ disabled={isRunning || loading}>- <span>{applyButtonLabel}</span>- <span className="ml-2 text-xs text-foreground-lighter">{modKeyLabel}↵</span>+ {backButtonLabel}</Button>- ) : !hideApply ? (- // New solution, when using the Form component, loading is handled by the Form itself- // Does not require applyFunction() callback- <Button- disabled={loading || disableApply}- loading={loading}- data-testid="action-bar-save-row"- htmlType="submit"- form={formId}- >- <span>{applyButtonLabel}</span>- <span className="ml-2 text-xs text-foreground-lighter">{modKeyLabel}↵</span>- </Button>- ) : (- <div />- )}++ {applyFunction !== undefined ? (+ // Old solution, necessary when loading is handled by this component itself+ <Button+ onClick={onSelectApply}+ disabled={disableApply || isRunning || loading}+ loading={isRunning || loading}+ >+ <span>{applyButtonLabel}</span>+ <span className="ml-2 text-xs text-foreground-lighter">{modKeyLabel}↵</span>+ </Button>+ ) : !hideApply ? (+ // New solution, when using the Form component, loading is handled by the Form itself+ // Does not require applyFunction() callback+ <Button+ disabled={loading || disableApply}+ loading={loading}+ data-testid="action-bar-save-row"+ htmlType="submit"+ form={formId}+ >+ <span>{applyButtonLabel}</span>+ <span className="ml-2 text-xs text-foreground-lighter">{modKeyLabel}↵</span>+ </Button>+ ) : (+ <div />+ )}+ </div></div>)}diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsxindex 6782454f4b6..d0f96cdad89 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx@@ -2,8 +2,8 @@ import type { PostgresColumn, PostgresTable } from '@supabase/postgres-meta'import { useParams } from 'common'import { FormSection, FormSectionContent, FormSectionLabel } from 'components/ui/Forms/FormSection'import {- CONSTRAINT_TYPE,Constraint,+ CONSTRAINT_TYPE,useTableConstraintsQuery,} from 'data/database/constraints-query'import {@@ -56,6 +56,7 @@ export interface ColumnEditorProps {primaryKey?: ConstraintforeignKeyRelations: ForeignKey[]existingForeignKeyRelations: ForeignKeyConstraint[]+ createMore?: boolean},resolve: any) => void@@ -76,6 +77,7 @@ export const ColumnEditor = ({const [errors, setErrors] = useState<Dictionary<any>>({})const [columnFields, setColumnFields] = useState<ColumnField>()const [fkRelations, setFkRelations] = useState<ForeignKey[]>([])+ const [createMore, setCreateMore] = useState(false)const [placeholder, setPlaceholder] = useState(getPlaceholderText(columnFields?.format, columnFields?.name))@@ -182,8 +184,20 @@ export const ColumnEditor = ({primaryKey,foreignKeyRelations: fkRelations,existingForeignKeyRelations: foreignKeys,+ createMore,}- saveChanges(payload, isNewRecord, configuration, resolve)+ saveChanges(payload, isNewRecord, configuration, (err?: any) => {+ resolve()+ if (!err && createMore && isNewRecord) {+ const freshColumnFields = generateColumnField({+ schema: selectedTable.schema,+ table: selectedTable.name,+ })+ setColumnFields(freshColumnFields)+ setFkRelations([])+ setErrors({})+ }+ })} else {resolve()}@@ -207,7 +221,23 @@ export const ColumnEditor = ({closePanel={closePanel}applyFunction={(resolve: () => void) => onSaveChanges(resolve)}visible={visible}- />+ >+ {isNewRecord && (+ <div className="flex items-center gap-x-2">+ <Toggle+ size="tiny"+ checked={createMore}+ onChange={() => setCreateMore(!createMore)}+ />+ <label+ className="text-foreground-light text-sm cursor-pointer select-none"+ onClick={() => setCreateMore(!createMore)}+ >+ Create more+ </label>+ </div>+ )}+ </ActionBar>}><FormSection header={<FormSectionLabel className="lg:!col-span-4">General</FormSectionLabel>}>diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsxindex b4db3f0f8ca..724aa533e7d 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsx@@ -4,7 +4,7 @@ import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'import { isEmpty, noop, partition } from 'lodash'import { useEffect, useMemo, useState } from 'react'import type { Dictionary } from 'types'-import { SidePanel } from 'ui'+import { SidePanel, Toggle } from 'ui'import { ActionBar } from '../ActionBar'import { formatForeignKeys } from '../ForeignKeySelector/ForeignKeySelector.utils'@@ -57,6 +57,7 @@ export const RowEditor = ({const isEditingJson = selectedValueForJsonEdit !== undefinedconst [loading, setLoading] = useState(false)+ const [createMore, setCreateMore] = useState(false)const [requiredFields, optionalFields] = partition(rowFields,@@ -143,7 +144,14 @@ export const RowEditor = ({configuration.rowIdx = row!.idx}- saveChanges(payload, isNewRecord, configuration, () => setLoading(false))+ saveChanges(payload, isNewRecord, { ...configuration, createMore }, (err?: any) => {+ setLoading(false)+ if (!err && createMore && isNewRecord) {+ const freshFields = generateRowFields(undefined, selectedTable, foreignKeys)+ setRowFields(freshFields)+ setErrors({})+ }+ })} else {setLoading(false)}@@ -178,7 +186,23 @@ export const RowEditor = ({closePanel={closePanel}hideApply={!editable}visible={visible}- />+ >+ {isNewRecord && editable && (+ <div className="flex items-center gap-x-2">+ <Toggle+ size="tiny"+ checked={createMore}+ onChange={() => setCreateMore(!createMore)}+ />+ <label+ className="text-foreground-light text-sm cursor-pointer select-none"+ onClick={() => setCreateMore(!createMore)}+ >+ Create more+ </label>+ </div>+ )}+ </ActionBar>}><form id={formId} onSubmit={(e) => onSaveChanges(e)} className="h-full">diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsxindex 0d46fcf6610..505845098da 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx@@ -1,19 +1,11 @@import type { PostgresColumn, PostgresTable } from '@supabase/postgres-meta'import { useQueryClient } from '@tanstack/react-query'-import { isEmpty, isUndefined, noop } from 'lodash'-import { useState } from 'react'-import { toast } from 'sonner'-+import { useParams } from 'common'import {queueCellEditWithOptimisticUpdate,queueRowAddWithOptimisticUpdate,} from 'components/grid/utils/queueOperationUtils'import { useIsQueueOperationsEnabled } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'-import { useTableApiAccessPrivilegesMutation } from '@/data/privileges/table-api-access-mutation'-import { useDataApiGrantTogglesEnabled } from '@/hooks/misc/useDataApiGrantTogglesEnabled'-import { type ApiPrivilegesByRole } from '@/lib/data-api-types'-import type { DeepReadonly, Prettify } from '@/lib/type-helpers'-import { useParams } from 'common'import { type GeneratedPolicy } from 'components/interfaces/Auth/Policies/Policies.utils'import { databasePoliciesKeys } from 'data/database-policies/keys'import { useDatabasePublicationCreateMutation } from 'data/database-publications/database-publications-create-mutation'@@ -41,14 +33,19 @@ import { useConfirmOnClose, type ConfirmOnCloseModalProps } from 'hooks/ui/useCoimport { usePHFlag } from 'hooks/ui/useFlag'import { useUrlState } from 'hooks/ui/useUrlState'import { useTrack } from 'lib/telemetry/track'+import { isEmpty, isUndefined, noop } from 'lodash'+import { useState } from 'react'+import { toast } from 'sonner'import { useGetImpersonatedRoleState } from 'state/role-impersonation-state'import { useTableEditorStateSnapshot, type TableEditorState } from 'state/table-editor'import { createTabId, useTabsStateSnapshot } from 'state/tabs'import type { Dictionary } from 'types'import { SonnerProgress } from 'ui'import { ConfirmationModal } from 'ui-patterns/Dialogs/ConfirmationModal'+import { ColumnEditor } from './ColumnEditor/ColumnEditor'import type { ForeignKey } from './ForeignKeySelector/ForeignKeySelector.types'+import { OperationQueueSidePanel } from './OperationQueueSidePanel/OperationQueueSidePanel'import { ForeignRowSelector } from './RowEditor/ForeignRowSelector/ForeignRowSelector'import { JsonEditor } from './RowEditor/JsonEditor'import { RowEditor } from './RowEditor/RowEditor'@@ -73,7 +70,10 @@ import {} from './TableEditor/ApiAccessToggle'import { TableEditor } from './TableEditor/TableEditor'import type { ImportContent } from './TableEditor/TableEditor.types'-import { OperationQueueSidePanel } from './OperationQueueSidePanel/OperationQueueSidePanel'+import { useTableApiAccessPrivilegesMutation } from '@/data/privileges/table-api-access-mutation'+import { useDataApiGrantTogglesEnabled } from '@/hooks/misc/useDataApiGrantTogglesEnabled'+import { type ApiPrivilegesByRole } from '@/lib/data-api-types'+import type { DeepReadonly, Prettify } from '@/lib/type-helpers'export type SaveTableParams =| SaveTableParamsNew@@ -266,7 +266,7 @@ export const SidePanelEditor = ({const saveRow = async (payload: any,isNewRecord: boolean,- configuration: { identifiers: any; rowIdx: number },+ configuration: { identifiers: any; rowIdx: number; createMore?: boolean },onComplete: (err?: any) => void) => {if (!project || selectedTable === undefined) {@@ -290,7 +290,7 @@ export const SidePanelEditor = ({// Close panel immediately without erroronComplete()setIsEdited(false)- snap.closeSidePanel()+ if (!configuration.createMore) snap.closeSidePanel()return}@@ -378,7 +378,7 @@ export const SidePanelEditor = ({onComplete(saveRowError)if (!saveRowError) {setIsEdited(false)- snap.closeSidePanel()+ if (!configuration.createMore) snap.closeSidePanel()}}@@ -444,6 +444,7 @@ export const SidePanelEditor = ({primaryKey?: ConstraintforeignKeyRelations: ForeignKey[]existingForeignKeyRelations: ForeignKeyConstraint[]+ createMore?: boolean},resolve: any) => {@@ -506,10 +507,10 @@ export const SidePanelEditor = ({})setIsEdited(false)- snap.closeSidePanel()+ if (!configuration.createMore) snap.closeSidePanel()}- resolve()+ resolve(response?.error)}/**