fix(oracle): lazy load table triggers
This commit is contained in:
1 parent
132ac8a2ec
commit
5600872565
4 files changed
+116
-25
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { shouldLoadTableStructureTriggers, visibleTableStructureRefreshScope } from "@/lib/table/tableStructureMetadataLoading";
|
||||
|
||||
describe("table structure metadata loading", () => {
|
||||
it("does not request triggers while opening the default columns tab", () => {
|
||||
expect(visibleTableStructureRefreshScope("columns").triggers).toBe(false);
|
||||
});
|
||||
|
||||
it("requests triggers when the structure editor opens on the trigger tab", () => {
|
||||
expect(visibleTableStructureRefreshScope("triggers").triggers).toBe(true);
|
||||
});
|
||||
|
||||
it("loads trigger metadata once when the trigger tab becomes visible", () => {
|
||||
const base = {
|
||||
activeTab: "triggers" as const,
|
||||
isCreateMode: false,
|
||||
supported: true,
|
||||
loading: false,
|
||||
structureLoading: false,
|
||||
};
|
||||
|
||||
expect(shouldLoadTableStructureTriggers({ ...base, loaded: false })).toBe(true);
|
||||
expect(shouldLoadTableStructureTriggers({ ...base, loaded: true })).toBe(false);
|
||||
});
|
||||
|
||||
it("waits for the initial structure load and skips create mode", () => {
|
||||
const base = {
|
||||
activeTab: "triggers" as const,
|
||||
supported: true,
|
||||
loaded: false,
|
||||
loading: false,
|
||||
};
|
||||
|
||||
expect(shouldLoadTableStructureTriggers({ ...base, isCreateMode: false, structureLoading: true })).toBe(false);
|
||||
expect(shouldLoadTableStructureTriggers({ ...base, isCreateMode: true, structureLoading: false })).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
import type { TableInfoTab } from "@/types/database";
|
||||
|
||||
export interface TableStructureRefreshScope {
|
||||
columns: boolean;
|
||||
indexes: boolean;
|
||||
foreignKeys: boolean;
|
||||
triggers: boolean;
|
||||
tableComment: boolean;
|
||||
}
|
||||
|
||||
export function visibleTableStructureRefreshScope(activeTab: TableInfoTab): TableStructureRefreshScope {
|
||||
return {
|
||||
columns: true,
|
||||
indexes: true,
|
||||
foreignKeys: true,
|
||||
// Trigger definitions can contain large source bodies, so defer them until
|
||||
// the trigger editor is actually visible.
|
||||
triggers: activeTab === "triggers",
|
||||
tableComment: true,
|
||||
};
|
||||
}
|
||||
|
||||
export const TRIGGERS_ONLY_REFRESH_SCOPE: TableStructureRefreshScope = {
|
||||
columns: false,
|
||||
indexes: false,
|
||||
foreignKeys: false,
|
||||
triggers: true,
|
||||
tableComment: false,
|
||||
};
|
||||
|
||||
export function shouldLoadTableStructureTriggers(options: { activeTab: TableInfoTab; isCreateMode: boolean; supported: boolean; loaded: boolean; loading: boolean; structureLoading: boolean }): boolean {
|
||||
return options.activeTab === "triggers" && !options.isCreateMode && options.supported && !options.loaded && !options.loading && !options.structureLoading;
|
||||
}
|
||||
Reference in new issue
Block a user