fix(structure): load editor on open
This commit is contained in:
1 parent
329664bfb8
commit
5b3b69f7fb
4 files changed
+52
-12
No files matched your search
@@ -39,7 +39,12 @@ import {
|
|||||||
type EditableStructureIndex,
|
type EditableStructureIndex,
|
||||||
} from "@/lib/tableStructureEditorSql";
|
} from "@/lib/tableStructureEditorSql";
|
||||||
import { getTableStructureCapabilities } from "@/lib/tableStructureCapabilities";
|
import { getTableStructureCapabilities } from "@/lib/tableStructureCapabilities";
|
||||||
import { createColumnDrafts, createIndexDrafts, toColumnNames } from "@/lib/tableStructureEditorState";
|
import {
|
||||||
|
buildStructureTargetLabel,
|
||||||
|
createColumnDrafts,
|
||||||
|
createIndexDrafts,
|
||||||
|
toColumnNames,
|
||||||
|
} from "@/lib/tableStructureEditorState";
|
||||||
import type { ForeignKeyInfo, TriggerInfo } from "@/types/database";
|
import type { ForeignKeyInfo, TriggerInfo } from "@/types/database";
|
||||||
import * as api from "@/lib/api";
|
import * as api from "@/lib/api";
|
||||||
|
|
||||||
@@ -116,11 +121,14 @@ const indexColLabels = computed(() => [
|
|||||||
const targetSchema = computed(() => props.prefillSchema || props.prefillDatabase || "");
|
const targetSchema = computed(() => props.prefillSchema || props.prefillDatabase || "");
|
||||||
const isCreateMode = computed(() => !props.prefillTable);
|
const isCreateMode = computed(() => !props.prefillTable);
|
||||||
const newTableName = ref("");
|
const newTableName = ref("");
|
||||||
const targetLabel = computed(() => {
|
const targetLabel = computed(() =>
|
||||||
const parts = [connection.value?.name, props.prefillDatabase, props.prefillSchema];
|
buildStructureTargetLabel(
|
||||||
if (!isCreateMode.value) parts.push(props.prefillTable);
|
connection.value?.name,
|
||||||
return parts.filter(Boolean).join(" / ");
|
props.prefillDatabase,
|
||||||
});
|
props.prefillSchema,
|
||||||
|
isCreateMode.value ? undefined : props.prefillTable,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
const changeSql = computed(() => {
|
const changeSql = computed(() => {
|
||||||
if (isCreateMode.value) {
|
if (isCreateMode.value) {
|
||||||
@@ -331,12 +339,16 @@ async function applyChanges() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(open, (value) => {
|
watch(
|
||||||
if (value) {
|
open,
|
||||||
resetState();
|
(value) => {
|
||||||
void loadStructure();
|
if (value) {
|
||||||
}
|
resetState();
|
||||||
});
|
void loadStructure();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -34,3 +34,15 @@ export function createIndexDrafts(indexes: IndexInfo[]): EditableStructureIndex[
|
|||||||
export function toColumnNames(columns: string[]): string {
|
export function toColumnNames(columns: string[]): string {
|
||||||
return columns.join(", ");
|
return columns.join(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function buildStructureTargetLabel(
|
||||||
|
connectionName: string | undefined,
|
||||||
|
database: string | undefined,
|
||||||
|
schema: string | undefined,
|
||||||
|
tableName: string | undefined,
|
||||||
|
): string {
|
||||||
|
const parts = [connectionName, database];
|
||||||
|
if (schema && schema !== database) parts.push(schema);
|
||||||
|
if (tableName) parts.push(tableName);
|
||||||
|
return parts.filter(Boolean).join(" / ");
|
||||||
|
}
|
||||||
@@ -18,6 +18,10 @@ test("structure editor keeps columns when optional metadata fails", () => {
|
|||||||
assert.match(source, /api\s*\n\s*\.listTriggers[\s\S]*\.catch\(\(\) => \[\]\)/);
|
assert.match(source, /api\s*\n\s*\.listTriggers[\s\S]*\.catch\(\(\) => \[\]\)/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("structure editor loads immediately when mounted open", () => {
|
||||||
|
assert.match(source, /watch\(\s*open,[\s\S]*\{\s*immediate:\s*true\s*\},?\s*\)/);
|
||||||
|
});
|
||||||
|
|
||||||
test("structure editor gates controls through table structure capabilities", () => {
|
test("structure editor gates controls through table structure capabilities", () => {
|
||||||
assert.match(source, /getTableStructureCapabilities/);
|
assert.match(source, /getTableStructureCapabilities/);
|
||||||
assert.match(source, /const structureCapabilities = computed/);
|
assert.match(source, /const structureCapabilities = computed/);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
import test from "node:test";
|
import test from "node:test";
|
||||||
import {
|
import {
|
||||||
|
buildStructureTargetLabel,
|
||||||
createColumnDrafts,
|
createColumnDrafts,
|
||||||
createIndexDrafts,
|
createIndexDrafts,
|
||||||
toColumnNames,
|
toColumnNames,
|
||||||
@@ -102,3 +103,14 @@ test("creates editable index drafts and splits pasted column lists", () => {
|
|||||||
]);
|
]);
|
||||||
assert.equal(toColumnNames(["id", "name"]), "id, name");
|
assert.equal(toColumnNames(["id", "name"]), "id, name");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("structure editor target label omits duplicate database and schema", () => {
|
||||||
|
assert.equal(
|
||||||
|
buildStructureTargetLabel("online-clickhouse", "testdb", "testdb", "users"),
|
||||||
|
"online-clickhouse / testdb / users",
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
buildStructureTargetLabel("online-postgres", "app", "public", "users"),
|
||||||
|
"online-postgres / app / public / users",
|
||||||
|
);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user