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

@@ -672,6 +672,7 @@ const resultsPaneSize = ref(Number(safeLocalStorageGet("dbx-results-pane-size"))
// re-normalize a single pane, and shrinking it would leave a blank dead zone.
const editorPaneSize = computed(() => (props.editorOnly || !resultsPaneOpen.value ? 100 : 100 - resultsPaneSize.value));
const queryRunningElapsed = ref(0);
const sourceLoadElapsed = ref(0);
function toggleResultsPane(): boolean {
if (props.activeTab.mode !== "query" || !hasQueryOutput.value) return false;
@@ -703,25 +704,36 @@ function onResultsResized(payload: { panes: { size: number }[] }) {
}
let queryRunningElapsedFrame: number | undefined;
function stopQueryRunningElapsedTimer() {
function stopRunningElapsedTimer() {
if (queryRunningElapsedFrame !== undefined) {
window.cancelAnimationFrame(queryRunningElapsedFrame);
queryRunningElapsedFrame = undefined;
}
}
function updateQueryRunningElapsed() {
const startedAt = props.activeTab.queryExecutionStartedAt;
queryRunningElapsed.value = props.activeTab.isExecuting && startedAt ? Math.max(0, Date.now() - startedAt) : 0;
/** 源码仍在加载(未失败)时的开始时间;用于耗时显示与 rAF 循环的续期判断。 */
function pendingSourceLoadStartedAt(): number | undefined {
const load = props.activeTab.sourceLoad;
return load && !load.error ? load.startedAt : undefined;
}
function startQueryRunningElapsedTimer() {
stopQueryRunningElapsedTimer();
updateQueryRunningElapsed();
if (!props.activeTab.isExecuting || !props.activeTab.queryExecutionStartedAt) return;
// 一个 rAF 循环同时驱动「查询执行中」与「对象源码加载中」两个耗时显示:
// issue #9035 的核心体感就是「不知道要等多久」,所以源码加载也要显示已耗时。
function updateRunningElapsed() {
const startedAt = props.activeTab.queryExecutionStartedAt;
queryRunningElapsed.value = props.activeTab.isExecuting && startedAt ? Math.max(0, Date.now() - startedAt) : 0;
const sourceStartedAt = pendingSourceLoadStartedAt();
sourceLoadElapsed.value = sourceStartedAt ? Math.max(0, Date.now() - sourceStartedAt) : 0;
}
function startRunningElapsedTimer() {
stopRunningElapsedTimer();
updateRunningElapsed();
const isTicking = () => (props.activeTab.isExecuting && !!props.activeTab.queryExecutionStartedAt) || pendingSourceLoadStartedAt() !== undefined;
if (!isTicking()) return;
const updateOnNextFrame = () => {
updateQueryRunningElapsed();
if (props.activeTab.isExecuting && props.activeTab.queryExecutionStartedAt) {
updateRunningElapsed();
if (isTicking()) {
queryRunningElapsedFrame = window.requestAnimationFrame(updateOnNextFrame);
}
};
@@ -729,11 +741,12 @@ function startQueryRunningElapsedTimer() {
}
const queryRunningElapsedSeconds = computed(() => formatElapsedSeconds(queryRunningElapsed.value));
const sourceLoadElapsedSeconds = computed(() => formatElapsedSeconds(sourceLoadElapsed.value));
watch(() => [props.activeTab.id, props.activeTab.isExecuting, props.activeTab.queryExecutionStartedAt] as const, startQueryRunningElapsedTimer, { immediate: true });
watch(() => [props.activeTab.id, props.activeTab.isExecuting, props.activeTab.queryExecutionStartedAt, props.activeTab.sourceLoad?.startedAt, props.activeTab.sourceLoad?.error] as const, startRunningElapsedTimer, { immediate: true });
onUnmounted(() => {
stopQueryRunningElapsedTimer();
stopRunningElapsedTimer();
standaloneResultToolbarResizeObserver?.disconnect();
window.removeEventListener("dbx-refresh-active-kv-browser", onRefreshActiveKvBrowser);
window.removeEventListener("resize", updateStandaloneResultToolbarDimensions);
@@ -1320,7 +1333,18 @@ defineExpose({
<div v-if="activeProductionContext.active" class="production-watermark pointer-events-none absolute inset-0 z-10 grid select-none" aria-hidden="true">
<span v-for="index in 4" :key="index" class="production-watermark__label whitespace-nowrap font-mono text-6xl font-extrabold text-red-700/[0.12] dark:text-red-200/[0.1]">{{ productionWatermarkText }}</span>
</div>
<!-- issue #9035:源码 tab 先出现再加载。pending 期间不挂载编辑器
(还没有内容可编辑,也省下一次 Monaco 初始化),失败则就地重试。 -->
<QueryLoadingState v-if="activeTab.sourceLoad && !activeTab.sourceLoad.error" class="relative z-0 flex-1" :elapsed-seconds="sourceLoadElapsedSeconds" />
<div v-else-if="activeTab.sourceLoad?.error" class="relative z-0 flex flex-1 min-h-0 flex-col items-center justify-center gap-3 px-6 text-sm" data-object-source-load-error>
<p class="max-w-[80%] text-center break-words text-destructive">{{ activeTab.sourceLoad.error }}</p>
<Button variant="outline" size="sm" class="gap-1.5" @click="queryStore.retryObjectSourceTab(activeTab.id)">
<RotateCcw class="h-4 w-4" />
{{ t("common.retry") }}
</Button>
</div>
<QueryEditor
v-else
ref="queryEditorRef"
class="relative z-0 flex-1"
:auto-focus="autoFocus !== false"
@@ -6,26 +6,24 @@ import { queryExecutionLabelKey } from "@/lib/sql/queryExecutionState";
import type { QueryTab } from "@/types/database";
const props = defineProps<{
tab: Pick<QueryTab, "mode" | "isExecuting" | "isCancelling">;
tab: Pick<QueryTab, "mode" | "isExecuting" | "isCancelling" | "sourceLoad">;
}>();
const { t } = useI18n();
const status = computed(() => {
if (props.tab.mode !== "query" || !props.tab.isExecuting) return undefined;
// 源码加载中(issue #9035)与查询执行中共用这一个 tab 栏转圈:两者都是
// 「这个 tab 正在等后端」,用户需要的反馈是同一种。
const status = computed<"running" | "cancelling" | "source-loading" | undefined>(() => {
if (props.tab.mode !== "query") return undefined;
if (props.tab.sourceLoad && !props.tab.sourceLoad.error) return "source-loading";
if (!props.tab.isExecuting) return undefined;
return props.tab.isCancelling ? "cancelling" : "running";
});
const labelKey = computed(() => (status.value === "source-loading" ? "common.loading" : queryExecutionLabelKey(props.tab)));
</script>
<template>
<span
v-if="status"
data-tab-execution-status
role="status"
class="inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center"
:class="status === 'cancelling' ? 'text-amber-600 dark:text-amber-400' : 'text-blue-600 dark:text-blue-400'"
:aria-label="t(queryExecutionLabelKey(tab))"
:title="t(queryExecutionLabelKey(tab))"
>
<span v-if="status" data-tab-execution-status role="status" class="inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center" :class="status === 'cancelling' ? 'text-amber-600 dark:text-amber-400' : 'text-blue-600 dark:text-blue-400'" :aria-label="t(labelKey)" :title="t(labelKey)">
<Loader2 aria-hidden="true" class="h-3.5 w-3.5 animate-spin motion-reduce:animate-none" />
</span>
<slot v-else />
@@ -10,7 +10,7 @@ vi.mock("vue-i18n", () => ({
const mountedApps: ReturnType<typeof createApp>[] = [];
function mountStatus(initial: { mode: "query" | "data"; isExecuting: boolean; isCancelling?: boolean }, withFallback = false) {
function mountStatus(initial: { mode: "query" | "data"; isExecuting: boolean; isCancelling?: boolean; sourceLoad?: { startedAt: number; error?: string; request: { name: string; objectType: string } } }, withFallback = false) {
const state = reactive(initial);
const root = document.createElement("div");
document.body.appendChild(root);
@@ -82,4 +82,31 @@ describe("TabExecutionStatus", () => {
expect(idle.root.querySelector("[data-tab-execution-status]")).toBeNull();
expect(data.root.querySelector("[data-tab-execution-status]")).toBeNull();
});
// issue #9035:源码 tab 先出现再加载,加载中的等待必须有反馈。
it("shows the loading indicator while an object source tab is still loading", async () => {
const { root, state } = mountStatus({ mode: "query", isExecuting: false, sourceLoad: { startedAt: Date.now(), request: { name: "v_orders", objectType: "VIEW" } } }, true);
await nextTick();
const status = root.querySelector<HTMLElement>("[data-tab-execution-status]");
expect(status).not.toBeNull();
expect(status?.getAttribute("aria-label")).toBe("common.loading");
expect(status?.className).toContain("text-blue-600");
// 加载态占用图标位,与查询执行中的表现一致
expect(root.querySelector("[data-tab-icon]")).toBeNull();
state.sourceLoad = undefined;
await nextTick();
expect(root.querySelector("[data-tab-execution-status]")).toBeNull();
expect(root.querySelector("[data-tab-icon]")).not.toBeNull();
});
it("stops the loading indicator once the object source load failed", async () => {
const { root } = mountStatus({ mode: "query", isExecuting: false, sourceLoad: { startedAt: Date.now(), error: "ORA-00942", request: { name: "v_orders", objectType: "VIEW" } } }, true);
await nextTick();
// 失败态由 tab 内容区的错误 + Retry 表达,tab 栏不应继续转圈
expect(root.querySelector("[data-tab-execution-status]")).toBeNull();
expect(root.querySelector("[data-tab-icon]")).not.toBeNull();
});
});