Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: several fe optimization (#20949)

ecmadao709fd54ad87c
diff --git a/frontend/src/components/AdvancedSearch.test.tsx b/frontend/src/components/AdvancedSearch.test.tsx
index 77fcb41a99..716068493f 100644
--- a/frontend/src/components/AdvancedSearch.test.tsx
+++ b/frontend/src/components/AdvancedSearch.test.tsx
@@ -60,4 +60,51 @@ describe("AdvancedSearch", () => {
expect(screen.getByText("common.search-no-result")).toBeInTheDocument();
});
+
+ test("scrolls the pending value option into view when navigating by keyboard", () => {
+ const scrollIntoView = vi.fn();
+ const originalScrollIntoView = HTMLElement.prototype.scrollIntoView;
+ let scrolledText = "";
+ HTMLElement.prototype.scrollIntoView = function (
+ options?: ScrollIntoViewOptions | boolean
+ ) {
+ scrolledText = this.textContent ?? "";
+ scrollIntoView(options);
+ };
+
+ try {
+ render(
+ <AdvancedSearch
+ params={emptySearchParams()}
+ scopeOptions={[
+ {
+ id: "state",
+ title: "State",
+ options: [
+ { value: "OPEN", keywords: ["open"] },
+ { value: "CLOSED", keywords: ["closed"] },
+ { value: "DONE", keywords: ["done"] },
+ ],
+ },
+ ]}
+ onParamsChange={vi.fn()}
+ />
+ );
+
+ fireEvent.click(screen.getByRole("textbox"));
+ fireEvent.click(screen.getByText("state"));
+
+ expect(scrollIntoView).not.toHaveBeenCalled();
+
+ fireEvent.keyDown(screen.getByRole("textbox"), { key: "ArrowDown" });
+
+ expect(scrollIntoView).toHaveBeenCalledWith({
+ block: "nearest",
+ inline: "nearest",
+ });
+ expect(scrolledText).toContain("CLOSED");
+ } finally {
+ HTMLElement.prototype.scrollIntoView = originalScrollIntoView;
+ }
+ });
});
diff --git a/frontend/src/components/AdvancedSearch.tsx b/frontend/src/components/AdvancedSearch.tsx
index 29ed2ca311..f8a57cf916 100644
--- a/frontend/src/components/AdvancedSearch.tsx
+++ b/frontend/src/components/AdvancedSearch.tsx
@@ -176,6 +176,7 @@ export function AdvancedSearch({
const asyncSearchRef = useRef<ReturnType<typeof setTimeout>>(undefined);
const asyncRequestRef = useRef(0);
const debounceRef = useRef<ReturnType<typeof setTimeout>>(undefined);
+ const scrollPendingMenuIndexRef = useRef(false);
// Sync external query changes
useEffect(() => {
@@ -528,16 +529,26 @@ export function AdvancedSearch({
if (e.key === "ArrowUp") {
e.preventDefault();
- setMenuIndex((prev) => Math.max(0, prev - 1));
+ setMenuIndex((prev) => {
+ const next = Math.max(0, prev - 1);
+ scrollPendingMenuIndexRef.current = next !== prev;
+ return next;
+ });
return;
}
if (e.key === "ArrowDown") {
e.preventDefault();
- const maxIdx =
+ const maxIdx = Math.max(
+ 0,
menuView === "scope"
? visibleScopeOptions.length - 1
- : visibleValueOptions.length - 1;
- setMenuIndex((prev) => Math.min(maxIdx, prev + 1));
+ : visibleValueOptions.length - 1
+ );
+ setMenuIndex((prev) => {
+ const next = Math.min(maxIdx, prev + 1);
+ scrollPendingMenuIndexRef.current = next !== prev;
+ return next;
+ });
return;
}
@@ -632,6 +643,24 @@ export function AdvancedSearch({
});
}, [focusedTagIndex]);
+ useEffect(() => {
+ if (!scrollPendingMenuIndexRef.current) return;
+ scrollPendingMenuIndexRef.current = false;
+ const menuList =
+ menuView === "scope"
+ ? scopeMenuListRef.current
+ : menuView === "value"
+ ? valueMenuListRef.current
+ : undefined;
+ const option = menuList?.querySelector<HTMLElement>(
+ `[data-search-menu-option-index="${menuIndex}"]`
+ );
+ option?.scrollIntoView({
+ block: "nearest",
+ inline: "nearest",
+ });
+ }, [menuIndex, menuView]);
+
return (
<div ref={containerRef} className="w-full min-w-0 relative">
{/* Input container */}
@@ -769,6 +798,7 @@ export function AdvancedSearch({
{visibleScopeOptions.map((option, index) => (
<div
key={option.id}
+ data-search-menu-option-index={index}
className={cn(
"flex gap-x-2 px-3 py-2 cursor-pointer text-sm items-center",
index > 0 && "border-t border-block-border",
@@ -832,6 +862,7 @@ export function AdvancedSearch({
{visibleValueOptions.map((option, index) => (
<div
key={option.value}
+ data-search-menu-option-index={index}
className={cn(
"h-[38px] flex gap-x-2 px-3 items-center cursor-pointer border-t border-block-border overflow-hidden",
index === menuIndex && "bg-control-bg-hover/75"
diff --git a/frontend/src/modules/sql-editor/components/ResultView/TableCell.test.tsx b/frontend/src/modules/sql-editor/components/ResultView/TableCell.test.tsx
index e8426d7687..b653d123b0 100644
--- a/frontend/src/modules/sql-editor/components/ResultView/TableCell.test.tsx
+++ b/frontend/src/modules/sql-editor/components/ResultView/TableCell.test.tsx
@@ -61,6 +61,9 @@ const longValue = "1.779696812227E+12";
const value = create(RowValueSchema, {
kind: { case: "stringValue", value: longValue },
});
+const indentedValue = create(RowValueSchema, {
+ kind: { case: "stringValue", value: " -> Seq Scan on project" },
+});
const rows: ResultTableRow[] = [
{
@@ -107,4 +110,28 @@ describe("TableCell", () => {
"max-w-[calc(100%-1.5rem)]"
);
});
+
+ test("preserves leading whitespace when rendering string cells", () => {
+ const { container } = render(
+ <SQLResultViewProvider
+ engine={Engine.POSTGRES}
+ rows={rows}
+ columns={columns}
+ >
+ <TableCell
+ value={indentedValue}
+ rowIndex={0}
+ colIndex={0}
+ allowSelect
+ columnType="TEXT"
+ database={database}
+ keyword=""
+ />
+ </SQLResultViewProvider>
+ );
+
+ const content = container.querySelector(".line-clamp-3");
+ expect(content?.textContent).toBe(" -> Seq Scan on project");
+ expect(content).toHaveClass("whitespace-pre-wrap");
+ });
});
diff --git a/frontend/src/modules/sql-editor/components/ResultView/TableCell.tsx b/frontend/src/modules/sql-editor/components/ResultView/TableCell.tsx
index c9e7a3f080..548fa2d23e 100644
--- a/frontend/src/modules/sql-editor/components/ResultView/TableCell.tsx
+++ b/frontend/src/modules/sql-editor/components/ResultView/TableCell.tsx
@@ -142,7 +142,7 @@ export function TableCell({
<div
ref={wrapperRef}
className={cn(
- "font-mono text-start wrap-break-word line-clamp-3",
+ "font-mono text-start wrap-break-word whitespace-pre-wrap line-clamp-3",
(hasByteData || clickable) && "max-w-[calc(100%-1.5rem)]",
hasByteData && clickable && "max-w-[calc(100%-3.25rem)]"
)}