feat(tabs): color editor tabs by connection
This commit is contained in:
19 files changed
+100
-9
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
import {
|
||||
connectionGroupDisplayName,
|
||||
executionSummaryItems,
|
||||
@@ -14,6 +15,7 @@ import {
|
||||
resultSourceRange,
|
||||
statementExecutionMarkers,
|
||||
tabColorStyle,
|
||||
tabConnectionColor,
|
||||
tabDatabaseIconType,
|
||||
tabDisplayTitle,
|
||||
tabDisplayTitles,
|
||||
@@ -704,6 +706,7 @@ describe("shared tab presentation helpers", () => {
|
||||
});
|
||||
|
||||
it("builds active/inactive color styles for classic and non-classic layouts", () => {
|
||||
useSettingsStore().editorSettings.colorizeConnectionTabs = false;
|
||||
// Node has no window/CSS globals: pin both to modern-engine answers.
|
||||
vi.stubGlobal("CSS", { supports: () => true });
|
||||
vi.stubGlobal("window", {
|
||||
@@ -725,6 +728,7 @@ describe("shared tab presentation helpers", () => {
|
||||
});
|
||||
|
||||
it("swaps inline color-mix tab colors for concrete rgba on legacy WebViews", () => {
|
||||
useSettingsStore().editorSettings.colorizeConnectionTabs = false;
|
||||
// WebKit without color-mix() invalidates the inline values at computed-value
|
||||
// time, which left the active tab with no background at all (macOS 12); and
|
||||
// it cannot substitute var() inside inline custom properties, so the legacy
|
||||
@@ -743,6 +747,18 @@ describe("shared tab presentation helpers", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("assigns stable palette colors to unconfigured connections", () => {
|
||||
const connectionStore = useConnectionStore();
|
||||
connectionStore.connections = [
|
||||
{ id: "conn-1", name: "One", db_type: "mysql", color: "" },
|
||||
{ id: "conn-2", name: "Two", db_type: "mysql", color: "#abcdef" },
|
||||
] as ConnectionConfig[];
|
||||
expect(tabConnectionColor("conn-1")).toBe(tabConnectionColor("conn-1"));
|
||||
expect(tabConnectionColor("conn-1")).not.toBe("");
|
||||
expect(tabConnectionColor("conn-1")).not.toBe(tabConnectionColor("conn-3"));
|
||||
expect(tabConnectionColor("conn-2")).toBe("#abcdef");
|
||||
});
|
||||
|
||||
it("resolves MQ driver icons from the connection store", () => {
|
||||
const connectionStore = useConnectionStore();
|
||||
connectionStore.connections = [
|
||||
|
||||
@@ -40,6 +40,11 @@ const translate = (key: string) => translations[key] ?? key;
|
||||
const allCategories = new Set(Object.keys(categoryLabels) as SettingsCategory[]);
|
||||
|
||||
describe("settings search", () => {
|
||||
it("finds connection tab colors by their Chinese label", () => {
|
||||
const entries = resolveSettingsSearchEntries(SETTINGS_SEARCH_DEFINITIONS, { isWeb: false, visibleCategories: allCategories }, (key) => (key === "settings.colorizeConnectionTabs" ? "按连接颜色区分标签页" : key), categoryLabels);
|
||||
expect(searchSettings(entries, "连接颜色", "zh-CN")).toEqual(expect.arrayContaining([expect.objectContaining({ id: "appearance-connection-tab-colors", category: "appearance", targetId: "appearance" })]));
|
||||
});
|
||||
|
||||
const definitions: readonly SettingsSearchDefinition[] = [
|
||||
{ id: "font", category: "editor", titleKey: "font", descriptionKey: "fontDescription" },
|
||||
{ id: "export", category: "data", titleKey: "export" },
|
||||
|
||||
@@ -46,6 +46,7 @@ export const EDITOR_SETTINGS_DRAFT_KEYS = [
|
||||
"appLayout",
|
||||
"tabLayout",
|
||||
"tabPlacement",
|
||||
"colorizeConnectionTabs",
|
||||
"tabGroupMode",
|
||||
"tabSortMode",
|
||||
"showColumnCommentsInHeader",
|
||||
|
||||
@@ -188,6 +188,7 @@ export const SETTINGS_SEARCH_DEFINITIONS: readonly SettingsSearchDefinition[] =
|
||||
{ id: "appearance-corners", category: "appearance", titleKey: "settings.cornerStyle", targetId: "appearance" },
|
||||
{ id: "appearance-layout", category: "appearance", titleKey: "settings.appLayout", targetId: "appearance" },
|
||||
{ id: "appearance-tab-layout", category: "appearance", titleKey: "settings.tabLayout", targetId: "appearance" },
|
||||
{ id: "appearance-connection-tab-colors", category: "appearance", titleKey: "settings.colorizeConnectionTabs", descriptionKey: "settings.colorizeConnectionTabsDescription", targetId: "appearance" },
|
||||
{ id: "appearance-icons", category: "appearance", titleKey: "settings.iconTheme", targetId: "appearance", visible: desktopOnly },
|
||||
{ id: "appearance-tray", category: "appearance", titleKey: "settings.showTrayIcon", descriptionKey: "settings.showTrayIconDescription", targetId: "appearance", visible: desktopOnly },
|
||||
{ id: "appearance-quit", category: "appearance", titleKey: "settings.quitOnClose", descriptionKey: "settings.quitOnCloseDescription", targetId: "appearance", visible: desktopOnly },
|
||||
|
||||
@@ -116,6 +116,7 @@ const SETTINGS_TRANSFER_CATEGORY_KEYS: Record<SettingsTransferCategoryId, readon
|
||||
"tabLayout",
|
||||
"tabPlacement",
|
||||
"tabGroupMode",
|
||||
"colorizeConnectionTabs",
|
||||
"tabSortMode",
|
||||
"sidebarActivation",
|
||||
"sidebarObjectDisplay",
|
||||
|
||||
@@ -42,6 +42,36 @@ export function connectionColor(connectionId: string): string {
|
||||
return connectionStore.getConfig(connectionId)?.color || "";
|
||||
}
|
||||
|
||||
function tabConnectionGeneratedColor(connectionId: string): string {
|
||||
let hash = 2166136261;
|
||||
for (const character of connectionId) {
|
||||
hash ^= character.codePointAt(0)!;
|
||||
hash = Math.imul(hash, 16777619);
|
||||
}
|
||||
const hue = (hash >>> 0) % 360;
|
||||
const saturation = 68;
|
||||
const lightness = 52;
|
||||
const chroma = (1 - Math.abs((2 * lightness) / 100 - 1)) * (saturation / 100);
|
||||
const hueSector = hue / 60;
|
||||
const x = chroma * (1 - Math.abs((hueSector % 2) - 1));
|
||||
const match = lightness / 100 - chroma / 2;
|
||||
const [red, green, blue] = hueSector < 1 ? [chroma, x, 0] : hueSector < 2 ? [x, chroma, 0] : hueSector < 3 ? [0, chroma, x] : hueSector < 4 ? [0, x, chroma] : hueSector < 5 ? [x, 0, chroma] : [chroma, 0, x];
|
||||
return `#${[red, green, blue]
|
||||
.map((channel) =>
|
||||
Math.round((channel + match) * 255)
|
||||
.toString(16)
|
||||
.padStart(2, "0"),
|
||||
)
|
||||
.join("")}`;
|
||||
}
|
||||
|
||||
/** Returns a stable visual identity for a tab's connection when no custom color is set. */
|
||||
export function tabConnectionColor(connectionId: string): string {
|
||||
const configured = connectionColor(connectionId);
|
||||
if (configured) return configured;
|
||||
return tabConnectionGeneratedColor(connectionId);
|
||||
}
|
||||
|
||||
export function isConnectionReadonly(connectionId: string): boolean {
|
||||
const connectionStore = useConnectionStore();
|
||||
return connectionStore.getConfig(connectionId)?.read_only ?? false;
|
||||
@@ -710,15 +740,14 @@ export function appTabActiveIndicator(): string {
|
||||
}
|
||||
|
||||
export function tabColorStyle(tab: QueryTab, active: boolean, isClassic: boolean): CSSProperties | undefined {
|
||||
const activeIndicator = appTabActiveIndicator();
|
||||
const color = connectionColor(tab.connectionId);
|
||||
if (!color) {
|
||||
if (!useSettingsStore().editorSettings.colorizeConnectionTabs) {
|
||||
const activeIndicator = appTabActiveIndicator();
|
||||
const background = appTabActiveBackground();
|
||||
if (isClassic) {
|
||||
return active ? { "--app-tab-background": background, boxShadow: activeIndicator } : undefined;
|
||||
}
|
||||
if (isClassic) return active ? { "--app-tab-background": background, boxShadow: activeIndicator } : undefined;
|
||||
return active ? { "--app-tab-background": background, borderColor: "var(--ring)" } : undefined;
|
||||
}
|
||||
const activeIndicator = appTabActiveIndicator();
|
||||
const color = tabConnectionColor(tab.connectionId);
|
||||
if (isClassic) {
|
||||
return {
|
||||
"--app-tab-background": hexToRgba(color, active ? 0.24 : 0.07),
|
||||
|
||||
Reference in new issue
Block a user