diff --git a/e2e/databaseDialogLayout.spec.ts b/e2e/databaseDialogLayout.spec.ts index ca28d183b..643f617e0 100644 --- a/e2e/databaseDialogLayout.spec.ts +++ b/e2e/databaseDialogLayout.spec.ts @@ -1,5 +1,29 @@ import { expect, test } from "./fixtures"; +test("data source tabs share a stable layout and scroll within a short window", async ({ workbench: page }) => { + await page.setViewportSize({ width: 560, height: 480 }); + await page.evaluate(async () => { + const path = "/src/features/database/store.ts"; + const { openSourceDialog } = await import(/* @vite-ignore */ path); + openSourceDialog(null, { name: "Local development", driver: "postgres", host: "localhost" }); + }); + + const dialog = page.getByRole("dialog", { name: "New Data Source" }); + const panel = dialog.getByRole("tabpanel"); + const dialogSize = () => dialog.evaluate((element) => [element.offsetWidth, element.offsetHeight]); + await expect(panel.getByRole("textbox", { name: "Host:" })).toBeVisible(); + const size = await dialogSize(); + await dialog.getByRole("tab", { name: "SSH/SSL" }).click(); + await expect(dialog.getByRole("tab", { name: "SSH/SSL" })).toHaveAttribute("aria-selected", "true"); + expect(await dialogSize()).toEqual(size); + + await dialog.getByRole("tab", { name: "General" }).click(); + const canScroll = await panel.evaluate((element) => element.scrollHeight > element.clientHeight); + expect(canScroll).toBe(true); + await panel.getByRole("textbox", { name: "URL:" }).scrollIntoViewIfNeeded(); + await expect(dialog.getByRole("button", { name: "Cancel" })).toBeInViewport(); +}); + for (const kind of ["password", "sshSecret", "params"] as const) { test(`database ${kind} dialog keeps its fields inside the window`, async ({ workbench: page }) => { await page.evaluate(async (kind) => { diff --git a/e2e/databaseResultTabs.spec.ts b/e2e/databaseResultTabs.spec.ts index abadb3eb0..29f75ddeb 100644 --- a/e2e/databaseResultTabs.spec.ts +++ b/e2e/databaseResultTabs.spec.ts @@ -1,6 +1,40 @@ import type { Page } from "@playwright/test"; import { expect, openFromTree, test } from "./fixtures"; +test("managed console tabs identify their data source and ordinary SQL tabs keep the file name", async ({ + workbench: page, +}) => { + await page.evaluate(async () => { + const database = "/src/features/database/store.ts"; + const workbench = "/src/workbench/contributions.ts"; + const { useDatabase, bindConsole } = await import(database); + const { editorService } = await import(workbench); + const console = "/app-data/consoles/db/demo/console.sql"; + useDatabase.setState({ loaded: true, sources: [{ id: "demo", name: "Shop Demo", driver: "sqlite" }] }); + bindConsole(console, "demo"); + bindConsole("/acme-api/console.sql", "demo"); + await editorService().openFile("/acme-api/console.sql", { focus: true }); + await editorService().openFile(console, { focus: true }); + }); + + const consoleTab = page.getByRole("tab", { name: "console [Shop Demo]", exact: true }); + await expect(consoleTab).toHaveAttribute("aria-selected", "true"); + await expect(page.getByRole("tab", { name: "console.sql", exact: true })).toBeVisible(); + await expect(page.getByRole("toolbar", { name: "Query Console", exact: true })).toContainText("main"); + + await page.evaluate(async () => { + const path = "/src/features/database/store.ts"; + const { useDatabase } = await import(path); + useDatabase.setState((state: { sources: Array<{ name: string }> }) => ({ + sources: state.sources.map((source) => ({ ...source, name: "Shop QA" })), + })); + }); + await expect(page.getByRole("tab", { name: "console [Shop QA]", exact: true })).toHaveAttribute( + "aria-selected", + "true", + ); +}); + const edgeTitle = "Result 3 — a long query result at the edge of the Services pane"; const bindings = { "alpha-console.sql": "alpha", "beta-console.sql": "beta" }; diff --git a/src/editor/core/model/tabTitles.ts b/src/editor/core/model/tabTitles.ts index b7bdbb212..0f2458afe 100644 --- a/src/editor/core/model/tabTitles.ts +++ b/src/editor/core/model/tabTitles.ts @@ -15,10 +15,10 @@ function parents(path: string): string[] { * For every path whose file name occurs more than once in `paths`, the * distinguishing directory hint. Paths with a unique name are absent. */ -export function disambiguateTitles(paths: readonly string[]): Map { +export function disambiguateTitles(paths: readonly string[], titleOf = baseName): Map { const groups = new Map(); for (const p of new Set(paths)) { - const name = baseName(p); + const name = titleOf(p); const list = groups.get(name); if (list) list.push(p); else groups.set(name, [p]); diff --git a/src/editor/core/view/EditorArea.tsx b/src/editor/core/view/EditorArea.tsx index 865563ba9..591058115 100644 --- a/src/editor/core/view/EditorArea.tsx +++ b/src/editor/core/view/EditorArea.tsx @@ -161,7 +161,11 @@ function useTitleHints(): Map { return out.sort(); }), ); - return useMemo(() => disambiguateTitles(paths), [paths]); + const labels = useFileDecorations(useShallow(() => paths.map((p) => getFileDecoration(p)?.tabTitle ?? basename(p)))); + return useMemo(() => { + const byPath = new Map(paths.map((p, i) => [p, labels[i]!])); + return disambiguateTitles(paths, (p) => byPath.get(p) ?? basename(p)); + }, [paths, labels]); } const virtualData = (input: EditorInput) => input.data as VirtualInputData | undefined; @@ -180,6 +184,8 @@ function PaneView({ paneId }: { paneId: string }) { const dirty = tabs.map((tab, i) => inputDirty(tab.input, kinds) ?? textDirty[i] ?? false); const colors = useFileDecorations(useShallow(() => paths.map((p) => (p ? (getFileDecoration(p)?.color ?? "") : "")))); const tints = useFileDecorations(useShallow(() => paths.map((p) => (p ? (getFileDecoration(p)?.tint ?? "") : "")))); + const tabLabels = useFileDecorations(useShallow(() => paths.map((p) => getFileDecoration(p)?.tabTitle))); + const tabIcons = useFileDecorations(useShallow(() => paths.map((p) => getFileDecoration(p)?.tabIcon))); const errors = useFileDecorations(useShallow(() => paths.map((p) => !!p && !!getFileDecoration(p)?.error))); const fileColors = useFileColors("editorTabs"); @@ -200,7 +206,7 @@ function PaneView({ paneId }: { paneId: string }) { return tabs.map((t, i) => { const full = names[i]!; const dot = full.lastIndexOf("."); - const name = t.input.kind === "file" && !showExtension && dot > 0 ? full.slice(0, dot) : full; + const name = tabLabels[i] ?? (t.input.kind === "file" && !showExtension && dot > 0 ? full.slice(0, dot) : full); const dupe = !showDirectoryForNonUnique ? null : t.input.kind === "file" && t.input.path @@ -223,7 +229,7 @@ function PaneView({ paneId }: { paneId: string }) { text: dupe ? `${name} — ${dupe}` : name, icon: showFileIcon ? t.input.kind === "file" && t.input.path - ? file?.icon + ? (tabIcons[i] ?? file?.icon) : tabIcon(t.input, kinds) : undefined, italic: t.preview, @@ -255,6 +261,8 @@ function PaneView({ paneId }: { paneId: string }) { colors, errors, tints, + tabLabels, + tabIcons, fileColors, hints, showExtension, diff --git a/src/features/database/DataDialogs.tsx b/src/features/database/DataDialogs.tsx index bf1bb11d5..281f5140b 100644 --- a/src/features/database/DataDialogs.tsx +++ b/src/features/database/DataDialogs.tsx @@ -210,7 +210,14 @@ export function ImportDialog({ id, schema, table }: { id: string; schema: string File:
- + void choose()} />
diff --git a/src/features/database/DataView.tsx b/src/features/database/DataView.tsx index 966e70fdc..d900c4e40 100644 --- a/src/features/database/DataView.tsx +++ b/src/features/database/DataView.tsx @@ -5,7 +5,7 @@ * Record / Value / Aggregates side panel following the selection. */ import { writeClipboardText } from "@/platform/clipboard"; -import { useMemo, useRef, useState, type KeyboardEvent, type RefObject } from "react"; +import { useMemo, useRef, useState, type KeyboardEvent, type ReactNode, type RefObject } from "react"; import clsx from "clsx"; import { Button, Checkbox, Icon, IconButton, Input, Popup, SearchField, Select, Tabs, T, type MenuItem } from "@/ui"; import { EXPORT_FORMATS, exportData, type ExportData, type ExportFormat } from "./export"; @@ -99,6 +99,7 @@ export interface DataViewProps extends Pick< /** Rows from here on (the table editor's added rows) are never filtered or sorted. */ fixedRows?: number; firstRowNumber?: number; + pager?: ReactNode; /** The side panel shown (`null`: hidden). */ panel: DataPanel | null; onPanelChange: (panel: DataPanel | null) => void; @@ -247,6 +248,7 @@ export function DataView(props: DataViewProps) { )} + {props.pager &&
{props.pager}
} {filterAt && ( input { - flex: 1; - min-width: 0; +.filterField:focus-within { + box-shadow: inset 0 -1px var(--focus-ring); } -.pager { - display: flex; - align-items: center; - gap: var(--space-0-5); - color: var(--fg-secondary); - font-size: var(--fs-small); - white-space: nowrap; +.filterField:has(input[aria-invalid="true"]) { + box-shadow: inset 0 -1px var(--danger); } .notice { - padding: 4px 8px; + padding: var(--space-1) var(--space-2); font-size: var(--fs-small); color: var(--fg-secondary); - background: var(--bg-editor-banner); + background: var(--bg-elev); border-bottom: 1px solid var(--border); } @@ -427,6 +435,28 @@ display: none; } /* Data source dialog. */ +.sourceLayout { + display: grid; + grid-template-rows: auto auto minmax(0, 1fr) auto; + height: clamp(220px, calc(100dvh - 150px), 560px); +} +.sourceLayout .form { + grid-template-columns: minmax(112px, 19%) minmax(0, 1fr); + align-content: start; + padding: var(--space-3) var(--space-4); +} +.sourceLayout .formLabel { + text-align: left; +} +.sourceLayout .formRow { + flex-wrap: wrap; +} +.sourceLayout .formRow > .fill { + flex: 1 1 160px; +} +.sourcePanel { + overflow: auto; +} .formSection { grid-column: 1 / -1; display: flex; @@ -549,10 +579,16 @@ font-size: var(--fs-small); } .testResult { - grid-column: 1 / -1; font-size: var(--fs-small); - min-height: 16px; - word-break: break-word; + max-height: 25vh; + padding: var(--space-2) var(--space-4); + overflow: auto; + overflow-wrap: anywhere; + border-top: 1px solid var(--border); +} +.testResult:empty { + padding: 0; + border: 0; } .ok { color: var(--success); @@ -737,17 +773,28 @@ .modifyBody { display: flex; flex-direction: column; - gap: 10px; - padding: 14px; + gap: var(--space-2); + height: clamp(320px, 68vh, 560px); + padding: var(--space-4); } .modifyMain { + flex: 1; display: grid; - grid-template-columns: 260px 1fr; - height: 240px; + grid-template-columns: minmax(108px, 34%) minmax(0, 1fr); + min-height: 0; border: 1px solid var(--border); border-radius: var(--radius-small); overflow: hidden; } +.modifyBody > .previewBlock { + flex: 0 0 38%; + min-height: 0; +} +.modifyBody .sqlPreview { + flex: 1; + min-height: 0; + max-height: none; +} .modifyColumns { display: flex; flex-direction: column; @@ -786,13 +833,17 @@ } .modifyProps { display: grid; - grid-template-columns: max-content 1fr; + grid-template-columns: minmax(0, 27%) minmax(0, 1fr); align-content: start; align-items: center; gap: var(--space-2) var(--space-3); padding: 12px; overflow: auto; } +.modifyProps .formLabel { + text-align: left; + overflow-wrap: anywhere; +} .quickDoc { width: 460px; max-width: calc(100vw - 32px); @@ -831,9 +882,6 @@ height: 100%; min-height: 0; } -.dataView > .fill { - min-width: 0; -} .headerFilter { flex: none; display: inline-flex; @@ -938,7 +986,8 @@ flex: none; display: flex; flex-direction: column; - width: 320px; + width: clamp(160px, 38%, 300px); + max-width: 50%; min-height: 0; border-left: 1px solid var(--border); } @@ -1165,29 +1214,42 @@ /* Export / history / import dialogs. */ .exportDialog { - display: flex; + display: grid; + grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: var(--space-4); - height: 420px; - padding: 14px; + height: min(440px, 65vh); + min-height: 340px; + padding: var(--space-4); } .exportOptions { display: flex; flex-direction: column; gap: var(--space-2); - width: 300px; - flex: none; +} +.exportOptions .formRow > input { + flex: 1; } .exportOptions .formLabel, .exportPreview .formLabel { text-align: left; } .exportPreview { - flex: 1; min-width: 0; + min-height: 0; display: flex; flex-direction: column; gap: var(--space-2); } +@media (max-width: 620px) { + .exportDialog { + grid-template-columns: minmax(0, 1fr); + height: auto; + } + .exportPreviewText { + height: 200px; + flex: none; + } +} .exportPreviewText, .historyPreview { flex: 1; @@ -1368,6 +1430,7 @@ flex: none; display: flex; align-items: center; + flex-wrap: wrap; gap: var(--space-1); padding: 4px 8px; background: var(--bg-elev); @@ -1375,8 +1438,8 @@ font-size: var(--fs-ui); } .gridSearchField { - flex: 0 1 360px; - min-width: 160px; + flex: 0 1 320px; + min-width: min(100%, 160px); } .gridSearchCount { font-family: var(--font-mono); @@ -1396,14 +1459,19 @@ background: var(--bg-text-search-result-current); } -/* IDEA's floating pager at the bottom of a result: |< < 1-500 of 501+ > >| and the page size. */ +.pagerDock { + flex: none; + display: flex; + justify-content: center; + padding: var(--space-1) var(--space-2) var(--space-2); + background: var(--bg-editor); +} .resultPager { - position: absolute; - left: 50%; - bottom: 12px; - transform: translateX(-50%); display: flex; align-items: center; + justify-content: center; + flex-wrap: wrap; + max-width: 100%; gap: var(--space-0-5); padding: 2px 4px; border: 1px solid var(--border-popup, var(--border)); diff --git a/src/features/database/DatabaseView.tsx b/src/features/database/DatabaseView.tsx index 27036339c..a2ed72772 100644 --- a/src/features/database/DatabaseView.tsx +++ b/src/features/database/DatabaseView.tsx @@ -16,6 +16,7 @@ import { Icon, IconButton, Menu, + Toolbar, Tree, showContextMenu, tooltipAttrs, @@ -523,6 +524,7 @@ export function DatabaseView() { return color ? `var(--db-color-${color})` : undefined; }} speedSearchField + horizontalScroll renderNode={(n: Node, state) => { const i = icon(n); const d = detail(n); @@ -611,7 +613,7 @@ function DatabaseToolbar() { const active = !!target && [...connected].some((t) => splitTarget(t).id === splitTarget(target).id); const button = { size: "small", iconSize: 16 } as const; return ( -
+ DDL -
+ ); } diff --git a/src/features/database/Grid.tsx b/src/features/database/Grid.tsx index 900eb9f62..e9d58322e 100644 --- a/src/features/database/Grid.tsx +++ b/src/features/database/Grid.tsx @@ -118,7 +118,6 @@ interface Sel { } const ROW_H = 24; -const NUM_W = 48; /** Wide enough for the whole header (icon, name, filter, sort) and the longest sampled value. */ function initialWidth(c: GridColumn, sample: Cell[], decorations: number): number { @@ -169,6 +168,7 @@ export function Grid(props: GridProps) { copyFormat = "tsv", } = props; const scrollRef = useRef(null); + const numberWidth = Math.max(40, String(firstRowNumber + rowCount - 1).length * 8 + 8); const [sel, setSel] = useState(null); const dragging = useRef(false); useEffect(() => { @@ -225,8 +225,8 @@ export function Grid(props: GridProps) { const scrollColumnIntoView = (c: number) => { const el = scrollRef.current; if (!el || c < 0 || c >= widths.length) return; - const left = c ? NUM_W + widths.slice(0, c).reduce((a, b) => a + b, 0) : 0; - const right = NUM_W + widths.slice(0, c + 1).reduce((a, b) => a + b, 0); + const left = c ? numberWidth + widths.slice(0, c).reduce((a, b) => a + b, 0) : 0; + const right = numberWidth + widths.slice(0, c + 1).reduce((a, b) => a + b, 0); if (left < el.scrollLeft) el.scrollLeft = left; else if (right > el.scrollLeft + el.clientWidth) el.scrollLeft = Math.min(left, right - el.clientWidth); }; @@ -252,8 +252,8 @@ export function Grid(props: GridProps) { // Runs once per request. // eslint-disable-next-line react-hooks/exhaustive-deps }, [revealColumn]); - const totalWidth = useMemo(() => NUM_W + widths.reduce((a, b) => a + b, 0), [widths]); - const template = `${NUM_W}px ${widths.map((w) => `${w}px`).join(" ")}`; + const totalWidth = useMemo(() => numberWidth + widths.reduce((a, b) => a + b, 0), [numberWidth, widths]); + const template = `${numberWidth}px ${widths.map((w) => `${w}px`).join(" ")}`; const selected = (r: number, c: number) => { if (!sel) return false; diff --git a/src/features/database/ResultsView.tsx b/src/features/database/ResultsView.tsx index 8dd2452b2..7389066bf 100644 --- a/src/features/database/ResultsView.tsx +++ b/src/features/database/ResultsView.tsx @@ -577,7 +577,7 @@ export function Result({ tab, onClose }: { tab: ResultTab; onClose?: () => void {notice} )} -
+
void searchOpen={searchOpen} onSearchOpenChange={setSearchOpen} firstRowNumber={(tab.page ?? 0) * (tab.pageSize ?? 0) + 1} + pager={} aria-label={tab.title} rowState={(row) => (row >= loaded ? "inserted" : edits.deletes.has(row) ? "deleted" : null)} isModified={(row, col) => !!edits.updates.get(row)?.has(resultNames[col]!)} @@ -611,7 +612,6 @@ export function Result({ tab, onClose }: { tab: ResultTab; onClose?: () => void : [] } /> -
)} @@ -817,7 +817,7 @@ export function ResultsView() { ...results.map((r) => ({ id: String(r.id), label: r.title, - icon: r.plan ? "db-plan" : "database", + icon: r.plan ? "db-plan" : "db-table", closable: true, pinned: r.pinned, tooltip: r.outcome.statement.text, diff --git a/src/features/database/SchemaCompare.module.css b/src/features/database/SchemaCompare.module.css index cb7c9ddc1..a6cc9fbda 100644 --- a/src/features/database/SchemaCompare.module.css +++ b/src/features/database/SchemaCompare.module.css @@ -2,8 +2,8 @@ display: flex; flex-direction: column; gap: var(--space-2); - height: 560px; - padding: 14px; + height: clamp(350px, 68vh, 620px); + padding: var(--space-4); } .pickers { display: flex; @@ -35,7 +35,8 @@ color: var(--fg-muted); } .panes { - display: flex; + display: grid; + grid-template-rows: minmax(0, 5fr) minmax(0, 4fr); gap: var(--space-2); flex: 1; min-height: 0; @@ -43,7 +44,6 @@ .tree { display: flex; flex-direction: column; - flex: 1.2; min-width: 0; border: 1px solid var(--border); border-radius: var(--radius-control); @@ -54,8 +54,19 @@ min-height: 0; } .preview { - flex: 1; + display: flex; + flex-direction: column; + gap: var(--space-1); min-width: 0; + min-height: 0; +} +.previewLabel { + color: var(--fg-secondary); + font-size: var(--fs-small); +} +.preview > :last-child { + flex: 1; + min-height: 0; } .row { display: inline-flex; diff --git a/src/features/database/SchemaCompareDialog.tsx b/src/features/database/SchemaCompareDialog.tsx index 9e39ea5fa..856ab66e4 100644 --- a/src/features/database/SchemaCompareDialog.tsx +++ b/src/features/database/SchemaCompareDialog.tsx @@ -328,7 +328,12 @@ export function SchemaCompareDialog({ initial }: { initial: Side | null }) { /> )}
- +
+ + Migration script + + +
diff --git a/src/features/database/SourceDialog.tsx b/src/features/database/SourceDialog.tsx index 15bd42d16..a635139c0 100644 --- a/src/features/database/SourceDialog.tsx +++ b/src/features/database/SourceDialog.tsx @@ -1404,7 +1404,7 @@ export function SourceDialog({ open onClose={closeDialog} title={initial ? tx`Data Source: ${initial.name}` : "New Data Source"} - width={640} + width={760} footerStart={