feat(query): pin, rename and label result run tabs
This commit is contained in:
26 files changed
+319
-32
No files matched your search
@@ -75,7 +75,7 @@ import { formatDdlForDisplay } from "@/lib/sql/ddlDisplay";
|
||||
import { buildTableSelectSql, quoteTableDataIdentifier } from "@/lib/table/tableSelectSql";
|
||||
import { connectionObjectTreeNodeSchema, connectionQueryExecutionSchema, connectionUsesDatabaseObjectTreeMode, effectiveDatabaseTypeForConnection, gaussdbCountQueryDopHint, jdbcConnectionUsesDriverRowOffset, metadataSchemaForConnection } from "@/lib/database/jdbcDialect";
|
||||
import { frontendQueryTimeoutDelayMs, frontendQueryTimeoutSecsForSql, queryTimeoutSecsForConnection } from "@/lib/sql/queryTimeout";
|
||||
import { queryResultNameFromPreamble, queryResultSourceLabel } from "@/lib/sql/queryResultSource";
|
||||
import { queryResultNameFromPreamble, queryResultSourceLabel, queryResultSourceNameParts } from "@/lib/sql/queryResultSource";
|
||||
import { sqlServerCountUsesLocalTempTable } from "@/lib/query/queryResultCountSession";
|
||||
import { stripPaginationRowNumber } from "@/lib/query/queryPaginationResult";
|
||||
import { beginDataGridNativeSelectionBlock, finishDataGridNativeSelectionBlock } from "@/lib/dataGrid/dataGridNativeSelection";
|
||||
@@ -380,6 +380,8 @@ function releaseResultObjectPayload(result: QueryResult): void {
|
||||
result.messages = undefined;
|
||||
result.error = undefined;
|
||||
result.sourceLabel = undefined;
|
||||
result.sourceQualifier = undefined;
|
||||
result.sourceName = undefined;
|
||||
result.sourceStatement = undefined;
|
||||
}
|
||||
|
||||
@@ -435,7 +437,12 @@ function annotateQueryResultSources(results: QueryResult[], sql: string, databas
|
||||
const documentStatement = sourceOffset === undefined ? undefined : findSourceDocumentStatement(documentStatements, sourceOffset + statement.from);
|
||||
const preamble = documentStatement ? sourceDocumentSql!.slice(documentStatement.hitFrom, documentStatement.from) : sql.slice(statement.hitFrom, statement.from);
|
||||
const customName = queryResultNameFromPreamble(preamble, { databaseType });
|
||||
if (customName) result.sourceLabel = customName;
|
||||
if (customName) {
|
||||
result.sourceLabel = customName;
|
||||
// 自定义名称(-- name: xxx)优先:清除结构化来源,避免“结果集名称包含数据库名”设置把它替换成表名
|
||||
result.sourceQualifier = undefined;
|
||||
result.sourceName = undefined;
|
||||
}
|
||||
const successfulUseDatabase = result.execution_error !== true ? useDatabaseFromStatement(statement.sql, databaseType) : undefined;
|
||||
if (successfulUseDatabase) {
|
||||
sourceDatabase = successfulUseDatabase;
|
||||
@@ -650,8 +657,14 @@ function annotateQueryResultSource(result: QueryResult, sourceStatement: string,
|
||||
result.sourceFrom = sourceRange.from;
|
||||
result.sourceTo = sourceRange.to;
|
||||
}
|
||||
const label = databaseType ? queryResultSourceLabel(sourceStatement, { database, databaseType }) : undefined;
|
||||
if (label) result.sourceLabel = label;
|
||||
const parts = databaseType ? queryResultSourceNameParts(sourceStatement, { database, databaseType }) : undefined;
|
||||
if (parts) {
|
||||
// 同时保留结构化来源信息:结果集页签可以按设置只展示对象名,避免退化成字符串切割
|
||||
result.sourceQualifier = parts.qualifier;
|
||||
result.sourceName = parts.name;
|
||||
const label = parts.qualifier ? `${parts.qualifier}.${parts.name}` : parts.name;
|
||||
if (label) result.sourceLabel = label;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1917,6 +1930,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
const run = tab?.resultRuns?.find((item) => item.id === runId);
|
||||
if (!tab || !run) return false;
|
||||
run.title = trimmed;
|
||||
run.customTitle = true;
|
||||
void persistResultRun(tab, run);
|
||||
return true;
|
||||
}
|
||||
@@ -2128,12 +2142,17 @@ export const useQueryStore = defineStore("query", () => {
|
||||
function captureDisplayedResultRun(tab: QueryTab, sql: string, createdAt = Date.now(), options: ResultRunCaptureOptions = {}) {
|
||||
if (tab.mode !== "query" || !tab.result) return;
|
||||
const sequence = nextResultRunSequence(tab);
|
||||
// 批次级来源:非活动批次的 payload 会被回收,结果标签命名需要独立保存来源
|
||||
const primaryResult = tab.results?.[0] ?? tab.result;
|
||||
const run: NonNullable<QueryTab["resultRuns"]>[number] = {
|
||||
id: uuid(),
|
||||
title: options.title ?? `Run ${sequence}`,
|
||||
customTitle: !!options.title,
|
||||
sequence,
|
||||
sql,
|
||||
createdAt,
|
||||
sourceLabel: primaryResult?.sourceLabel,
|
||||
sourceName: primaryResult?.sourceName,
|
||||
result: tab.result,
|
||||
results: tab.results,
|
||||
activeResultIndex: tab.activeResultIndex,
|
||||
@@ -2206,6 +2225,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
...workerRun,
|
||||
id: runId,
|
||||
title,
|
||||
customTitle: true,
|
||||
sequence: nextResultRunSequence(source),
|
||||
multiDbExecution: execution,
|
||||
resultCacheKey: undefined,
|
||||
@@ -2562,6 +2582,9 @@ export const useQueryStore = defineStore("query", () => {
|
||||
sql: run.sql,
|
||||
createdAt: run.createdAt,
|
||||
pinned: run.pinned,
|
||||
customTitle: run.customTitle,
|
||||
sourceLabel: run.sourceLabel,
|
||||
sourceName: run.sourceName,
|
||||
activeResultIndex: run.activeResultIndex,
|
||||
resultCacheKey: run.resultCacheKey,
|
||||
resultEvicted: run.resultEvicted,
|
||||
@@ -6972,6 +6995,8 @@ export const useQueryStore = defineStore("query", () => {
|
||||
const annotateMongoResult = (result: QueryResult): QueryResult => {
|
||||
const annotated = annotateQueryResultSource(result, sourceStatement, undefined, undefined, sourceRange);
|
||||
if ("collection" in mongoCommand) {
|
||||
annotated.sourceQualifier = currentDatabase || undefined;
|
||||
annotated.sourceName = mongoCommand.collection;
|
||||
annotated.sourceLabel = currentDatabase ? `${currentDatabase}.${mongoCommand.collection}` : mongoCommand.collection;
|
||||
}
|
||||
return annotated;
|
||||
|
||||
@@ -860,6 +860,8 @@ export interface EditorSettings {
|
||||
mongoViewMode: "document" | "table";
|
||||
showColumnCommentsInHeader: boolean;
|
||||
showColumnTypesInHeader: boolean;
|
||||
/** 结果集页签/结果列表的名称是否带上库名(关闭后只显示表名,完整名称仍在悬浮提示中)。 */
|
||||
showResultSourceDatabase: boolean;
|
||||
dataGridShowTransposeFieldMetadata: boolean;
|
||||
colorizeDataGridCellTypes: boolean;
|
||||
dataGridTypeColorSchemes: DataGridTypeColorScheme[];
|
||||
@@ -1137,6 +1139,7 @@ export const DEFAULT_EDITOR_SETTINGS: EditorSettings = {
|
||||
mongoViewMode: "document",
|
||||
showColumnCommentsInHeader: true,
|
||||
showColumnTypesInHeader: true,
|
||||
showResultSourceDatabase: true,
|
||||
dataGridShowTransposeFieldMetadata: false,
|
||||
colorizeDataGridCellTypes: false,
|
||||
dataGridTypeColorSchemes: [],
|
||||
@@ -1691,6 +1694,7 @@ export function normalizeEditorSettings(settings: Partial<EditorSettings>, exist
|
||||
mongoViewMode: settings.mongoViewMode === "table" ? "table" : DEFAULT_EDITOR_SETTINGS.mongoViewMode,
|
||||
showColumnCommentsInHeader: settings.showColumnCommentsInHeader ?? DEFAULT_EDITOR_SETTINGS.showColumnCommentsInHeader,
|
||||
showColumnTypesInHeader: settings.showColumnTypesInHeader ?? DEFAULT_EDITOR_SETTINGS.showColumnTypesInHeader,
|
||||
showResultSourceDatabase: settings.showResultSourceDatabase ?? DEFAULT_EDITOR_SETTINGS.showResultSourceDatabase,
|
||||
dataGridShowTransposeFieldMetadata: settings.dataGridShowTransposeFieldMetadata === true,
|
||||
colorizeDataGridCellTypes: settings.colorizeDataGridCellTypes ?? DEFAULT_EDITOR_SETTINGS.colorizeDataGridCellTypes,
|
||||
dataGridTypeColorSchemes,
|
||||
@@ -2511,6 +2515,7 @@ export const useSettingsStore = defineStore("settings", () => {
|
||||
if (partial.mongoViewMode !== undefined) editorSettings.value.mongoViewMode = partial.mongoViewMode;
|
||||
if (partial.showColumnCommentsInHeader !== undefined) editorSettings.value.showColumnCommentsInHeader = partial.showColumnCommentsInHeader;
|
||||
if (partial.showColumnTypesInHeader !== undefined) editorSettings.value.showColumnTypesInHeader = partial.showColumnTypesInHeader;
|
||||
if (partial.showResultSourceDatabase !== undefined) editorSettings.value.showResultSourceDatabase = partial.showResultSourceDatabase;
|
||||
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