feat(grid): support hiding identical value columns
This commit is contained in:
1 parent
7e324bdd01
commit
09c47b1851
18 files changed
+224
-7
No files matched your search
@@ -288,7 +288,7 @@ import {
|
|||||||
import { normalizeResultPageSize, resultPageSizeMenuOptions } from "@/lib/dataGrid/paginationPageSize";
|
import { normalizeResultPageSize, resultPageSizeMenuOptions } from "@/lib/dataGrid/paginationPageSize";
|
||||||
import { dataGridPageSizeSettingsPatch, preferredDataGridPageSize, resolveDataGridPageSizePreference, type DataGridPageSizePreference } from "@/lib/dataGrid/dataGridPageSizePreference";
|
import { dataGridPageSizeSettingsPatch, preferredDataGridPageSize, resolveDataGridPageSizePreference, type DataGridPageSizePreference } from "@/lib/dataGrid/dataGridPageSizePreference";
|
||||||
import { continuousQueryResultMaxRows, effectiveQueryResultMaxRows } from "@/lib/dataGrid/queryResultRowLimit";
|
import { continuousQueryResultMaxRows, effectiveQueryResultMaxRows } from "@/lib/dataGrid/queryResultRowLimit";
|
||||||
import { allNullColumnIndexes } from "@/lib/dataGrid/dataGridColumnVisibility";
|
import { allNullColumnIndexes, identicalValueColumnIndexes } from "@/lib/dataGrid/dataGridColumnVisibility";
|
||||||
import { buildDataGridColumnLookupItems, dataGridColumnCommentFor, filterDataGridColumnLookupItems } from "@/lib/dataGrid/dataGridColumnLookup";
|
import { buildDataGridColumnLookupItems, dataGridColumnCommentFor, filterDataGridColumnLookupItems } from "@/lib/dataGrid/dataGridColumnLookup";
|
||||||
import { uniqueDataGridColumnOrderKeys } from "@/lib/dataGrid/dataGridColumnOrder";
|
import { uniqueDataGridColumnOrderKeys } from "@/lib/dataGrid/dataGridColumnOrder";
|
||||||
import { dataGridColumnLayoutScopeKey, TABLE_DATA_GRID_COLUMN_ORDER_CHANGED_EVENT, tableDataGridColumnOrderScopeKey } from "@/lib/dataGrid/dataGridColumnLayoutStorage";
|
import { dataGridColumnLayoutScopeKey, TABLE_DATA_GRID_COLUMN_ORDER_CHANGED_EVENT, tableDataGridColumnOrderScopeKey } from "@/lib/dataGrid/dataGridColumnLayoutStorage";
|
||||||
@@ -2745,6 +2745,24 @@ function showAllColumns() {
|
|||||||
void nextTick(scheduleColumnLayoutRefresh);
|
void nextTick(scheduleColumnLayoutRefresh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getComparisonRows(): ReadonlyArray<ReadonlyArray<unknown>> {
|
||||||
|
// 比较行必须取全宽 data:identicalValueColumnIndexes 的候选索引是原始列索引,
|
||||||
|
// 不能用经过可见列投影(visibleRowData 重排)后的行。
|
||||||
|
const affected = affectedRowIds();
|
||||||
|
if (affected.length > 1) {
|
||||||
|
const affectedSet = new Set(affected);
|
||||||
|
return displayItems.value.filter((item) => affectedSet.has(item.id) && !item.isDraft).map((item) => item.data);
|
||||||
|
}
|
||||||
|
const displayRows = displayItems.value.filter((item) => !item.isDraft).map((item) => item.data);
|
||||||
|
return displayRows.length > 0 ? displayRows : props.result.rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideIdenticalColumns() {
|
||||||
|
const identical = identicalValueColumnIndexes(getComparisonRows(), visibleColumnIndexes.value);
|
||||||
|
if (identical.length === 0) return;
|
||||||
|
hideColumns(identical);
|
||||||
|
}
|
||||||
|
|
||||||
// --- 表头拖拽进 SQL 编辑器:目标导向模式切换的控制器 ---
|
// --- 表头拖拽进 SQL 编辑器:目标导向模式切换的控制器 ---
|
||||||
// 按选择顺序(Set 插入序)取列名;被拖列未选中时仅拖该列。
|
// 按选择顺序(Set 插入序)取列名;被拖列未选中时仅拖该列。
|
||||||
function columnReferenceDragNames(draggedVisibleColIdx: number): string[] | null {
|
function columnReferenceDragNames(draggedVisibleColIdx: number): string[] | null {
|
||||||
@@ -12638,6 +12656,11 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const comparisonRows = getComparisonRows();
|
||||||
|
const identicalColumnIndexes = identicalValueColumnIndexes(comparisonRows, visibleColumnIndexes.value);
|
||||||
|
const canHideIdenticalColumns = identicalColumnIndexes.length > 0;
|
||||||
|
const identicalColumnCount = identicalColumnIndexes.length;
|
||||||
|
|
||||||
return createDataGridContextMenuItems(
|
return createDataGridContextMenuItems(
|
||||||
createDataGridColumnContextMenuItems({
|
createDataGridColumnContextMenuItems({
|
||||||
headerColumn: !!contextHeaderColumn.value,
|
headerColumn: !!contextHeaderColumn.value,
|
||||||
@@ -12653,6 +12676,7 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
|
|||||||
selectedColumnCount,
|
selectedColumnCount,
|
||||||
visibleColumnCount: visibleColumnCount.value,
|
visibleColumnCount: visibleColumnCount.value,
|
||||||
hiddenColumnCount: hiddenColumnCount.value,
|
hiddenColumnCount: hiddenColumnCount.value,
|
||||||
|
canHideIdenticalColumns,
|
||||||
labels: {
|
labels: {
|
||||||
copyName:
|
copyName:
|
||||||
selectedColumnNamesForCopy.value.length > 1
|
selectedColumnNamesForCopy.value.length > 1
|
||||||
@@ -12675,6 +12699,7 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
|
|||||||
unfreezeColumns: t("grid.unfreezeColumns", { count: frozenColumnCount.value }),
|
unfreezeColumns: t("grid.unfreezeColumns", { count: frozenColumnCount.value }),
|
||||||
hideColumn: t("grid.hideColumn"),
|
hideColumn: t("grid.hideColumn"),
|
||||||
hideSelectedColumns: t("grid.hideSelectedColumns", { count: selectedColumnCount }),
|
hideSelectedColumns: t("grid.hideSelectedColumns", { count: selectedColumnCount }),
|
||||||
|
hideIdenticalColumns: identicalColumnCount > 0 ? t("grid.hideIdenticalColumnsCount", { count: identicalColumnCount }) : t("grid.hideIdenticalColumns"),
|
||||||
showAllColumnsMenu: t("grid.showAllColumnsMenu"),
|
showAllColumnsMenu: t("grid.showAllColumnsMenu"),
|
||||||
},
|
},
|
||||||
icons: {
|
icons: {
|
||||||
@@ -12720,6 +12745,7 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
|
|||||||
},
|
},
|
||||||
hideColumn: hideContextColumn,
|
hideColumn: hideContextColumn,
|
||||||
hideSelectedColumns,
|
hideSelectedColumns,
|
||||||
|
hideIdenticalColumns,
|
||||||
showAllColumnsMenu: showAllColumns,
|
showAllColumnsMenu: showAllColumns,
|
||||||
},
|
},
|
||||||
filterSubmenu: filterSubmenu(),
|
filterSubmenu: filterSubmenu(),
|
||||||
|
|||||||
@@ -2135,6 +2135,8 @@ export default withEnglishFallback({
|
|||||||
unfreezeColumns: "Sütunların sabitlənməsini ləğv et ({count})",
|
unfreezeColumns: "Sütunların sabitlənməsini ləğv et ({count})",
|
||||||
hideColumn: "Bu sütunu gizlət",
|
hideColumn: "Bu sütunu gizlət",
|
||||||
hideSelectedColumns: "Seçilmiş sütunları gizlət ({count})",
|
hideSelectedColumns: "Seçilmiş sütunları gizlət ({count})",
|
||||||
|
hideIdenticalColumns: "Eyni dəyərlərə malik sütunları gizlət",
|
||||||
|
hideIdenticalColumnsCount: "Eyni dəyərlərə malik sütunları gizlət ({count})",
|
||||||
showAllColumnsMenu: "Bütün sütunları göstər",
|
showAllColumnsMenu: "Bütün sütunları göstər",
|
||||||
pasted: "Yerləşdirildi!",
|
pasted: "Yerləşdirildi!",
|
||||||
batchAppendPasteNotEditable: "Bu nəticəni redaktə etmək mümkün deyil.",
|
batchAppendPasteNotEditable: "Bu nəticəni redaktə etmək mümkün deyil.",
|
||||||
|
|||||||
@@ -2548,6 +2548,8 @@ export default {
|
|||||||
unfreezeColumns: "Unfreeze Columns ({count})",
|
unfreezeColumns: "Unfreeze Columns ({count})",
|
||||||
hideColumn: "Hide This Column",
|
hideColumn: "Hide This Column",
|
||||||
hideSelectedColumns: "Hide Selected Columns ({count})",
|
hideSelectedColumns: "Hide Selected Columns ({count})",
|
||||||
|
hideIdenticalColumns: "Hide Columns with Identical Values",
|
||||||
|
hideIdenticalColumnsCount: "Hide Columns with Identical Values ({count})",
|
||||||
showAllColumnsMenu: "Show All Columns",
|
showAllColumnsMenu: "Show All Columns",
|
||||||
pasted: "Pasted!",
|
pasted: "Pasted!",
|
||||||
batchAppendPasteNotEditable: "This result cannot be edited.",
|
batchAppendPasteNotEditable: "This result cannot be edited.",
|
||||||
|
|||||||
@@ -2388,6 +2388,8 @@ export default withEnglishFallback({
|
|||||||
unfreezeColumns: "Desinmovilizar columnas ({count})",
|
unfreezeColumns: "Desinmovilizar columnas ({count})",
|
||||||
hideColumn: "Ocultar esta columna",
|
hideColumn: "Ocultar esta columna",
|
||||||
hideSelectedColumns: "Ocultar columnas seleccionadas ({count})",
|
hideSelectedColumns: "Ocultar columnas seleccionadas ({count})",
|
||||||
|
hideIdenticalColumns: "Ocultar columnas con valores idénticos",
|
||||||
|
hideIdenticalColumnsCount: "Ocultar columnas con valores idénticos ({count})",
|
||||||
showAllColumnsMenu: "Mostrar todas las columnas",
|
showAllColumnsMenu: "Mostrar todas las columnas",
|
||||||
pasted: "¡Pegado!",
|
pasted: "¡Pegado!",
|
||||||
search: "Buscar...",
|
search: "Buscar...",
|
||||||
|
|||||||
@@ -2407,6 +2407,8 @@ export default withEnglishFallback({
|
|||||||
unfreezeColumns: "Batalkan Pembekuan Kolom ({count})",
|
unfreezeColumns: "Batalkan Pembekuan Kolom ({count})",
|
||||||
hideColumn: "Sembunyikan Kolom Ini",
|
hideColumn: "Sembunyikan Kolom Ini",
|
||||||
hideSelectedColumns: "Sembunyikan Kolom Terpilih ({count})",
|
hideSelectedColumns: "Sembunyikan Kolom Terpilih ({count})",
|
||||||
|
hideIdenticalColumns: "Sembunyikan Kolom dengan Nilai yang Sama",
|
||||||
|
hideIdenticalColumnsCount: "Sembunyikan Kolom dengan Nilai yang Sama ({count})",
|
||||||
showAllColumnsMenu: "Tampilkan Semua Kolom",
|
showAllColumnsMenu: "Tampilkan Semua Kolom",
|
||||||
pasted: "Ditempel!",
|
pasted: "Ditempel!",
|
||||||
batchAppendPasteNotEditable: "Hasil ini tidak dapat diedit.",
|
batchAppendPasteNotEditable: "Hasil ini tidak dapat diedit.",
|
||||||
|
|||||||
@@ -2282,6 +2282,8 @@ export default withEnglishFallback({
|
|||||||
unfreezeColumns: "Sblocca colonne ({count})",
|
unfreezeColumns: "Sblocca colonne ({count})",
|
||||||
hideColumn: "Nascondi questa colonna",
|
hideColumn: "Nascondi questa colonna",
|
||||||
hideSelectedColumns: "Nascondi colonne selezionate ({count})",
|
hideSelectedColumns: "Nascondi colonne selezionate ({count})",
|
||||||
|
hideIdenticalColumns: "Nascondi colonne con valori identici",
|
||||||
|
hideIdenticalColumnsCount: "Nascondi colonne con valori identici ({count})",
|
||||||
showAllColumnsMenu: "Mostra tutte le colonne",
|
showAllColumnsMenu: "Mostra tutte le colonne",
|
||||||
pasted: "Incollato!",
|
pasted: "Incollato!",
|
||||||
search: "Cerca...",
|
search: "Cerca...",
|
||||||
|
|||||||
@@ -2289,6 +2289,8 @@ export default withEnglishFallback({
|
|||||||
unfreezeColumns: "列の固定を解除 ({count})",
|
unfreezeColumns: "列の固定を解除 ({count})",
|
||||||
hideColumn: "この列を非表示",
|
hideColumn: "この列を非表示",
|
||||||
hideSelectedColumns: "選択した列を非表示 ({count})",
|
hideSelectedColumns: "選択した列を非表示 ({count})",
|
||||||
|
hideIdenticalColumns: "同一値の列を非表示",
|
||||||
|
hideIdenticalColumnsCount: "同一値の列を非表示({count} 列)",
|
||||||
showAllColumnsMenu: "すべての列を表示",
|
showAllColumnsMenu: "すべての列を表示",
|
||||||
pasted: "貼り付けました!",
|
pasted: "貼り付けました!",
|
||||||
search: "検索...",
|
search: "検索...",
|
||||||
|
|||||||
@@ -2326,6 +2326,8 @@ export default withEnglishFallback({
|
|||||||
unfreezeColumns: "컬럼 고정 해제 ({count})",
|
unfreezeColumns: "컬럼 고정 해제 ({count})",
|
||||||
hideColumn: "이 컬럼 숨기기",
|
hideColumn: "이 컬럼 숨기기",
|
||||||
hideSelectedColumns: "선택한 컬럼 숨기기 ({count})",
|
hideSelectedColumns: "선택한 컬럼 숨기기 ({count})",
|
||||||
|
hideIdenticalColumns: "동일한 값의 컬럼 숨기기",
|
||||||
|
hideIdenticalColumnsCount: "동일한 값의 컬럼 숨기기 ({count}개)",
|
||||||
showAllColumnsMenu: "모든 컬럼 표시",
|
showAllColumnsMenu: "모든 컬럼 표시",
|
||||||
pasted: "붙여넣었습니다!",
|
pasted: "붙여넣었습니다!",
|
||||||
replaceText: "바꿀 내용",
|
replaceText: "바꿀 내용",
|
||||||
|
|||||||
@@ -2284,6 +2284,8 @@ export default withEnglishFallback({
|
|||||||
unfreezeColumns: "Descongelar colunas ({count})",
|
unfreezeColumns: "Descongelar colunas ({count})",
|
||||||
hideColumn: "Ocultar esta coluna",
|
hideColumn: "Ocultar esta coluna",
|
||||||
hideSelectedColumns: "Ocultar colunas selecionadas ({count})",
|
hideSelectedColumns: "Ocultar colunas selecionadas ({count})",
|
||||||
|
hideIdenticalColumns: "Ocultar colunas com valores idênticos",
|
||||||
|
hideIdenticalColumnsCount: "Ocultar colunas com valores idênticos ({count})",
|
||||||
showAllColumnsMenu: "Mostrar todas as colunas",
|
showAllColumnsMenu: "Mostrar todas as colunas",
|
||||||
pasted: "Colado!",
|
pasted: "Colado!",
|
||||||
search: "Pesquisar...",
|
search: "Pesquisar...",
|
||||||
|
|||||||
@@ -2442,6 +2442,8 @@ export default withEnglishFallback({
|
|||||||
unfreezeColumns: "Открепить столбцы ({count})",
|
unfreezeColumns: "Открепить столбцы ({count})",
|
||||||
hideColumn: "Скрыть этот столбец",
|
hideColumn: "Скрыть этот столбец",
|
||||||
hideSelectedColumns: "Скрыть выбранные столбцы ({count})",
|
hideSelectedColumns: "Скрыть выбранные столбцы ({count})",
|
||||||
|
hideIdenticalColumns: "Скрыть столбцы с одинаковыми значениями",
|
||||||
|
hideIdenticalColumnsCount: "Скрыть столбцы с одинаковыми значениями ({count})",
|
||||||
showAllColumnsMenu: "Показать все столбцы",
|
showAllColumnsMenu: "Показать все столбцы",
|
||||||
pasted: "Вставлено!",
|
pasted: "Вставлено!",
|
||||||
batchAppendPasteNotEditable: "Этот результат нельзя редактировать.",
|
batchAppendPasteNotEditable: "Этот результат нельзя редактировать.",
|
||||||
|
|||||||
@@ -2128,6 +2128,8 @@ export default withEnglishFallback({
|
|||||||
unfreezeColumns: "Sütun Dondurmayı Kaldır ({count})",
|
unfreezeColumns: "Sütun Dondurmayı Kaldır ({count})",
|
||||||
hideColumn: "Bu Sütunu Gizle",
|
hideColumn: "Bu Sütunu Gizle",
|
||||||
hideSelectedColumns: "Seçili Sütunları Gizle ({count})",
|
hideSelectedColumns: "Seçili Sütunları Gizle ({count})",
|
||||||
|
hideIdenticalColumns: "Aynı Değerlere Sahip Sütunları Gizle",
|
||||||
|
hideIdenticalColumnsCount: "Aynı Değerlere Sahip Sütunları Gizle ({count})",
|
||||||
showAllColumnsMenu: "Tüm Sütunları Göster",
|
showAllColumnsMenu: "Tüm Sütunları Göster",
|
||||||
pasted: "Yapıştırıldı!",
|
pasted: "Yapıştırıldı!",
|
||||||
batchAppendPasteNotEditable: "Bu sonuç düzenlenemez.",
|
batchAppendPasteNotEditable: "Bu sonuç düzenlenemez.",
|
||||||
|
|||||||
@@ -2483,6 +2483,8 @@ export default withEnglishFallback({
|
|||||||
unfreezeColumns: "取消冻结({count} 列)",
|
unfreezeColumns: "取消冻结({count} 列)",
|
||||||
hideColumn: "隐藏此列",
|
hideColumn: "隐藏此列",
|
||||||
hideSelectedColumns: "隐藏选中列({count} 列)",
|
hideSelectedColumns: "隐藏选中列({count} 列)",
|
||||||
|
hideIdenticalColumns: "隐藏相同数值列",
|
||||||
|
hideIdenticalColumnsCount: "隐藏相同数值列({count} 列)",
|
||||||
showAllColumnsMenu: "显示全部列",
|
showAllColumnsMenu: "显示全部列",
|
||||||
pasted: "已粘贴!",
|
pasted: "已粘贴!",
|
||||||
batchAppendPasteNotEditable: "当前结果不可编辑。",
|
batchAppendPasteNotEditable: "当前结果不可编辑。",
|
||||||
|
|||||||
@@ -2284,6 +2284,8 @@ export default withEnglishFallback({
|
|||||||
unfreezeColumns: "取消凍結({count} 欄)",
|
unfreezeColumns: "取消凍結({count} 欄)",
|
||||||
hideColumn: "隱藏此欄",
|
hideColumn: "隱藏此欄",
|
||||||
hideSelectedColumns: "隱藏選取欄({count} 欄)",
|
hideSelectedColumns: "隱藏選取欄({count} 欄)",
|
||||||
|
hideIdenticalColumns: "隱藏相同數值欄",
|
||||||
|
hideIdenticalColumnsCount: "隱藏相同數值欄({count} 欄)",
|
||||||
showAllColumnsMenu: "顯示全部欄",
|
showAllColumnsMenu: "顯示全部欄",
|
||||||
pasted: "已貼上!",
|
pasted: "已貼上!",
|
||||||
search: "搜尋……",
|
search: "搜尋……",
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ describe("dataGridContextMenu", () => {
|
|||||||
expect(rowItems.find((item) => item.label === "delete")?.variant).toBe("destructive");
|
expect(rowItems.find((item) => item.label === "delete")?.variant).toBe("destructive");
|
||||||
});
|
});
|
||||||
|
|
||||||
function columnMenuItems(overrides: { hasColumnSelection?: boolean; selectedColumnCount?: number; visibleColumnCount?: number; hiddenColumnCount?: number }) {
|
function columnMenuItems(overrides: { headerColumn?: boolean; contextColumn?: boolean; contextVisibleColIdx?: number; hasColumnSelection?: boolean; selectedColumnCount?: number; visibleColumnCount?: number; hiddenColumnCount?: number; canHideIdenticalColumns?: boolean }) {
|
||||||
const action = vi.fn();
|
const action = vi.fn();
|
||||||
const filter = createDataGridFilterSubmenu({
|
const filter = createDataGridFilterSubmenu({
|
||||||
label: "filter",
|
label: "filter",
|
||||||
@@ -149,13 +149,13 @@ describe("dataGridContextMenu", () => {
|
|||||||
clear: action,
|
clear: action,
|
||||||
});
|
});
|
||||||
return createDataGridColumnContextMenuItems({
|
return createDataGridColumnContextMenuItems({
|
||||||
headerColumn: true,
|
headerColumn: overrides.headerColumn ?? true,
|
||||||
contextColumn: false,
|
contextColumn: overrides.contextColumn ?? false,
|
||||||
canCopyAlterSql: false,
|
canCopyAlterSql: false,
|
||||||
canFilter: false,
|
canFilter: false,
|
||||||
hasSort: false,
|
hasSort: false,
|
||||||
sortMode: "database",
|
sortMode: "database",
|
||||||
contextVisibleColIdx: 0,
|
contextVisibleColIdx: overrides.contextVisibleColIdx !== undefined ? overrides.contextVisibleColIdx : 0,
|
||||||
hasColumnSelection: false,
|
hasColumnSelection: false,
|
||||||
selectedColumnCount: 1,
|
selectedColumnCount: 1,
|
||||||
visibleColumnCount: 3,
|
visibleColumnCount: 3,
|
||||||
@@ -175,10 +175,11 @@ describe("dataGridContextMenu", () => {
|
|||||||
unfreezeColumns: "unfreeze",
|
unfreezeColumns: "unfreeze",
|
||||||
hideColumn: "hide column",
|
hideColumn: "hide column",
|
||||||
hideSelectedColumns: "hide selected (3)",
|
hideSelectedColumns: "hide selected (3)",
|
||||||
|
hideIdenticalColumns: "hide identical",
|
||||||
showAllColumnsMenu: "show all columns",
|
showAllColumnsMenu: "show all columns",
|
||||||
},
|
},
|
||||||
icons: { copy: icon, columnDetails: icon, database: icon, ascending: icon, descending: icon, clearSort: icon },
|
icons: { copy: icon, columnDetails: icon, database: icon, ascending: icon, descending: icon, clearSort: icon },
|
||||||
actions: { copyName: action, copyNames: action, details: action, copyAlterSql: action, sort: action, freezeToColumn: action, freezeSelectedColumns: action, unfreezeColumns: action, hideColumn: action, hideSelectedColumns: action, showAllColumnsMenu: action },
|
actions: { copyName: action, copyNames: action, details: action, copyAlterSql: action, sort: action, freezeToColumn: action, freezeSelectedColumns: action, unfreezeColumns: action, hideColumn: action, hideSelectedColumns: action, hideIdenticalColumns: action, showAllColumnsMenu: action },
|
||||||
filterSubmenu: filter,
|
filterSubmenu: filter,
|
||||||
...overrides,
|
...overrides,
|
||||||
});
|
});
|
||||||
@@ -221,4 +222,30 @@ describe("dataGridContextMenu", () => {
|
|||||||
expect(hideColumn).toBeDefined();
|
expect(hideColumn).toBeDefined();
|
||||||
expect(hideColumn?.disabled).toBe(false);
|
expect(hideColumn?.disabled).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("offers hide identical columns on a header and disables it when no identical columns exist", () => {
|
||||||
|
const items = columnMenuItems({ canHideIdenticalColumns: false });
|
||||||
|
const hideIdentical = items.find((item) => item.label === "hide identical");
|
||||||
|
|
||||||
|
expect(hideIdentical).toBeDefined();
|
||||||
|
expect(hideIdentical?.disabled).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("enables hide identical columns when identical columns exist", () => {
|
||||||
|
const items = columnMenuItems({ canHideIdenticalColumns: true });
|
||||||
|
const hideIdentical = items.find((item) => item.label === "hide identical");
|
||||||
|
|
||||||
|
expect(hideIdentical).toBeDefined();
|
||||||
|
expect(hideIdentical?.disabled).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("offers hide identical columns on a cell context menu and shows recovery entry if hidden columns exist", () => {
|
||||||
|
const items = columnMenuItems({ headerColumn: false, contextColumn: true, contextVisibleColIdx: undefined, canHideIdenticalColumns: true, hiddenColumnCount: 2 });
|
||||||
|
const hideIdentical = items.find((item) => item.label === "hide identical");
|
||||||
|
const showAll = items.find((item) => item.label === "show all columns");
|
||||||
|
|
||||||
|
expect(hideIdentical).toBeDefined();
|
||||||
|
expect(hideIdentical?.disabled).toBe(false);
|
||||||
|
expect(showAll).toBeDefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -149,3 +149,49 @@ export function removeAutoHiddenColumnIndexes(hiddenIndexes: ReadonlySet<number>
|
|||||||
}
|
}
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function areCellValuesEqual(a: unknown, b: unknown): boolean {
|
||||||
|
if (a === b) return true;
|
||||||
|
if (typeof a === "number" && typeof b === "number" && Number.isNaN(a) && Number.isNaN(b)) return true;
|
||||||
|
if (a === null || b === null || a === undefined || b === undefined) return false;
|
||||||
|
if (typeof a !== "object" || typeof b !== "object") return false;
|
||||||
|
if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();
|
||||||
|
if (a instanceof Uint8Array && b instanceof Uint8Array) {
|
||||||
|
if (a.length !== b.length) return false;
|
||||||
|
for (let i = 0; i < a.length; i++) {
|
||||||
|
if (a[i] !== b[i]) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return JSON.stringify(a) === JSON.stringify(b);
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function identicalValueColumnIndexes(rows: ReadonlyArray<ReadonlyArray<unknown>>, candidateIndexes: readonly number[]): number[] {
|
||||||
|
if (rows.length < 2) return [];
|
||||||
|
const candidates = [...candidateIndexes];
|
||||||
|
let count = candidates.length;
|
||||||
|
if (count === 0) return [];
|
||||||
|
|
||||||
|
const firstRow = rows[0];
|
||||||
|
if (!firstRow) return [];
|
||||||
|
|
||||||
|
for (let rowIndex = 1; rowIndex < rows.length; rowIndex++) {
|
||||||
|
const row = rows[rowIndex];
|
||||||
|
if (!row) continue;
|
||||||
|
let write = 0;
|
||||||
|
for (let read = 0; read < count; read++) {
|
||||||
|
const col = candidates[read]!;
|
||||||
|
if (areCellValuesEqual(row[col], firstRow[col])) {
|
||||||
|
candidates[write++] = col;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
count = write;
|
||||||
|
if (count === 0) return [];
|
||||||
|
}
|
||||||
|
candidates.length = count;
|
||||||
|
return candidates;
|
||||||
|
}
|
||||||
@@ -87,11 +87,12 @@ export function createDataGridColumnContextMenuItems(options: {
|
|||||||
visibleColumnCount?: number;
|
visibleColumnCount?: number;
|
||||||
/** 当前被隐藏的列数量,用于决定是否显示「显示全部列」。 */
|
/** 当前被隐藏的列数量,用于决定是否显示「显示全部列」。 */
|
||||||
hiddenColumnCount?: number;
|
hiddenColumnCount?: number;
|
||||||
|
canHideIdenticalColumns?: boolean;
|
||||||
labels: Record<
|
labels: Record<
|
||||||
"copyName" | "copyNames" | "details" | "copyAlterSql" | "databaseAscending" | "databaseDescending" | "localAscending" | "localDescending" | "clearSort" | "freezeToColumn" | "freezeSelectedColumns" | "unfreezeColumns" | "hideColumn" | "hideSelectedColumns" | "showAllColumnsMenu",
|
"copyName" | "copyNames" | "details" | "copyAlterSql" | "databaseAscending" | "databaseDescending" | "localAscending" | "localDescending" | "clearSort" | "freezeToColumn" | "freezeSelectedColumns" | "unfreezeColumns" | "hideColumn" | "hideSelectedColumns" | "showAllColumnsMenu",
|
||||||
string
|
string
|
||||||
> &
|
> &
|
||||||
Partial<Record<"freezeCurrentColumn" | "unfreezeCurrentColumn", string>>;
|
Partial<Record<"freezeCurrentColumn" | "unfreezeCurrentColumn" | "hideIdenticalColumns", string>>;
|
||||||
icons: Pick<DataGridContextMenuIcons, "copy" | "columnDetails" | "database" | "ascending" | "descending" | "clearSort">;
|
icons: Pick<DataGridContextMenuIcons, "copy" | "columnDetails" | "database" | "ascending" | "descending" | "clearSort">;
|
||||||
actions: {
|
actions: {
|
||||||
copyName: () => void;
|
copyName: () => void;
|
||||||
@@ -106,6 +107,7 @@ export function createDataGridColumnContextMenuItems(options: {
|
|||||||
unfreezeColumns: () => void;
|
unfreezeColumns: () => void;
|
||||||
hideColumn: () => void;
|
hideColumn: () => void;
|
||||||
hideSelectedColumns: () => void;
|
hideSelectedColumns: () => void;
|
||||||
|
hideIdenticalColumns?: () => void;
|
||||||
showAllColumnsMenu: () => void;
|
showAllColumnsMenu: () => void;
|
||||||
};
|
};
|
||||||
filterSubmenu: DataGridContextMenuItem;
|
filterSubmenu: DataGridContextMenuItem;
|
||||||
@@ -141,6 +143,13 @@ export function createDataGridColumnContextMenuItems(options: {
|
|||||||
if (options.hasColumnSelection && selectedColumnCount > 1) {
|
if (options.hasColumnSelection && selectedColumnCount > 1) {
|
||||||
items.push({ label: options.labels.hideSelectedColumns, action: options.actions.hideSelectedColumns, disabled: visibleColumnCount > 0 && selectedColumnCount >= visibleColumnCount });
|
items.push({ label: options.labels.hideSelectedColumns, action: options.actions.hideSelectedColumns, disabled: visibleColumnCount > 0 && selectedColumnCount >= visibleColumnCount });
|
||||||
}
|
}
|
||||||
|
if (options.labels.hideIdenticalColumns && options.actions.hideIdenticalColumns) {
|
||||||
|
items.push({
|
||||||
|
label: options.labels.hideIdenticalColumns,
|
||||||
|
action: options.actions.hideIdenticalColumns,
|
||||||
|
disabled: options.canHideIdenticalColumns === false,
|
||||||
|
});
|
||||||
|
}
|
||||||
if ((options.hiddenColumnCount ?? 0) > 0) {
|
if ((options.hiddenColumnCount ?? 0) > 0) {
|
||||||
items.push({ label: options.labels.showAllColumnsMenu, action: options.actions.showAllColumnsMenu });
|
items.push({ label: options.labels.showAllColumnsMenu, action: options.actions.showAllColumnsMenu });
|
||||||
}
|
}
|
||||||
@@ -153,6 +162,16 @@ export function createDataGridColumnContextMenuItems(options: {
|
|||||||
}
|
}
|
||||||
if (options.labels.freezeCurrentColumn && options.actions.freezeCurrentColumn) items.push({ label: options.labels.freezeCurrentColumn, action: options.actions.freezeCurrentColumn });
|
if (options.labels.freezeCurrentColumn && options.actions.freezeCurrentColumn) items.push({ label: options.labels.freezeCurrentColumn, action: options.actions.freezeCurrentColumn });
|
||||||
items.push({ label: options.labels.freezeToColumn, action: options.actions.freezeToColumn });
|
items.push({ label: options.labels.freezeToColumn, action: options.actions.freezeToColumn });
|
||||||
|
} else if (options.labels.hideIdenticalColumns && options.actions.hideIdenticalColumns) {
|
||||||
|
items.push({ label: "", separator: true });
|
||||||
|
items.push({
|
||||||
|
label: options.labels.hideIdenticalColumns,
|
||||||
|
action: options.actions.hideIdenticalColumns,
|
||||||
|
disabled: options.canHideIdenticalColumns === false,
|
||||||
|
});
|
||||||
|
if ((options.hiddenColumnCount ?? 0) > 0) {
|
||||||
|
items.push({ label: options.labels.showAllColumnsMenu, action: options.actions.showAllColumnsMenu });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ import { test } from "vitest";
|
|||||||
import { buildDataGridColumnLookupItems, filterDataGridColumnLookupItems } from "../../apps/desktop/src/lib/dataGrid/dataGridColumnLookup.ts";
|
import { buildDataGridColumnLookupItems, filterDataGridColumnLookupItems } from "../../apps/desktop/src/lib/dataGrid/dataGridColumnLookup.ts";
|
||||||
import {
|
import {
|
||||||
allNullColumnIndexes,
|
allNullColumnIndexes,
|
||||||
|
areCellValuesEqual,
|
||||||
filterColumnVisibilityOptions,
|
filterColumnVisibilityOptions,
|
||||||
hiddenColumnIndexesAfterHiding,
|
hiddenColumnIndexesAfterHiding,
|
||||||
hiddenColumnIndexesForKeys,
|
hiddenColumnIndexesForKeys,
|
||||||
hiddenColumnIndexesWithAllNullColumns,
|
hiddenColumnIndexesWithAllNullColumns,
|
||||||
hiddenColumnKeysForIndexes,
|
hiddenColumnKeysForIndexes,
|
||||||
|
identicalValueColumnIndexes,
|
||||||
invertedHiddenColumnIndexes,
|
invertedHiddenColumnIndexes,
|
||||||
nextHiddenColumnIndexes,
|
nextHiddenColumnIndexes,
|
||||||
removeAutoHiddenColumnIndexes,
|
removeAutoHiddenColumnIndexes,
|
||||||
@@ -212,3 +214,69 @@ test("keeps one all-null column visible when every column is NULL", () => {
|
|||||||
assert.deepEqual([...result.hiddenIndexes].sort(), [1, 2]);
|
assert.deepEqual([...result.hiddenIndexes].sort(), [1, 2]);
|
||||||
assert.deepEqual([...result.autoHiddenIndexes].sort(), [1, 2]);
|
assert.deepEqual([...result.autoHiddenIndexes].sort(), [1, 2]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("compares cell values for equality correctly", () => {
|
||||||
|
assert.equal(areCellValuesEqual(1, 1), true);
|
||||||
|
assert.equal(areCellValuesEqual(1, 2), false);
|
||||||
|
assert.equal(areCellValuesEqual("a", "a"), true);
|
||||||
|
assert.equal(areCellValuesEqual("a", "b"), false);
|
||||||
|
assert.equal(areCellValuesEqual(null, null), true);
|
||||||
|
assert.equal(areCellValuesEqual(undefined, undefined), true);
|
||||||
|
assert.equal(areCellValuesEqual(null, undefined), false);
|
||||||
|
assert.equal(areCellValuesEqual(null, ""), false);
|
||||||
|
assert.equal(areCellValuesEqual(Number.NaN, Number.NaN), true);
|
||||||
|
assert.equal(areCellValuesEqual(new Date("2026-01-01"), new Date("2026-01-01")), true);
|
||||||
|
assert.equal(areCellValuesEqual(new Date("2026-01-01"), new Date("2026-01-02")), false);
|
||||||
|
assert.equal(areCellValuesEqual({ a: 1 }, { a: 1 }), true);
|
||||||
|
assert.equal(areCellValuesEqual({ a: 1 }, { a: 2 }), false);
|
||||||
|
assert.equal(areCellValuesEqual([1, 2], [1, 2]), true);
|
||||||
|
assert.equal(areCellValuesEqual([1, 2], [1, 3]), false);
|
||||||
|
assert.equal(areCellValuesEqual(new Uint8Array([1, 2]), new Uint8Array([1, 2])), true);
|
||||||
|
assert.equal(areCellValuesEqual(new Uint8Array([1, 2]), new Uint8Array([1, 3])), false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("finds columns where all rows have identical values", () => {
|
||||||
|
const rows = [
|
||||||
|
[1, "status_ok", "same", 100],
|
||||||
|
[2, "status_ok", "diff", 100],
|
||||||
|
[3, "status_ok", "diff2", 100],
|
||||||
|
];
|
||||||
|
|
||||||
|
const identical = identicalValueColumnIndexes(rows, [0, 1, 2, 3]);
|
||||||
|
assert.deepEqual(identical, [1, 3]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns empty array when fewer than 2 rows exist", () => {
|
||||||
|
assert.deepEqual(identicalValueColumnIndexes([], [0, 1]), []);
|
||||||
|
assert.deepEqual(identicalValueColumnIndexes([[1, "a"]], [0, 1]), []);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns empty array when candidate indexes is empty", () => {
|
||||||
|
assert.deepEqual(identicalValueColumnIndexes([[1, 2], [1, 2]], []), []);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns empty array when no columns have identical values", () => {
|
||||||
|
const rows = [
|
||||||
|
[1, "a"],
|
||||||
|
[2, "b"],
|
||||||
|
];
|
||||||
|
assert.deepEqual(identicalValueColumnIndexes(rows, [0, 1]), []);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("detects identical values by original index when middle column is hidden", () => {
|
||||||
|
// 行保持全宽、候选是原始列索引(模拟第 1 列被隐藏后只剩 [0, 2, 3] 可见)
|
||||||
|
const rows = [
|
||||||
|
[1, "hidden_a", "same", 100],
|
||||||
|
[2, "hidden_b", "same", 101],
|
||||||
|
[3, "hidden_c", "same", 102],
|
||||||
|
];
|
||||||
|
assert.deepEqual(identicalValueColumnIndexes(rows, [0, 2, 3]), [2]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("identifies identical columns with null and json objects", () => {
|
||||||
|
const rows = [
|
||||||
|
[null, { k: 1 }, "x"],
|
||||||
|
[null, { k: 1 }, "y"],
|
||||||
|
];
|
||||||
|
assert.deepEqual(identicalValueColumnIndexes(rows, [0, 1, 2]), [0, 1]);
|
||||||
|
});
|
||||||
@@ -14,6 +14,13 @@ test("set NULL applies a real null value only to editable selections", () => {
|
|||||||
assert.doesNotMatch(handler, /fillSelectionWithValue\(["'](?:NULL)?["']\)/);
|
assert.doesNotMatch(handler, /fillSelectionWithValue\(["'](?:NULL)?["']\)/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("hide identical columns compares full-width rows, not visibility-projected ones", () => {
|
||||||
|
const fn = dataGridSource.match(/function getComparisonRows\(\)[^{]*\{[^]*?\n\}/)?.[0] ?? "";
|
||||||
|
assert.ok(fn, "getComparisonRows not found");
|
||||||
|
assert.match(fn, /\bdisplayItems\.value/);
|
||||||
|
assert.doesNotMatch(fn, /visibleDisplayItems/);
|
||||||
|
});
|
||||||
|
|
||||||
test("editable cell selections expose generation after bulk edit", () => {
|
test("editable cell selections expose generation after bulk edit", () => {
|
||||||
const icon = {};
|
const icon = {};
|
||||||
const action = () => {};
|
const action = () => {};
|
||||||
|
|||||||
Reference in new issue
Block a user