From 3439da88eb8f72d1cf00a6190eda6d4cd2a8c187 Mon Sep 17 00:00:00 2001 From: Wenjun Xu <906626481@qq.com> Date: Fri, 1 Dec 2023 17:12:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BC=BA=E5=A4=B1?= =?UTF-8?q?=E7=BB=B4=E5=BA=A6=E6=89=80=E7=94=9F=E6=88=90=E7=9A=84=20query?= =?UTF-8?q?=20=E5=A4=9A=E4=BA=86=20empty=20extra=20value=20=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=20(#2444)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spreadsheet/miss-dimension-values-spec.ts | 173 ++++++++++-------- .../layout/get-dims-condition-by-node.ts | 3 +- 2 files changed, 97 insertions(+), 79 deletions(-) diff --git a/packages/s2-core/__tests__/spreadsheet/miss-dimension-values-spec.ts b/packages/s2-core/__tests__/spreadsheet/miss-dimension-values-spec.ts index 0ebf2b44af..3542ef8f85 100644 --- a/packages/s2-core/__tests__/spreadsheet/miss-dimension-values-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/miss-dimension-values-spec.ts @@ -15,10 +15,7 @@ const s2Options: S2Options = { }, reverseLayout: false, reverseSubLayout: false, - subTotalsDimensions: [ - '2d7feabd-76a2-4c11-8f24-79764af936b4', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec', - ], + subTotalsDimensions: ['first', 'second'], }, col: { showGrandTotals: false, @@ -40,133 +37,142 @@ const s2Options: S2Options = { const testDataCfg: S2DataConfig = { meta: [ { - field: '2d7feabd-76a2-4c11-8f24-79764af936b4', + field: 'first', name: '一级维度', }, { - field: '30b4b32d-d69a-4772-b7f9-84cd54cf0cec', + field: 'second', name: '二级维度', }, { - field: 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee', + field: 'third', + name: '三级维度', + }, + { + field: 'number', name: '数值', }, ], fields: { - rows: [ - '2d7feabd-76a2-4c11-8f24-79764af936b4', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec', - ], + rows: ['first', 'second', 'third'], columns: [], - values: ['c5ce4e54-795a-42b3-9cc8-e8b685da44ee'], + values: ['number'], valueInCols: true, }, data: [ { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '总计', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 1732771, + first: '总计', + number: 1732771, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '维值-1', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec': '维值-2', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 172245, + first: '维值-1', + second: '维值-2', + third: '维度-3', + number: 172245, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '维值-1', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec': '维值-2', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 12222, + first: '维值-1', + second: '维值-2', + third: '维度-3', + number: 12222, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '维值-1', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec': '维值-3', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 11111, + first: '维值-1', + second: '维值-3', + third: '维值-3', + number: 11111, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '维值-1', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec': '维值-3', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 11111, + first: '维值-1', + second: '维值-3', + third: '维度-3', + number: 11111, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '维值-1', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 456, + first: '维值-1', + number: 456, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '测试-1', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec': '测试-2', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 12, + first: '测试-1', + second: '测试-2', + third: '维度-3', + number: 12, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '测试-1', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec': '测试-2', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 4444567, + first: '测试-1', + second: '测试-2', + third: '维度-3', + number: 4444567, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '测试-1', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec': '测试-3', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 111233, + first: '测试-1', + second: '测试-3', + number: 111233, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '测试-1', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec': '测试-3', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 785222, + first: '测试-1', + second: '测试-3', + number: 785222, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '测试-1', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec': '测试-4', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 6455644, + first: '测试-1', + second: '测试-4', + third: '维度-3', + number: 6455644, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '测试-1', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec': '测试-4', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 289898, + first: '测试-1', + second: '测试-4', + number: 289898, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '测试-1', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec': '测试-5', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 2222, + first: '测试-1', + second: '测试-5', + number: 2222, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '测试-1', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec': '测试-5', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 1111, + first: '测试-1', + second: '测试-5', + third: '维度-3', + number: 1111, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '测试-1', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 125555, + first: '测试-1', + number: 125555, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '测试-6', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec': '测试-x', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 409090, + first: '测试-6', + second: '测试-x', + number: 409090, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '测试-6', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec': '测试-x', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 111111, + first: '测试-6', + second: '测试-x', + number: 111111, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '测试-6', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec': '测试-7', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 5555, + first: '测试-6', + second: '测试-7', + number: 5555, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '测试-6', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec': '测试-7', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 67878, + first: '测试-6', + second: '测试-7', + number: 67878, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '测试-6', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec': '测试-8', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 53445.464, + first: '测试-6', + second: '测试-8', + number: 53445.464, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '测试-6', - '30b4b32d-d69a-4772-b7f9-84cd54cf0cec': '测试-8', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 456.464, + first: '测试-6', + second: '测试-8', + number: 456.464, }, { - '2d7feabd-76a2-4c11-8f24-79764af936b4': '测试-6', - 'c5ce4e54-795a-42b3-9cc8-e8b685da44ee': 123.416, + first: '测试-6', + number: 123.416, }, ], }; @@ -181,7 +187,6 @@ describe('Miss Dimension Values Tests', () => { test('should get correctly empty dimension values', () => { const emptyDimensionValueNode = s2.getRowNodes()[0].children[0]; - expect(emptyDimensionValueNode.value).toEqual(EMPTY_FIELD_VALUE); expect(emptyDimensionValueNode.id).toEqual( `root[&]总计[&]${EMPTY_FIELD_VALUE}`, @@ -203,6 +208,18 @@ describe('Miss Dimension Values Tests', () => { ); }); + test('should generate correct query for empty node', () => { + const emptyDimensionValueNode1 = s2.facet.layoutResult.rowNodes[0]; + expect(emptyDimensionValueNode1.query).toEqual({ + first: '总计', + }); + + const emptyDimensionValueNode2 = s2.facet.layoutResult.rowNodes[1]; + expect(emptyDimensionValueNode2.query).toEqual({ + first: '总计', + }); + }); + test('should get correctly dimension data and ignore empty dimension value', () => { const emptyDimensionValueNode = s2.getRowNodes()[0].children[0]; @@ -221,10 +238,10 @@ describe('Miss Dimension Values Tests', () => { Array [ Array [ Object { - "$$extra$$": "c5ce4e54-795a-42b3-9cc8-e8b685da44ee", + "$$extra$$": "number", "$$value$$": 1732771, - "2d7feabd-76a2-4c11-8f24-79764af936b4": "总计", - "c5ce4e54-795a-42b3-9cc8-e8b685da44ee": 1732771, + "first": "总计", + "number": 1732771, }, ], ] diff --git a/packages/s2-core/src/utils/layout/get-dims-condition-by-node.ts b/packages/s2-core/src/utils/layout/get-dims-condition-by-node.ts index 3bc44b3b31..b87cbd452c 100644 --- a/packages/s2-core/src/utils/layout/get-dims-condition-by-node.ts +++ b/packages/s2-core/src/utils/layout/get-dims-condition-by-node.ts @@ -1,3 +1,4 @@ +import { EMPTY_FIELD_VALUE } from '../../common/constant'; import type { Node } from '../../facet/layout/node'; export function getDimsCondition(parent: Node, force?: boolean) { @@ -8,7 +9,7 @@ export function getDimsCondition(parent: Node, force?: boolean) { * 当为表格布局时,小计行的内容是“小计”不需要作为筛选条件 * 当为树状布局时,force可以强行指定小计行,即父类目作为筛选条件 */ - if (!p.isTotalRoot || force) { + if ((!p.isTotalRoot || force) && p.value !== EMPTY_FIELD_VALUE) { cond[p.key] = p.value; } p = p.parent;