дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
feat(plugins): expose database table menus and read-only schema (#7372)
Plugin API 1.20 adds wit/database.wit with describe-table behind the database.schema capability: a read-only view of a connected source's table (columns, keys, indexes) through DbManager::connected_table_details. Plugins can contribute database.table.context menu entries (needs_api 20) that receive the non-secret table identity and the when keys databaseDriver, databaseObjectKind, databaseSchema, databaseTable and databaseSelectionCount. Co-authored-by: gejun123456 <[email protected]>
Цей коміт міститься в:
1 джерело
abc5b2b2c6
коміт
b7c2d4eacb
201 files changed
+1180
-176
No files matched your search
@@ -0,0 +1,80 @@
|
||||
import { expect, stubDesktop, test } from "./fixtures";
|
||||
|
||||
test("table menu contributions preserve selected table identities", async ({ workbench: page }, info) => {
|
||||
await stubDesktop(page);
|
||||
await page.evaluate(async () => {
|
||||
const storePath = "/src/features/database/store.ts";
|
||||
const contributionsPath = "/src/workbench/contributions.ts";
|
||||
const { useDatabase } = await import(storePath);
|
||||
const { toolWindowService } = await import(contributionsPath);
|
||||
useDatabase.setState({
|
||||
sources: [{ id: "local", name: "Inventory", driver: "sqlite", file: "inventory.sqlite" }],
|
||||
loaded: true,
|
||||
connected: new Set(["local"]),
|
||||
schemas: { local: { status: "ok", value: ["main"] } },
|
||||
foldersLoaded: true,
|
||||
tables: {
|
||||
["local\u0000main"]: {
|
||||
status: "ok",
|
||||
value: [
|
||||
{ name: "users", kind: "table" },
|
||||
{ name: "orders", kind: "table" },
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
toolWindowService().show("database", true);
|
||||
});
|
||||
const panel = page.locator('section[aria-label="Database"]');
|
||||
const source = panel.getByRole("treeitem").filter({ hasText: "Inventory" });
|
||||
await source.locator("[data-tree-toggle]").click();
|
||||
const schema = panel.getByRole("treeitem").filter({ hasText: /^main/ });
|
||||
if (await schema.count()) await schema.locator("[data-tree-toggle]").click();
|
||||
await panel
|
||||
.getByRole("treeitem")
|
||||
.filter({ hasText: /^tables/ })
|
||||
.locator("[data-tree-toggle]")
|
||||
.click();
|
||||
const users = panel.getByRole("treeitem").filter({ hasText: /^users/ });
|
||||
await expect(users).toBeVisible();
|
||||
await users.click({ button: "right" });
|
||||
await expect(page.getByRole("menu").last()).toBeVisible();
|
||||
await page.screenshot({ path: info.outputPath("before.png"), animations: "disabled" });
|
||||
await page.keyboard.press("Escape");
|
||||
await page.evaluate(async () => {
|
||||
const actionsPath = "/src/platform/actions.ts";
|
||||
const projectionPath = "/src/features/plugins/projection.ts";
|
||||
const { registerAction } = await import(actionsPath);
|
||||
const { syncUiContributions } = await import(projectionPath);
|
||||
registerAction({
|
||||
id: "plugin.mapper.generate",
|
||||
title: "Generate MyBatis mapper",
|
||||
run: ({ arg }: { arg?: unknown }) => {
|
||||
Object.assign(window, { __tableSelection: arg });
|
||||
},
|
||||
});
|
||||
syncUiContributions(
|
||||
[
|
||||
{
|
||||
pluginId: "mapper",
|
||||
point: "menus",
|
||||
key: "database.table.context/generate",
|
||||
decl: { menu: "database.table.context", command: "generate", when: "databaseObjectKind == table" },
|
||||
},
|
||||
],
|
||||
[{ id: "mapper", name: "Mapper generator", enabled: true, status: "active", icon: null }],
|
||||
);
|
||||
});
|
||||
await users.click({ button: "right" });
|
||||
const generate = page.getByRole("menuitem", { name: "Generate MyBatis mapper" });
|
||||
await expect(generate).toBeVisible();
|
||||
await page.screenshot({ path: info.outputPath("after.png"), animations: "disabled" });
|
||||
await generate.click();
|
||||
await expect
|
||||
.poll(() => page.evaluate(() => (window as unknown as { __tableSelection?: string }).__tableSelection))
|
||||
.toBeTruthy();
|
||||
const selection = await page.evaluate(() => (window as unknown as { __tableSelection: string }).__tableSelection);
|
||||
expect(JSON.parse(selection)).toEqual({
|
||||
tables: [{ sourceId: "local", catalog: null, schema: "main", table: "users", kind: "table", driver: "sqlite" }],
|
||||
});
|
||||
});
|
||||
Reference in new issue
Заблокувати користувача