feat(editor): auto-transpose single-row query results

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-07-24 10:02:45 +08:00
1 parent b121240b2f
commit 0ad8e4a326
14 files changed
+73 -1

No files matched your search

@@ -1,5 +1,16 @@
import { describe, expect, it } from "vitest";
import { averageTransposeRecordWidth, calculateTransposeRecordWidth, defaultTransposeRecordWidth, minTransposeFieldWidth, transposeFieldWidth, transposeRecordWidthsForDensity, visibleTransposeRecordWindow } from "@/lib/dataGrid/dataGridTranspose";
import { averageTransposeRecordWidth, calculateTransposeRecordWidth, defaultTransposeRecordWidth, minTransposeFieldWidth, shouldAutoTransposeSingleRow, transposeFieldWidth, transposeRecordWidthsForDensity, visibleTransposeRecordWindow } from "@/lib/dataGrid/dataGridTranspose";
describe("single-row automatic transpose", () => {
it("only opens for enabled multi-column results that are not preserving a manual transpose", () => {
expect(shouldAutoTransposeSingleRow({ enabled: true, preserveTranspose: false, rowCount: 1, columnCount: 2 })).toBe(true);
expect(shouldAutoTransposeSingleRow({ enabled: false, preserveTranspose: false, rowCount: 1, columnCount: 2 })).toBe(false);
expect(shouldAutoTransposeSingleRow({ enabled: true, preserveTranspose: true, rowCount: 1, columnCount: 2 })).toBe(false);
expect(shouldAutoTransposeSingleRow({ enabled: true, preserveTranspose: false, rowCount: 0, columnCount: 2 })).toBe(false);
expect(shouldAutoTransposeSingleRow({ enabled: true, preserveTranspose: false, rowCount: 2, columnCount: 2 })).toBe(false);
expect(shouldAutoTransposeSingleRow({ enabled: true, preserveTranspose: false, rowCount: 1, columnCount: 1 })).toBe(false);
});
});
describe("dataGridTranspose density widths", () => {
it("uses the shared density preset for record and field widths", () => {
@@ -168,6 +168,13 @@ export interface TransposeRecordIndexesForModeOptions {
visibleRecordIndexes: number[];
}
export interface AutoTransposeSingleRowOptions {
enabled: boolean;
preserveTranspose: boolean;
rowCount: number;
columnCount: number;
}
export function nextTransposeState(showTranspose: boolean, transposeRowIndex: number | null, requestedRowIndex: number): DataGridTransposeState {
if (showTranspose && transposeRowIndex === requestedRowIndex) {
return { showTranspose: false, transposeRowIndex: null };
@@ -209,6 +216,10 @@ export function nextTransposeStateForRecordCount(showTranspose: boolean, transpo
};
}
export function shouldAutoTransposeSingleRow(options: AutoTransposeSingleRowOptions): boolean {
return options.enabled && !options.preserveTranspose && options.rowCount === 1 && options.columnCount > 1;
}
export function buildTransposeRows<T>(options: BuildTransposeRowsOptions<T>): Array<DataGridTransposeRow<T>> {
return options.columns.map((column, columnIndex) => {
return {
@@ -28,6 +28,7 @@ export const EDITOR_SETTINGS_DRAFT_KEYS = [
"showColumnTypesInHeader",
"compactColumnHeaderActions",
"dataGridQuickEntry",
"dataGridAutoTransposeSingleRow",
"tableOpenPageSize",
"infiniteScroll",
"infiniteScrollMaxRows",