diff --git a/frontend/src/lib/components/DBManager.svelte b/frontend/src/lib/components/DBManager.svelte index 2c00593ead..f8c4db4aaa 100644 --- a/frontend/src/lib/components/DBManager.svelte +++ b/frontend/src/lib/components/DBManager.svelte @@ -1,34 +1,36 @@ @@ -111,47 +109,41 @@ >

{tableKey}

- {#if dbTableActionsFactory} - {@const dbTableActions = dbTableActionsFactory.map((f) => - f({ - tableKey: `${selected.schemaKey}.${tableKey}`, - refresh: refresh ?? (() => {}) - }) - )} - - dbTableActions.map((tableAction) => ({ - displayName: tableAction.displayName, - ...(tableAction.icon ? { icon: tableAction.icon } : {}), - action: () => - (askingForConfirmation = { - title: tableAction.confirmTitle ?? 'Are you sure ?', - confirmationText: tableAction.confirmBtnText ?? 'Confirm', - open: true, - onConfirm: async () => { - askingForConfirmation && (askingForConfirmation.loading = true) - try { - await tableAction.action() - tableAction.successText && sendUserToast(tableAction.successText) - } catch (e) { - let msg: string | undefined = (e as Error).message - if (typeof msg !== 'string') msg = e ? JSON.stringify(e) : undefined - sendUserToast(msg ?? 'Action failed!', true) - } - askingForConfirmation = undefined + [ + { + displayName: 'Delete table', + icon: Trash2Icon, + action: () => + (askingForConfirmation = { + title: `Are you sure you want to delete ${tableKey} ? This action is irreversible`, + confirmationText: 'Delete permanently', + open: true, + onConfirm: async () => { + askingForConfirmation && (askingForConfirmation.loading = true) + try { + await dbSchemaOps.onDelete({ tableKey }) + refresh?.() + sendUserToast(`Table '${tableKey}' deleted successfully`) + } catch (e) { + let msg: string | undefined = (e as Error).message + if (typeof msg !== 'string') msg = e ? JSON.stringify(e) : undefined + sendUserToast(msg ?? 'Action failed!', true) } - }) - }))} - class="w-fit" - > - - - - - {/if} + askingForConfirmation = undefined + } + }) + } + ]} + class="w-fit" + > + + + + {/each} @@ -176,31 +168,30 @@
- (askingForConfirmation = undefined)} - on:confirmed={askingForConfirmation?.onConfirm ?? (() => {})} -/> + + (askingForConfirmation = undefined)} + on:confirmed={askingForConfirmation?.onConfirm ?? (() => {})} + /> + -{#if dbTableEditorProps} - (dbTableEditorState = { open: false })} - > - (dbTableEditorState = { open: false })} - title="Create a new table" - > - { - await dbTableEditorProps.onConfirm(values) - dbTableEditorState = { open: false } - }} - /> - - -{/if} + (dbTableEditorState = { open: false })} +> + (dbTableEditorState = { open: false })} title="Create a new table"> + { + await dbSchemaOps.onCreate({ values, schema: selected.schemaKey }) + refresh?.() + dbTableEditorState = { open: false } + }} + {dbType} + previewSql={(values) => dbSchemaOps.previewCreateSql({ values, schema: selected.schemaKey })} + /> + + diff --git a/frontend/src/lib/components/DBManagerDrawer.svelte b/frontend/src/lib/components/DBManagerDrawer.svelte index 6010cd5889..2c79c73c6c 100644 --- a/frontend/src/lib/components/DBManagerDrawer.svelte +++ b/frontend/src/lib/components/DBManagerDrawer.svelte @@ -5,26 +5,19 @@ import DrawerContent from './common/drawer/DrawerContent.svelte' import { sendUserToast, sortArray } from '$lib/utils' import { ArrowLeft, Expand, Loader2, Minimize, RefreshCcw } from 'lucide-svelte' - import { - dbSupportsSchemas, - getLanguageByResourceType, - type TableMetadata - } from './apps/components/display/dbtable/utils' + import { dbSupportsSchemas, type TableMetadata } from './apps/components/display/dbtable/utils' import DbManager from './DBManager.svelte' import { - dbDeleteTableActionWithPreviewScript, + dbSchemaOpsWithPreviewScripts, dbTableOpsWithPreviewScripts, - getDatabaseArg, + getDbType, getDucklakeSchema } from './dbOps' - import { makeCreateTableQuery } from './apps/components/display/dbtable/queries/createTable' - import { runScriptAndPollResult } from './jobs/utils' import { Pane, Splitpanes } from 'svelte-splitpanes' import SqlRepl from './SqlRepl.svelte' import SimpleAgTable from './SimpleAgTable.svelte' import { untrack } from 'svelte' import type { DbInput } from './dbTypes' - import { wrapDucklakeQuery } from './ducklake' import { getDbSchemas, loadAllTablesMetaData, @@ -163,7 +156,7 @@ > {#if dbSchema && $workspaceStore && input} {@const _input = input} - {@const dbType = input.type == 'database' ? input.resourceType : 'duckdb'} + {@const dbType = getDbType(_input)} @@ -197,25 +190,12 @@ input: _input, workspace: $workspaceStore })} - dbTableActionsFactory={[ - dbDeleteTableActionWithPreviewScript({ input: _input, workspace: $workspaceStore }) - ]} - {refresh} - dbTableEditorPropsFactory={({ selectedSchemaKey }) => ({ - dbType, - previewSql: (values) => makeCreateTableQuery(values, dbType, selectedSchemaKey), - async onConfirm(values) { - const dbArg = getDatabaseArg(input) - const language = getLanguageByResourceType(dbType) - let query = makeCreateTableQuery(values, dbType, selectedSchemaKey) - if (input?.type === 'ducklake') query = wrapDucklakeQuery(query, input.ducklake) - await runScriptAndPollResult({ - workspace: $workspaceStore, - requestBody: { args: dbArg, content: query, language } - }) - refresh() - } + dbSchemaOps={dbSchemaOpsWithPreviewScripts({ + input: _input, + workspace: $workspaceStore })} + {dbType} + {refresh} /> diff --git a/frontend/src/lib/components/DBTableEditor.svelte b/frontend/src/lib/components/DBTableEditor.svelte index 507e82236a..214fc1a42c 100644 --- a/frontend/src/lib/components/DBTableEditor.svelte +++ b/frontend/src/lib/components/DBTableEditor.svelte @@ -36,14 +36,6 @@ if (Object.values(errs).every((v) => !v)) return undefined return errs } - - export type DBTableEditorProps = { - onConfirm: (values: CreateTableValues) => void | Promise - previewSql?: (values: CreateTableValues) => string - dbType: DbType - dbSchema?: DBSchema - currentSchema?: string - }