feat(query): add configurable result tab naming
This commit is contained in:
26 files changed
+332
-39
No files matched your search
@@ -978,6 +978,10 @@ describe("queryStore multi-statement errors", () => {
|
||||
await store.executeTabSql(tabId, sql);
|
||||
|
||||
expect(store.tabs.find((item) => item.id === tabId)?.results?.map((result) => result.sourceLabel)).toEqual(["Orders", "Users"]);
|
||||
expect(store.tabs.find((item) => item.id === tabId)?.results).toMatchObject([
|
||||
{ sourceLabelKind: "comment", sourceQualifier: "app", sourceName: "orders" },
|
||||
{ sourceLabelKind: "comment", sourceQualifier: "app", sourceName: "users" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("does not repeatedly scan the full document when naming a selected large batch", async () => {
|
||||
|
||||
@@ -20,6 +20,13 @@ import type { AiConfigItem } from "@/types/ai";
|
||||
import { DATA_GRID_EXTRACTOR_OPTIONS_MIGRATION_VERSION } from "@/lib/dataGrid/dataGridCopyExtractor";
|
||||
|
||||
describe("normalizeEditorSettings", () => {
|
||||
it("preserves comment-first naming for existing settings and permits opting out", () => {
|
||||
expect(DEFAULT_EDITOR_SETTINGS.resultTabPreferComments).toBe(true);
|
||||
expect(normalizeEditorSettings({}).resultTabPreferComments).toBe(true);
|
||||
expect(normalizeEditorSettings({ resultTabPreferComments: false }).resultTabPreferComments).toBe(false);
|
||||
expect(normalizeEditorSettings({ resultTabPreferComments: "false" } as any).resultTabPreferComments).toBe(true);
|
||||
});
|
||||
|
||||
it("defaults and sanitizes AI conversation typography independently", () => {
|
||||
expect(normalizeEditorSettings({})).toMatchObject({ aiFontFamily: "", aiFontSize: 12 });
|
||||
expect(
|
||||
|
||||
@@ -405,6 +405,7 @@ function releaseResultObjectPayload(result: QueryResult): void {
|
||||
result.messages = undefined;
|
||||
result.error = undefined;
|
||||
result.sourceLabel = undefined;
|
||||
result.sourceLabelKind = undefined;
|
||||
result.sourceQualifier = undefined;
|
||||
result.sourceName = undefined;
|
||||
result.sourceStatement = undefined;
|
||||
@@ -464,9 +465,9 @@ function annotateQueryResultSources(results: QueryResult[], sql: string, databas
|
||||
const customName = queryResultNameFromPreamble(preamble, { databaseType });
|
||||
if (customName) {
|
||||
result.sourceLabel = customName;
|
||||
// 自定义名称(-- name: xxx)优先:清除结构化来源,避免“结果集名称包含数据库名”设置把它替换成表名
|
||||
result.sourceQualifier = undefined;
|
||||
result.sourceName = undefined;
|
||||
result.sourceLabelKind = "comment";
|
||||
// 保留结构化来源,方便“来源表名”模式在注释存在时仍显示表名。
|
||||
// “注释”模式通过 sourceLabelKind 选择这个自定义名称。
|
||||
}
|
||||
const successfulUseDatabase = result.execution_error !== true ? useDatabaseFromStatement(statement.sql, databaseType) : undefined;
|
||||
if (successfulUseDatabase) {
|
||||
@@ -688,7 +689,10 @@ function annotateQueryResultSource(result: QueryResult, sourceStatement: string,
|
||||
result.sourceQualifier = parts.qualifier;
|
||||
result.sourceName = parts.name;
|
||||
const label = parts.qualifier ? `${parts.qualifier}.${parts.name}` : parts.name;
|
||||
if (label) result.sourceLabel = label;
|
||||
if (label) {
|
||||
result.sourceLabel = label;
|
||||
result.sourceLabelKind = "source";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -2184,6 +2188,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
createdAt,
|
||||
sourceLabel: primaryResult?.sourceLabel,
|
||||
sourceName: primaryResult?.sourceName,
|
||||
sourceLabelKind: primaryResult?.sourceLabelKind,
|
||||
result: tab.result,
|
||||
results: tab.results,
|
||||
activeResultIndex: tab.activeResultIndex,
|
||||
@@ -2621,6 +2626,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
customTitle: run.customTitle,
|
||||
sourceLabel: run.sourceLabel,
|
||||
sourceName: run.sourceName,
|
||||
sourceLabelKind: run.sourceLabelKind,
|
||||
activeResultIndex: run.activeResultIndex,
|
||||
resultCacheKey: run.resultCacheKey,
|
||||
resultEvicted: run.resultEvicted,
|
||||
@@ -5936,8 +5942,12 @@ export const useQueryStore = defineStore("query", () => {
|
||||
});
|
||||
if (nextLabel) {
|
||||
tab.result.sourceLabel = nextLabel;
|
||||
tab.result.sourceLabelKind = "source";
|
||||
const matching = tab.results?.find((result) => result === tab.result);
|
||||
if (matching) matching.sourceLabel = nextLabel;
|
||||
if (matching) {
|
||||
matching.sourceLabel = nextLabel;
|
||||
matching.sourceLabelKind = "source";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7119,6 +7129,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
annotated.sourceQualifier = currentDatabase || undefined;
|
||||
annotated.sourceName = mongoCommand.collection;
|
||||
annotated.sourceLabel = currentDatabase ? `${currentDatabase}.${mongoCommand.collection}` : mongoCommand.collection;
|
||||
annotated.sourceLabelKind = "source";
|
||||
}
|
||||
return commandTiming.finish(annotated);
|
||||
};
|
||||
|
||||
@@ -727,6 +727,8 @@ export type DataGridFilterEditorView = "quick" | "conditions" | "text";
|
||||
export type DataGridToolbarLayout = "single" | "split";
|
||||
const RESULT_RUN_DISPLAY_MODES = ["tabs", "list"] as const;
|
||||
export type ResultRunDisplayMode = (typeof RESULT_RUN_DISPLAY_MODES)[number];
|
||||
export const RESULT_TAB_NAMING_MODES = ["source", "ordinal", "comment"] as const;
|
||||
export type ResultTabNamingMode = (typeof RESULT_TAB_NAMING_MODES)[number];
|
||||
const MULTI_STATEMENT_DEFAULT_VIEWS = ["result", "summary"] as const;
|
||||
export type MultiStatementDefaultView = (typeof MULTI_STATEMENT_DEFAULT_VIEWS)[number];
|
||||
export const TABLE_FONT_SIZE_MIN = 8;
|
||||
@@ -909,6 +911,10 @@ export interface EditorSettings {
|
||||
showColumnHeaderTooltips: boolean;
|
||||
/** 结果集页签/结果列表的名称是否带上库名(关闭后只显示表名,完整名称仍在悬浮提示中)。 */
|
||||
showResultSourceDatabase: boolean;
|
||||
/** Naming strategy for query result execution and result-set tabs. */
|
||||
resultTabNamingMode: ResultTabNamingMode;
|
||||
/** Prefer SQL preamble comments in source naming mode, preserving the original naming behavior. */
|
||||
resultTabPreferComments: boolean;
|
||||
dataGridShowTransposeFieldMetadata: boolean;
|
||||
colorizeDataGridCellTypes: boolean;
|
||||
dataGridTypeColorSchemes: DataGridTypeColorScheme[];
|
||||
@@ -1199,6 +1205,8 @@ export const DEFAULT_EDITOR_SETTINGS: EditorSettings = {
|
||||
showColumnTypesInHeader: true,
|
||||
showColumnHeaderTooltips: true,
|
||||
showResultSourceDatabase: true,
|
||||
resultTabNamingMode: "source",
|
||||
resultTabPreferComments: true,
|
||||
dataGridShowTransposeFieldMetadata: false,
|
||||
colorizeDataGridCellTypes: false,
|
||||
dataGridTypeColorSchemes: [],
|
||||
@@ -1416,6 +1424,10 @@ function normalizeResultRunDisplayMode(value: unknown): ResultRunDisplayMode {
|
||||
return RESULT_RUN_DISPLAY_MODES.includes(value as ResultRunDisplayMode) ? (value as ResultRunDisplayMode) : DEFAULT_EDITOR_SETTINGS.resultRunDisplayMode;
|
||||
}
|
||||
|
||||
function normalizeResultTabNamingMode(value: unknown): ResultTabNamingMode {
|
||||
return RESULT_TAB_NAMING_MODES.includes(value as ResultTabNamingMode) ? (value as ResultTabNamingMode) : DEFAULT_EDITOR_SETTINGS.resultTabNamingMode;
|
||||
}
|
||||
|
||||
function normalizeMultiStatementDefaultView(value: unknown): MultiStatementDefaultView {
|
||||
return MULTI_STATEMENT_DEFAULT_VIEWS.includes(value as MultiStatementDefaultView) ? (value as MultiStatementDefaultView) : DEFAULT_EDITOR_SETTINGS.multiStatementDefaultView;
|
||||
}
|
||||
@@ -1773,6 +1785,8 @@ export function normalizeEditorSettings(settings: Partial<EditorSettings>, exist
|
||||
showColumnTypesInHeader: settings.showColumnTypesInHeader ?? DEFAULT_EDITOR_SETTINGS.showColumnTypesInHeader,
|
||||
showColumnHeaderTooltips: settings.showColumnHeaderTooltips ?? DEFAULT_EDITOR_SETTINGS.showColumnHeaderTooltips,
|
||||
showResultSourceDatabase: settings.showResultSourceDatabase ?? DEFAULT_EDITOR_SETTINGS.showResultSourceDatabase,
|
||||
resultTabNamingMode: normalizeResultTabNamingMode(settings.resultTabNamingMode),
|
||||
resultTabPreferComments: settings.resultTabPreferComments !== false,
|
||||
dataGridShowTransposeFieldMetadata: settings.dataGridShowTransposeFieldMetadata === true,
|
||||
colorizeDataGridCellTypes: settings.colorizeDataGridCellTypes ?? DEFAULT_EDITOR_SETTINGS.colorizeDataGridCellTypes,
|
||||
dataGridTypeColorSchemes,
|
||||
@@ -2614,6 +2628,8 @@ export const useSettingsStore = defineStore("settings", () => {
|
||||
if (partial.showColumnTypesInHeader !== undefined) editorSettings.value.showColumnTypesInHeader = partial.showColumnTypesInHeader;
|
||||
if (partial.showColumnHeaderTooltips !== undefined) editorSettings.value.showColumnHeaderTooltips = partial.showColumnHeaderTooltips;
|
||||
if (partial.showResultSourceDatabase !== undefined) editorSettings.value.showResultSourceDatabase = partial.showResultSourceDatabase;
|
||||
if (partial.resultTabNamingMode !== undefined) editorSettings.value.resultTabNamingMode = normalizeResultTabNamingMode(partial.resultTabNamingMode);
|
||||
if (partial.resultTabPreferComments !== undefined) editorSettings.value.resultTabPreferComments = partial.resultTabPreferComments !== false;
|
||||
if (partial.dataGridShowTransposeFieldMetadata !== undefined) editorSettings.value.dataGridShowTransposeFieldMetadata = partial.dataGridShowTransposeFieldMetadata === true;
|
||||
if (partial.colorizeDataGridCellTypes !== undefined) editorSettings.value.colorizeDataGridCellTypes = partial.colorizeDataGridCellTypes === true;
|
||||
if (partial.dataGridTypeColorSchemes !== undefined) {
|
||||
|
||||
Reference in new issue
Block a user