Skip to content

Commit

Permalink
fix: 增加树状模式自定义宽度的容错 (#2519)
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Jan 18, 2024
1 parent 47a34d4 commit 552cecd
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SpreadSheet Resize Active Tests should render correctly layout when tree row width is invalid number 1`] = `
Array [
Object {
"height": 30,
"id": "root[&]浙江",
"width": 120,
},
Object {
"height": 30,
"id": "root[&]浙江[&]义乌",
"width": 120,
},
Object {
"height": 30,
"id": "root[&]浙江[&]杭州",
"width": 120,
},
]
`;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
KEY_GROUP_COL_RESIZE_AREA,
} from '../../src';

async function renderSheet(options: S2Options) {
async function renderSheet(options?: S2Options) {
const s2 = new PivotSheet(getContainer(), mockDataConfig, {
height: 150,
...options,
Expand All @@ -22,6 +22,7 @@ async function renderSheet(options: S2Options) {
},
},
});

await s2.render();

return s2;
Expand Down Expand Up @@ -191,4 +192,31 @@ describe('SpreadSheet Resize Active Tests', () => {
expect(group.getElementById(KEY_GROUP_ROW_RESIZE_AREA)).toBeNull();
expect(group.getElementById(KEY_GROUP_CORNER_RESIZE_AREA)).toBeNull();
});

test('should render correctly layout when tree row width is invalid number', async () => {
const s2 = await renderSheet();

s2.setOptions({
hierarchyType: 'tree',
style: {
rowCell: {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
width: '@',
},
},
});

await s2.render(false);

const nodes = s2.facet.getRowNodes().map((node) => {
return {
id: node.id,
width: node.width,
height: node.height,
};
});

expect(nodes).toMatchSnapshot();
});
});
3 changes: 1 addition & 2 deletions packages/s2-core/src/facet/pivot-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
get,
isArray,
isEmpty,
isNil,
isNumber,
keys,
last,
Expand Down Expand Up @@ -726,7 +725,7 @@ export class PivotFacet extends FrozenFacet {
// 1. 用户拖拽或手动指定的行头宽度优先级最高
const customRowWidth = this.getCellCustomSize(null, rowCell?.width!);

if (!isNil(customRowWidth)) {
if (isNumber(customRowWidth)) {
return customRowWidth;
}

Expand Down

0 comments on commit 552cecd

Please sign in to comment.