fix(grid): toggle context transpose view

This commit is contained in:
t8y2 committed 2026-05-18 11:09:00 +08:00
1 parent 1d57bc575f
commit efdf843d2f
3 files changed
+44 -9

No files matched your search

+16 -9
View File
@@ -83,8 +83,8 @@ import {
import { formatGridSqlLiteral } from "@/lib/dataGridSql"; import { formatGridSqlLiteral } from "@/lib/dataGridSql";
import { import {
buildTransposeRows, buildTransposeRows,
nextContextTransposeState,
nextTransposeState, nextTransposeState,
transposeAnchorRowIndex,
transposeFieldWidth, transposeFieldWidth,
transposeScrollLeftForRecord, transposeScrollLeftForRecord,
visibleTransposeRecordWindow, visibleTransposeRecordWindow,
@@ -2029,14 +2029,21 @@ function openTranspose(rowIndex: number) {
function openContextTranspose() { function openContextTranspose() {
if (!contextCell.value) return; if (!contextCell.value) return;
openTranspose( const next = nextContextTransposeState({
transposeAnchorRowIndex({ showTranspose: showTranspose.value,
requestedRowIndex: contextCell.value.rowIndex, transposeRowIndex: transposeRowIndex.value,
rowIds: displayItems.value.map((item) => item.id), requestedRowIndex: contextCell.value.rowIndex,
selectedRowIds: selectedRowIds.value, rowIds: displayItems.value.map((item) => item.id),
selectedRange: selectedRange.value, selectedRowIds: selectedRowIds.value,
}), selectedRange: selectedRange.value,
); });
transposeRowIndex.value = next.transposeRowIndex;
showTranspose.value = next.showTranspose;
if (next.showTranspose) {
showCellDetail.value = false;
nextTick(updateTransposeViewport);
if (next.transposeRowIndex !== null) scrollTransposeRecordIntoView(next.transposeRowIndex);
}
} }
function toggleTranspose(rowIndex: number) { function toggleTranspose(rowIndex: number) {
+10
View File
@@ -53,6 +53,11 @@ export interface TransposeAnchorOptions {
selectedRange: TransposeSelectionRange | null; selectedRange: TransposeSelectionRange | null;
} }
export interface ContextTransposeStateOptions extends TransposeAnchorOptions {
showTranspose: boolean;
transposeRowIndex: number | null;
}
export interface TransposeFieldWidthOptions { export interface TransposeFieldWidthOptions {
minWidth?: number; minWidth?: number;
maxWidth?: number; maxWidth?: number;
@@ -79,6 +84,11 @@ export function nextTransposeState(
return { showTranspose: true, transposeRowIndex: requestedRowIndex }; return { showTranspose: true, transposeRowIndex: requestedRowIndex };
} }
export function nextContextTransposeState(options: ContextTransposeStateOptions): DataGridTransposeState {
const anchorRowIndex = transposeAnchorRowIndex(options);
return nextTransposeState(options.showTranspose, options.transposeRowIndex, anchorRowIndex);
}
export function buildTransposeRows<T>(options: BuildTransposeRowsOptions<T>): Array<DataGridTransposeRow<T>> { export function buildTransposeRows<T>(options: BuildTransposeRowsOptions<T>): Array<DataGridTransposeRow<T>> {
return options.columns.map((column, columnIndex) => { return options.columns.map((column, columnIndex) => {
return { return {
@@ -2,6 +2,7 @@ import { strict as assert } from "node:assert";
import test from "node:test"; import test from "node:test";
import { import {
buildTransposeRows, buildTransposeRows,
nextContextTransposeState,
nextTransposeState, nextTransposeState,
transposeAnchorRowIndex, transposeAnchorRowIndex,
transposeFieldWidth, transposeFieldWidth,
@@ -30,6 +31,23 @@ test("row number double click closes transpose for the same row", () => {
}); });
}); });
test("context menu transpose closes when invoked for the current anchor row", () => {
assert.deepEqual(
nextContextTransposeState({
showTranspose: true,
transposeRowIndex: 2,
requestedRowIndex: 3,
rowIds: [10, 11, 12, 13, 14],
selectedRowIds: new Set([12, 13]),
selectedRange: null,
}),
{
showTranspose: false,
transposeRowIndex: null,
},
);
});
test("builds one virtualizable transpose row per field with all record values", () => { test("builds one virtualizable transpose row per field with all record values", () => {
const rows = buildTransposeRows({ const rows = buildTransposeRows({
columns: ["id", "name", "notes"], columns: ["id", "name", "notes"],