Skip to content

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

chore: optimize schema editor (#20657)

ecmadao854472acf608
diff --git a/backend/api/v1/instance_service_converter.go b/backend/api/v1/instance_service_converter.go
index 17991c5837..50b97c6324 100644
--- a/backend/api/v1/instance_service_converter.go
+++ b/backend/api/v1/instance_service_converter.go
@@ -142,9 +142,15 @@ func convertDataSourceExternalSecret(externalSecret *storepb.DataSourceExternalS
case v1pb.DataSourceExternalSecret_VAULT_APP_ROLE:
appRole := externalSecret.GetAppRole()
if appRole != nil {
+ secretType := v1pb.DataSourceExternalSecret_AppRoleAuthOption_SecretType(appRole.Type)
+ if secretType == v1pb.DataSourceExternalSecret_AppRoleAuthOption_SECRET_TYPE_UNSPECIFIED {
+ // Legacy data has no secret type; surface it as PLAIN explicitly so
+ // the API never exposes an ambiguous UNSPECIFIED for an existing secret.
+ secretType = v1pb.DataSourceExternalSecret_AppRoleAuthOption_PLAIN
+ }
resp.AuthOption = &v1pb.DataSourceExternalSecret_AppRole{
AppRole: &v1pb.DataSourceExternalSecret_AppRoleAuthOption{
- Type: v1pb.DataSourceExternalSecret_AppRoleAuthOption_SecretType(appRole.Type),
+ Type: secretType,
MountPath: appRole.MountPath,
},
}
diff --git a/frontend/src/react/components/SchemaEditorLite/Aside/AsideTree.tsx b/frontend/src/react/components/SchemaEditorLite/Aside/AsideTree.tsx
index d80e127b22..4d46534a70 100644
--- a/frontend/src/react/components/SchemaEditorLite/Aside/AsideTree.tsx
+++ b/frontend/src/react/components/SchemaEditorLite/Aside/AsideTree.tsx
@@ -161,6 +161,18 @@ export function AsideTree() {
"dropped"
);
}
+ // Close the table's open tab — its editor is no longer relevant once
+ // the table is dropped (and points at a removed object when created).
+ const tab = tabs.findTab({
+ type: "table",
+ database: node.db,
+ metadata: {
+ database: node.metadata.database,
+ schema: node.metadata.schema,
+ table: node.metadata.table,
+ },
+ });
+ if (tab) tabs.closeTab(tab.id);
rebuildTree(false);
} else if (key === "restore-table" && node.type === "table") {
editStatus.removeEditStatus(
diff --git a/frontend/src/react/components/SchemaEditorLite/Panels/PreviewPane.tsx b/frontend/src/react/components/SchemaEditorLite/Panels/PreviewPane.tsx
index a02cd931f1..69a52ed500 100644
--- a/frontend/src/react/components/SchemaEditorLite/Panels/PreviewPane.tsx
+++ b/frontend/src/react/components/SchemaEditorLite/Panels/PreviewPane.tsx
@@ -133,7 +133,7 @@ export function PreviewPane({ db, database, schema, table }: Props) {
<div
role="separator"
aria-orientation="horizontal"
- className={resizeHandleClass("horizontal")}
+ className={resizeHandleClass("horizontal", "h-0.5")}
onMouseDown={handleResizeStart}
/>
)}
diff --git a/frontend/src/react/components/SchemaEditorLite/Panels/TableColumnEditor/DataTypeCell.tsx b/frontend/src/react/components/SchemaEditorLite/Panels/TableColumnEditor/DataTypeCell.tsx
index 2a8ef0dec2..08e9c0a895 100644
--- a/frontend/src/react/components/SchemaEditorLite/Panels/TableColumnEditor/DataTypeCell.tsx
+++ b/frontend/src/react/components/SchemaEditorLite/Panels/TableColumnEditor/DataTypeCell.tsx
@@ -1,5 +1,21 @@
-import { useMemo } from "react";
+import { ChevronDown } from "lucide-react";
+import {
+ useCallback,
+ useEffect,
+ useLayoutEffect,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
+import { createPortal } from "react-dom";
+import {
+ getPortalDropdownStyle,
+ isPortalDropdownStyleEqual,
+ shouldIgnorePortalDropdownScroll,
+} from "@/react/components/ui/combobox-position";
import { Input } from "@/react/components/ui/input";
+import { getLayerRoot, LAYER_SURFACE_CLASS } from "@/react/components/ui/layer";
+import { cn } from "@/react/lib/utils";
import type { Engine } from "@/types/proto-es/v1/common_pb";
import type { ColumnMetadata } from "@/types/proto-es/v1/database_service_pb";
import { getDataTypeSuggestionList } from "@/utils";
@@ -10,49 +26,170 @@ interface Props {
engine: Engine;
readonly: boolean;
onUpdateValue: (value: string) => void;
- /** Shared id for the host <datalist> element (one per engine). */
- datalistId: string;
}
+/**
+ * Free-text type input with a clickable suggestion dropdown, mirroring the old
+ * Vue `DropdownInput`: users can type any custom type (e.g. `varchar(255)`) or
+ * pick one of the engine's known types from the dropdown. The native
+ * `<input list>` it replaced never opened reliably on click.
+ *
+ * Focus/click handlers live on the wrapping container because Base UI's Input
+ * can swallow `onClick`/`onFocus`; React focus/click events still bubble there.
+ */
export function DataTypeCell({
column,
- readonly: isReadonly,
+ engine,
+ readonly,
onUpdateValue,
- datalistId,
}: Props) {
- return (
- <Input
- list={datalistId}
- value={column.type ?? ""}
- disabled={isReadonly}
- placeholder="column type"
- size="xs"
- className={INLINE_EDIT_INPUT_CLASS}
- onChange={(e) => onUpdateValue(e.target.value)}
- />
- );
-}
+ const containerRef = useRef<HTMLDivElement>(null);
+ const dropdownRef = useRef<HTMLDivElement>(null);
+ const inputRef = useRef<HTMLInputElement>(null);
+ const [open, setOpen] = useState(false);
+ const [dropdownStyle, setDropdownStyle] = useState<React.CSSProperties>({});
-/**
- * Renders the suggestion datalist that DataTypeCell rows reference via
- * the `list` attribute. Mount once per table.
- */
-export function DataTypeSuggestionsDatalist({
- id,
- engine,
-}: {
- id: string;
- engine: Engine;
-}) {
- const suggestions = useMemo(
+ const value = column.type ?? "";
+
+ // The type as first rendered. We only filter once the user edits the value
+ // away from this; an unchanged value shows the full list (matches Vue's
+ // `allowFilter`). Otherwise opening e.g. a `bigint` cell would filter to just
+ // "bigint" while a `timestamp(...)` cell — matching nothing — shows them all.
+ const originalTypeRef = useRef(value);
+
+ const allSuggestions = useMemo(
() => getDataTypeSuggestionList(engine),
[engine]
);
+
+ const suggestions = useMemo(() => {
+ const q = value.trim().toLowerCase();
+ if (!q || value === originalTypeRef.current) return allSuggestions;
+ const filtered = allSuggestions.filter((t) => t.toLowerCase().includes(q));
+ // Fall back to the full list when nothing matches the in-progress text so
+ // the dropdown still offers the engine's types instead of going empty.
+ return filtered.length > 0 ? filtered : allSuggestions;
+ }, [allSuggestions, value]);
+
+ // Position the portaled dropdown under the cell and keep it pinned while the
+ // surrounding table scrolls. Mirrors the shared Combobox's portal handling.
+ useLayoutEffect(() => {
+ if (!open || !containerRef.current) return;
+
+ const updatePosition = () => {
+ if (!containerRef.current) return;
+ const rect = containerRef.current.getBoundingClientRect();
+ const height = dropdownRef.current?.offsetHeight ?? 0;
+ const next = getPortalDropdownStyle(rect, height, window.innerHeight);
+ setDropdownStyle((prev) =>
+ isPortalDropdownStyleEqual(prev, next) ? prev : next
+ );
+ };
+
+ const handleScroll = (event: Event) => {
+ if (shouldIgnorePortalDropdownScroll(event.target, dropdownRef.current)) {
+ return;
+ }
+ updatePosition();
+ };
+
+ updatePosition();
+ window.addEventListener("resize", updatePosition);
+ window.addEventListener("scroll", handleScroll, true);
+ return () => {
+ window.removeEventListener("resize", updatePosition);
+ window.removeEventListener("scroll", handleScroll, true);
+ };
+ }, [open, suggestions]);
+
+ // Close on outside click (covers both the cell and the portaled dropdown).
+ useEffect(() => {
+ if (!open) return;
+ const handler = (e: MouseEvent) => {
+ const target = e.target as Node;
+ if (containerRef.current?.contains(target)) return;
+ if (dropdownRef.current?.contains(target)) return;
+ setOpen(false);
+ };
+ document.addEventListener("mousedown", handler);
+ return () => document.removeEventListener("mousedown", handler);
+ }, [open]);
+
+ // Open the dropdown on focus/click and close it on Escape. Attached to the
+ // native input element (not the wrapper) so the wrapper stays a plain layout
+ // div, and because Base UI's Input can swallow React onFocus/onClick props.
+ useEffect(() => {
+ const el = inputRef.current;
+ if (!el || readonly) return;
+ const handleOpen = () => setOpen(true);
+ const handleKeyDown = (e: KeyboardEvent) => {
+ if (e.key === "Escape") setOpen(false);
+ };
+ el.addEventListener("focus", handleOpen);
+ el.addEventListener("click", handleOpen);
+ el.addEventListener("keydown", handleKeyDown);
+ return () => {
+ el.removeEventListener("focus", handleOpen);
+ el.removeEventListener("click", handleOpen);
+ el.removeEventListener("keydown", handleKeyDown);
+ };
+ }, [readonly]);
+
+ const handleSelect = useCallback(
+ (type: string) => {
+ onUpdateValue(type);
+ setOpen(false);
+ },
+ [onUpdateValue]
+ );
+
return (
- <datalist id={id}>
- {suggestions.map((dataType) => (
- <option key={dataType} value={dataType} />
- ))}
- </datalist>
+ <div ref={containerRef} className="relative">
+ <Input
+ ref={inputRef}
+ value={value}
+ disabled={readonly}
+ placeholder="column type"
+ size="xs"
+ className={cn(INLINE_EDIT_INPUT_CLASS, "pr-7")}
+ onChange={(e) => onUpdateValue(e.target.value)}
+ />
+ {!readonly && (
+ <ChevronDown className="pointer-events-none absolute right-2 top-1/2 size-4 -translate-y-1/2 text-control-light" />
+ )}
+ {open &&
+ !readonly &&
+ suggestions.length > 0 &&
+ createPortal(
+ <div
+ ref={dropdownRef}
+ style={dropdownStyle}
+ className={cn(
+ "max-h-60 overflow-y-auto rounded-sm border border-control-border bg-background py-1 shadow-lg",
+ LAYER_SURFACE_CLASS
+ )}
+ >
+ {suggestions.map((type) => (
+ <button
+ key={type}
+ type="button"
+ className={cn(
+ "block w-full px-3 py-1 text-left text-sm hover:bg-control-bg",
+ type === value && "bg-accent/5 text-accent"
+ )}
+ // onMouseDown (not onClick) so selection happens before the
+ // input's blur / outside-click would close the dropdown.
+ onMouseDown={(e) => {
+ e.preventDefault();
+ handleSelect(type);
+ }}
+ >
+ {type}
+ </button>
+ ))}
+ </div>,
+ getLayerRoot("overlay")
+ )}
+ </div>
);
}
diff --git a/frontend/src/react/components/SchemaEditorLite/Panels/TableColumnEditor/TableColumnEditor.tsx b/frontend/src/react/components/SchemaEditorLite/Panels/TableColumnEditor/TableColumnEditor.tsx
index ea5c8b6848..a7ba10db76 100644
--- a/frontend/src/react/components/SchemaEditorLite/Panels/TableColumnEditor/TableColumnEditor.tsx
+++ b/frontend/src/react/components/SchemaEditorLite/Panels/TableColumnEditor/TableColumnEditor.tsx
@@ -1,5 +1,5 @@
import { RotateCcw, Trash2 } from "lucide-react";
-import { useCallback, useMemo } from "react";
+import { useCallback, useLayoutEffect, useMemo, useRef } from "react";
import { useTranslation } from "react-i18next";
import { Button } from "@/react/components/ui/button";
import { Checkbox } from "@/react/components/ui/checkbox";
@@ -12,6 +12,10 @@ import {
TableHeader,
TableRow,
} from "@/react/components/ui/table";
+import {
+ distributeColumnWidths,
+ useColumnWidths,
+} from "@/react/hooks/useColumnWidths";
import { cn } from "@/react/lib/utils";
import type { Engine } from "@/types/proto-es/v1/common_pb";
import type {
@@ -26,8 +30,9 @@ import {
removeColumnPrimaryKey,
upsertColumnPrimaryKey,
} from "../../core/edit";
+import { refreshTableEditStatus } from "../../core/refreshEditStatus";
import { INLINE_EDIT_INPUT_CLASS, markUUID } from "../common";
-import { DataTypeCell, DataTypeSuggestionsDatalist } from "./DataTypeCell";
+import { DataTypeCell } from "./DataTypeCell";
import { DefaultValueCell } from "./DefaultValueCell";
interface Props {
@@ -40,7 +45,6 @@ interface Props {
disableChangeTable: boolean;
allowChangePrimaryKeys: boolean;
searchPattern?: string;
- onMarkTableStatus: (status: "updated") => void;
}
export function TableColumnEditor({
@@ -53,10 +57,23 @@ export function TableColumnEditor({
disableChangeTable,
allowChangePrimaryKeys,
searchPattern,
- onMarkTableStatus,
}: Props) {
const { t } = useTranslation();
- const { editStatus } = useSchemaEditorContext();
+ const { editStatus, targets } = useSchemaEditorContext();
+
+ const baselineMetadata = useMemo(
+ () =>
+ targets.find((target) => target.database.name === db.name)
+ ?.baselineMetadata,
+ [targets, db.name]
+ );
+
+ // Recompute this table's edit status by diffing against the baseline, so
+ // reverting a field back to its original value clears the dirty marker.
+ const refreshStatus = useCallback(() => {
+ if (!baselineMetadata) return;
+ refreshTableEditStatus(editStatus, db, baselineMetadata, schema, table);
+ }, [editStatus, db, baselineMetadata, schema, table]);
const primaryKey = useMemo(() => {
return table.indexes.find((idx) => idx.primary);
@@ -89,6 +106,11 @@ export function TableColumnEditor({
const handleColumnNameChange = useCallback(
(column: ColumnMetadata, newName: string) => {
const oldName = column.name;
+ if (newName === oldName) return;
+ // Status is keyed by column name, so capture it before renaming and
+ // clear the old-name key (avoids leaving a stale dirty entry behind).
+ const status = editStatus.getColumnStatus(db, { schema, table, column });
+ editStatus.removeEditStatus(db, { schema, table, column }, false);
column.name = newName;
// Sync PK name if column is in PK
if (primaryKey && primaryKey.expressions.includes(oldName)) {
@@ -97,25 +119,33 @@ export function TableColumnEditor({
primaryKey.expressions[idx] = newName;
}
}
- const status = getStatus(column);
- if (status === "normal") {
- editStatus.markEditStatus(db, { schema, table, column }, "updated");
+ // Re-keying "created" onto a name that already belongs to another column
+ // would make that existing column read as "created" too (shared name key),
+ // so its trash action would splice the real column out. Only preserve
+ // "created" when the new name is unique within the table.
+ const nameCollides = table.columns.some(
+ (c) => c !== column && c.name === newName
+ );
+ if (status === "created" && !nameCollides) {
+ // A freshly-added column being named for the first time must stay
+ // "created" (re-keyed to the new name) — otherwise refreshStatus would
+ // diff it against a non-existent baseline and downgrade it to
+ // "updated", and the trash action would then drop it instead of
+ // splicing the unsaved column out.
+ editStatus.markEditStatus(db, { schema, table, column }, "created");
+ } else {
+ refreshStatus();
}
- onMarkTableStatus("updated");
},
- [primaryKey, getStatus, editStatus, db, schema, table, onMarkTableStatus]
+ [primaryKey, editStatus, db, schema, table, refreshStatus]
);
const handleColumnTypeChange = useCallback(
(column: ColumnMetadata, newType: string) => {
column.type = newType;
- const status = getStatus(column);
- if (status === "normal") {
- editStatus.markEditStatus(db, { schema, table, column }, "updated");
- }
- onMarkTableStatus("updated");
+ refreshStatus();
},
- [getStatus, editStatus, db, schema, table, onMarkTableStatus]
+ [refreshStatus]
);
const handleDefaultChange = useCallback(
@@ -125,25 +155,17 @@ export function TableColumnEditor({
) => {
column.hasDefault = value.hasDefault;
column.default = value.default;
- const status = getStatus(column);
- if (status === "normal") {
- editStatus.markEditStatus(db, { schema, table, column }, "updated");
- }
- onMarkTableStatus("updated");
+ refreshStatus();
},
- [getStatus, editStatus, db, schema, table, onMarkTableStatus]
+ [refreshStatus]
);
const handleNullableChange = useCallback(
(column: ColumnMetadata, nullable: boolean) => {
column.nullable = nullable;
- const status = getStatus(column);
- if (status === "normal") {
- editStatus.markEditStatus(db, { schema, table, column }, "updated");
- }
- onMarkTableStatus("updated");
+ refreshStatus();
},
- [getStatus, editStatus, db, schema, table, onMarkTableStatus]
+ [refreshStatus]
);
const handlePrimaryKeyChange = useCallback(
@@ -154,25 +176,17 @@ export function TableColumnEditor({
} else {
removeColumnPrimaryKey(table, column.name);
}
- const status = getStatus(column);
- if (status === "normal") {
- editStatus.markEditStatus(db, { schema, table, column }, "updated");
- }
- onMarkTableStatus("updated");
+ refreshStatus();
},
- [engine, table, getStatus, editStatus, db, schema, onMarkTableStatus]
+ [engine, table, refreshStatus]
);
const handleCommentChange = useCallback(
(column: ColumnMetadata, comment: string) => {
column.comment = comment; // ColumnMetadata.comment
- const status = getStatus(column);
- if (status === "normal") {
- editStatus.markEditStatus(db, { schema, table, column }, "updated");
- }
- onMarkTableStatus("updated");
+ refreshStatus();
},
- [getStatus, editStatus, db, schema, table, onMarkTableStatus]
+ [refreshStatus]
);
const handleDropColumn = useCallback(
@@ -185,9 +199,8 @@ export function TableColumnEditor({
} else {
editStatus.markEditStatus(db, { schema, table, column }, "dropped");
}
- onMarkTableStatus("updated");
},
- [getStatus, table, editStatus, db, schema, onMarkTableStatus]
+ [getStatus, table, editStatus, db, schema]
);
const handleRestoreColumn = useCallback(
@@ -197,41 +210,121 @@ export function TableColumnEditor({
[editStatus, db, schema, table]
);
- const datalistId = `schema-editor-types-${engine}`;
- // Use the shared Table defaults (px-4 py-3 cells, h-10 headers) so this grid
- // matches the table-list grid. Headers only add whitespace-nowrap.
- const cellClass = "";
- const headClass = "whitespace-nowrap";
+ // Compact rows: trim the shared Table's default vertical padding (py-3 cells,
+ // h-10 headers) but keep py-2 so inline editors have breathing room around
+ // them. Kept in sync with TableList.
+ const cellClass = "py-2";
+ const headClass = "h-8 py-1 whitespace-nowrap";
+
+ // Resizable column layout. Name/type/default/comment can be dragged wider;
+ // the fixed-content columns (not-null/primary/operations) keep their width.
+ // `widths[i]` is positional, so the body cells below must stay in this order.
+ const columnDefs = useMemo(
+ () => [
+ {
+ key: "name",
+ title: t("schema-editor.column.name"),
+ defaultWidth: 160,
+ minWidth: 80,
+ resizable: true,
+ align: "",
+ },
+ {
+ key: "type",
+ title: t("schema-editor.column.type"),
+ defaultWidth: 180,
+ minWidth: 80,
+ resizable: true,
+ align: "",
+ },
+ {
+ key: "default",
+ title: t("schema-editor.column.default"),
+ defaultWidth: 200,
+ minWidth: 80,
+ resizable: true,
+ align: "",
+ },
+ {
+ key: "comment",
+ title: t("schema-editor.column.comment"),
+ defaultWidth: 240,
+ minWidth: 80,
+ resizable: true,
+ align: "",
+ },
+ {
+ key: "not-null",
+ title: t("schema-editor.column.not-null"),
+ defaultWidth: 72,
+ resizable: false,
+ align: "text-center",
+ },
+ {
+ key: "primary",
+ title: t("schema-editor.column.primary"),
+ defaultWidth: 72,
+ resizable: false,
+ align: "text-center",
+ },
+ ...(isReadonly
+ ? []
+ : [
+ {
+ key: "operations",
+ title: t("schema-editor.column.operations"),
+ defaultWidth: 96,
+ resizable: false,
+ align: "text-right",
+ },
+ ]),
+ ],
+ [t, isReadonly]
+ );
+
+ const { widths, totalWidth, onResizeStart, setWidths } =
+ useColumnWidths(columnDefs);
+
+ // Fit the columns to the available width on first layout so the grid fills
+ // the panel instead of overflowing at the sum of the default widths. Runs
+ // once; later panel resizes leave any user-dragged widths untouched.
+ const containerRef = useRef<HTMLDivElement>(null);
+ const didFitRef = useRef(false);
+ useLayoutEffect(() => {
+ if (didFitRef.current) return;
+ const width = containerRef.current?.clientWidth ?? 0;
+ if (width <= 0) return;
+ didFitRef.current = true;
+ setWidths(distributeColumnWidths(columnDefs, width));
+ }, [columnDefs, setWidths]);
return (
- <div className="size-full overflow-auto">
- <DataTypeSuggestionsDatalist id={datalistId} engine={engine} />
- <Table>
+ <div ref={containerRef} className="size-full overflow-auto">
+ {/* Exact-width (not w-full) so rendered widths match state and dragging
+ stays precise; the container scrolls when columns exceed it. */}
+ <Table
+ className="w-auto table-fixed"
+ style={{ width: `${totalWidth}px` }}
+ >
+ <colgroup>
+ {widths.map((w, i) => (
+ <col key={columnDefs[i].key} style={{ width: `${w}px` }} />
+ ))}
+ </colgroup>
<TableHeader>
<TableRow>
- <TableHead className={cn(headClass, "w-[160px]")}>
- {t("schema-editor.column.name")}
- </TableHead>
- <TableHead className={cn(headClass, "w-[180px]")}>
- {t("schema-editor.column.type")}
- </TableHead>
- <TableHead className={cn(headClass, "w-[200px]")}>
- {t("schema-editor.column.default")}
- </TableHead>
- <TableHead className={cn(headClass)}>
- {t("schema-editor.column.comment")}
- </TableHead>
- <TableHead className={cn(headClass, "w-[72px] text-center")}>
- {t("schema-editor.column.not-null")}
- </TableHead>
- <TableHead className={cn(headClass, "w-[72px] text-center")}>
- {t("schema-editor.column.primary")}
- </TableHead>
- {!isReadonly && (
- <TableHead className={cn(headClass, "w-[60px] text-right")}>
- {t("schema-editor.column.operations")}
+ {columnDefs.map((col, colIdx) => (
+ <TableHead
+ key={col.key}
+ className={cn(headClass, col.align)}
+ resizable={col.resizable}
+ onResizeStart={
+ col.resizable ? (e) => onResizeStart(colIdx, e) : undefined
+ }
+ >
+ {col.title}
</TableHead>
- )}
+ ))}
</TableRow>
</TableHeader>
<TableBody>
@@ -279,7 +372,6 @@ export function TableColumnEditor({
column={column}
engine={engine}
readonly={disabled}
- datalistId={datalistId}
onUpdateValue={(val) => handleColumnTypeChange(column, val)}
/>
</TableCell>
diff --git a/frontend/src/react/components/SchemaEditorLite/Panels/TableEditor.tsx b/frontend/src/react/components/SchemaEditorLite/Panels/TableEditor.tsx
index 7e02ab4bce..f668c240bd 100644
--- a/frontend/src/react/components/SchemaEditorLite/Panels/TableEditor.tsx
+++ b/frontend/src/react/components/SchemaEditorLite/Panels/TableEditor.tsx
@@ -148,14 +148,6 @@ export function TableEditor({
handleAddPartition,
]);
- const markTableStatus = useCallback(
- (status: "updated") => {
- if (tableStatus === "created" || tableStatus === "dropped") return;
- editStatus.markEditStatus(db, { schema, table }, status);
- },
- [tableStatus, editStatus, db, schema, table]
- );
-
const modeOptions = useMemo(() => {
const items: { value: EditorMode; label: string }[] = [
{ value: "COLUMNS", label: t("schema-editor.columns") },
@@ -211,7 +203,6 @@ export function TableEditor({
disableChangeTable={disableChangeTable}
allowChangePrimaryKeys={allowChangePrimaryKeys}
searchPattern={searchPattern}
- onMarkTableStatus={markTableStatus}
/>
)}
{mode === "INDEXES" && (
diff --git a/frontend/src/react/components/SchemaEditorLite/Panels/TableList/TableList.tsx b/frontend/src/react/components/SchemaEditorLite/Panels/TableList/TableList.tsx
index 979ff0126b..73e2abdbd4 100644
--- a/frontend/src/react/components/SchemaEditorLite/Panels/TableList/TableList.tsx
+++ b/frontend/src/react/components/SchemaEditorLite/Panels/TableList/TableList.tsx
@@ -1,5 +1,5 @@
import { RotateCcw, Trash2 } from "lucide-react";
-import { useCallback, useMemo } from "react";
+import { useCallback, useLayoutEffect, useMemo, useRef } from "react";
import { useTranslation } from "react-i18next";
import { Button } from "@/react/components/ui/button";
import { Input } from "@/react/components/ui/input";
@@ -11,6 +11,10 @@ import {
TableHeader,
TableRow,
} from "@/react/components/ui/table";
+import {
+ distributeColumnWidths,
+ useColumnWidths,
+} from "@/react/hooks/useColumnWidths";
import { cn } from "@/react/lib/utils";
import type {
Database,
@@ -19,6 +23,7 @@ import type {
TableMetadata,
} from "@/types/proto-es/v1/database_service_pb";
import { useSchemaEditorContext } from "../../context";
+import { refreshTableEditStatus } from "../../core/refreshEditStatus";
import { INLINE_EDIT_INPUT_CLASS } from "../common";
interface Props {
@@ -32,13 +37,21 @@ interface Props {
export function TableList({
db,
+ database,
schema,
tables,
searchPattern,
onEditTable,
}: Props) {
const { t } = useTranslation();
- const { readonly, editStatus } = useSchemaEditorContext();
+ const { readonly, editStatus, targets, tabs } = useSchemaEditorContext();
+
+ const baselineMetadata = useMemo(
+ () =>
+ targets.find((target) => target.database.name === db.name)
+ ?.baselineMetadata,
+ [targets, db.name]
+ );
const filteredTables = useMemo(() => {
if (!searchPattern) return tables;
@@ -64,8 +77,16 @@ export function TableList({
} else {
editStatus.markEditStatus(db, { schema, table }, "dropped");
}
+ // Close the table's open tab — its editor is no longer relevant once the
+ // table is dropped (and points at a removed object for created tables).
+ const tab = tabs.findTab({
+ type: "table",
+ database: db,
+ metadata: { database, schema, table },
+ });
+ if (tab) tabs.closeTab(tab.id);
},
- [getStatus, schema, editStatus, db]
+ [getStatus, schema, editStatus, db, database, tabs]
);
const handleRestore = useCallback(
@@ -78,13 +99,63 @@ export function TableList({
const handleCommentChange = useCallback(
(table: TableMetadata, comment: string) => {
table.comment = comment;
- if (getStatus(table) === "normal") {
- editStatus.markEditStatus(db, { schema, table }, "updated");
+ // Recompute against the baseline so reverting the comment clears dirty.
+ if (baselineMetadata) {
+ refreshTableEditStatus(editStatus, db, baselineMetadata, schema, table);
}
},
- [getStatus, editStatus, db, schema]
+ [editStatus, db, baselineMetadata, schema]
+ );
+
+ // Resizable column layout. Name/comment can be dragged wider; operations
+ // keeps a fixed width. `widths[i]` is positional with `columnDefs`.
+ const columnDefs = useMemo(
+ () => [
+ {
+ key: "name",
+ title: t("schema-editor.column.name"),
+ defaultWidth: 240,
+ minWidth: 100,
+ resizable: true,
+ align: "",
+ },
+ {
+ key: "comment",
+ title: t("schema-editor.column.comment"),
+ defaultWidth: 360,
+ minWidth: 100,
+ resizable: true,
+ align: "",
+ },
+ ...(readonly
+ ? []
+ : [
+ {
+ key: "operations",
+ title: t("schema-editor.column.operations"),
+ defaultWidth: 96,
+ resizable: false,
+ align: "text-right",
+ },
+ ]),
+ ],
+ [t, readonly]
);
+ const { widths, totalWidth, onResizeStart, setWidths } =
+ useColumnWidths(columnDefs);
+
+ // Fit columns to the available width on first layout (see TableColumnEditor).
+ const containerRef = useRef<HTMLDivElement>(null);
+ const didFitRef = useRef(false);
+ useLayoutEffect(() => {
+ if (didFitRef.current) return;
+ const width = containerRef.current?.clientWidth ?? 0;
+ if (width <= 0) return;
+ didFitRef.current = true;
+ setWidths(distributeColumnWidths(columnDefs, width));
+ }, [columnDefs, setWidths]);
+
if (filteredTables.length === 0) {
return (
<div className="flex size-full items-center justify-center py-8 text-sm text-control-light">
@@ -96,84 +167,99 @@ export function TableList({
}
return (
- <Table>
- <TableHeader>
- <TableRow>
- <TableHead className="w-[40%]">
- {t("schema-editor.column.name")}
- </TableHead>
- <TableHead>{t("schema-editor.column.comment")}</TableHead>
- {!readonly && (
- <TableHead className="w-20 text-right">
- {t("schema-editor.column.operations")}
- </TableHead>
- )}
- </TableRow>
- </TableHeader>
- <TableBody>
- {filteredTables.map((table) => {
- const status = getStatus(table);
- return (
- <TableRow
- key={table.name}
- className={cn(
- "cursor-pointer",
- status === "created" && "text-success",
- status === "updated" && "text-warning",
- status === "dropped" && "text-error line-through"
- )}
- onClick={() => onEditTable(table)}
- >
- <TableCell className="font-medium">{table.name}</TableCell>
- <TableCell
- className="text-control-light"
- onClick={(e) => e.stopPropagation()}
+ <div ref={containerRef} className="w-full overflow-x-auto">
+ <Table
+ className="w-auto table-fixed"
+ style={{ width: `${totalWidth}px` }}
+ >
+ <colgroup>
+ {widths.map((w, i) => (
+ <col key={columnDefs[i].key} style={{ width: `${w}px` }} />
+ ))}
+ </colgroup>
+ <TableHeader>
+ <TableRow>
+ {columnDefs.map((col, colIdx) => (
+ <TableHead
+ key={col.key}
+ className={cn("h-8 py-1 whitespace-nowrap", col.align)}
+ resizable={col.resizable}
+ onResizeStart={
+ col.resizable ? (e) => onResizeStart(colIdx, e) : undefined
+ }
>
- {readonly ? (
- table.comment || "—"
- ) : (
- <Input
- value={table.comment}
- disabled={status === "dropped"}
- size="xs"
- className={INLINE_EDIT_INPUT_CLASS}
- onChange={(e) => handleCommentChange(table, e.target.value)}
- />
+ {col.title}
+ </TableHead>
+ ))}
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {filteredTables.map((table) => {
+ const status = getStatus(table);
+ return (
+ <TableRow
+ key={table.name}
+ className={cn(
+ "cursor-pointer",
+ status === "created" && "text-success",
+ status === "updated" && "text-warning",
+ status === "dropped" && "text-error line-through"
)}
- </TableCell>
- {!readonly && (
- <TableCell className="text-right">
- {status === "dropped" ? (
- <Button
- variant="ghost"
- size="sm"
- className="size-7 p-0"
- onClick={(e) => {
- e.stopPropagation();
- handleRestore(table);
- }}
- >
- <RotateCcw className="size-3.5" />
- </Button>
+ onClick={() => onEditTable(table)}
+ >
+ <TableCell className="py-2 font-medium">{table.name}</TableCell>
+ <TableCell
+ className="py-2 text-control-light"
+ onClick={(e) => e.stopPropagation()}
+ >
+ {readonly ? (
+ table.comment || "—"
) : (
- <Button
- variant="ghost"
- size="sm"
- className="size-7 p-0 text-error hover:text-error"
- onClick={(e) => {
- e.stopPropagation();
- handleDrop(table);
- }}
- >
- <Trash2 className="size-3.5" />
- </Button>
+ <Input
+ value={table.comment}
+ disabled={status === "dropped"}
+ size="xs"
+ className={INLINE_EDIT_INPUT_CLASS}
+ onChange={(e) =>
+ handleCommentChange(table, e.target.value)
+ }
+ />
)}
</TableCell>
- )}
- </TableRow>
- );
- })}
- </TableBody>
- </Table>
+ {!readonly && (
+ <TableCell className="py-2 text-right">
+ {status === "dropped" ? (
+ <Button
+ variant="ghost"
+ size="sm"
+ className="size-7 p-0"
+ onClick={(e) => {
+ e.stopPropagation();
+ handleRestore(table);
+ }}
+ >
+ <RotateCcw className="size-3.5" />
+ </Button>
+ ) : (
+ <Button
+ variant="ghost"
+ size="sm"
+ className="size-7 p-0 text-error hover:text-error"
+ onClick={(e) => {
+ e.stopPropagation();
+ handleDrop(table);
+ }}
+ >
+ <Trash2 className="size-3.5" />
+ </Button>
+ )}
+ </TableCell>
+ )}
+ </TableRow>
+ );
+ })}
+ </TableBody>
+ </Table>
+ </div>
);
}
diff --git a/frontend/src/react/components/SchemaEditorLite/Panels/common.ts b/frontend/src/react/components/SchemaEditorLite/Panels/common.ts
index 4fd7344208..bef1a71bd3 100644
--- a/frontend/src/react/components/SchemaEditorLite/Panels/common.ts
+++ b/frontend/src/react/components/SchemaEditorLite/Panels/common.ts
@@ -6,10 +6,11 @@ import type { EditStatus } from "../types";
// (a hover-only border was too hard to discover). The border darkens on hover
// and turns accent on focus. `text-sm` overrides the smaller font from the
// `size="xs"` input variant so inline-edit cells match the table's default
-// plain-text cells (also text-sm), and `h-8 px-3` overrides the cramped
-// `h-6 px-2` from that variant for roomier padding inside the field.
+// plain-text cells (also text-sm), and `h-7 px-3` overrides the cramped
+// `h-6 px-2` from that variant: roomier horizontal padding but a shorter height
+// so rows stay compact.
export const INLINE_EDIT_INPUT_CLASS =
- "h-8 border border-control-border/50 bg-transparent px-3 text-sm shadow-none enabled:hover:border-control-border focus-visible:border-accent focus-visible:ring-1";
+ "h-7 border border-control-border/50 bg-transparent px-3 text-sm shadow-none enabled:hover:border-control-border focus-visible:border-accent focus-visible:ring-1";
interface ObjectWithHiddenProps {
__uuid?: string;
diff --git a/frontend/src/react/components/SchemaEditorLite/SchemaEditorLite.tsx b/frontend/src/react/components/SchemaEditorLite/SchemaEditorLite.tsx
index 9a67650b59..a3035adbe8 100644
--- a/frontend/src/react/components/SchemaEditorLite/SchemaEditorLite.tsx
+++ b/frontend/src/react/components/SchemaEditorLite/SchemaEditorLite.tsx
@@ -186,7 +186,9 @@ export const SchemaEditorLite = forwardRef<
<AsideTree />
</div>
</Panel>
- <PanelResizeHandle className={resizeHandleClass("vertical")} />
+ <PanelResizeHandle
+ className={resizeHandleClass("vertical", "w-0.5")}
+ />
<Panel defaultSize="75%">
<div className="size-full overflow-hidden">
<EditorPanel />
diff --git a/frontend/src/react/components/SchemaEditorLite/core/refreshEditStatus.ts b/frontend/src/react/components/SchemaEditorLite/core/refreshEditStatus.ts
new file mode 100644
index 0000000000..81f9f29089
--- /dev/null
+++ b/frontend/src/react/components/SchemaEditorLite/core/refreshEditStatus.ts
@@ -0,0 +1,157 @@
+import { isEqual, pick } from "lodash-es";
+import type {
+ Database,
+ DatabaseMetadata,
+ ForeignKeyMetadata,
+ IndexMetadata,
+ SchemaMetadata,
+ TableMetadata,
+ TablePartitionMetadata,
+} from "@/types/proto-es/v1/database_service_pb";
+import {
+ ComparableColumnFields,
+ ComparableForeignKeyFields,
+ ComparableIndexFields,
+ ComparableTableFields,
+ ComparableTablePartitionFields,
+} from "@/utils";
+import type { EditStatusContext } from "../types";
+import { keyForResource } from "./keyForResource";
+
+function isEqualForeignKeys(
+ source: ForeignKeyMetadata[],
+ target: ForeignKeyMetadata[]
+): boolean {
+ if (source.length !== target.length) return false;
+ return source.every((fk, i) =>
+ isEqual(
+ pick(fk, ComparableForeignKeyFields),
+ pick(target[i], ComparableForeignKeyFields)
+ )
+ );
+}
+
+function isEqualIndexes(
+ source: IndexMetadata[],
+ target: IndexMetadata[]
+): boolean {
+ if (source.length !== target.length) return false;
+ const targetByName = new Map(target.map((idx) => [idx.name, idx]));
+ return source.every((sourceIndex) => {
+ const targetIndex = targetByName.get(sourceIndex.name);
+ return (
+ !!targetIndex &&
+ isEqual(
+ pick(sourceIndex, ComparableIndexFields),
+ pick(targetIndex, ComparableIndexFields)
+ )
+ );
+ });
+}
+
+function isEqualPartitions(
+ source: TablePartitionMetadata[],
+ target: TablePartitionMetadata[]
+): boolean {
+ if (source.length !== target.length) return false;
+ const targetByName = new Map(target.map((part) => [part.name, part]));
+ return source.every((sourcePartition) => {
+ const targetPartition = targetByName.get(sourcePartition.name);
+ return (
+ !!targetPartition &&
+ isEqual(
+ pick(sourcePartition, ComparableTablePartitionFields),
+ pick(targetPartition, ComparableTablePartitionFields)
+ ) &&
+ isEqualPartitions(
+ sourcePartition.subpartitions ?? [],
+ targetPartition.subpartitions ?? []
+ )
+ );
+ });
+}
+
+/**
+ * Recompute the edit status of a single table and its columns by diffing the
+ * current metadata against the baseline, so reverting an edit back to its
+ * original value clears the dirty marker. Unlike `DiffMerge`/`rebuildMetadataEdit`
+ * this is non-mutating (it never re-inserts dropped rows or reorders), so it's
+ * safe to call on every keystroke. It's scoped to the one edited table to stay
+ * cheap.
+ *
+ * `created`/`dropped` resources are left untouched — those are structural
+ * changes, not field edits, and must not be cleared by a value comparison.
+ */
+export function refreshTableEditStatus(
+ editStatus: EditStatusContext,
+ db: Database,
+ baselineMetadata: DatabaseMetadata,
+ schema: SchemaMetadata,
+ table: TableMetadata
+): void {
+ const ownStatus = editStatus.getEditStatusByKey(
+ keyForResource(db, { schema, table })
+ );
+ if (ownStatus !== "created" && ownStatus !== "dropped") {
+ const baselineTable = baselineMetadata.schemas
+ .find((s) => s.name === schema.name)
+ ?.tables.find((t) => t.name === table.name);
+
+ // The table's own status reflects its scalar fields plus indexes, foreign
+ // keys, and partitions. Index/FK/partition edits are all tracked on the
+ // table key (see TableEditor's add handlers), so partitions must be
+ // compared here too — otherwise a reverted column/comment edit could clear
+ // the only marker for an added partition. Column edits surface separately
+ // via the per-column statuses below.
+ const ownChanged =
+ !baselineTable ||
+ !isEqual(
+ pick(table, ComparableTableFields),
+ pick(baselineTable, ComparableTableFields)
+ ) ||
+ !isEqualForeignKeys(baselineTable.foreignKeys, table.foreignKeys) ||
+ !isEqualIndexes(baselineTable.indexes, table.indexes) ||
+ !isEqualPartitions(baselineTable.partitions, table.partitions);
+ if (ownChanged) {
+ editStatus.markEditStatus(db, { schema, table }, "updated");
+ } else {
+ // Non-recursive: clear only the table's own key so the per-column
+ // statuses (set below) survive.
+ editStatus.removeEditStatus(db, { schema, table }, false);
+ }
+
+ // Edit-status keys are column-name based, so two columns sharing a name
+ // (an in-progress rename collision) map to the same key. Treat any such
+ // duplicate as changed and never clear its key — otherwise the unchanged
+ // twin could remove the dirty marker the renamed twin just set, leaving
+ // the editor wrongly clean while the metadata actually differs.
+ const nameCounts = new Map<string, number>();
+ for (const column of table.columns) {
+ nameCounts.set(column.name, (nameCounts.get(column.name) ?? 0) + 1);
+ }
+
+ for (const column of table.columns) {
+ const columnStatus = editStatus.getColumnStatus(db, {
+ schema,
+ table,
+ column,
+ });
+ if (columnStatus === "created" || columnStatus === "dropped") continue;
+ const baselineColumn = baselineTable?.columns.find(
+ (c) => c.name === column.name
+ );
+ const changed =
+ (nameCounts.get(column.name) ?? 0) > 1 ||
+ !baselineColumn ||
+ !isEqual(
+ pick(column, ComparableColumnFields),
+ pick(baselineColumn, ComparableColumnFields)
+ );
+ if (changed) {
+ editStatus.markEditStatus(db, { schema, table, column }, "updated");
+ } else {
+ editStatus.removeEditStatus(db, { schema, table, column }, false);
+ }
+ }
+ }
+}
diff --git a/frontend/src/react/components/instance/DataSourceForm.tsx b/frontend/src/react/components/instance/DataSourceForm.tsx
index 62476cf538..daeaa29751 100644
--- a/frontend/src/react/components/instance/DataSourceForm.tsx
+++ b/frontend/src/react/components/instance/DataSourceForm.tsx
@@ -1216,7 +1216,8 @@ export function DataSourceForm({
type="radio"
checked={
dataSource.externalSecret
- .authOption.value.type === 0
+ .authOption.value.type ===
+ DataSourceExternalSecret_AppRoleAuthOption_SecretType.PLAIN
}
disabled={!allowEdit}
onChange={() => {
@@ -1233,7 +1234,7 @@ export function DataSourceForm({
value: {
...ds.externalSecret
.authOption.value,
- type: 0,
+ type: DataSourceExternalSecret_AppRoleAuthOption_SecretType.PLAIN,
},
},
};
@@ -1250,7 +1251,8 @@ export function DataSourceForm({
type="radio"
checked={
dataSource.externalSecret
- .authOption.value.type === 1
+ .authOption.value.type ===
+ DataSourceExternalSecret_AppRoleAuthOption_SecretType.ENVIRONMENT
}
disabled={!allowEdit}
onChange={() => {
@@ -1267,7 +1269,7 @@ export function DataSourceForm({
value: {
...ds.externalSecret
.authOption.value,
- type: 1,
+ type: DataSourceExternalSecret_AppRoleAuthOption_SecretType.ENVIRONMENT,
},
},
};
diff --git a/frontend/src/react/components/ui/column-resize-handle.tsx b/frontend/src/react/components/ui/column-resize-handle.tsx
index 528c4689d2..4f86a578c6 100644
--- a/frontend/src/react/components/ui/column-resize-handle.tsx
+++ b/frontend/src/react/components/ui/column-resize-handle.tsx
@@ -22,7 +22,7 @@ export function ColumnResizeHandle({
onMouseDown={onMouseDown}
onClick={(e) => e.stopPropagation()}
>
- <span className="pointer-events-none absolute left-1/2 top-1/4 h-1/2 w-[3px] -translate-x-1/2 rounded-full bg-control-bg-hover transition-colors group-hover:bg-accent/60 group-active:bg-accent" />
+ <span className="pointer-events-none absolute left-1/2 top-1/4 h-1/2 w-0.5 -translate-x-1/2 rounded-full bg-control-bg-hover transition-colors group-hover:bg-accent/60 group-active:bg-accent" />
</div>
);
}
diff --git a/frontend/src/react/components/ui/table.test.tsx b/frontend/src/react/components/ui/table.test.tsx
index 02a657ba1b..01f41bdd03 100644
--- a/frontend/src/react/components/ui/table.test.tsx
+++ b/frontend/src/react/components/ui/table.test.tsx
@@ -26,12 +26,12 @@ describe("table primitives", () => {
expect(element.props.className).toContain("!bg-transparent");
});
- test("ColumnResizeHandle uses a raised 12px hitbox around a 3px visual bar", () => {
+ test("ColumnResizeHandle uses a raised 12px hitbox around a 2px visual bar", () => {
const element = ColumnResizeHandle({ onMouseDown: () => {} });
expect(element.props.className).toContain("right-[-6px]");
expect(element.props.className).toContain("w-3");
expect(element.props.className).toContain("z-10");
- expect(element.props.children.props.className).toContain("w-[3px]");
+ expect(element.props.children.props.className).toContain("w-0.5");
});
});
diff --git a/frontend/src/react/hooks/useColumnWidths.ts b/frontend/src/react/hooks/useColumnWidths.ts
index 08587371d1..5445aa2f87 100644
--- a/frontend/src/react/hooks/useColumnWidths.ts
+++ b/frontend/src/react/hooks/useColumnWidths.ts
@@ -11,6 +11,34 @@ export interface ColumnWithWidth {
minWidth?: number;
}
+/**
+ * Distributes `containerWidth` across columns so the table fills its container
+ * on first render instead of overflowing at the sum of `defaultWidth`s.
+ * Columns with `resizable === false` keep their `defaultWidth`; the rest share
+ * the remaining space proportionally to their `defaultWidth` (each clamped to
+ * `minWidth`). Falls back to the raw default widths when the container is too
+ * narrow to honor the minimums (the table then scrolls).
+ */
+export function distributeColumnWidths<
+ T extends ColumnWithWidth & { resizable?: boolean },
+>(columns: T[], containerWidth: number): number[] {
+ const fixedTotal = columns
+ .filter((c) => c.resizable === false)
+ .reduce((sum, c) => sum + c.defaultWidth, 0);
+ const flexBaseTotal = columns
+ .filter((c) => c.resizable !== false)
+ .reduce((sum, c) => sum + c.defaultWidth, 0);
+ const available = Math.max(0, containerWidth - fixedTotal);
+ return columns.map((c) => {
+ if (c.resizable === false) return c.defaultWidth;
+ const proportional =
+ flexBaseTotal > 0
+ ? Math.round(available * (c.defaultWidth / flexBaseTotal))
+ : c.defaultWidth;
+ return Math.max(c.minWidth ?? 40, proportional);
+ });
+}
+
/**
* Tracks per-column widths for a `table-fixed` table and exposes a mouse
* handler to start a drag-to-resize gesture on a column header. State is
@@ -129,5 +157,5 @@ export function useColumnWidths<T extends ColumnWithWidth>(columns: T[]) {
const totalWidth = widths.reduce((sum, w) => sum + w, 0);
- return { widths, totalWidth, onResizeStart };
+ return { widths, totalWidth, onResizeStart, setWidths };
}