Skip to content

Commit

Permalink
fix: 修复自定义目录树同名节点展示异常 close #2455
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Feb 19, 2024
1 parent 93e1151 commit 2f40aca
Show file tree
Hide file tree
Showing 23 changed files with 633 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ exports[`SpreadSheet Custom Tree Tests should collapse node by collapsed 1`] = `
Array [
Object {
"iconName": "Plus",
"id": "root[&]自定义节点A",
"id": "root[&]custom-node-1",
"isCollapsed": true,
"value": "自定义节点A",
},
Object {
"iconName": "Plus",
"id": "root[&]指标E",
"id": "root[&]measure-e",
"isCollapsed": true,
"value": "指标E",
},
]
`;
Expand All @@ -46,32 +50,68 @@ exports[`SpreadSheet Custom Tree Tests should collapse node by collapsed field 1
Array [
Object {
"iconName": "Minus",
"id": "root[&]自定义节点 a-1",
"id": "root[&]a-1",
"isCollapsed": false,
"value": "自定义节点 a-1",
},
Object {
"iconName": "Plus",
"id": "root[&]自定义节点 a-1[&]自定义节点 a-1-1",
"id": "root[&]a-1[&]a-1-1",
"isCollapsed": true,
"value": "自定义节点 a-1-1",
},
Object {
"iconName": undefined,
"id": "root[&]自定义节点 a-1[&]自定义节点 a-1-2",
"id": "root[&]a-1[&]a-1-2",
"isCollapsed": false,
"value": "自定义节点 a-1-2",
},
Object {
"iconName": undefined,
"id": "root[&]自定义节点 a-2",
"id": "root[&]a-2",
"isCollapsed": false,
"value": "自定义节点 a-2",
},
]
`;

exports[`SpreadSheet Custom Tree Tests should collapse node by collapsed fields id 1`] = `
Array [
Object {
"iconName": "Plus",
"id": "root[&]自定义节点 a-1",
"iconName": "Minus",
"id": "root[&]a-1",
"isCollapsed": false,
"value": "自定义节点 a-1",
},
Object {
"iconName": "Minus",
"id": "root[&]a-1[&]a-1-1",
"isCollapsed": false,
"value": "自定义节点 a-1-1",
},
Object {
"iconName": undefined,
"id": "root[&]a-1[&]a-1-1[&]measure-1",
"isCollapsed": false,
"value": "指标1",
},
Object {
"iconName": undefined,
"id": "root[&]a-1[&]a-1-1[&]measure-2",
"isCollapsed": false,
"value": "指标2",
},
Object {
"iconName": undefined,
"id": "root[&]a-1[&]a-1-2",
"isCollapsed": false,
"value": "自定义节点 a-1-2",
},
Object {
"iconName": undefined,
"id": "root[&]自定义节点 a-2",
"id": "root[&]a-2",
"isCollapsed": false,
"value": "自定义节点 a-2",
},
]
`;
Expand All @@ -80,11 +120,44 @@ exports[`SpreadSheet Custom Tree Tests should collapse node by user collapseFiel
Array [
Object {
"iconName": "Plus",
"id": "root[&]自定义节点A",
"id": "root[&]custom-node-1",
"isCollapsed": true,
"value": "自定义节点A",
},
Object {
"iconName": "Plus",
"id": "root[&]measure-e",
"isCollapsed": true,
"value": "指标E",
},
]
`;

exports[`SpreadSheet Custom Tree Tests should only collapse first node by node id 1`] = `
Array [
Object {
"iconName": "Plus",
"id": "root[&]custom-node-1",
"isCollapsed": true,
"value": "自定义节点A",
},
Object {
"iconName": "Minus",
"id": "root[&]measure-e",
"isCollapsed": false,
"value": "自定义节点A",
},
Object {
"iconName": undefined,
"id": "root[&]measure-e[&]custom-node-3",
"isCollapsed": false,
"value": "自定义节点C",
},
Object {
"iconName": "Plus",
"id": "root[&]指标E",
"id": "root[&]measure-e[&]custom-node-4",
"isCollapsed": true,
"value": "自定义节点D",
},
]
`;
Expand Down
45 changes: 36 additions & 9 deletions packages/s2-core/__tests__/spreadsheet/custom-tree-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ describe('SpreadSheet Custom Tree Tests', () => {

return {
id: node.id,
value: node.value,
isCollapsed: node.isCollapsed,
iconName,
};
});
Expand Down Expand Up @@ -119,7 +121,7 @@ describe('SpreadSheet Custom Tree Tests', () => {
// 选中单元格本身
expect(s2.interaction.getActiveCells()).toHaveLength(1);
// 高亮子节点
expectHighlightActiveNodes(s2, ['root[&]自定义节点 a-1']);
expectHighlightActiveNodes(s2, ['root[&]a-1']);

// 取消选中 a - 1
s2.interaction.selectHeaderCell({
Expand Down Expand Up @@ -158,11 +160,10 @@ describe('SpreadSheet Custom Tree Tests', () => {

test('should render custom corner text by default title', async () => {
s2.setDataCfg({
...customRowDataCfg,
meta: [],
});

await s2.render();
await s2.render(true);

const cornerCellLabels = getCornerCellLabels();

Expand All @@ -174,7 +175,6 @@ describe('SpreadSheet Custom Tree Tests', () => {

test('should render custom corner text by meta formatter', async () => {
s2.setDataCfg({
...customRowDataCfg,
meta: [
{
field: 'a-1',
Expand All @@ -187,7 +187,7 @@ describe('SpreadSheet Custom Tree Tests', () => {
],
});

await s2.render();
await s2.render(true);
const cornerCellLabels = getCornerCellLabels();

expect(cornerCellLabels).toEqual(['文本1/文本2/数值', 'type']);
Expand Down Expand Up @@ -224,9 +224,7 @@ describe('SpreadSheet Custom Tree Tests', () => {

test('should collapse node by collapsed', async () => {
s2.setDataCfg({
...customRowDataCfg,
fields: {
...s2.dataSet.fields,
rows: customTreeNodes.map((node) => {
return {
...node,
Expand Down Expand Up @@ -273,9 +271,7 @@ describe('SpreadSheet Custom Tree Tests', () => {
const collapsedField = 'custom-node-1';

s2.setDataCfg({
...customRowDataCfg,
fields: {
...s2.dataSet.fields,
rows: customTreeNodes.map((node) => {
return {
...node,
Expand All @@ -298,4 +294,35 @@ describe('SpreadSheet Custom Tree Tests', () => {

expect(mapRowNodes(s2)).toMatchSnapshot();
});

// https://github.com/antvis/S2/issues/2455
test('should only collapse first node by node id', async () => {
const collapsedField = 'custom-node-1';

s2.setDataCfg({
fields: {
rows: customTreeNodes.map((node) => {
return {
...node,
// 让两个节点名一样
title: '自定义节点A',
collapsed: false,
};
}),
},
});

s2.setOptions({
style: {
rowCell: {
collapseFields: {
[collapsedField]: true,
},
},
},
});
await s2.render(true);

expect(mapRowNodes(s2)).toMatchSnapshot();
});
});
3 changes: 0 additions & 3 deletions packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,16 +457,13 @@ describe('SpreadSheet Hidden Columns Tests', () => {
.find((node) => node.isGrandTotals)!;

const rootNode = pivotSheet.facet.getColNodeById('root[&]笔')!;
const parentNode = pivotSheet.facet.getColNodeById('root[&]笔[&]义乌')!;

const hiddenColumnsInfo = pivotSheet.store.get('hiddenColumnsDetail')[0];

expect(rootNode.width).toEqual(100);
expect(rootNode.x).toEqual(100);
expect(grandTotalsNode.width).toEqual(100);
expect(grandTotalsNode.x).toEqual(0);
expect(hiddenColumnsInfo).toBeTruthy();
expect(parentNode.hiddenChildNodeInfo).toEqual(hiddenColumnsInfo);
});

// https://github.com/antvis/S2/issues/2355
Expand Down
Loading

0 comments on commit 2f40aca

Please sign in to comment.