25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
feat(grid): add MIN/MAX/COUNT/DISTINCT to the selection summary
弈秋e835d542d2a1
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vueindex ce17311b86..87a7e3b9c3 100644--- a/apps/desktop/src/components/grid/DataGrid.vue+++ b/apps/desktop/src/components/grid/DataGrid.vue@@ -6679,6 +6679,16 @@ const selectionSummaryAverageText = computed(() => {if (isSelectingCells.value) return "…";return formatSelectionAverage(selectionSummary.value?.average);});+const selectionSummaryMinText = computed(() => {+ if (isSelectingCells.value) return "…";+ const min = selectionSummary.value?.min;+ return typeof min === "string" ? formatSelectionAggregate(min) : "—";+});+const selectionSummaryMaxText = computed(() => {+ if (isSelectingCells.value) return "…";+ const max = selectionSummary.value?.max;+ return typeof max === "string" ? formatSelectionAggregate(max) : "—";+});const isMultiRow = computed(() => multiRowCount.value > 1);@@ -16710,6 +16720,10 @@ useUpdateBlocker(() => (hasPendingChanges.value || hasPendingDataEditorDraft.val:selection-summary="selectionSummary":selection-summary-sum-text="selectionSummarySumText":selection-summary-average-text="selectionSummaryAverageText"+ :selection-summary-min-text="selectionSummaryMinText"+ :selection-summary-max-text="selectionSummaryMaxText"+ :selection-summary-count="selectionSummary?.numericCount ?? 0"+ :selection-summary-distinct-count="selectionSummary?.distinctCount ?? 0":selection-summary-pending="isSelectingCells":loading="gridPaginationBusy || infiniteScrollLoading":infinite-scroll-enabled="infiniteScrollEnabled"diff --git a/apps/desktop/src/components/grid/DataGridPagination.vue b/apps/desktop/src/components/grid/DataGridPagination.vueindex 52ea53d45d..86a2808497 100644--- a/apps/desktop/src/components/grid/DataGridPagination.vue+++ b/apps/desktop/src/components/grid/DataGridPagination.vue@@ -17,6 +17,10 @@ const props = withDefaults(selectionSummary: { cellCount: number; rowCount: number } | null;selectionSummarySumText: string;selectionSummaryAverageText: string;+ selectionSummaryMinText: string;+ selectionSummaryMaxText: string;+ selectionSummaryCount?: number;+ selectionSummaryDistinctCount?: number;// 拖拽选区期间聚合值只是占位符,父组件把该状态传下来,值不可复制selectionSummaryPending?: boolean;loading: boolean;@@ -111,7 +115,15 @@ function handlePageInputKeydown(event: KeyboardEvent) {<button type="button" class="shrink-0 text-left" :class="selectionSummaryValueClass" :title="selectionSummaryPending ? undefined : t('grid.copyValue')" :disabled="selectionSummaryPending" data-selection-summary-average @click="copySelectionSummaryValue(selectionSummaryAverageText)"><span v-if="!selectionSummaryPending" class="sr-only">{{ t("grid.copyValue") }}: </span>{{ t("grid.selectionAverage", { value: selectionSummaryAverageText }) }}</button>+ <button type="button" class="shrink-0 text-left" :class="selectionSummaryValueClass" :title="selectionSummaryPending ? undefined : t('grid.copyValue')" :disabled="selectionSummaryPending" data-selection-summary-min @click="copySelectionSummaryValue(selectionSummaryMinText)">+ <span v-if="!selectionSummaryPending" class="sr-only">{{ t("grid.copyValue") }}: </span>{{ t("grid.selectionMin", { value: selectionSummaryMinText }) }}+ </button>+ <button type="button" class="shrink-0 text-left" :class="selectionSummaryValueClass" :title="selectionSummaryPending ? undefined : t('grid.copyValue')" :disabled="selectionSummaryPending" data-selection-summary-max @click="copySelectionSummaryValue(selectionSummaryMaxText)">+ <span v-if="!selectionSummaryPending" class="sr-only">{{ t("grid.copyValue") }}: </span>{{ t("grid.selectionMax", { value: selectionSummaryMaxText }) }}+ </button><div class="flex shrink-0 items-center gap-1">+ <span v-if="selectionSummaryCount" class="shrink-0">{{ t("grid.selectionCount", { count: selectionSummaryCount }) }}</span>+ <span v-if="selectionSummaryDistinctCount" class="shrink-0">{{ t("grid.selectionDistinct", { count: selectionSummaryDistinctCount }) }}</span><span class="shrink-0">{{ t("grid.selectionCells", { count: selectionSummary.cellCount }) }}</span><span class="shrink-0">{{ t("grid.rows", { count: selectionSummary.rowCount }) }}</span></div>diff --git a/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.ts b/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.tsindex 5acd70e3bf..b6807c0c38 100644--- a/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.ts+++ b/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.ts@@ -224,6 +224,34 @@ describe("DataGridPagination", () => {expect(summaryText).toContain("grid.rows");});+ it("shows min, max, count and distinct beside sum and average when numbers are selected (#13286)", () => {+ const mounted = mountComponent(DataGridPagination, {+ selectionSummary: { cellCount: 4, rowCount: 2 },+ selectionSummarySumText: "10",+ selectionSummaryAverageText: "2.5",+ selectionSummaryMinText: "1",+ selectionSummaryMaxText: "4",+ selectionSummaryCount: 4,+ selectionSummaryDistinctCount: 3,+ loading: false,+ infiniteScrollEnabled: false,+ infiniteScrollAllLoaded: false,+ pageSize: 100,+ customPageSizeInput: "",+ pageSizeMenuItems: [],+ exportMenuItems: [],+ currentPage: 1,+ canGoNextPage: false,+ canJumpLastPage: false,+ });++ const summaryText = hostText(mounted.root);+ expect(summaryText).toContain("grid.selectionMin");+ expect(summaryText).toContain("grid.selectionMax");+ expect(summaryText).toContain("grid.selectionCount");+ expect(summaryText).toContain("grid.selectionDistinct");+ });+it("keeps the loading icon mounted with a constant footprint and only animates while loading", async () => {const mounted = mountComponent(DataGridPagination, {selectionSummary: null,diff --git a/apps/desktop/src/i18n/locales/az.ts b/apps/desktop/src/i18n/locales/az.tsindex 77602d0e1b..2b7d405b33 100644--- a/apps/desktop/src/i18n/locales/az.ts+++ b/apps/desktop/src/i18n/locales/az.ts@@ -1983,6 +1983,10 @@ export default withEnglishFallback({copyAll: "Hamısını kopyala (TSV)",selectionSum: "SUM: {value}",selectionAverage: "AVG: {value}",+ selectionMin: "Min {value}",+ selectionMax: "Maks {value}",+ selectionCount: "Say {count}",+ selectionDistinct: "Unikal {count}",selectionCells: "{count} xana",clearSelection: "Seçimi təmizlə",export: "İxrac et",diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.tsindex a97a274c9c..c904d251ed 100644--- a/apps/desktop/src/i18n/locales/en.ts+++ b/apps/desktop/src/i18n/locales/en.ts@@ -2857,6 +2857,10 @@ export default {copyAll: "Copy All (TSV)",selectionSum: "SUM: {value}",selectionAverage: "AVG: {value}",+ selectionMin: "MIN: {value}",+ selectionMax: "MAX: {value}",+ selectionCount: "COUNT {count}",+ selectionDistinct: "DISTINCT {count}",selectionCells: "{count} cells",clearSelection: "Clear Selection",export: "Export",diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.tsindex 11dfc69230..8584b5b028 100644--- a/apps/desktop/src/i18n/locales/es.ts+++ b/apps/desktop/src/i18n/locales/es.ts@@ -2509,6 +2509,10 @@ export default withEnglishFallback({copyAll: "Copiar todo (TSV)",selectionSum: "SUM: {value}",selectionAverage: "AVG: {value}",+ selectionMin: "Mín {value}",+ selectionMax: "Máx {value}",+ selectionCount: "COUNT {count}",+ selectionDistinct: "DISTINCT {count}",selectionCells: "{count} celdas",clearSelection: "Limpiar selección",export: "Exportar",diff --git a/apps/desktop/src/i18n/locales/id.ts b/apps/desktop/src/i18n/locales/id.tsindex 55048c1d16..741e03d134 100644--- a/apps/desktop/src/i18n/locales/id.ts+++ b/apps/desktop/src/i18n/locales/id.ts@@ -2283,6 +2283,10 @@ export default withEnglishFallback({copyAll: "Salin Semua (TSV)",selectionSum: "SUM: {value}",selectionAverage: "AVG: {value}",+ selectionMin: "Min {value}",+ selectionMax: "Maks {value}",+ selectionCount: "Jumlah {count}",+ selectionDistinct: "Berbeda {count}",selectionCells: "{count} sel",clearSelection: "Bersihkan Pilihan",export: "Ekspor",diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.tsindex 81c1e7cdc6..254dc08d1a 100644--- a/apps/desktop/src/i18n/locales/it.ts+++ b/apps/desktop/src/i18n/locales/it.ts@@ -2407,6 +2407,10 @@ export default withEnglishFallback({copyAll: "Copia Tutto (TSV)",selectionSum: "SUM: {value}",selectionAverage: "AVG: {value}",+ selectionMin: "Min {value}",+ selectionMax: "Max {value}",+ selectionCount: "COUNT {count}",+ selectionDistinct: "DISTINCT {count}",selectionCells: "{count} celle",clearSelection: "Cancella Selezione",export: "Esporta",diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.tsindex 167fa501e2..867abf212d 100644--- a/apps/desktop/src/i18n/locales/ja.ts+++ b/apps/desktop/src/i18n/locales/ja.ts@@ -2416,6 +2416,10 @@ export default withEnglishFallback({copyAll: "すべてコピー (TSV)",selectionSum: "SUM: {value}",selectionAverage: "AVG: {value}",+ selectionMin: "最小 {value}",+ selectionMax: "最大 {value}",+ selectionCount: "件数 {count}",+ selectionDistinct: "重複除外 {count}",selectionCells: "{count} 個のセル",clearSelection: "選択をクリア",export: "エクスポート",diff --git a/apps/desktop/src/i18n/locales/ko.ts b/apps/desktop/src/i18n/locales/ko.tsindex fa2b8d4275..c4159be418 100644--- a/apps/desktop/src/i18n/locales/ko.ts+++ b/apps/desktop/src/i18n/locales/ko.ts@@ -2522,6 +2522,10 @@ export default withEnglishFallback({copyAll: "모두 복사 (TSV)",selectionSum: "합계: {value}",selectionAverage: "평균: {value}",+ selectionMin: "최소 {value}",+ selectionMax: "최대 {value}",+ selectionCount: "개수 {count}",+ selectionDistinct: "고유 {count}",selectionCells: "{count}개 셀",clearSelection: "선택 해제",export: "내보내기",diff --git a/apps/desktop/src/i18n/locales/pl.ts b/apps/desktop/src/i18n/locales/pl.tsindex a67dfd7435..2979043403 100644--- a/apps/desktop/src/i18n/locales/pl.ts+++ b/apps/desktop/src/i18n/locales/pl.ts@@ -2367,6 +2367,10 @@ export default withEnglishFallback({copyAll: "Kopiuj wszystko (TSV)",selectionSum: "SUMA: {value}",selectionAverage: "ŚREDNIA: {value}",+ selectionMin: "Min {value}",+ selectionMax: "Maks {value}",+ selectionCount: "COUNT {count}",+ selectionDistinct: "DISTINCT {count}",selectionCells: "Komórki: {count}",clearSelection: "Wyczyść zaznaczenie",export: "Eksportuj",diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.tsindex f7f3c0335c..f39c4aedd3 100644--- a/apps/desktop/src/i18n/locales/pt-BR.ts+++ b/apps/desktop/src/i18n/locales/pt-BR.ts@@ -2409,6 +2409,10 @@ export default withEnglishFallback({copyAll: "Copiar Tudo (TSV)",selectionSum: "SUM: {value}",selectionAverage: "AVG: {value}",+ selectionMin: "Mín {value}",+ selectionMax: "Máx {value}",+ selectionCount: "COUNT {count}",+ selectionDistinct: "DISTINCT {count}",selectionCells: "{count} células",clearSelection: "Limpar Seleção",export: "Exportar",diff --git a/apps/desktop/src/i18n/locales/ru.ts b/apps/desktop/src/i18n/locales/ru.tsindex 5b5794c3d0..e0165d5965 100644--- a/apps/desktop/src/i18n/locales/ru.ts+++ b/apps/desktop/src/i18n/locales/ru.ts@@ -2608,6 +2608,10 @@ export default withEnglishFallback({copyAll: "Копировать всё (TSV)",selectionSum: "СУММА: {value}",selectionAverage: "СРЕДНЕЕ: {value}",+ selectionMin: "Мин {value}",+ selectionMax: "Макс {value}",+ selectionCount: "COUNT {count}",+ selectionDistinct: "DISTINCT {count}",selectionCells: "Ячеек: {count}",clearSelection: "Снять выделение",export: "Экспорт",diff --git a/apps/desktop/src/i18n/locales/th.ts b/apps/desktop/src/i18n/locales/th.tsindex 1349f7564d..8a5c4191d1 100644--- a/apps/desktop/src/i18n/locales/th.ts+++ b/apps/desktop/src/i18n/locales/th.ts@@ -2775,6 +2775,10 @@ export default withEnglishFallback({copyAll: "คัดลอกทั้งหมด (TSV)",selectionSum: "SUM: {value}",selectionAverage: "AVG: {value}",+ selectionMin: "ต่ำสุด {value}",+ selectionMax: "สูงสุด {value}",+ selectionCount: "นับ {count}",+ selectionDistinct: "ไม่ซ้ำ {count}",selectionCells: "{count} เซลล์",clearSelection: "ล้างการเลือก",export: "ส่งออก",diff --git a/apps/desktop/src/i18n/locales/tr.ts b/apps/desktop/src/i18n/locales/tr.tsindex a0487686f6..89942ce01d 100644--- a/apps/desktop/src/i18n/locales/tr.ts+++ b/apps/desktop/src/i18n/locales/tr.ts@@ -1981,6 +1981,10 @@ export default withEnglishFallback({copyAll: "Tümünü Kopyala (TSV)",selectionSum: "TOPLAM: {value}",selectionAverage: "ORT: {value}",+ selectionMin: "Min {value}",+ selectionMax: "Maks {value}",+ selectionCount: "Sayı {count}",+ selectionDistinct: "Benzersiz {count}",selectionCells: "{count} hücre",clearSelection: "Seçimi Temizle",export: "Dışa Aktar",diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.tsindex e097f88066..f3274a8221 100644--- a/apps/desktop/src/i18n/locales/zh-CN.ts+++ b/apps/desktop/src/i18n/locales/zh-CN.ts@@ -2787,6 +2787,10 @@ export default withEnglishFallback({copyAll: "复制全部 (TSV)",selectionSum: "SUM: {value}",selectionAverage: "AVG: {value}",+ selectionMin: "最小 {value}",+ selectionMax: "最大 {value}",+ selectionCount: "计数 {count}",+ selectionDistinct: "去重 {count}",selectionCells: "{count} 个单元",clearSelection: "清除选区",export: "导出",diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.tsindex 9c4beadbdb..97bb3392f4 100644--- a/apps/desktop/src/i18n/locales/zh-TW.ts+++ b/apps/desktop/src/i18n/locales/zh-TW.ts@@ -2405,6 +2405,10 @@ export default withEnglishFallback({copyAll: "複製全部 (TSV)",selectionSum: "SUM: {value}",selectionAverage: "AVG: {value}",+ selectionMin: "最小 {value}",+ selectionMax: "最大 {value}",+ selectionCount: "計數 {count}",+ selectionDistinct: "去重 {count}",selectionCells: "{count} 個儲存格",clearSelection: "清除選區",export: "匯出",diff --git a/apps/desktop/src/lib/__tests__/dataGrid/gridSelection.spec.ts b/apps/desktop/src/lib/__tests__/dataGrid/gridSelection.spec.tsindex 49c46ed6c9..40365b659c 100644--- a/apps/desktop/src/lib/__tests__/dataGrid/gridSelection.spec.ts+++ b/apps/desktop/src/lib/__tests__/dataGrid/gridSelection.spec.ts@@ -9,6 +9,9 @@ describe("gridSelection", () => {numericCount: 0,sum: "0",average: null,+ min: null,+ max: null,+ distinctCount: 0,});});@@ -27,6 +30,9 @@ describe("gridSelection", () => {numericCount: 4,sum: "10",average: "2.5",+ min: "1",+ max: "4",+ distinctCount: 4,});});@@ -45,6 +51,9 @@ describe("gridSelection", () => {numericCount: 3,sum: "105.5",average: "35.166666666667",+ min: "2.5",+ max: "100",+ distinctCount: 3,});});@@ -60,6 +69,9 @@ describe("gridSelection", () => {numericCount: 0,sum: "0",average: null,+ min: null,+ max: null,+ distinctCount: 0,});});@@ -151,6 +163,9 @@ describe("gridSelection", () => {numericCount: 0,sum: "0",average: null,+ min: null,+ max: null,+ distinctCount: 0,});expect(formatSelectionAggregate(-0, "en-US")).toBe("0");expect(formatSelectionAggregate(1 / 3, "en-US")).toBe("0.333333333333");@@ -180,6 +195,23 @@ describe("gridSelection", () => {expect(plainSelectionNumericValue(null)).toBeUndefined();});+ it("reports min and max as exact decimal text over the same participation as sum (#13286)", () => {+ expect(summarizeSelection({ columns: ["v"], rows: [["0.10"], ["0.2"], ["-3"]] })).toMatchObject({ min: "-3", max: "0.2" });+ // 0.1 text versus 0.10 text are the same value; the exact scale keeps digits intact.+ expect(summarizeSelection({ columns: ["v"], rows: [["1762018465054523393"], ["2041776918834970625"]] })).toMatchObject({+ min: "1762018465054523393",+ max: "2041776918834970625",+ });+ // No participating values leaves min/max empty even when cells are selected.+ expect(summarizeSelection({ columns: ["v"], rows: [[null], ["x"]] })).toMatchObject({ numericCount: 0, min: null, max: null });+ });++ it("counts distinct participating values by their exact decimal text (#13286)", () => {+ expect(summarizeSelection({ columns: ["v"], rows: [[2], [2], ["2.0"], [3]] })).toMatchObject({ numericCount: 4, distinctCount: 2 });+ expect(summarizeSelection({ columns: ["v"], rows: [["0.1"], ["0.10"]] })).toMatchObject({ distinctCount: 1 });+ expect(summarizeSelection({ columns: ["v"], rows: [[null], [true]] })).toMatchObject({ distinctCount: 0 });+ });+it("dedupeColumnIndexes preserves the first visible occurrence instead of sorting", () => {// After drag-reordering, visible order is [2, 0, 1]; extraction must keep it,// not revert to numeric [0, 1, 2].diff --git a/apps/desktop/src/lib/dataGrid/gridSelection.ts b/apps/desktop/src/lib/dataGrid/gridSelection.tsindex 652b331aaf..1a70f268df 100644--- a/apps/desktop/src/lib/dataGrid/gridSelection.ts+++ b/apps/desktop/src/lib/dataGrid/gridSelection.ts@@ -29,6 +29,12 @@ export interface SelectionSummary {/** Exact decimal text, so integers beyond 2^53 and DECIMAL scales survive. */sum: string;average: string | null;+ /** Smallest participating numeric value as exact decimal text (#13286). */+ min: string | null;+ /** Largest participating numeric value as exact decimal text (#13286). */+ max: string | null;+ /** Distinct participating numeric values, compared by exact decimal text (#13286). */+ distinctCount: number;}export interface SelectionSummaryOptions {@@ -184,9 +190,20 @@ function rescaleDecimal(value: ExactDecimal, scale: number): bigint {return value.scale === scale ? value.coefficient : value.coefficient * 10n ** BigInt(scale - value.scale);}+/** Compares two exact decimals by rescaling to the finer of the two scales. */+function compareExactDecimal(left: ExactDecimal, right: ExactDecimal): number {+ const scale = Math.max(left.scale, right.scale);+ const a = rescaleDecimal(left, scale);+ const b = rescaleDecimal(right, scale);+ return a < b ? -1 : a > b ? 1 : 0;+}+/** Adds a cell to an exact running total; `resolved` is the number the cell counts as. */export function addExactSelectionValue(sum: ExactDecimal, value: GridCellValue, resolved: number): ExactDecimal {- const exact = exactSelectionValue(value, resolved);+ return addExactDecimal(sum, exactSelectionValue(value, resolved));+}++function addExactDecimal(sum: ExactDecimal, exact: ExactDecimal): ExactDecimal {const scale = Math.max(sum.scale, exact.scale);return { coefficient: rescaleDecimal(sum, scale) + rescaleDecimal(exact, scale), scale };}@@ -214,13 +231,20 @@ export function summarizeSelection(selection: SelectionData, options: SelectionSconst numericValue = options.numericValue ?? plainSelectionNumericValue;let numericCount = 0;let sum: ExactDecimal = { coefficient: 0n, scale: 0 };+ let min: ExactDecimal | null = null;+ let max: ExactDecimal | null = null;+ const distinctValues = new Set<string>();for (const row of selection.rows) {for (const value of row) {const resolved = numericValue(value);if (resolved === undefined || !Number.isFinite(resolved)) continue;numericCount += 1;- sum = addExactSelectionValue(sum, value, resolved);+ const exact = exactSelectionValue(value, resolved);+ sum = addExactDecimal(sum, exact);+ if (min === null || compareExactDecimal(exact, min) < 0) min = exact;+ if (max === null || compareExactDecimal(exact, max) > 0) max = exact;+ distinctValues.add(exactDecimalText(exact));}}@@ -233,6 +257,9 @@ export function summarizeSelection(selection: SelectionData, options: SelectionSnumericCount,sum: exactDecimalText(sum),average,+ min: min === null ? null : exactDecimalText(min),+ max: max === null ? null : exactDecimalText(max),+ distinctCount: distinctValues.size,};}@@ -243,6 +270,9 @@ export function createPendingSelectionSummary(cellCount: number, rowCount: numbenumericCount: 0,sum: "0",average: null,+ min: null,+ max: null,+ distinctCount: 0,};}