feat(neo4j): expand node query properties into result columns
This commit is contained in:
1 parent
38a00c7cb7
commit
660071870b
12 files changed
+433
-29
No files matched your search
@@ -500,6 +500,7 @@ interface DataGridProps {
|
||||
sortColumnIndex?: number;
|
||||
sortDirection?: DataGridSortDirection;
|
||||
sortMode?: DataGridSortMode;
|
||||
databaseSortEnabled?: boolean;
|
||||
tableMeta?: {
|
||||
catalog?: string;
|
||||
database?: string;
|
||||
@@ -599,6 +600,7 @@ const props = withDefaults(defineProps<DataGridProps>(), {
|
||||
totalRowCountIsExact: true,
|
||||
inexactTotalRowCountMode: "at-least",
|
||||
paginationEnabled: true,
|
||||
databaseSortEnabled: true,
|
||||
loadAllRowsEnabled: true,
|
||||
// Omitted row-action limits must keep normal table-data editing.
|
||||
allowInsertRows: undefined,
|
||||
@@ -922,7 +924,7 @@ function sortMenuItems(column: string, columnIndex: number) {
|
||||
column,
|
||||
columnIndex,
|
||||
state: currentColumnSortState(),
|
||||
databaseSortEnabled: databaseSortSupportedForDatabase(resolvedDatabaseType.value),
|
||||
databaseSortEnabled: props.databaseSortEnabled !== false && databaseSortSupportedForDatabase(resolvedDatabaseType.value),
|
||||
labels: {
|
||||
databaseAscending: t("grid.sortDatabaseAscending"),
|
||||
databaseDescending: t("grid.sortDatabaseDescending"),
|
||||
@@ -12358,7 +12360,7 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
|
||||
canFilter: canUseWhereSearch.value,
|
||||
hasSort: !!sortCol.value,
|
||||
sortMode: sortMode.value,
|
||||
databaseSortEnabled: databaseSortSupportedForDatabase(resolvedDatabaseType.value),
|
||||
databaseSortEnabled: props.databaseSortEnabled !== false && databaseSortSupportedForDatabase(resolvedDatabaseType.value),
|
||||
frozenColumnCount: frozenColumnCount.value,
|
||||
contextVisibleColIdx: contextHeaderVisibleColIdx.value ?? undefined,
|
||||
hasColumnSelection: hasColumnSelection.value,
|
||||
|
||||
@@ -75,7 +75,7 @@ function transposeRecordHeader(host: HTMLElement, recordIndex: number): HTMLElem
|
||||
return header;
|
||||
}
|
||||
|
||||
function mountGrid() {
|
||||
function mountGrid(databaseSortEnabled?: boolean) {
|
||||
const pinia = createPinia();
|
||||
setActivePinia(pinia);
|
||||
const settingsStore = useSettingsStore();
|
||||
@@ -121,6 +121,7 @@ function mountGrid() {
|
||||
h(DataGrid, {
|
||||
result: result.value,
|
||||
databaseType: "mysql",
|
||||
databaseSortEnabled,
|
||||
context: "table-data",
|
||||
sortColumn: sortColumn.value,
|
||||
sortColumnIndex: sortColumnIndex.value,
|
||||
@@ -174,6 +175,21 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
describe("DataGrid transpose sorting", () => {
|
||||
it("retains local sorting when database sorting is explicitly disabled", async () => {
|
||||
const { host, onSort } = mountGrid(false);
|
||||
await settle();
|
||||
await openTranspose(host);
|
||||
transposeField(host, 1).querySelector<HTMLButtonElement>("[data-grid-transpose-sort]")!.click();
|
||||
await settle();
|
||||
const labels = [...document.querySelectorAll('[role="menuitem"]')].map((item) => item.textContent?.trim());
|
||||
expect(labels).toContain(i18n.global.t("grid.sortCurrentPageAscending"));
|
||||
expect(labels).not.toContain(i18n.global.t("grid.sortDatabaseDescending"));
|
||||
menuAction(i18n.global.t("grid.sortCurrentPageAscending")).click();
|
||||
await settle();
|
||||
expect(onSort).toHaveBeenLastCalledWith("score", 1, "asc", undefined, "local");
|
||||
expect(transposeValues(host, 1)).toEqual(["2", "10", "NULL"]);
|
||||
});
|
||||
|
||||
it("uses the shared local/database sort actions and keeps the active record and row selection", async () => {
|
||||
const { host, onSort } = mountGrid();
|
||||
await settle();
|
||||
|
||||
@@ -4,6 +4,8 @@ import { safeLocalStorageGet, safeLocalStorageSet } from "@/lib/backend/safeStor
|
||||
import { appendDebugLog, isDebugLoggingEnabled } from "@/lib/backend/debugLog";
|
||||
import { canReloadUnavailableDataTab, restoredDataTabReloadFilters } from "@/lib/table/tableDataRefresh";
|
||||
import { defaultViewForResult } from "@/lib/query/queryResultDefaultView";
|
||||
import { extractNeo4jNodeCells, projectNeo4jNodeResult } from "@/lib/neo4j/neo4jNodeResult";
|
||||
import { useNeo4jNodeTableResult } from "@/composables/useNeo4jNodeTableResult";
|
||||
import { queryResultMessages } from "@/lib/query/queryResultMessages";
|
||||
import { isQueryExecutionErrorResult } from "@/lib/query/queryResultError";
|
||||
import { hasQueryOutput as tabHasQueryOutput } from "@/lib/query/queryOutput";
|
||||
@@ -513,7 +515,7 @@ const tabularResults = computed(() => tabularResultItems(props.activeTab.results
|
||||
const allResultExportSheets = computed(() =>
|
||||
tabularResults.value.map((item) => ({
|
||||
sheetName: item.label || t("tabs.resultN", { n: item.n }),
|
||||
result: item.result,
|
||||
result: activeEffectiveDatabaseType.value === "neo4j" ? projectNeo4jNodeResult(item.result) : item.result,
|
||||
sql: item.index === props.activeTab.activeResultIndex ? queryResultExecutionSql(props.activeTab) : item.result.sourceStatement,
|
||||
})),
|
||||
);
|
||||
@@ -607,6 +609,26 @@ const resultRunFallbackLabel = (sequence: number) => t(resultTabNamingMode.value
|
||||
const activeResultGridCacheKey = computed(() => resultGridCacheKey(props.activeTab));
|
||||
const activeResultGridColumnWidthCacheKey = computed(() => resultGridColumnWidthCacheKey(props.activeTab));
|
||||
const activeResultGridInstanceKey = computed(() => resultGridInstanceKey(props.activeTab));
|
||||
const hasNeo4jNodes = computed(() => activeEffectiveDatabaseType.value === "neo4j" && !!props.activeTab.result?.neo4j_node_cells?.length);
|
||||
const neo4jNodeTable = useNeo4jNodeTableResult(
|
||||
computed(() => props.activeTab.result),
|
||||
activeResultGridInstanceKey,
|
||||
);
|
||||
const activeGridResult = computed(() => (hasNeo4jNodes.value ? neo4jNodeTable.result.value : props.activeTab.result));
|
||||
const activeGridSort = computed(() => (hasNeo4jNodes.value ? neo4jNodeTable.sort.value : undefined));
|
||||
|
||||
function sortQueryGrid(column: string, columnIndex: number, direction: "asc" | "desc" | null, whereInput?: string, mode?: DataGridSortMode, effectiveOrderBy?: string) {
|
||||
if (hasNeo4jNodes.value) neo4jNodeTable.setSort(column, columnIndex, direction);
|
||||
else emit("sort", props.activeTab.id, column, columnIndex, direction, whereInput, mode, effectiveOrderBy);
|
||||
}
|
||||
|
||||
async function fetchGridResultForExport(onProgress?: (info: { rowsExported: number; totalRows: number | null }) => void) {
|
||||
const isNeo4j = activeEffectiveDatabaseType.value === "neo4j";
|
||||
const result = await queryStore.fetchTabResultForExport(props.activeTab.id, onProgress);
|
||||
if (!result || !isNeo4j) return result;
|
||||
extractNeo4jNodeCells(result);
|
||||
return projectNeo4jNodeResult(result);
|
||||
}
|
||||
const activeResultSql = computed(() => resultSqlForGrid(props.activeTab));
|
||||
const activeResultExportSql = computed(() => queryResultExecutionSql(props.activeTab));
|
||||
const activeStatementExecutionMarkers = computed(() =>
|
||||
@@ -2422,21 +2444,22 @@ defineExpose({
|
||||
:pending-state-key="activeResultGridInstanceKey"
|
||||
:view-generation="activeTab.resultViewGeneration"
|
||||
class="flex-1 min-h-0"
|
||||
:result="activeTab.result"
|
||||
:sort-column="activeTab.resultSortColumn"
|
||||
:sort-column-index="activeTab.resultSortColumnIndex"
|
||||
:sort-direction="activeTab.resultSortDirection"
|
||||
:sort-mode="activeTab.resultSortMode"
|
||||
:result="activeGridResult!"
|
||||
:sort-column="hasNeo4jNodes ? activeGridSort?.column : activeTab.resultSortColumn"
|
||||
:sort-column-index="hasNeo4jNodes ? activeGridSort?.columnIndex : activeTab.resultSortColumnIndex"
|
||||
:sort-direction="hasNeo4jNodes ? activeGridSort?.direction : activeTab.resultSortDirection"
|
||||
:sort-mode="hasNeo4jNodes ? 'local' : activeTab.resultSortMode"
|
||||
:database-sort-enabled="!hasNeo4jNodes"
|
||||
:initial-order-by-input="activeTab.orderByInput"
|
||||
:sql="activeResultSql"
|
||||
:export-sql="activeResultExportSql"
|
||||
:loading="activeResultIsLoading"
|
||||
:editable="!!activeTab.queryAnalysis || !!mongoQueryResultSaveHandler"
|
||||
:source-columns="activeTab.querySourceColumns"
|
||||
:joined-write-targets="activeTab.queryWriteTargets"
|
||||
:readonly-column-indexes="groupedQueryReadonlyColumnIndexes(activeTab)"
|
||||
:result-column-comments="activeTab.resultColumnComments"
|
||||
:query-display-source-columns="activeTab.queryDisplaySourceColumns"
|
||||
:editable="!hasNeo4jNodes && (!!activeTab.queryAnalysis || !!mongoQueryResultSaveHandler)"
|
||||
:source-columns="hasNeo4jNodes ? undefined : activeTab.querySourceColumns"
|
||||
:joined-write-targets="hasNeo4jNodes ? undefined : activeTab.queryWriteTargets"
|
||||
:readonly-column-indexes="hasNeo4jNodes ? undefined : groupedQueryReadonlyColumnIndexes(activeTab)"
|
||||
:result-column-comments="hasNeo4jNodes ? undefined : activeTab.resultColumnComments"
|
||||
:query-display-source-columns="hasNeo4jNodes ? undefined : activeTab.queryDisplaySourceColumns"
|
||||
:custom-save-handler="mongoQueryResultSaveHandler"
|
||||
:mongo-update-target="mongoQueryResultSaveHandler && activeTab.result.mongo_copy_documents?.length === activeTab.result.rows.length ? activeTab.mongoEditTarget : undefined"
|
||||
:query-editability-reason="activeTab.queryEditabilityReason"
|
||||
@@ -2451,7 +2474,7 @@ defineExpose({
|
||||
:connection-id="activeResultConnectionId"
|
||||
:database="activeResultDatabase"
|
||||
:schema="activeResultSchema"
|
||||
:table-meta="activeTab.tableMeta"
|
||||
:table-meta="hasNeo4jNodes ? undefined : activeTab.tableMeta"
|
||||
:table-info-tab="activeTab.tableInfoTab"
|
||||
:page-offset="activeTab.resultPageOffset"
|
||||
:page-limit="activeTab.resultPageLimit"
|
||||
@@ -2464,18 +2487,20 @@ defineExpose({
|
||||
:total-row-count-loading="activeTab.resultTotalRowCountLoading"
|
||||
:page-jump-progress="activeTab.resultPageJumpProgress"
|
||||
:on-execute-sql="async (sql: string) => emit('executeSql', activeTab.id, sql)"
|
||||
:full-export-result="(onProgress?: (info: { rowsExported: number; totalRows: number | null }) => void) => queryStore.fetchTabResultForExport(activeTab.id, onProgress)"
|
||||
:full-export-result="fetchGridResultForExport"
|
||||
:query-result-export-request="
|
||||
(options: {
|
||||
exportId: string;
|
||||
filePath: string;
|
||||
format: 'csv' | 'xlsx' | 'json' | 'txt' | 'sql';
|
||||
includeSqlSheet?: boolean;
|
||||
exportTableName?: string;
|
||||
exportColumnTypes?: Array<string | null | undefined>;
|
||||
exportColumnExtras?: Array<string | null | undefined>;
|
||||
insertMode?: SqlInsertMode;
|
||||
}) => queryStore.buildQueryResultExportRequest(activeTab.id, options)
|
||||
hasNeo4jNodes
|
||||
? undefined
|
||||
: (options: {
|
||||
exportId: string;
|
||||
filePath: string;
|
||||
format: 'csv' | 'xlsx' | 'json' | 'txt' | 'sql';
|
||||
includeSqlSheet?: boolean;
|
||||
exportTableName?: string;
|
||||
exportColumnTypes?: Array<string | null | undefined>;
|
||||
exportColumnExtras?: Array<string | null | undefined>;
|
||||
insertMode?: SqlInsertMode;
|
||||
}) => queryStore.buildQueryResultExportRequest(activeTab.id, options)
|
||||
"
|
||||
:all-export-results="allResultExportSheets"
|
||||
:export-file-base-name="activeQueryResultExportBaseName"
|
||||
@@ -2487,7 +2512,7 @@ defineExpose({
|
||||
@local-column-filters-change="(filters: Record<string, string[]>) => queryStore.updateDataGridLocalColumnFilters(activeTab.id, filters)"
|
||||
@reload="(sql?: string, searchText?: string, whereInput?: string, orderBy?: string, limit?: number, offset?: number, intent?: DataGridReloadIntent) => emit('reload', activeTab.id, sql, searchText, whereInput, orderBy, limit, offset, intent)"
|
||||
@paginate="(offset: number, limit: number, whereInput?: string, orderBy?: string, appendResult?: boolean) => emit('paginate', activeTab.id, offset, limit, whereInput, orderBy, appendResult)"
|
||||
@sort="(column: string, columnIndex: number, direction: 'asc' | 'desc' | null, whereInput?: string, mode?: DataGridSortMode, effectiveOrderBy?: string) => emit('sort', activeTab.id, column, columnIndex, direction, whereInput, mode, effectiveOrderBy)"
|
||||
@sort="sortQueryGrid"
|
||||
@change-query-timeout="(connectionId: string) => emit('openConnectionSettings', connectionId, 'advanced')"
|
||||
>
|
||||
<template #result-toolbar-leading="{ compact }">
|
||||
|
||||
Reference in new issue
Block a user