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() === ''}