fix(source): open pending tab while loading object source

This commit is contained in:
Abeautifulsnow authored and GitHub committed 2026-09-14 19:59:21 +08:00
1 parent eba6853480
commit 760d2c6409
14 files changed
+824 -149

No files matched your search

@@ -2067,18 +2067,11 @@ function openSidebarObjectSource(node: TreeNode, initialEditing: boolean) {
// connections list user-defined types without a CREATE TYPE getter this cycle.
if ((node.type === "type" || node.type === "type-body") && !supportsTypeObjectSource(store.getConfig(node.connectionId)?.db_type)) return;
const target = createSidebarActionTarget(node);
const requestGeneration = beginSidebarAction();
void store
.ensureConnected(target.connectionId!)
.then(() => {
if (requestGeneration !== sidebarActionGeneration) return;
store.activeConnectionId = target.connectionId!;
sidebarObjectSourceTarget.value = { node: target, initialEditing };
sidebarObjectSourceOpen.value = true;
})
.catch((error: any) => {
if (requestGeneration === sidebarActionGeneration) toast(error?.message || String(error), 5000);
});
beginSidebarAction();
// issue #9035:弹窗立即挂载。此前先 await ensureConnected 再开弹窗,这段时间
// 界面上没有任何反馈;现在连接与取源都在弹窗自身的加载态之内完成。
sidebarObjectSourceTarget.value = { node: target, initialEditing };
sidebarObjectSourceOpen.value = true;
}
function openSidebarSettings(initialTab: string) {
@@ -156,8 +156,7 @@ import {
type TableChildObjectType,
} from "@/lib/database/dbAdminSql";
import { buildRenameObjectSql, buildRenameDatabaseSql, buildRenameDatabasePreflightSql, databaseRenameMaintenanceDatabase, supportsDatabaseRename, supportsObjectRename, type RenameableObjectType } from "@/lib/table/objectRenameSql";
import { buildEditableObjectSource, buildRoutineRenameObjectSourceStatements, supportsSourceBackedRoutineRename } from "@/lib/table/objectSourceEditor";
import { loadEditableObjectSourceForEditor } from "@/lib/table/objectSourceLoad";
import { buildRoutineRenameObjectSourceStatements, supportsSourceBackedRoutineRename } from "@/lib/table/objectSourceEditor";
import { buildViewDdl } from "@/lib/table/viewDdl";
import { formatSqlForDisplay, sqlFormatDialectForDbType } from "@/lib/sql/sqlFormatter";
import { omitDdlIdentifierQuotes } from "@/lib/sql/ddlDisplay";
@@ -352,7 +351,7 @@ const settingsStore = useSettingsStore();
const savedSqlStore = useSavedSqlStore();
const { toast, message: toastMessage, dismissToast } = useToast();
const { toast } = useToast();
const installedPlugins = ref<InstalledPlugin[]>([]);
const sidebarPluginRegistry = computed(() => createFrontendPluginRegistry(installedPlugins.value, appLocale.value));
@@ -2526,70 +2525,22 @@ function openObjectSourceDialog(initialEditing: boolean, viewPackageBody = false
const database = node.database;
const sourceTarget = objectSourceTargetForTreeNode(sourceNode);
if (!sourceTarget) return;
const openMode = settingsStore.editorSettings.routineSourceOpenMode;
if (openMode === "query-tab") {
const loadingMessage = t("common.loading");
const loadingToastTimer = window.setTimeout(() => toast(loadingMessage, 30000), 350);
const finishLoadingToast = () => {
window.clearTimeout(loadingToastTimer);
if (toastMessage.value === loadingMessage) dismissToast();
};
void connectionStore
.ensureConnected(connectionId)
.then(async () => {
connectionStore.activeConnectionId = connectionId;
const schema = sourceTarget.schema || database;
const databaseType = effectiveDatabaseTypeForConnection(connectionStore.getConfig(connectionId));
if (!databaseType) throw new Error("Connection type is unavailable.");
const objectName = sourceTarget.name;
const {
raw,
editableSource,
objectType: resolvedType,
} = await loadEditableObjectSourceForEditor(api.getObjectSource, buildEditableObjectSource, {
connectionId,
database,
schema,
name: objectName,
objectType: sourceTarget.objectType as any,
databaseType,
signature: sourceNode.signature,
});
const sourceIsEditable = raw.editable !== false && !["SEQUENCE", "TRIGGER", "TYPE", "TYPE_BODY", "JOB"].includes(resolvedType);
if (sourceIsEditable) {
queryStore.openObjectSourceTab({
connectionId,
database,
title: `Source - ${node.label}`,
schema,
catalog: node.catalog,
sql: editableSource,
objectSource: {
schema,
name: objectName,
objectType: resolvedType,
signature: node.signature,
},
});
} else {
queryStore.createTab(connectionId, database, `Source - ${node.label}`, "query", schema, editableSource, node.catalog, { forceNew: true, sourceView: true });
}
})
.catch((e: any) => {
toast(e?.message || String(e), 5000);
})
.finally(finishLoadingToast);
const schema = sourceTarget.schema || database;
// issue #9035:两个分支都不再 await 连接与取源。先把容器挂出来(源码 tab /
// 源码弹窗),ensureConnected 与 getObjectSource 都发生在已挂载的 UI 之内,
// 加载中有状态、失败就地重试,而不是点击后一段时间毫无反应。
if (settingsStore.editorSettings.routineSourceOpenMode === "query-tab") {
queryStore.openObjectSourceTabPending({
connectionId,
database,
title: `Source - ${node.label}`,
schema,
catalog: node.catalog,
request: { name: sourceTarget.name, objectType: sourceTarget.objectType, signature: sourceNode.signature },
});
return;
}
void connectionStore
.ensureConnected(connectionId)
.then(() => {
connectionStore.activeConnectionId = connectionId;
emit("open-object-source", sourceNode, initialEditing);
})
.catch((e: any) => {
toast(e?.message || String(e), 5000);
});
emit("open-object-source", sourceNode, initialEditing);
}
function openProcedureExecution() {