Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: optimize sql editor ui and query history (#20326)
ecmadaofa03ce2ffb70
diff --git a/frontend/src/composables/useExecuteSQL.ts b/frontend/src/composables/useExecuteSQL.tsindex 192cb205d3..964a266cc2 100644--- a/frontend/src/composables/useExecuteSQL.ts+++ b/frontend/src/composables/useExecuteSQL.ts@@ -38,6 +38,7 @@ import {getValidDataSourceByPolicy,hasPermissionToCreateChangeDatabaseIssueInProject,} from "@/utils";+import { sqlEditorEvents } from "@/views/sql-editor/events";import { flattenNoSQLResult } from "./utils";// QUERY_INTERVAL_LIMIT is the minimal gap between two queries@@ -288,20 +289,23 @@ const useExecuteSQL = () => {abortController.signal);- // After all the queries are executed, we update the tab with the latest query result map.- // Refresh the query history list when the query executed successfully- // (with or without warnings).- queryHistoryStore.resetPageToken({- project: sqlEditorStore.project,- database: database.name,- });+ // Merge the freshly-executed statement into the history cache+ // WITHOUT resetting pagination — the user keeps whatever pages+ // they had already loaded ("Load more"d), and the new entry just+ // gets prepended. After the cache update lands, emit the event so+ // the HistoryPane re-renders from it (store reactivity alone+ // doesn't reliably propagate into the React `useVueState`+ // subscriber, so we trigger the re-render explicitly).queryHistoryStore- .fetchQueryHistoryList({+ .mergeLatest({project: sqlEditorStore.project,database: database.name,}).catch(() => {/* nothing */+ })+ .finally(() => {+ void sqlEditorEvents.emit("query-executed");});const instanceResource = getInstanceResource(database);diff --git a/frontend/src/react/components/AdvancedSearch.tsx b/frontend/src/react/components/AdvancedSearch.tsxindex ed8cdeca8a..a945d7e853 100644--- a/frontend/src/react/components/AdvancedSearch.tsx+++ b/frontend/src/react/components/AdvancedSearch.tsx@@ -633,7 +633,7 @@ export function AdvancedSearch({<div ref={containerRef} className="w-full min-w-0 relative">{/* Input container */}<div- className="flex min-w-0 items-center h-9 overflow-hidden border border-control-border rounded-xs bg-background transition-colors"+ className="flex min-w-0 items-center h-9 overflow-hidden border border-control-border rounded-xs bg-background transition-colors dark:bg-dark-bg dark:border-zinc-700"onClick={() => inputRef.current?.focus()}>{/*@@ -664,7 +664,7 @@ export function AdvancedSearch({data-search-scope-id={scope.id}data-search-scope-index={originalIndex}className={cn(- "inline-flex max-w-[16rem] min-w-0 shrink-0 items-center gap-1 rounded-xs bg-control-bg px-1.5 py-0.5 text-xs whitespace-nowrap",+ "inline-flex max-w-[16rem] min-w-0 shrink-0 items-center gap-1 rounded-xs bg-control-bg px-1.5 py-0.5 text-xs whitespace-nowrap dark:bg-zinc-700 dark:text-gray-100",focusedTagIndex === originalIndex && "ring-1 ring-accent")}onClick={(e) => {@@ -721,7 +721,7 @@ export function AdvancedSearch({<inputref={inputRef}className={cn(- "flex-1 bg-transparent border-none px-2 text-sm text-main placeholder:text-control-placeholder focus:outline-none focus:border-none focus:ring-0 focus:shadow-none",+ "flex-1 bg-transparent border-none px-2 text-sm text-main placeholder:text-control-placeholder focus:outline-none focus:border-none focus:ring-0 focus:shadow-none dark:text-gray-100 dark:placeholder:text-gray-500",visibleTags.length > 0 ? "min-w-[40px]" : "min-w-[120px]")}value={inputText}diff --git a/frontend/src/react/components/header/HeaderBreadcrumb.tsx b/frontend/src/react/components/header/HeaderBreadcrumb.tsxindex 6efb39bd61..55a7316235 100644--- a/frontend/src/react/components/header/HeaderBreadcrumb.tsx+++ b/frontend/src/react/components/header/HeaderBreadcrumb.tsx@@ -103,7 +103,7 @@ function WorkspaceSegment() {{label && (<Badgevariant={planVariant(currentPlan)}- className="text-[10px] px-1.5 py-0"+ className="text-[10px] px-1.5 py-0 hidden lg:block">{label}</Badge>@@ -154,7 +154,7 @@ function WorkspaceSegment() {// ---------------------------------------------------------------------------// ProjectSegment — shows project name + dropdown, only when inside a project// ----------------------------------------------------------------------------function ProjectSegment({ showSeparator }: { showSeparator: boolean }) {+function ProjectSegment() {const { t } = useTranslation();const route = useCurrentRoute();const [open, setOpen] = useState(false);@@ -172,9 +172,6 @@ function ProjectSegment({ showSeparator }: { showSeparator: boolean }) {return (<>- {showSeparator && (- <span className="text-control-placeholder select-none">/</span>- )}<Popover open={open} onOpenChange={setOpen}><PopoverTriggerrender={@@ -223,8 +220,11 @@ function ProjectSegment({ showSeparator }: { showSeparator: boolean }) {export function HeaderBreadcrumb() {return (<div className="flex items-center gap-x-1">- <WorkspaceSegment />- <ProjectSegment showSeparator />+ <div className="hidden md:flex items-center gap-x-1">+ <WorkspaceSegment />+ <span className="text-control-placeholder select-none">/</span>+ </div>+ <ProjectSegment /></div>);}diff --git a/frontend/src/react/components/sql-editor/HistoryPane.test.tsx b/frontend/src/react/components/sql-editor/HistoryPane.test.tsxindex b62c1df74c..5e54477efc 100644--- a/frontend/src/react/components/sql-editor/HistoryPane.test.tsx+++ b/frontend/src/react/components/sql-editor/HistoryPane.test.tsx@@ -35,6 +35,8 @@ vi.mock("@/store", () => ({vi.mock("@/views/sql-editor/events", () => ({sqlEditorEvents: {emit: mocks.sqlEditorEventsEmit,+ on: vi.fn().mockReturnValue(() => {}),+ off: vi.fn(),},}));diff --git a/frontend/src/react/components/sql-editor/HistoryPane.tsx b/frontend/src/react/components/sql-editor/HistoryPane.tsxindex 8ff49a29ef..c05aa4fbc4 100644--- a/frontend/src/react/components/sql-editor/HistoryPane.tsx+++ b/frontend/src/react/components/sql-editor/HistoryPane.tsx@@ -1,6 +1,13 @@import dayjs from "dayjs";import { Copy, Loader2 } from "lucide-react";-import { useCallback, useEffect, useMemo, useRef, useState } from "react";+import {+ useCallback,+ useEffect,+ useMemo,+ useReducer,+ useRef,+ useState,+} from "react";import { useTranslation } from "react-i18next";import { Button } from "@/react/components/ui/button";import { SearchInput } from "@/react/components/ui/search-input";@@ -30,6 +37,10 @@ export function HistoryPane() {const [searchText, setSearchText] = useState("");const [loading, setLoading] = useState(false);+ // Bumped when `query-executed` fires; forces React to re-read the+ // store cache (which `useExecuteSQL` / `webTerminal` have already+ // refreshed via `mergeLatest` by the time we get the event).+ const [, bumpRefresh] = useReducer((c: number) => c + 1, 0);const searchTimerRef = useRef<ReturnType<typeof setTimeout>>(undefined);const currentTabDatabase = useVueState(@@ -70,6 +81,19 @@ export function HistoryPane() {};}, [historyQuery]);+ // Force a re-render on every post-execute event. The store cache is+ // already up-to-date by the time the event fires (`useExecuteSQL` /+ // `webTerminal` chain the emit in `.finally` after `mergeLatest`+ // resolves). The bumped reducer state triggers a render, which+ // re-runs the `useVueState` getter and reads the merged list —+ // preserving any pages the user had already loaded.+ useEffect(() => {+ sqlEditorEvents.on("query-executed", bumpRefresh);+ return () => {+ sqlEditorEvents.off("query-executed", bumpRefresh);+ };+ }, []);+const onSearchUpdate = useCallback((next: string) => {queryHistoryStore.resetPageToken({ ...historyQuery, statement: next });diff --git a/frontend/src/react/components/sql-editor/ResultView/SelectionCopyTooltips.tsx b/frontend/src/react/components/sql-editor/ResultView/SelectionCopyTooltips.tsxindex 08215f8980..f9c7cc4d27 100644--- a/frontend/src/react/components/sql-editor/ResultView/SelectionCopyTooltips.tsx+++ b/frontend/src/react/components/sql-editor/ResultView/SelectionCopyTooltips.tsx@@ -40,13 +40,18 @@ export function SelectionCopyTooltips() {return (<div- className="w-full absolute h-full bg-background flex flex-row justify-start items-center text-control"+ // `bg-background` is the light page bg and doesn't dark-switch+ // automatically. The tip is `absolute h-full` over the result+ // toolbar — without an opaque dark bg under it the white shows+ // through admin mode's `bg-dark-bg`. Match the result-view chrome+ // for both themes.+ className="w-full absolute h-full bg-background dark:bg-dark-bg flex flex-row justify-start items-center text-control dark:text-gray-100"onClick={(e) => {e.preventDefault();e.stopPropagation();}}>- <InfoIcon size={16} className="mr-2 text-control" />+ <InfoIcon size={16} className="mr-2 text-control dark:text-gray-100" /><p className="text-sm flex flex-row justify-start items-center gap-1">{tokens.map((token, i) => {if (token === "action") {@@ -55,7 +60,11 @@ export function SelectionCopyTooltips() {key={i}size="sm"variant="outline"- className="h-6 px-2 gap-x-1"+ // `outline` is `bg-transparent + text-control` and the+ // tip sits over `bg-dark-bg` in admin mode → invisible.+ // Force an opaque dark surface with a light shortcut+ // label so the keyboard hint reads against the toolbar.+ className="h-6 px-2 gap-x-1 dark:bg-gray-700 dark:text-gray-100 dark:border-zinc-600 dark:disabled:opacity-100"disabled>{isMac ? (@@ -87,7 +96,18 @@ export function SelectionCopyTooltips() {})}</p><div className="ml-1">- <Button size="sm" variant="ghost" onClick={deselect}>+ {/*+ * `ghost` is `text-control` with no background — invisible+ * label against the admin-mode dark backdrop. Lift the label+ * to a light gray and give it a hover surface so the cancel+ * action is reachable.+ */}+ <Button+ size="sm"+ variant="ghost"+ className="dark:text-gray-100 dark:hover:bg-gray-700"+ onClick={deselect}+ >{t("sql-editor.cancel-selection")}</Button></div>diff --git a/frontend/src/react/components/sql-editor/ResultView/SingleResultView.tsx b/frontend/src/react/components/sql-editor/ResultView/SingleResultView.tsxindex f79ca31e0d..e8e74045d2 100644--- a/frontend/src/react/components/sql-editor/ResultView/SingleResultView.tsx+++ b/frontend/src/react/components/sql-editor/ResultView/SingleResultView.tsx@@ -534,10 +534,14 @@ function SingleResultViewInner({</span></div>{!disallowCopyingData && rows.length > 0 && (+ // `variant="outline"` is `bg-transparent + text-control`, which+ // disappears inside the admin-mode dark backdrop. Force an+ // opaque light-on-dark surface in `.dark` to match the Vue+ // toolbar's contrast (light gray bg + dark text).<Buttonsize="sm"variant="outline"- className="h-7 px-2"+ className="h-7 px-2 dark:bg-gray-700 dark:text-gray-100 dark:border-zinc-600 dark:hover:bg-gray-600"onClick={copyAll}><CopyIcon className="size-4" />diff --git a/frontend/src/react/components/sql-editor/ResultView/VirtualDataBlock.tsx b/frontend/src/react/components/sql-editor/ResultView/VirtualDataBlock.tsxindex 1141064eba..2311f0d7c9 100644--- a/frontend/src/react/components/sql-editor/ResultView/VirtualDataBlock.tsx+++ b/frontend/src/react/components/sql-editor/ResultView/VirtualDataBlock.tsx@@ -72,6 +72,11 @@ export const VirtualDataBlock = forwardRef<estimateSize: estimateRowHeight,measureElement: (el) => el.getBoundingClientRect().height,overscan: 4,+ // Each row is `position: absolute` (placed by `translateY(start)`),+ // so a margin / padding-bottom on the row div has no effect on the+ // gap to the next row. The virtualizer's `gap` option adds the+ // requested pixels into each row's `start` so cards visibly breathe.+ gap: 16,});useImperativeHandle(@@ -131,19 +136,19 @@ export const VirtualDataBlock = forwardRef<key={virtualRow.key}ref={virtualizer.measureElement}data-index={rowIndex}- className="font-mono mb-2 mx-2 absolute inset-x-0"+ className="font-mono mx-2 absolute inset-x-0"style={{top: 0,transform: `translateY(${virtualRow.start}px)`,}}>- <p className="font-bold text-control-light overflow-hidden whitespace-nowrap mb-1">+ <p className="font-bold text-control-light dark:text-gray-300 overflow-hidden whitespace-nowrap mb-1">******************************** {rowIndex + 1}. row********************************</p><divclassName={cn(- "py-2 px-3 bg-control-bg rounded relative",+ "py-2 px-3 bg-control-bg dark:bg-gray-700 rounded relative",isActive && "border-2 border-accent/20 bg-accent/10!")}>@@ -156,7 +161,7 @@ export const VirtualDataBlock = forwardRef<return (<divkey={column.id}- className="flex items-start text-control-light text-sm"+ className="flex items-start text-control-light dark:text-gray-300 text-sm"><div className="min-w-28 text-left flex items-center font-medium pt-1"><div className="flex items-center gap-x-1">@@ -217,10 +222,16 @@ function CopyJSONButton({return (<div className="absolute right-2 top-2 z-10 opacity-70 hover:opacity-100"><Tooltip content={label}>+ {/*+ * In admin mode the row card is `dark:bg-gray-700`, and the+ * `ghost` variant's `text-control` icon nearly disappears+ * against it. Force a light icon + visible hover surface inside+ * the `.dark` parent so the action is reachable.+ */}<Buttonsize="sm"variant="ghost"- className="size-7 p-0"+ className="size-7 p-0 dark:text-gray-100 dark:hover:bg-gray-600"onClick={handleCopy}>{copied ? (diff --git a/frontend/src/store/modules/sqlEditor/queryHistory.ts b/frontend/src/store/modules/sqlEditor/queryHistory.tsindex 90885e4bea..8a12a0d7cd 100644--- a/frontend/src/store/modules/sqlEditor/queryHistory.ts+++ b/frontend/src/store/modules/sqlEditor/queryHistory.ts@@ -68,7 +68,19 @@ export const useSQLEditorQueryHistoryStore = defineStore(queryHistoryMap.get(key)!.nextPageToken = resp.nextPageToken;if (pageToken) {- queryHistoryMap.get(key)!.queryHistories.push(...resp.queryHistories);+ // Dedupe by `name` on the append path. The backend uses+ // offset-based page tokens, so when `mergeLatest` prepends a+ // freshly-executed query the cached cursor is now off by one+ // (the new entry shifted every server position). The next+ // "Load more" call may return rows that already live in the+ // cache; filtering by `name` prevents visible duplicates.+ const cachedNames = new Set(+ queryHistoryMap.get(key)!.queryHistories.map((h) => h.name)+ );+ const fresh = resp.queryHistories.filter(+ (h) => !cachedNames.has(h.name)+ );+ queryHistoryMap.get(key)!.queryHistories.push(...fresh);} else {queryHistoryMap.get(key)!.queryHistories = resp.queryHistories;}@@ -85,10 +97,41 @@ export const useSQLEditorQueryHistoryStore = defineStore(queryHistoryMap.set(key, { queryHistories: [] });};+ /**+ * Post-execute refresh that preserves pagination state. Fetches+ * page 1 (no cursor) and prepends entries whose `name` isn't+ * already cached. Keeps the existing `nextPageToken`, so a user+ * who has loaded pages 1–3 stays at pages 1–3 after running a new+ * query — the just-executed statement appears at the top without+ * resetting the list.+ */+ const mergeLatest = async (filter: QueryHistoryFilter) => {+ const key = getCacheKey(filter);+ const resp = await sqlServiceClientConnect.searchQueryHistories(+ create(SearchQueryHistoriesRequestSchema, {+ pageSize: 5,+ filter: getListQueryHistoryFilter(filter),+ })+ );+ const existing = queryHistoryMap.get(key);+ const existingNames = new Set(+ (existing?.queryHistories ?? []).map((h) => h.name)+ );+ const fresh = resp.queryHistories.filter(+ (h) => !existingNames.has(h.name)+ );+ queryHistoryMap.set(key, {+ nextPageToken: existing?.nextPageToken ?? resp.nextPageToken,+ queryHistories: [...fresh, ...(existing?.queryHistories ?? [])],+ });+ return resp;+ };+return {resetPageToken,fetchQueryHistoryList,getQueryHistoryList,+ mergeLatest,};});diff --git a/frontend/src/store/modules/sqlEditor/webTerminal.ts b/frontend/src/store/modules/sqlEditor/webTerminal.tsindex b6ce96bdf8..80a31538ed 100644--- a/frontend/src/store/modules/sqlEditor/webTerminal.ts+++ b/frontend/src/store/modules/sqlEditor/webTerminal.ts@@ -8,7 +8,12 @@ import { fromEventPattern, Observable } from "rxjs";import { markRaw, ref, shallowRef } from "vue";import { useCancelableTimeout } from "@/composables/useCancelableTimeout";import { refreshTokens } from "@/connect/refreshToken";-import { pushNotification, useDatabaseV1Store } from "@/store";+import {+ pushNotification,+ useDatabaseV1Store,+ useSQLEditorQueryHistoryStore,+ useSQLEditorStore,+} from "@/store";import type {SQLEditorQueryParams,SQLEditorTab,@@ -32,6 +37,7 @@ import {extractGrpcErrorMessage,getErrorCode as extractGrpcStatusCode,} from "@/utils/connect";+import { sqlEditorEvents } from "@/views/sql-editor/events";const ENDPOINT = "/v1:adminExecute";const SIG_ABORT = 3000 + Code.Aborted;@@ -265,6 +271,25 @@ const useQueryStateLogic = (qs: WebTerminalQueryState) => {});}}+ // Admin-mode queries don't go through `useExecuteSQL`, so mirror+ // its post-exec history refresh here. `mergeLatest` prepends the+ // just-run statement without resetting the user's pagination.+ const database = activeQuery().params?.connection.database;+ if (database) {+ useSQLEditorQueryHistoryStore()+ .mergeLatest({+ project: useSQLEditorStore().project,+ database,+ })+ .catch(() => {+ /* nothing */+ })+ .finally(() => {+ void sqlEditorEvents.emit("query-executed");+ });+ } else {+ void sqlEditorEvents.emit("query-executed");+ }cleanup();});};diff --git a/frontend/src/views/sql-editor/events.ts b/frontend/src/views/sql-editor/events.tsindex 6f12f21c03..de475e28a8 100644--- a/frontend/src/views/sql-editor/events.ts+++ b/frontend/src/views/sql-editor/events.ts@@ -20,6 +20,12 @@ export type SQLEditorEvents = {"set-editor-selection": IRange;"append-editor-content": { content: string; select: boolean };"insert-at-caret": { content: string };+ // Fired after a SQL statement has finished executing — by both the+ // worksheet (`useExecuteSQL`) and admin/terminal (`webTerminal`)+ // paths. `HistoryPane` listens and refetches. Bypasses store+ // reactivity that doesn't reliably propagate the post-exec+ // mutations into the React `useVueState` subscriber.+ "query-executed": undefined;};export const sqlEditorEvents: Emittery<SQLEditorEvents> =