fix(desktop): restore legacy webview dialog and highlight fixes

This commit is contained in:
知食分子 authored and GitHub committed 2026-08-30 01:33:59 +08:00
1 parent 0fdddfc083
commit f4971d509a
19 files changed
+810 -332

No files matched your search

@@ -158,7 +158,7 @@ const previewVisible = computed(() => open.value && !!props.source);
<Dialog v-model:open="open">
<!-- 对话框整体限高:高度上限跟随 --dbx-viewport-height(兼容旧版 WebView 中 vh 不准的情况);
内部采用纵向 flex 布局,header/footer 固定,只有中间预览区滚动,保证底部按钮始终可见 -->
<DialogContent class="dbx-code-snapshot-dialog flex max-h-[calc(var(--dbx-viewport-height)-2rem)] flex-col overflow-hidden border border-border !bg-background text-foreground shadow-2xl !backdrop-blur-none sm:max-w-[860px]">
<DialogContent class="flex max-h-[calc(var(--dbx-viewport-height)-2rem)] flex-col overflow-hidden border border-border !bg-background text-foreground shadow-2xl !backdrop-blur-none sm:max-w-[860px]">
<DialogHeader>
<DialogTitle class="flex items-center gap-2">
<Camera class="h-5 w-5 text-primary" />
@@ -209,7 +209,7 @@ const previewVisible = computed(() => open.value && !!props.source);
</div>
</div>
<DialogFooter class="dbx-code-snapshot-dialog__footer">
<DialogFooter>
<Button variant="outline" @click="open = false">{{ t("codeSnapshot.close") }}</Button>
<Button variant="outline" :disabled="exporting" @click="exportSnapshot('clipboard')">
<Check v-if="copied" class="mr-1.5 h-4 w-4 text-green-500" />
@@ -224,21 +224,3 @@ const previewVisible = computed(() => open.value && !!props.source);
</DialogContent>
</Dialog>
</template>
<style>
html.dbx-legacy-webview [data-slot="dialog-content"].dbx-code-snapshot-dialog {
display: flex !important;
flex-direction: column !important;
width: calc(100vw - 2rem) !important;
max-width: 860px !important;
min-width: 0 !important;
}
html.dbx-legacy-webview .dbx-code-snapshot-dialog__footer {
display: flex !important;
flex-direction: row !important;
align-items: center !important;
justify-content: flex-end !important;
flex-wrap: nowrap !important;
}
</style>
@@ -55,6 +55,9 @@ const importPreview = ref<BusinessTag[]>([]);
const whitelistInput = ref("");
const environments = ["", "development", "staging", "production"];
// reka-ui Select throws on SelectItem value="" (and the leftover dismissable
// layer then blocks all clicks), so "all environments" uses a sentinel value.
const ALL_ENVIRONMENTS = "__all__";
const filteredTags = computed(() => {
return props.tags.filter((tag) => {
@@ -174,12 +177,14 @@ function handleExport() {
<Input v-model="filter.search" :placeholder="t('common.search')" />
</div>
<div class="filter-controls">
<Select v-model="filter.environment">
<!-- reka-ui throws on SelectItem value="" and the leftover dismissable
layer then blocks every click, so the "all" entry uses a sentinel. -->
<Select :model-value="filter.environment || ALL_ENVIRONMENTS" @update:model-value="(value: any) => (filter.environment = value === ALL_ENVIRONMENTS ? '' : String(value))">
<SelectTrigger class="w-[160px]">
<SelectValue :placeholder="t('tag.environment')" />
</SelectTrigger>
<SelectContent>
<SelectItem value="">
<SelectItem :value="ALL_ENVIRONMENTS">
{{ t("common.all") }}
</SelectItem>
<SelectItem v-for="env in environments.filter(Boolean)" :key="env" :value="env">
@@ -1859,7 +1859,7 @@ onUnmounted(() => {
<template>
<Dialog v-model:open="open">
<DialogContent class="gap-0 p-0 overflow-hidden flex flex-col min-w-0" :class="isFullscreen ? '' : 'sm:max-w-[94vw] md:max-w-[94vw] lg:max-w-[94vw] xl:max-w-[94vw]'" :style="dialogStyle" :portal-class="isFullscreen ? 'p-0' : undefined">
<DialogContent class="gap-0 p-0 overflow-hidden flex flex-col min-w-0" :class="isFullscreen ? 'dbx-diagram-fullscreen' : 'sm:max-w-[94vw] md:max-w-[94vw] lg:max-w-[94vw] xl:max-w-[94vw]'" :style="dialogStyle" :portal-class="isFullscreen ? 'p-0' : undefined">
<DialogHeader class="px-4 py-3 border-b">
<DialogTitle class="flex items-center gap-2">
<Network class="w-4 h-4" />
@@ -4,6 +4,7 @@ import { useI18n } from "vue-i18n";
import { AlertTriangle, Check, CheckSquare, ChevronDown, ChevronRight, FolderOpen, Layers, Loader2, MinusSquare, Pencil, Play, RefreshCw, Search, Settings2, Square, Trash2, X } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { Input } from "@/components/ui/input";
import { Badge } from "@/components/ui/badge";
import { ScrollArea } from "@/components/ui/scroll-area";
@@ -43,6 +44,9 @@ const selectedTargets = ref<MultiDbExecutionTarget[]>([]);
const validationResults = ref<SqlExecutionTargetValidation[]>([]);
const searchText = ref("");
const selectedGroupId = ref<string>();
// reka-ui Select throws on SelectItem value="" — the "no group" entry uses this
// sentinel and the change handler maps it back to "".
const NO_GROUP_VALUE = "__none__";
const manageGroups = ref(false);
const expandedConnections = ref<Set<string>>(new Set());
const expandedCatalogs = ref<Set<string>>(new Set());
@@ -808,10 +812,13 @@ watch(
<span>{{ t("multiDbExecute.selectGroup") }}</span>
<Button variant="ghost" size="sm" class="h-6 px-1.5 text-xs" @click="manageGroups = true"><Settings2 class="mr-1 h-3.5 w-3.5" />{{ t("multiDbExecute.manageGroups") }}</Button>
</div>
<select class="h-8 w-full rounded-md border border-input bg-background px-2 text-sm" :value="selectedGroupId || ''" :disabled="isExecuting" @change="requestGroupSelection(($event.target as HTMLSelectElement).value)">
<option value="">{{ t("multiDbExecute.noGroupSelected") }}</option>
<option v-for="group in compatibleGroups" :key="group.id" :value="group.id">{{ group.name }} · {{ group.targets.length }}</option>
</select>
<Select :model-value="selectedGroupId ?? NO_GROUP_VALUE" :disabled="isExecuting" @update:model-value="(value: any) => requestGroupSelection(value === NO_GROUP_VALUE ? '' : String(value))">
<SelectTrigger class="h-8 w-full text-sm"><SelectValue /></SelectTrigger>
<SelectContent>
<SelectItem :value="NO_GROUP_VALUE">{{ t("multiDbExecute.noGroupSelected") }}</SelectItem>
<SelectItem v-for="group in compatibleGroups" :key="group.id" :value="group.id">{{ group.name }} · {{ group.targets.length }}</SelectItem>
</SelectContent>
</Select>
<div class="flex items-center justify-between text-xs text-muted-foreground">
<span
>{{ t("multiDbExecute.databaseType") }}: <strong class="text-foreground">{{ databaseType || "-" }}</strong></span
@@ -0,0 +1,23 @@
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { describe, expect, it } from "vitest";
// reka-ui's SelectItem throws on value="" (SelectItem.js: "A <SelectItem /> must
// have a value prop that is not an empty string"). The throw happens while the
// select's dismissable layer is up, and the leftover layer then blocks every
// click in the app — dialogs can no longer be closed. These dialogs use
// sentinel values instead; keep it that way.
const multiDbDialogSource = readFileSync(resolve(process.cwd(), "apps/desktop/src/components/editor/MultiDbExecuteDialog.vue"), "utf8");
const tagPanelSource = readFileSync(resolve(process.cwd(), "apps/desktop/src/components/config/TagManagementPanel.vue"), "utf8");
describe("Select empty-value regression guard", () => {
it("keeps the multi-db target-group select free of empty SelectItem values", () => {
expect(multiDbDialogSource).not.toMatch(/<SelectItem\s+value=""/);
expect(multiDbDialogSource).toContain("NO_GROUP_VALUE");
});
it("keeps the tag environment select free of empty SelectItem values", () => {
expect(tagPanelSource).not.toMatch(/<SelectItem\s+value=""/);
expect(tagPanelSource).toContain("ALL_ENVIRONMENTS");
});
});
@@ -82,7 +82,7 @@ const emit = defineEmits<{
}}</span>
</span>
<template #content>
<div class="grid min-w-56 grid-cols-[auto_minmax(0,1fr)] gap-x-2 gap-y-1 px-3 py-2">
<div class="dbx-column-info-tooltip grid min-w-56 grid-cols-[auto_minmax(0,1fr)] gap-x-2 gap-y-1 px-3 py-2">
<span class="text-background/70">{{ columnNameLabel }}</span>
<span class="flex min-w-0 items-center gap-2">
<span class="min-w-0 flex-1 truncate font-mono">{{ name }}</span>
@@ -101,6 +101,7 @@ import DataGridQueryControls from "@/components/grid/DataGridQueryControls.vue";
import DataGridSearchBar from "@/components/grid/DataGridSearchBar.vue";
const dataGridSource = readFileSync("apps/desktop/src/components/grid/DataGrid.vue", "utf8");
const globalsCss = readFileSync("apps/desktop/src/styles/globals.css", "utf8");
function detail(patch: Partial<DataGridCellDetail> = {}): DataGridCellDetail {
return {
@@ -419,6 +420,32 @@ describe("DataGridColumnHeader", () => {
expect(resizeHandle.parent).not.toBe(tooltip);
});
it("renders the metadata tooltip type value with the softened type palette", () => {
const mounted = mountComponent(DataGridColumnHeader, {
name: "title",
actualColumnIndex: 0,
visibleColumnIndex: 0,
showTypeLine: true,
columnType: "varchar(255)",
typeClass: "data-grid-type-string",
copyColumnNameLabel: "copy",
columnNameLabel: "name",
columnTypeLabel: "type",
columnCommentLabel: "comment",
});
// The vivid 300-level dark-mode type palette is tuned for grid cells and
// glares on the popover surface. The tooltip container re-defines the type
// CSS variables with softer 400-level values while keeping the per-kind hue.
const tooltipContent = findOne(mounted.root, (node) => String(node.props?.class ?? "").includes("dbx-column-info-tooltip"));
expect(tooltipContent).toBeDefined();
const tooltipType = findOne(mounted.root, (node) => hostText(node) === "varchar(255)" && node.props["data-grid-header-type-line"] === undefined);
expect(String(tooltipType.props.class ?? "")).toContain("data-grid-type-string");
const headerTypeLine = findOne(mounted.root, (node) => hostText(node) === "varchar(255)" && node.props["data-grid-header-type-line"] === "");
expect(String(headerTypeLine.props.class)).toContain("data-grid-type-string");
// Softer dark-mode palette override for the tooltip container.
expect(globalsCss).toMatch(/\.dark \.dbx-column-info-tooltip \{[^}]*--data-grid-type-string-fg: #4ade80/);
});
it("cancels resize-handle clicks without leaking header click events", () => {
const click = vi.fn();
const clickCapture = vi.fn();
@@ -90,7 +90,7 @@ watch(
<template>
<Dialog :open="open" @update:open="handleOpenChange">
<DialogContent
class="dbx-update-dialog sm:max-w-[700px]"
class="sm:max-w-[700px]"
:show-close-button="!isCloseBlocked"
@interact-outside="
(e: Event) => {
@@ -174,14 +174,3 @@ watch(
</DialogContent>
</Dialog>
</template>
<style>
html.dbx-legacy-webview [data-slot="dialog-content"].dbx-update-dialog[class~="max-w-sm"] {
max-width: 700px !important;
}
html.dbx-legacy-webview [data-slot="dialog-content"].dbx-update-dialog [data-slot="dialog-footer"] {
flex-direction: row !important;
justify-content: flex-end !important;
}
</style>
@@ -276,13 +276,4 @@ function onClose() {
.ddl-view-editor :deep(.cm-content ::selection) {
background: var(--dbx-editor-selection-background, rgba(59, 130, 246, 0.35)) !important;
}
html.dbx-legacy-webview [data-slot="dialog-content"].dbx-ddl-view-dialog[class~="max-w-sm"] {
max-width: 47.5rem !important;
}
html.dbx-legacy-webview [data-slot="dialog-content"].dbx-ddl-view-dialog [data-slot="dialog-footer"] {
flex-direction: row !important;
justify-content: flex-end !important;
}
</style>
@@ -0,0 +1,25 @@
<template>
<Dialog :open="true">
<DialogContent class="dbx-ddl-view-dialog sm:max-w-190">
<div>fixture body</div>
<DialogFooter>
<Button>fixture action</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</template>
<script setup lang="ts">
import { Dialog, DialogContent, DialogFooter } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
</script>
<style scoped>
html.dbx-legacy-webview [data-slot="dialog-content"].dbx-ddl-view-dialog[class~="max-w-sm"] {
max-width: 47.5rem !important;
}
html.dbx-legacy-webview [data-slot="dialog-content"].dbx-ddl-view-dialog [data-slot="dialog-footer"] {
flex-direction: row !important;
}
</style>
@@ -0,0 +1,74 @@
// @vitest-environment happy-dom
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { createApp, defineComponent, h, nextTick, type App } from "vue";
import { createI18n } from "vue-i18n";
import { afterEach, describe, expect, it } from "vitest";
import DdlScopeFixture from "./DdlDialog.legacyScope.fixture.vue";
const ddlViewDialogSource = readFileSync(resolve(process.cwd(), "apps/desktop/src/components/objects/DdlViewDialog.vue"), "utf8");
const mountedApps: App[] = [];
afterEach(() => {
for (const app of mountedApps) app.unmount();
mountedApps.length = 0;
document.body.innerHTML = "";
});
async function flushFrames(frames = 4) {
for (let i = 0; i < frames; i += 1) {
await nextTick();
await new Promise((resolve) => setTimeout(resolve, 0));
}
}
function mountFixture() {
const host = defineComponent({
setup: () => () => h(DdlScopeFixture),
});
const container = document.createElement("div");
document.body.append(container);
const app = createApp(host);
app.use(
createI18n({
legacy: false,
locale: "zh-CN",
messages: { "zh-CN": {} },
}),
);
app.mount(container);
mountedApps.push(app);
}
describe("DdlViewDialog legacy fallback selectors", () => {
it("does not deliver the parent scope attribute to teleported dialog content", async () => {
mountFixture();
await flushFrames();
const scopeId = (DdlScopeFixture as unknown as { __scopeId?: string }).__scopeId;
expect(scopeId).toMatch(/^data-v-/);
const content = document.body.querySelector<HTMLElement>('[data-slot="dialog-content"]');
const footer = document.body.querySelector<HTMLElement>('[data-slot="dialog-footer"]');
expect(content).not.toBeNull();
expect(content!.className).toContain("dbx-ddl-view-dialog");
expect(content!.className).toContain("max-w-sm");
// The dialog content element is rendered by the child DialogContent component
// through reka-ui's portal Teleport, so the parent scoped-style attribute
// never reaches it; the footer element is one level down and does get it.
expect(content!.hasAttribute(scopeId!)).toBe(false);
expect(footer!.hasAttribute(scopeId!)).toBe(true);
});
it("keeps the DDL dialog free of per-dialog legacy fallback rules", () => {
// The dialog content element is rendered through reka-ui's portal Teleport and
// never carries this component's scoped data-v attribute, so per-dialog rules
// are avoided entirely: width comes from the global sm:max-w-190 legacy entry
// and the footer layout from the global dialog-footer rule.
expect(ddlViewDialogSource).not.toContain("dbx-legacy-webview");
expect(ddlViewDialogSource).not.toContain("@media");
expect(ddlViewDialogSource).toContain('class="dbx-ddl-view-dialog sm:max-w-190"');
});
});