parent
51560c49ae
commit
892a40274e
|
|
@ -1035,6 +1035,28 @@ async function fetchTableTriggers() {
|
|||
}
|
||||
}
|
||||
|
||||
async function refreshActiveTableInfo() {
|
||||
if (sidePanelMode.value !== "table-info" || !sidePanelRow.value) return;
|
||||
sidePanelGuard.bump();
|
||||
|
||||
if (tableInfoTab.value === "ddl") {
|
||||
tableDdlContent.value = "";
|
||||
await fetchTableDdl();
|
||||
} else if (tableInfoTab.value === "columns") {
|
||||
tableColumns.value = [];
|
||||
await fetchTableColumns();
|
||||
} else if (tableInfoTab.value === "indexes") {
|
||||
tableIndexes.value = [];
|
||||
await fetchTableIndexes();
|
||||
} else if (tableInfoTab.value === "foreignKeys") {
|
||||
tableForeignKeys.value = [];
|
||||
await fetchTableForeignKeys();
|
||||
} else if (tableInfoTab.value === "triggers") {
|
||||
tableTriggers.value = [];
|
||||
await fetchTableTriggers();
|
||||
}
|
||||
}
|
||||
|
||||
function copyTableDdl() {
|
||||
void copyToClipboard(tableDdlContent.value);
|
||||
toast(t("grid.copyDdl"), 2000);
|
||||
|
|
@ -2454,6 +2476,7 @@ async function reload(options?: { allowCachedObjects?: boolean; contextEpoch?: n
|
|||
|
||||
function refresh(): boolean {
|
||||
void reload();
|
||||
void refreshActiveTableInfo();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -2778,7 +2801,7 @@ function getObjectBrowserMenuItems(item: ObjectBrowserRow): ContextMenuItem[] {
|
|||
<CheckSquare v-if="settingsStore.editorSettings.objectBrowserShowCheckbox" class="h-3.5 w-3.5" />
|
||||
<Square v-else class="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
<Button variant="ghost" size="icon" class="h-7 w-7" :title="refreshTooltip" :disabled="loadingObjects" @click="reload">
|
||||
<Button variant="ghost" size="icon" class="h-7 w-7" :title="refreshTooltip" :disabled="loadingObjects" @click="refresh">
|
||||
<RefreshCw class="h-3.5 w-3.5" :class="{ 'animate-spin': loadingObjects }" />
|
||||
</Button>
|
||||
<Button v-if="canPasteTableClipboard()" variant="ghost" size="sm" class="h-7 px-2 text-xs" @click="openPasteTableDialog">
|
||||
|
|
|
|||
43
apps/desktop/src/components/objects/__tests__/ObjectBrowserMetadataRefresh.spec.ts
vendored
Normal file
43
apps/desktop/src/components/objects/__tests__/ObjectBrowserMetadataRefresh.spec.ts
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const source = readFileSync(new URL("../ObjectBrowser.vue", import.meta.url), "utf8");
|
||||
|
||||
function functionBody(name: string): string {
|
||||
const signature = new RegExp(`(?:async\\s+)?function\\s+${name}\\s*\\([^)]*\\)\\s*(?::\\s*[^\\{]+)?\\{`, "m").exec(source);
|
||||
if (!signature) throw new Error(`Missing function ${name}`);
|
||||
const bodyStart = signature.index + signature[0].length;
|
||||
let depth = 1;
|
||||
for (let index = bodyStart; index < source.length; index += 1) {
|
||||
if (source[index] === "{") depth += 1;
|
||||
else if (source[index] === "}") depth -= 1;
|
||||
if (depth === 0) return source.slice(bodyStart, index);
|
||||
}
|
||||
throw new Error(`Unclosed function ${name}`);
|
||||
}
|
||||
|
||||
describe("ObjectBrowser table metadata refresh", () => {
|
||||
it("refreshes the object list and the open table-info tab from the toolbar", () => {
|
||||
const refresh = functionBody("refresh");
|
||||
|
||||
expect(refresh).toContain("void reload();");
|
||||
expect(refresh).toContain("void refreshActiveTableInfo();");
|
||||
expect(source).toContain('@click="refresh"');
|
||||
});
|
||||
|
||||
it("invalidates stale requests and reloads only the active metadata surface", () => {
|
||||
const refreshTableInfo = functionBody("refreshActiveTableInfo");
|
||||
|
||||
expect(refreshTableInfo).toContain('sidePanelMode.value !== "table-info" || !sidePanelRow.value');
|
||||
expect(refreshTableInfo).toContain("sidePanelGuard.bump();");
|
||||
expect(refreshTableInfo).toMatch(/tableInfoTab\.value === "ddl"[\s\S]*?tableDdlContent\.value = "";[\s\S]*?await fetchTableDdl\(\);/);
|
||||
expect(refreshTableInfo).toMatch(/tableInfoTab\.value === "columns"[\s\S]*?tableColumns\.value = \[\];[\s\S]*?await fetchTableColumns\(\);/);
|
||||
expect(refreshTableInfo).toMatch(/tableInfoTab\.value === "indexes"[\s\S]*?tableIndexes\.value = \[\];[\s\S]*?await fetchTableIndexes\(\);/);
|
||||
expect(refreshTableInfo).toMatch(/tableInfoTab\.value === "foreignKeys"[\s\S]*?tableForeignKeys\.value = \[\];[\s\S]*?await fetchTableForeignKeys\(\);/);
|
||||
expect(refreshTableInfo).toMatch(/tableInfoTab\.value === "triggers"[\s\S]*?tableTriggers\.value = \[\];[\s\S]*?await fetchTableTriggers\(\);/);
|
||||
});
|
||||
|
||||
it("keeps automatic object reloads free of extra metadata requests", () => {
|
||||
expect(functionBody("reload")).not.toContain("refreshActiveTableInfo");
|
||||
});
|
||||
});
|
||||
|
|
@ -35,14 +35,14 @@ describe("ContentArea object browser refresh wiring", () => {
|
|||
expect(contentAreaSource).toContain('if (props.activeTab.mode === "objects") return objectBrowserRef.value?.refresh?.() ?? false;');
|
||||
});
|
||||
|
||||
it("exposes the existing ObjectBrowser reload path as refresh", () => {
|
||||
expect(objectBrowserSource).toMatch(/function refresh\(\): boolean \{\s+void reload\(\);\s+return true;\s+\}/);
|
||||
it("exposes object and active table-info reloads as refresh", () => {
|
||||
expect(objectBrowserSource).toMatch(/function refresh\(\): boolean \{\s+void reload\(\);\s+void refreshActiveTableInfo\(\);\s+return true;\s+\}/);
|
||||
expect(objectBrowserSource).toContain("defineExpose({ focusSearch, refresh });");
|
||||
});
|
||||
|
||||
it("shows the configured content refresh shortcut on the refresh button", () => {
|
||||
expect(objectBrowserSource).toContain("formatShortcut(settingsStore.editorSettings.shortcuts.refreshData)");
|
||||
expect(objectBrowserSource).toMatch(/<Button[^>]*:title="refreshTooltip"[^>]*@click="reload">/);
|
||||
expect(objectBrowserSource).toMatch(/<Button[^>]*:title="refreshTooltip"[^>]*@click="refresh">/);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue