fix(docs): move Documentation to database context menu
This commit is contained in:
1 parent
9a255aa135
commit
bdf87ac255
7 files changed
+560
-24
No files matched your search
@@ -6,7 +6,6 @@ import {
|
||||
ArrowDown,
|
||||
ArrowRightLeft,
|
||||
ArrowUp,
|
||||
BookOpen,
|
||||
Braces,
|
||||
CheckSquare,
|
||||
Clipboard,
|
||||
@@ -1463,16 +1462,6 @@ function openDiagram(row: ObjectBrowserRow) {
|
||||
};
|
||||
}
|
||||
|
||||
function openDocs(row: ObjectBrowserRow) {
|
||||
// The docs viewer documents the whole schema rather than one object, so the
|
||||
// row only supplies which schema to collect.
|
||||
connectionStore.docsSource = {
|
||||
connectionId: props.connection.id,
|
||||
database: props.database,
|
||||
schema: row.schema || selectedSchema.value,
|
||||
};
|
||||
}
|
||||
|
||||
function openTableImport(row: ObjectBrowserRow) {
|
||||
if (row.type !== "TABLE") return;
|
||||
connectionStore.tableImportSource = {
|
||||
@@ -2663,12 +2652,7 @@ function getTableMenuItems(item: ObjectBrowserRow): ContextMenuItem[] {
|
||||
...(canOpenStructureEditor.value ? [{ label: t("contextMenu.editStructure"), action: () => openStructureEditor(item), icon: PencilRuler }] : []),
|
||||
...(canRename(item) ? [{ label: t("contextMenu.renameObject"), action: () => requestRename(item), icon: Pencil }] : []),
|
||||
{ label: t("contextMenu.newQuery"), action: () => openNewQuery(item), icon: TerminalSquare },
|
||||
...(canOpenDiagram.value
|
||||
? [
|
||||
{ label: t("diagram.open"), action: () => openDiagram(item), icon: Network },
|
||||
{ label: t("docs.title"), action: () => openDocs(item), icon: BookOpen },
|
||||
]
|
||||
: []),
|
||||
...(canOpenDiagram.value ? [{ label: t("diagram.open"), action: () => openDiagram(item), icon: Network }] : []),
|
||||
...(canOpenTableImport.value ? [{ label: t("contextMenu.importData"), action: () => openTableImport(item), icon: Download }] : []),
|
||||
{ label: t("dataCompare.title"), action: () => openDataCompare(item), icon: ArrowRightLeft },
|
||||
{ label: "", separator: true },
|
||||
@@ -2718,12 +2702,7 @@ function getViewMenuItems(item: ObjectBrowserRow): ContextMenuItem[] {
|
||||
},
|
||||
...(canRename(item) ? [{ label: t("contextMenu.renameObject"), action: () => requestRename(item), icon: Pencil }] : []),
|
||||
{ label: t("contextMenu.newQuery"), action: () => openNewQuery(item), icon: TerminalSquare },
|
||||
...(canOpenDiagram.value
|
||||
? [
|
||||
{ label: t("diagram.open"), action: () => openDiagram(item), icon: Network },
|
||||
{ label: t("docs.title"), action: () => openDocs(item), icon: BookOpen },
|
||||
]
|
||||
: []),
|
||||
...(canOpenDiagram.value ? [{ label: t("diagram.open"), action: () => openDiagram(item), icon: Network }] : []),
|
||||
{ label: "", separator: true },
|
||||
exportDataSubmenu(item),
|
||||
{ label: t("contextMenu.exportDatabase"), action: () => openDatabaseExport(item), icon: Upload },
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
function source(relative: string): string {
|
||||
return readFileSync(fileURLToPath(new URL(relative, import.meta.url)), "utf8");
|
||||
}
|
||||
|
||||
/**
|
||||
* Slices the body of one sidebar menu builder out of SidebarTreeRuntimeHost.vue.
|
||||
* Matching the builder rather than a formatted line keeps this guard indifferent
|
||||
* to how oxfmt lays the menu pushes out.
|
||||
*/
|
||||
function sidebarMenuBuilder(name: string): string {
|
||||
const text = source("../../sidebar/SidebarTreeRuntimeHost.vue");
|
||||
const start = text.indexOf(`function ${name}(`);
|
||||
expect(start, `${name} not found`).toBeGreaterThan(-1);
|
||||
const next = text.indexOf("\nfunction ", start + 1);
|
||||
return text.slice(start, next === -1 ? undefined : next);
|
||||
}
|
||||
|
||||
describe("documentation menu placement", () => {
|
||||
it("registers the entry on database and schema nodes", () => {
|
||||
// The docs viewer documents a database or a schema, so it belongs on the
|
||||
// tree nodes that name one. buildDatabaseSidebarMenu serves both types.
|
||||
expect(sidebarMenuBuilder("buildDatabaseSidebarMenu")).toContain("docs.title");
|
||||
});
|
||||
|
||||
it("keeps the entry off the sidebar's per-object menu", () => {
|
||||
expect(sidebarMenuBuilder("buildObjectSidebarMenu")).not.toContain("docs.title");
|
||||
});
|
||||
|
||||
it("keeps the entry off the object browser's menus", () => {
|
||||
// openDocs never read the row's table: a table-level entry advertised a
|
||||
// scope the viewer cannot render.
|
||||
expect(source("../ObjectBrowser.vue")).not.toContain("docs.title");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user