feat(sidebar): add exclusive right panel setting

This commit is contained in:
t8y2 committed 2026-07-21 21:56:24 +08:00
1 parent bbfbdf7ff5
commit d4c28c5a9a
12 files changed
+197 -32

No files matched your search

+36 -1
View File
@@ -1,5 +1,5 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { EXECUTE_MODE_CURRENT_DEFAULT_VERSION, normalizeDesktopSettings, normalizeEditorSettings, normalizeMcpGlobalPolicy } from "@/stores/settingsStore";
import { enforceRightSidebarPanelExclusivity, EXECUTE_MODE_CURRENT_DEFAULT_VERSION, normalizeDesktopSettings, normalizeEditorSettings, normalizeMcpGlobalPolicy, transitionRightSidebarPanels, type RightSidebarPanelState } from "@/stores/settingsStore";
import { createPinia, setActivePinia } from "pinia";
import type { AiConfigItem } from "@/types/ai";
@@ -124,6 +124,41 @@ describe("normalizeEditorSettings", () => {
expect(settings.toolbarItems.sqlFileTree).toBe(false);
expect(settings.toolbarItems.history).toBe(false);
expect(settings.toolbarItems.sqlLibrary).toBe(true);
expect(settings.toolbarItems.exclusiveRightSidebarPanels).toBe(true);
});
it("preserves disabled right sidebar panel exclusivity", () => {
expect(
normalizeEditorSettings({
toolbarItems: {
exclusiveRightSidebarPanels: false,
} as any,
}).toolbarItems.exclusiveRightSidebarPanels,
).toBe(false);
});
});
describe("right sidebar panel transitions", () => {
const state = (overrides: Partial<RightSidebarPanelState> = {}): RightSidebarPanelState => ({
ai: false,
history: false,
sqlLibrary: false,
sqlFile: false,
...overrides,
});
it("allows multiple panels when exclusivity is disabled", () => {
expect(transitionRightSidebarPanels(state({ ai: true }), "history", true, false)).toEqual(state({ ai: true, history: true }));
});
it("switches panels and allows the active panel to toggle closed", () => {
const switched = transitionRightSidebarPanels(state({ ai: true }), "sqlLibrary", true, true);
expect(switched).toEqual(state({ sqlLibrary: true }));
expect(transitionRightSidebarPanels(switched, "sqlLibrary", false, true)).toEqual(state());
});
it("collapses synchronized multi-panel state to the preferred open panel", () => {
expect(enforceRightSidebarPanelExclusivity(state({ ai: true, history: true, sqlFile: true }), "history")).toEqual(state({ history: true }));
});
});
+23
View File
@@ -471,6 +471,7 @@ export interface ToolbarItems {
ai: boolean;
theme: boolean;
github: boolean;
exclusiveRightSidebarPanels: boolean;
}
export const DEFAULT_TOOLBAR_ITEMS: ToolbarItems = {
@@ -486,8 +487,28 @@ export const DEFAULT_TOOLBAR_ITEMS: ToolbarItems = {
ai: true,
theme: true,
github: true,
exclusiveRightSidebarPanels: true,
};
export const RIGHT_SIDEBAR_PANEL_IDS = ["ai", "history", "sqlLibrary", "sqlFile"] as const;
export type RightSidebarPanelId = (typeof RIGHT_SIDEBAR_PANEL_IDS)[number];
export type RightSidebarPanelState = Record<RightSidebarPanelId, boolean>;
export function transitionRightSidebarPanels(current: RightSidebarPanelState, panel: RightSidebarPanelId, open: boolean, exclusive: boolean): RightSidebarPanelState {
const next = { ...current };
if (open && exclusive) {
for (const panelId of RIGHT_SIDEBAR_PANEL_IDS) next[panelId] = false;
}
next[panel] = open;
return next;
}
export function enforceRightSidebarPanelExclusivity(current: RightSidebarPanelState, preferred?: RightSidebarPanelId): RightSidebarPanelState {
const panelToKeep = preferred && current[preferred] ? preferred : RIGHT_SIDEBAR_PANEL_IDS.find((panelId) => current[panelId]);
if (!panelToKeep) return { ...current };
return transitionRightSidebarPanels(current, panelToKeep, true, true);
}
export const EDITOR_THEMES: { value: EditorTheme; label: string; dark: boolean }[] = [
{ value: "app", label: "Follow app theme", dark: false },
{ value: "one-dark", label: "One Dark", dark: true },
@@ -752,6 +773,8 @@ function normalizeToolbarItems(items: Partial<ToolbarItems> | undefined): Toolba
ai: items.ai ?? defaults.ai,
theme: items.theme ?? defaults.theme,
github: items.github ?? defaults.github,
// Saved settings from before right-sidebar exclusivity must adopt the new default.
exclusiveRightSidebarPanels: items.exclusiveRightSidebarPanels !== false,
};
}