From 77965f1458252ff312a2ff3d8fa541ba8b67f647 Mon Sep 17 00:00:00 2001 From: Diego Imbert Date: Tue, 25 Aug 2026 19:47:50 +0200 Subject: [PATCH] feat(datatables): create tables and schemas from any data table in the tree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The New table / New schema rows now show under every data table, not only the one the manager is pointed at. Creating outside it switches to that data table first, and the request rides through the parent because the switch re-mounts the manager. Tree rows also read uniformly now — the background alone marks the current one — with the create rows set apart in secondary. --- frontend/src/lib/components/DBManager.svelte | 87 ++++++++++++------- .../lib/components/DBManagerContent.svelte | 5 +- .../src/lib/components/DBManagerDrawer.svelte | 18 ++-- .../raw_apps/RawAppDataTableDrawer.svelte | 6 +- 4 files changed, 72 insertions(+), 44 deletions(-) diff --git a/frontend/src/lib/components/DBManager.svelte b/frontend/src/lib/components/DBManager.svelte index 57000750a8..6ee0544aee 100644 --- a/frontend/src/lib/components/DBManager.svelte +++ b/frontend/src/lib/components/DBManager.svelte @@ -47,6 +47,10 @@ table: string } + /** A create started from a row of another data table. Switching data table + * re-mounts this component, so the request has to travel through the parent. */ + export type PendingCreate = { kind: 'table'; schema: string } | { kind: 'schema' } + type Props = { dbType: DbType dbSchema: DBSchema @@ -66,6 +70,7 @@ datatableTree?: DataTableTables[] datatableTreeLoading?: boolean onSelectDatatable?: (datatable: string) => void + pendingCreate?: PendingCreate | undefined /** Row-menu actions on a data table, run against that row's data table. */ onDatatableAction?: (datatable: string, action: DatatableRowAction) => void canManageDatatable?: boolean @@ -95,6 +100,7 @@ datatableTree, datatableTreeLoading, onSelectDatatable, + pendingCreate = $bindable(undefined), onDatatableAction, canManageDatatable = false, multiSelectMode = false, @@ -266,11 +272,6 @@ : 'group-hover:opacity-0 ' + (current ? 'opacity-0 ' : 'opacity-100 ')) + (open ? '' : '-rotate-90') - /** Every row in the tree reads the same way: what you are looking at now is - * emphasized, everything else recedes. */ - const rowText = (current: boolean) => - current ? 'text-primary font-semibold' : 'text-secondary font-normal' - /** Reveal a node, dropping a stale "closed" that would hide a new selection. */ function reveal(dt: string | undefined, schemaKey?: string) { const next = new Map(expandOverrides) @@ -293,6 +294,40 @@ selected = { schemaKey, tableKey } } + function startCreateTable(dt: string | undefined, schemaKey: string) { + if (dt !== undefined && dt !== currentDatatable) { + selectedSchemaKey = schemaKey + pendingCreate = { kind: 'table', schema: schemaKey } + onSelectDatatable?.(dt) + return + } + selected = { schemaKey, tableKey: undefined } + dbTableEditorState = { open: true } + } + + function startCreateSchema(dt: string | undefined) { + if (dt !== undefined && dt !== currentDatatable) { + pendingCreate = { kind: 'schema' } + onSelectDatatable?.(dt) + return + } + newSchemaDialogOpen = true + } + + // Finishes a create requested before the switch, now that this component is + // mounted against the data table it targeted. + $effect(() => { + const req = pendingCreate + if (!req || !schemaKeys.length) return + pendingCreate = undefined + if (req.kind === 'schema') { + newSchemaDialogOpen = true + } else if (schemaKeys.includes(req.schema)) { + selected = { schemaKey: req.schema, tableKey: undefined } + dbTableEditorState = { open: true } + } + }) + let search = $state('') let selected: { schemaKey?: undefined | string @@ -415,8 +450,7 @@ {@const dtOpen = isExpanded(root.datatable)} {#if root.datatable !== undefined} {/each} - {#if root.datatable === currentDatatable || root.datatable === undefined} - - {/if} + {/if} {/each} - {#if dbSupportsSchemas && (root.datatable === currentDatatable || root.datatable === undefined) && search.trim() === ''} + {#if dbSupportsSchemas && search.trim() === ''}