fix(neo4j): correct label grids typed saves and menus
This commit is contained in:
1 parent
8d9e2dc49f
commit
6a2a15796e
14 files changed
+394
-112
No files matched your search
@@ -2792,7 +2792,7 @@ function requestDropTableChildObject() {
|
||||
}
|
||||
|
||||
function canDropTreeNode(node: TreeNode): boolean {
|
||||
if (databaseTypeForNode(node) === "nebula") return false;
|
||||
if (["neo4j", "nebula"].includes(databaseTypeForNode(node) || "")) return false;
|
||||
if (isSqlServerLinkedNode(node)) return false;
|
||||
if (node.type === "table") return !!node.connectionId && !!node.database;
|
||||
if (node.type === "view" || node.type === "materialized_view" || node.type === "procedure" || node.type === "function" || node.type === "event") {
|
||||
@@ -3135,7 +3135,7 @@ function requestDropSelectedNodes(): boolean {
|
||||
}
|
||||
|
||||
function requestDropSelectedNode(): boolean {
|
||||
if (currentDatabaseType() === "nebula") return false;
|
||||
if (["neo4j", "nebula"].includes(currentDatabaseType() || "")) return false;
|
||||
if (activeNode.value.type === "table") {
|
||||
dropTable();
|
||||
return true;
|
||||
@@ -4760,7 +4760,7 @@ const canOpenSqlFileExecution = computed(() => {
|
||||
const canExportAllDatabases = computed(() => {
|
||||
if (activeNode.value.type !== "connection" || !activeNode.value.connectionId) return false;
|
||||
const dbType = connectionStore.getConfig(activeNode.value.connectionId)?.db_type;
|
||||
return !["redis", "mongodb", "dynamodb", "elasticsearch", "easysearch", "meilisearch", "solr", "qdrant", "milvus", "weaviate", "chromadb", "etcd", "zookeeper", "consul", "mq", "nacos", "plugin", "salesforce", "nebula"].includes(dbType || "");
|
||||
return !["redis", "mongodb", "dynamodb", "elasticsearch", "easysearch", "meilisearch", "solr", "qdrant", "milvus", "weaviate", "chromadb", "etcd", "zookeeper", "consul", "mq", "nacos", "plugin", "salesforce", "neo4j", "nebula"].includes(dbType || "");
|
||||
});
|
||||
|
||||
const canOpenScheduledBackups = computed(() => {
|
||||
@@ -5867,15 +5867,17 @@ function buildDatabaseSidebarMenu(context: SidebarMenuFactoryContext): boolean {
|
||||
});
|
||||
return true;
|
||||
}
|
||||
if (currentDatabaseType() === "nebula" && node.type === "database") {
|
||||
if (["neo4j", "nebula"].includes(currentDatabaseType() || "") && node.type === "database") {
|
||||
if (canCloseDatabaseConnection.value) items.push({ label: t("contextMenu.closeDatabaseConnection"), action: closeDatabaseConnection, icon: Unplug });
|
||||
items.push(copyNameMenuItem());
|
||||
items.push({ label: "", separator: true });
|
||||
if (canOpenObjectBrowser.value) items.push({ label: t("contextMenu.openObjectBrowser"), action: openObjectBrowser, icon: TableProperties });
|
||||
items.push({ label: t("contextMenu.newQuery"), action: newQuery, icon: TerminalSquare });
|
||||
if (supportsAiAssistantContext(currentDatabaseType())) items.push(addToAiMenuItem(node));
|
||||
const sqlHistoryMenu = savedSqlHistorySubmenu();
|
||||
if (sqlHistoryMenu) items.push(sqlHistoryMenu);
|
||||
items.push({ label: isNodeDefaultDatabase.value ? t("contextMenu.clearDefaultDatabase") : t("contextMenu.setDefaultDatabase"), action: isNodeDefaultDatabase.value ? clearNodeDefaultDatabase : setNodeAsDefaultDatabase, icon: Database });
|
||||
if (canOpenSqlFileExecution.value) items.push({ label: t("sqlFile.title"), action: openSqlFileExecution, icon: FileCode });
|
||||
items.push({ label: "", separator: true });
|
||||
items.push({ label: t("contextMenu.refreshChildren"), action: refresh, icon: RefreshCw, shortcut: shortcutRefresh });
|
||||
return true;
|
||||
@@ -6286,13 +6288,15 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
|
||||
appendPluginTableMenuItems(items, node);
|
||||
return true;
|
||||
}
|
||||
if (currentDatabaseType() === "nebula") {
|
||||
if (["neo4j", "nebula"].includes(currentDatabaseType() || "")) {
|
||||
items.push(copyNameMenuItem());
|
||||
items.push({ label: t("contextMenu.newQuery"), action: newQuery, icon: TerminalSquare });
|
||||
if (supportsAiAssistantContext(currentDatabaseType())) items.push(addToAiMenuItem(node));
|
||||
items.push({ label: "", separator: true });
|
||||
items.push({ label: t("contextMenu.viewData"), action: openDataImmediately, icon: TableProperties });
|
||||
items.push({ label: t("contextMenu.openInNewDataTab"), action: openDataInNewTabImmediately, icon: CopyPlus, shortcut: shortcutOpenDataInNewTab.value });
|
||||
items.push({ label: t("contextMenu.viewDdl"), action: openDdl, icon: FileCode });
|
||||
if (currentDatabaseType() === "nebula") items.push({ label: t("contextMenu.viewDdl"), action: openDdl, icon: FileCode });
|
||||
if (currentDatabaseType() === "neo4j") items.push(exportDataSubmenu(false));
|
||||
const sqlHistoryMenu = savedSqlHistorySubmenu();
|
||||
if (sqlHistoryMenu) items.push(sqlHistoryMenu);
|
||||
items.push({ label: "", separator: true });
|
||||
@@ -6652,7 +6656,8 @@ function buildObjectGroupSidebarMenu(context: SidebarMenuFactoryContext): boolea
|
||||
const mysqlObjectTemplate = node.connectionId ? mysqlObjectTemplateForGroup(connectionStore.getConfig(node.connectionId), node) : null;
|
||||
const hasMongoCreateIndexAction = node.type === "group-indexes" && canCreateMongoIndex.value;
|
||||
const hasMongoDropAllIndexesAction = node.type === "group-indexes" && canDropAllMongoIndexes.value;
|
||||
const hasGroupAction = (node.type === "group-tables" && canCreateTable.value) || (node.type === "group-views" && !!node.connectionId && !!node.database && currentDatabaseType() !== "nebula") || !!mysqlObjectTemplate || hasMongoCreateIndexAction || hasMongoDropAllIndexesAction;
|
||||
const canCreateGroupView = node.type === "group-views" && !!node.connectionId && !!node.database && !["neo4j", "nebula"].includes(currentDatabaseType() || "");
|
||||
const hasGroupAction = (node.type === "group-tables" && canCreateTable.value) || canCreateGroupView || !!mysqlObjectTemplate || hasMongoCreateIndexAction || hasMongoDropAllIndexesAction;
|
||||
const canLoadAllObjectGroup = node.type === "group-tables" || node.type === "group-dolt-system-tables" || node.type === "group-views" || node.type === "group-materialized-views";
|
||||
if (node.type === "group-tables" && canCreateTable.value) {
|
||||
items.push({ label: t("contextMenu.createTable"), action: createTable, icon: Plus });
|
||||
@@ -6663,7 +6668,7 @@ function buildObjectGroupSidebarMenu(context: SidebarMenuFactoryContext): boolea
|
||||
items.push({ label: t("contextMenu.pasteTable"), action: openPasteTableDialog, icon: Clipboard });
|
||||
}
|
||||
}
|
||||
if (node.type === "group-views" && node.connectionId && node.database && currentDatabaseType() !== "nebula") {
|
||||
if (canCreateGroupView) {
|
||||
items.push({ label: t("contextMenu.createView"), action: createView, icon: Plus });
|
||||
}
|
||||
if (node.type === "group-events" && node.connectionId && node.database) {
|
||||
|
||||
Vendored
+77
@@ -0,0 +1,77 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { createApp, defineComponent, h, nextTick, ref, type App } from "vue";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import i18n from "@/i18n";
|
||||
import type { ContextMenuItem } from "@/components/ui/CustomContextMenu.vue";
|
||||
import type { DatabaseType, TreeNode } from "@/types/database";
|
||||
import { supportsTableTruncate } from "@/lib/database/databaseFeatureSupport";
|
||||
|
||||
vi.mock("@/lib/backend/api", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("@/lib/backend/api")>();
|
||||
return { ...actual, listPlugins: vi.fn().mockResolvedValue([]) };
|
||||
});
|
||||
|
||||
import SidebarTreeRuntimeHost from "@/components/sidebar/SidebarTreeRuntimeHost.vue";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
|
||||
const node = (type: TreeNode["type"], label: string): TreeNode => ({ id: `sample:${type}:${label}`, type, label, connectionId: "sample", database: "sample", tableName: label });
|
||||
const mountedApps: App<Element>[] = [];
|
||||
const labels = (items: ContextMenuItem[]): string[] => items.flatMap((item) => [...(item.label ? [item.label] : []), ...(item.children ? labels(item.children) : [])]);
|
||||
const tr = (key: string) => i18n.global.t(key);
|
||||
|
||||
async function mountHost(dbType: DatabaseType = "neo4j") {
|
||||
const pinia = createPinia();
|
||||
setActivePinia(pinia);
|
||||
useConnectionStore().connections = [{ id: "sample", name: "Sample", db_type: dbType, driver_profile: dbType, host: "localhost", port: 7687, username: "sample", password: "" }];
|
||||
const host = ref<InstanceType<typeof SidebarTreeRuntimeHost> | null>(null);
|
||||
const root = defineComponent({ setup: () => () => h(SidebarTreeRuntimeHost, { ref: host, node: node("connection", "Sample"), depth: 0 }) });
|
||||
const container = document.createElement("div");
|
||||
document.body.appendChild(container);
|
||||
const app = createApp(root);
|
||||
app.use(pinia);
|
||||
app.use(i18n);
|
||||
app.mount(container);
|
||||
mountedApps.push(app);
|
||||
await nextTick();
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
await nextTick();
|
||||
return host.value as { buildContextMenu(node: TreeNode): ContextMenuItem[] };
|
||||
}
|
||||
|
||||
describe("Neo4j sidebar capabilities", () => {
|
||||
afterEach(() => {
|
||||
for (const app of mountedApps.splice(0)) app.unmount();
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
|
||||
it("keeps database browsing and queries without relational comparisons or transfers", async () => {
|
||||
const host = await mountHost();
|
||||
const items = labels(host.buildContextMenu(node("database", "sample")));
|
||||
expect(items).toEqual(expect.arrayContaining([tr("contextMenu.newQuery"), tr("contextMenu.openObjectBrowser"), tr("contextMenu.refreshChildren"), tr("sqlFile.title")]));
|
||||
for (const key of ["transfer.dataTransfer", "diff.title", "dataCompare.title", "contextMenu.exportDatabase", "dataDictionary.title"]) expect(items).not.toContain(tr(key));
|
||||
});
|
||||
|
||||
it.each(["table", "view"] as const)("keeps %s data browsing without SQL structure mutations", async (type) => {
|
||||
const host = await mountHost();
|
||||
const items = labels(host.buildContextMenu(node(type, "Person")));
|
||||
expect(items).toEqual(expect.arrayContaining([tr("contextMenu.viewData"), tr("contextMenu.newQuery"), tr("contextMenu.exportData")]));
|
||||
for (const key of ["contextMenu.viewDdl", "contextMenu.generateSql", "contextMenu.duplicateStructure", "contextMenu.dropTable", "contextMenu.dropView", "contextMenu.truncateTable", "contextMenu.emptyTable", "contextMenu.exportDatabase", "dataCompare.title"]) expect(items).not.toContain(tr(key));
|
||||
});
|
||||
|
||||
it("does not offer SQL view creation or relational database backups", async () => {
|
||||
const host = await mountHost();
|
||||
expect(labels(host.buildContextMenu(node("group-views", "Views")))).not.toContain(tr("contextMenu.createView"));
|
||||
const connectionItems = labels(host.buildContextMenu(node("connection", "Sample")));
|
||||
expect(connectionItems).toContain(tr("contextMenu.newQuery"));
|
||||
expect(connectionItems).not.toContain(tr("contextMenu.exportAllDatabases"));
|
||||
expect(supportsTableTruncate("neo4j")).toBe(false);
|
||||
});
|
||||
|
||||
it("preserves MySQL relational menus", async () => {
|
||||
const host = await mountHost("mysql");
|
||||
expect(labels(host.buildContextMenu(node("database", "sample")))).toContain(tr("transfer.dataTransfer"));
|
||||
expect(labels(host.buildContextMenu(node("table", "Person")))).toContain(tr("contextMenu.generateSql"));
|
||||
expect(supportsTableTruncate("mysql")).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -425,8 +425,8 @@ describe("useSidebarDataOpenRuntime", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("waits for NebulaGraph properties before building the first table query", async () => {
|
||||
mocks.databaseType = "nebula";
|
||||
it.each(["nebula", "neo4j"])("waits for %s properties before building the first table query", async (databaseType) => {
|
||||
mocks.databaseType = databaseType;
|
||||
let releaseMetadata: () => void = () => {};
|
||||
const gate = new Promise<void>((resolve) => {
|
||||
releaseMetadata = resolve;
|
||||
@@ -455,7 +455,7 @@ describe("useSidebarDataOpenRuntime", () => {
|
||||
releaseMetadata();
|
||||
await opening;
|
||||
|
||||
expect(mocks.buildTableSelectSql).toHaveBeenCalledWith(expect.objectContaining({ databaseType: "nebula", columns: ["name"] }));
|
||||
expect(mocks.buildTableSelectSql).toHaveBeenCalledWith(expect.objectContaining({ databaseType, columns: ["name"] }));
|
||||
expect(mocks.callOrder).toEqual(["query"]);
|
||||
});
|
||||
|
||||
|
||||
@@ -64,6 +64,13 @@ describe("dataGridCellDisplayText", () => {
|
||||
});
|
||||
|
||||
describe("coerceDataGridCellValue", () => {
|
||||
it.each(["Integer", "Long", "int"])("keeps Neo4j %s edits as exact text for the Cypher builder", (data_type) => {
|
||||
for (const value of ["1001", "9007199254740999", "9223372036854775807", "-9223372036854775808"]) {
|
||||
expect(coerceDataGridCellValue({ value, oldValue: "1", databaseType: "neo4j", columnInfo: { data_type } })).toBe(value);
|
||||
expect(coerceDataGridCellValue({ value: `${value}\n`, oldValue: "1", databaseType: "neo4j", columnInfo: { data_type } })).toBe(value);
|
||||
}
|
||||
});
|
||||
|
||||
it.each(["null", "NULL", "Null", "nUlL"])("preserves literal %s input as text", (value) => {
|
||||
expect(
|
||||
coerceDataGridCellValue({
|
||||
|
||||
@@ -323,6 +323,7 @@ describe("quoteTableIdentifier", () => {
|
||||
expect(requiresEagerTableMetadataForDataOpen("mysql")).toBe(true);
|
||||
expect(requiresEagerTableMetadataForDataOpen("postgres")).toBe(true);
|
||||
expect(requiresEagerTableMetadataForDataOpen("nebula")).toBe(true);
|
||||
expect(requiresEagerTableMetadataForDataOpen("neo4j")).toBe(true);
|
||||
// Drivers whose preview works from `SELECT *` keep loading metadata lazily.
|
||||
expect(requiresEagerTableMetadataForDataOpen("sqlite")).toBe(false);
|
||||
expect(requiresEagerTableMetadataForDataOpen(undefined)).toBe(false);
|
||||
|
||||
@@ -37,6 +37,9 @@ export function coerceDataGridCellValue(options: CoerceDataGridCellValueOptions)
|
||||
const useSampledValueType = normalizeDataType(options.columnInfo?.data_type) === "";
|
||||
const numericInput = isNumericColumnType(options.columnInfo?.data_type) || (useSampledValueType && typeof oldValue === "number");
|
||||
const numericText = normalizeGroupedNumberText(value, options.columnInfo, oldValue, options.numberFormat ?? runtimeNumberFormat());
|
||||
// Neo4j INTEGER is always signed 64-bit. Keep its input as text until the
|
||||
// Cypher builder validates it, including values outside JavaScript's range.
|
||||
if (options.databaseType === "neo4j" && ["integer", "long", "int"].includes(normalizeDataType(options.columnInfo?.data_type))) return numericText.trim();
|
||||
if (isBooleanInputColumn(options) || (useSampledValueType && typeof oldValue === "boolean")) {
|
||||
// MySQL exposes TINYINT(1) as an integer in the grid. Keep its numeric
|
||||
// 0/1 edits numeric while still accepting explicit TRUE/FALSE aliases.
|
||||
|
||||
@@ -268,6 +268,7 @@ export function supportsTableTruncate(dbType?: DatabaseType): boolean {
|
||||
dbType !== "victoriametrics" &&
|
||||
dbType !== "manticoresearch" &&
|
||||
dbType !== "salesforce" &&
|
||||
dbType !== "neo4j" &&
|
||||
dbType !== "nebula"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -447,11 +447,11 @@ export function normalizeWhereInput(whereInput?: string): string {
|
||||
* * Salesforce: SOQL has no `SELECT *`. With no known fields the backend builder
|
||||
* falls back to the `FIELDS(ALL)` selector, which the org only accepts with
|
||||
* `LIMIT 200` or less — awaiting the describe keeps every page size working.
|
||||
* * NebulaGraph: without tag/edge properties, the grid can only show a single
|
||||
* * Neo4j/NebulaGraph: without node/tag/edge properties, the grid can only show a single
|
||||
* vertex/edge value instead of separate property columns.
|
||||
*/
|
||||
export function requiresEagerTableMetadataForDataOpen(databaseType: DatabaseType | undefined): boolean {
|
||||
return databaseType === "mysql" || databaseType === "postgres" || databaseType === "salesforce" || databaseType === "nebula";
|
||||
return databaseType === "mysql" || databaseType === "postgres" || databaseType === "salesforce" || databaseType === "neo4j" || databaseType === "nebula";
|
||||
}
|
||||
|
||||
export async function buildTableSelectSql(options: BuildTableSelectSqlOptions): Promise<string> {
|
||||
|
||||
Reference in new issue
Block a user