From 3b771c0df436ef3687f6e20968cf5aa20680e732 Mon Sep 17 00:00:00 2001 From: wuhaiyang Date: Fri, 17 Nov 2023 16:36:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=9A=90=E8=97=8F?= =?UTF-8?q?=E5=88=97=E6=80=BB=E8=AE=A1=E6=97=B6=E8=A1=8C=E6=80=BB=E8=AE=A1?= =?UTF-8?q?=E4=B9=9F=E8=A2=AB=E9=9A=90=E8=97=8F=E9=97=AE=E9=A2=98=20(#2417?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修复隐藏列总计时行总计也被隐藏了 * fix: add fix bug comment * fix: add test case * fix: optimize test case --------- Co-authored-by: wuding.why --- .../spreadsheet/hidden-columns-spec.ts | 20 +++++++++++++++++++ .../s2-core/src/facet/layout/layout-hooks.ts | 6 +++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts b/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts index 7aecda2f1d..8774ead68e 100644 --- a/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts @@ -554,6 +554,26 @@ describe('SpreadSheet Hidden Columns Tests', () => { expect(leafNodes.some((node) => node.id === nodeId)).toBeFalsy(); expect(leafNodes).toHaveLength(5); }); + + test.each(['grid', 'tree'])( + 'hiding the column totals should not hide the row totals for %s mode', + (hierarchyType: 'grid' | 'tree') => { + sheet.setOptions({ hierarchyType }); + sheet.render(); + const nodeId = 'root[&]总计'; + const preRowNodes = sheet.facet.layoutResult.rowNodes; + const preColumnNodes = sheet.facet.layoutResult.colNodes; + sheet.interaction.hideColumns([nodeId]); + + expect(sheet.facet.layoutResult.rowNodes[0].id).toBe(nodeId); + expect(sheet.facet.layoutResult.rowNodes.length).toBe( + preRowNodes.length, + ); + expect(sheet.facet.layoutResult.colNodes.length).toBe( + preColumnNodes.length - 1, + ); + }, + ); }); }); }); diff --git a/packages/s2-core/src/facet/layout/layout-hooks.ts b/packages/s2-core/src/facet/layout/layout-hooks.ts index 4aadb1e8f5..67b59afb61 100644 --- a/packages/s2-core/src/facet/layout/layout-hooks.ts +++ b/packages/s2-core/src/facet/layout/layout-hooks.ts @@ -43,7 +43,11 @@ export const layoutHierarchy = ( const hiddenColumnNode = facetCfg.spreadsheet?.facet?.getHiddenColumnsInfo(currentNode); - if (hiddenColumnNode) { + if ( + hiddenColumnNode && + // fix: Only hiding the column headers is supported to prevent the row subtotals from being hidden when the IDs of the row totals and column totals are the same. + facetCfg.columns.find((field) => field === currentNode.field) + ) { return false; }