дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-30 06:12:33 +02:00
feat(database): show a table's DDL from the data view (#6909)
The data view's toolbar gets a DDL button that opens the table's definition through the same openDdl the tree's Go to DDL uses, so checking an index or constraint no longer means leaving the rows. It is disabled while the DDL loads, for custom JDBC sources (no vendor DDL) and for catalog-qualified tables. Closes #6910 Co-authored-by: junchangpeng <[email protected]> Co-authored-by: junchangpeng <[email protected]>
Цей коміт міститься в:
1 джерело
6aa613d4ec
коміт
d9fbb19787
3 files changed
+46
-2
No files matched your search
@@ -14,7 +14,7 @@ import {
|
||||
type DbTablePage,
|
||||
type RequestId,
|
||||
} from "@/platform/ipc";
|
||||
import { EmptyState, Icon, IconButton, Select, Spinner, Toolbar, showContextMenu } from "@/ui";
|
||||
import { Button, EmptyState, Icon, IconButton, Select, Spinner, Toolbar, showContextMenu } from "@/ui";
|
||||
import { notifications, type EditorInput } from "@/workbench/contributions";
|
||||
import { SqlFilterInput } from "./SqlFilterInput";
|
||||
import { ColumnsPopup } from "./ColumnsPopup";
|
||||
@@ -31,7 +31,7 @@ import {
|
||||
type Cell,
|
||||
type PendingEdits,
|
||||
} from "./model";
|
||||
import { openDialog, sourceById, withConnection } from "./store";
|
||||
import { openDialog, openDdl, sourceById, withConnection } from "./store";
|
||||
import type { TableRef } from "./tableInput";
|
||||
import styles from "./Database.module.css";
|
||||
import { registerTableEditor, tableEditorChanged, type TableEditorHandle } from "./tableEditorFocus";
|
||||
@@ -98,6 +98,9 @@ export function TableEditor({ input }: { input: EditorInput }) {
|
||||
[input.key],
|
||||
);
|
||||
const [nonce, setNonce] = useState(0);
|
||||
// The DDL travels to the backend and back, so the button shows it is working instead of
|
||||
// leaving a click with nothing on screen for a few hundred milliseconds.
|
||||
const [ddlBusy, setDdlBusy] = useState(false);
|
||||
const [edits, setEdits] = useState<PendingEdits>(emptyEdits);
|
||||
const [panel, setPanel] = useState<DataPanel | null>(null);
|
||||
const [searchOpen, setSearchOpen] = useState(false);
|
||||
@@ -282,6 +285,14 @@ export function TableEditor({ input }: { input: EditorInput }) {
|
||||
if (page && r) setColumnsAt({ x: r.left + r.width / 2, y: r.top + 48 });
|
||||
};
|
||||
const addRow = () => setEdits((e) => ({ ...e, inserts: [...e.inserts, new Map()] }));
|
||||
const showDdl = async () => {
|
||||
setDdlBusy(true);
|
||||
try {
|
||||
await openDdl(ref.id, ref.schema, ref.table);
|
||||
} finally {
|
||||
setDdlBusy(false);
|
||||
}
|
||||
};
|
||||
const restoreRows = (rows: number[]) =>
|
||||
setEdits((e) => ({ ...e, deletes: new Set([...e.deletes].filter((d) => !rows.includes(d))) }));
|
||||
const showExport = (at: { x: number; y: number }) =>
|
||||
@@ -350,6 +361,15 @@ export function TableEditor({ input }: { input: EditorInput }) {
|
||||
aria-pressed={searchOpen}
|
||||
onClick={() => setSearchOpen(!searchOpen)}
|
||||
/>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="small"
|
||||
title="Show DDL"
|
||||
disabled={ddlBusy || ref.catalog !== undefined || source?.driver === "jdbc"}
|
||||
onClick={() => void showDdl()}
|
||||
>
|
||||
DDL
|
||||
</Button>
|
||||
{editable && (
|
||||
<>
|
||||
<span className={styles.toolbarSeparator} />
|
||||
|
||||
@@ -13,6 +13,7 @@ const backend = vi.hoisted(() => ({
|
||||
page: vi.fn(),
|
||||
catalogPage: vi.fn(),
|
||||
applyEdits: vi.fn(),
|
||||
openDdl: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("@/platform/ipc", async (importOriginal) => {
|
||||
@@ -32,6 +33,7 @@ vi.mock("./store", () => ({
|
||||
sourceById: () => ({ driver: backend.driver, readOnly: false }),
|
||||
withConnection: (_id: string, run: () => unknown) => run(),
|
||||
openDialog: vi.fn(),
|
||||
openDdl: backend.openDdl,
|
||||
}));
|
||||
|
||||
vi.mock("@tanstack/react-virtual", () => ({
|
||||
@@ -126,6 +128,27 @@ describe("table editor capabilities", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it("opens the table's DDL from the data view's toolbar", async () => {
|
||||
backend.driver = "postgres";
|
||||
await act(async () => {
|
||||
render(<TableEditor input={tableInput("source", "public", "users")} />);
|
||||
});
|
||||
const button = await screen.findByRole("button", { name: "DDL" });
|
||||
fireEvent.click(button);
|
||||
expect(backend.openDdl).toHaveBeenCalledWith("source", "public", "users");
|
||||
});
|
||||
|
||||
it("does not offer DDL where the source cannot report it", async () => {
|
||||
// A custom JDBC source answers no vendor DDL, and a catalog-qualified table is not the
|
||||
// connection's own database, so neither can ask `db_ddl` for a definition.
|
||||
backend.driver = "jdbc";
|
||||
await act(async () => {
|
||||
render(<TableEditor input={tableInput("source", "public", "users")} />);
|
||||
});
|
||||
await screen.findByRole("gridcell", { name: "Ann" });
|
||||
expect(screen.getByRole("button", { name: "DDL" })).toHaveProperty("disabled", true);
|
||||
});
|
||||
|
||||
it("keeps keyed PostgreSQL rows editable", async () => {
|
||||
backend.driver = "postgres";
|
||||
await act(async () => {
|
||||
|
||||
@@ -2217,6 +2217,7 @@
|
||||
"Go to Child Commit": "转到子提交",
|
||||
"Go to Class…": "转到类…",
|
||||
"Go to DDL": "转到 DDL",
|
||||
"Show DDL": "显示 DDL",
|
||||
"Go to File": "转到文件",
|
||||
"Go to File…": "转到文件…",
|
||||
"Go to Line:Column": "转到行:列",
|
||||
|
||||
Reference in new issue
Заблокувати користувача