fix(connection): refresh and display connection notes
This commit is contained in:
19 files changed
+199
-19
No files matched your search
@@ -118,12 +118,18 @@ describe("connectionStore database info", () => {
|
||||
const store = useConnectionStore();
|
||||
await store.addConnection(config);
|
||||
await store.connect(config);
|
||||
const connectionNode = store.treeNodes[0];
|
||||
connectionNode.isExpanded = true;
|
||||
const existingChildIds = connectionNode.children?.map((child) => child.id);
|
||||
|
||||
await store.updateConnection({ ...config, note: "Production reporting" });
|
||||
|
||||
expect(saveConnections).toHaveBeenLastCalledWith([expect.objectContaining({ id: config.id, note: "Production reporting" })]);
|
||||
expect(store.getConfig(config.id)?.note).toBe("Production reporting");
|
||||
expect(store.connectedIds.has(config.id)).toBe(true);
|
||||
expect(store.treeNodes[0].comment).toBe("Production reporting");
|
||||
expect(store.treeNodes[0].isExpanded).toBe(true);
|
||||
expect(store.treeNodes[0].children?.map((child) => child.id)).toEqual(existingChildIds);
|
||||
});
|
||||
|
||||
it("does not delay connection success while optional metadata is loading", async () => {
|
||||
|
||||
@@ -41,6 +41,12 @@ describe("normalizeEditorSettings", () => {
|
||||
expect(normalizeEditorSettings({ sidebarObjectInfoMode: "invalid" } as any).sidebarObjectInfoMode).toBe("comment-inline");
|
||||
});
|
||||
|
||||
it("hides connection notes by default and preserves an explicit opt-in", () => {
|
||||
expect(normalizeEditorSettings({}).sidebarShowConnectionNotes).toBe(false);
|
||||
expect(normalizeEditorSettings({ sidebarShowConnectionNotes: true }).sidebarShowConnectionNotes).toBe(true);
|
||||
expect(normalizeEditorSettings({ sidebarShowConnectionNotes: false }).sidebarShowConnectionNotes).toBe(false);
|
||||
});
|
||||
|
||||
it("defaults SQL execution to the current statement and migrates legacy execute-all settings", () => {
|
||||
expect(normalizeEditorSettings({}).executeMode).toBe("current");
|
||||
expect(normalizeEditorSettings({ executeMode: "all" }).executeMode).toBe("current");
|
||||
@@ -665,6 +671,26 @@ describe("settingsStore persisted settings initialization", () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("atomically updates connection note visibility and supports retry", async () => {
|
||||
const loadEditorSettings = vi.fn().mockResolvedValue({ sidebarShowConnectionNotes: false });
|
||||
const saveEditorSettings = vi.fn().mockResolvedValue(undefined);
|
||||
vi.doMock("@/lib/backend/api", () => ({ loadEditorSettings, saveEditorSettings }));
|
||||
|
||||
const { useSettingsStore } = await import("@/stores/settingsStore");
|
||||
const store = useSettingsStore();
|
||||
await store.initEditorSettings();
|
||||
saveEditorSettings.mockClear();
|
||||
saveEditorSettings.mockRejectedValueOnce(new Error("storage unavailable")).mockResolvedValueOnce(undefined);
|
||||
|
||||
await expect(store.updateEditorSettingsAndPersist({ sidebarShowConnectionNotes: true })).rejects.toThrow("storage unavailable");
|
||||
expect(store.editorSettings.sidebarShowConnectionNotes).toBe(false);
|
||||
|
||||
await store.updateEditorSettingsAndPersist({ sidebarShowConnectionNotes: true });
|
||||
expect(store.editorSettings.sidebarShowConnectionNotes).toBe(true);
|
||||
expect(saveEditorSettings).toHaveBeenCalledTimes(2);
|
||||
expect(saveEditorSettings).toHaveBeenLastCalledWith(expect.objectContaining({ sidebarShowConnectionNotes: true }));
|
||||
});
|
||||
});
|
||||
|
||||
describe("settingsStore editor settings persistence", () => {
|
||||
|
||||
@@ -6763,6 +6763,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
return inheritNaturalTreeNodeOrder(node, {
|
||||
...existing,
|
||||
label: node.label,
|
||||
comment: node.comment,
|
||||
pinned: node.pinned,
|
||||
children: withSavedSqlRoot(node.connectionId!, existing.children || [], existing),
|
||||
});
|
||||
|
||||
@@ -577,6 +577,7 @@ export interface EditorSettings {
|
||||
updateNotificationsEnabled: boolean;
|
||||
sidebarHiddenTablePrefixes: string[];
|
||||
sidebarObjectInfoMode: SidebarObjectInfoMode;
|
||||
sidebarShowConnectionNotes: boolean;
|
||||
sidebarAllowHorizontalScroll: boolean;
|
||||
columnFormatters: Record<string, ColumnFormatterConfig>;
|
||||
customColumnFormatters: Record<string, CustomColumnFormatterConfig>;
|
||||
@@ -767,6 +768,7 @@ export const DEFAULT_EDITOR_SETTINGS: EditorSettings = {
|
||||
updateNotificationsEnabled: true,
|
||||
sidebarHiddenTablePrefixes: [],
|
||||
sidebarObjectInfoMode: "comment-inline",
|
||||
sidebarShowConnectionNotes: false,
|
||||
sidebarAllowHorizontalScroll: false,
|
||||
columnFormatters: {},
|
||||
customColumnFormatters: {},
|
||||
@@ -1142,6 +1144,7 @@ export function normalizeEditorSettings(settings: Partial<EditorSettings>, exist
|
||||
}
|
||||
).sidebarShowDatabaseSizes,
|
||||
),
|
||||
sidebarShowConnectionNotes: settings.sidebarShowConnectionNotes === true,
|
||||
sidebarAllowHorizontalScroll: settings.sidebarAllowHorizontalScroll ?? DEFAULT_EDITOR_SETTINGS.sidebarAllowHorizontalScroll,
|
||||
columnFormatters: normalizeColumnFormatters(settings.columnFormatters),
|
||||
customColumnFormatters: normalizeCustomColumnFormatters(settings.customColumnFormatters),
|
||||
@@ -1678,6 +1681,7 @@ export const useSettingsStore = defineStore("settings", () => {
|
||||
if (partial.updateNotificationsEnabled !== undefined) editorSettings.value.updateNotificationsEnabled = partial.updateNotificationsEnabled;
|
||||
if (partial.sidebarHiddenTablePrefixes !== undefined) editorSettings.value.sidebarHiddenTablePrefixes = normalizeSidebarHiddenTablePrefixes(partial.sidebarHiddenTablePrefixes);
|
||||
if (partial.sidebarObjectInfoMode !== undefined) editorSettings.value.sidebarObjectInfoMode = normalizeSidebarObjectInfoMode(partial.sidebarObjectInfoMode);
|
||||
if (partial.sidebarShowConnectionNotes !== undefined) editorSettings.value.sidebarShowConnectionNotes = partial.sidebarShowConnectionNotes === true;
|
||||
if (partial.sidebarAllowHorizontalScroll !== undefined) editorSettings.value.sidebarAllowHorizontalScroll = partial.sidebarAllowHorizontalScroll;
|
||||
if (partial.columnFormatters !== undefined) editorSettings.value.columnFormatters = partial.columnFormatters;
|
||||
if (partial.customColumnFormatters !== undefined) editorSettings.value.customColumnFormatters = partial.customColumnFormatters;
|
||||
|
||||
Reference in new issue
Block a user