From b2491fbe51098882557f1e0a7845f7cd65906f90 Mon Sep 17 00:00:00 2001 From: "wuding.why" Date: Thu, 16 Nov 2023 14:28:01 +0800 Subject: [PATCH 1/4] =?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=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/s2-core/src/facet/layout/layout-hooks.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/s2-core/src/facet/layout/layout-hooks.ts b/packages/s2-core/src/facet/layout/layout-hooks.ts index 4aadb1e8f5..d782f6ae0e 100644 --- a/packages/s2-core/src/facet/layout/layout-hooks.ts +++ b/packages/s2-core/src/facet/layout/layout-hooks.ts @@ -43,7 +43,10 @@ export const layoutHierarchy = ( const hiddenColumnNode = facetCfg.spreadsheet?.facet?.getHiddenColumnsInfo(currentNode); - if (hiddenColumnNode) { + if ( + hiddenColumnNode && + facetCfg.columns.find((field) => field === currentNode.field) + ) { return false; } From cddaeabce6a5ef4b24beaf9e1e22482633f2d265 Mon Sep 17 00:00:00 2001 From: "wuding.why" Date: Thu, 16 Nov 2023 14:34:41 +0800 Subject: [PATCH 2/4] fix: add fix bug comment --- packages/s2-core/src/facet/layout/layout-hooks.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/s2-core/src/facet/layout/layout-hooks.ts b/packages/s2-core/src/facet/layout/layout-hooks.ts index d782f6ae0e..67b59afb61 100644 --- a/packages/s2-core/src/facet/layout/layout-hooks.ts +++ b/packages/s2-core/src/facet/layout/layout-hooks.ts @@ -45,6 +45,7 @@ export const layoutHierarchy = ( 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; From bdbad7e067ac5e8b260c8f5092409d386b9675fa Mon Sep 17 00:00:00 2001 From: "wuding.why" Date: Thu, 16 Nov 2023 20:53:46 +0800 Subject: [PATCH 3/4] fix: add test case --- .../spreadsheet/hidden-columns-spec.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts b/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts index 7aecda2f1d..d4fae5a0dd 100644 --- a/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts @@ -554,6 +554,39 @@ describe('SpreadSheet Hidden Columns Tests', () => { expect(leafNodes.some((node) => node.id === nodeId)).toBeFalsy(); expect(leafNodes).toHaveLength(5); }); + + test('hiding the column totals should not hide the row totals', () => { + 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, + ); + }); + + test('hiding the column totals should not hide the row totals tree', () => { + sheet.setOptions({ hierarchyType: 'tree' }); + 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, + ); + }); }); }); }); From dcd048780a93b72f5eb64811f3464cb5c839734d Mon Sep 17 00:00:00 2001 From: "wuding.why" Date: Fri, 17 Nov 2023 12:12:48 +0800 Subject: [PATCH 4/4] fix: optimize test case --- .../spreadsheet/hidden-columns-spec.ts | 51 +++++++------------ 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts b/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts index d4fae5a0dd..8774ead68e 100644 --- a/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts @@ -555,38 +555,25 @@ describe('SpreadSheet Hidden Columns Tests', () => { expect(leafNodes).toHaveLength(5); }); - test('hiding the column totals should not hide the row totals', () => { - 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, - ); - }); - - test('hiding the column totals should not hide the row totals tree', () => { - sheet.setOptions({ hierarchyType: 'tree' }); - 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, - ); - }); + 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, + ); + }, + ); }); }); });