Skip to content

Commit

Permalink
fix: 列头label存在数组,复制导出列头层级补齐错误 (#1990)
Browse files Browse the repository at this point in the history
* fix: 列头label存在数组,层级补齐错误
当headers存在数组,但不是每一列都存在数组时,仅需要对header[0]为数组的项进行补齐(当列各层级都是string类型时会补齐过多的空格)

* test: 添加单测
  • Loading branch information
mmmml-zhao authored Dec 22, 2022
1 parent 8d28254 commit ec62409
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
12 changes: 9 additions & 3 deletions packages/s2-core/src/utils/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,15 @@ const getPlaceholder = (
*/
const processColHeaders = (headers: any[][]) => {
const result = headers.map((header) =>
header.map((item) =>
isArray(item) ? item : [item, ...new Array(header[0].length - 1)],
),
header.map((item) => {
if (isArray(item)) {
return item;
}
if (isArray(header[0])) {
return [item, ...new Array(header[0].length - 1)];
}
return item;
}),
);
return result;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<StrategySheet/> Tests StrategySheet Export Tests should export correct data 1`] = `
" \\"日期\\" \\"2022-09\\" \\"2022-10\\" \\"2022-11\\" \\"2021年净增完成度\\" \\"趋势\\" \\"2022\\"
\\"数值\\" \\"数值\\" \\"环比\\" \\"同比\\" \\"数值\\" \\"环比\\" \\"数值\\" \\"环比\\" \\"同比\\" \\"净增完成度\\" \\"趋势\\" \\"数值\\" \\"环比\\"
" \\"日期\\" \\"2022-09\\" \\"2022-10\\" \\"2022-11\\" \\"2021年净增完成度\\" \\"趋势\\" \\"2022\\"
\\"数值\\" \\"数值\\" \\"环比\\" \\"同比\\" \\"数值\\" \\"环比\\" \\"数值\\" \\"环比\\" \\"同比\\" \\"净增完成度\\" \\"趋势\\" \\"数值\\" \\"环比\\"
\\"自定义节点A\\"
\\"自定义节点A\\" \\"指标A\\" \\"377\\" \\"3877\\" \\"4324\\" \\"0.42\\" \\"377\\"
\\"自定义节点A\\" \\"指标A\\" \\"指标B\\" \\"377\\" \\"324\\" \\"377\\" \\"324\\" \\"-0.02\\" \\"377\\" \\"324\\"
Expand All @@ -16,8 +16,8 @@ exports[`<StrategySheet/> Tests StrategySheet Export Tests should export correct
`;

exports[`<StrategySheet/> Tests StrategySheet Export Tests should export correct data for empty cell 1`] = `
" \\"日期\\" \\"2022-09\\" \\"2022-10\\" \\"2022-11\\" \\"2021年净增完成度\\" \\"趋势\\" \\"2022\\"
\\"数值\\" \\"数值\\" \\"环比\\" \\"同比\\" \\"数值\\" \\"环比\\" \\"数值\\" \\"环比\\" \\"同比\\" \\"净增完成度\\" \\"趋势\\" \\"数值\\" \\"环比\\"
" \\"日期\\" \\"2022-09\\" \\"2022-10\\" \\"2022-11\\" \\"2021年净增完成度\\" \\"趋势\\" \\"2022\\"
\\"数值\\" \\"数值\\" \\"环比\\" \\"同比\\" \\"数值\\" \\"环比\\" \\"数值\\" \\"环比\\" \\"同比\\" \\"净增完成度\\" \\"趋势\\" \\"数值\\" \\"环比\\"
\\"自定义节点A\\"
\\"自定义节点A\\" \\"指标A\\" \\"377\\" \\"3877\\" \\"4324\\" \\"0.42\\" \\"377\\"
\\"自定义节点A\\" \\"指标A\\" \\"指标B\\" \\"377\\" \\"324\\" \\"377\\" \\"324\\" \\"-0.02\\" \\"377\\" \\"324\\"
Expand All @@ -31,8 +31,8 @@ exports[`<StrategySheet/> Tests StrategySheet Export Tests should export correct
`;

exports[`<StrategySheet/> Tests StrategySheet Export Tests should export correct data for multi different cycle compare data 1`] = `
" \\"日期\\" \\"2022-09\\" \\"2022-10\\" \\"2022-11\\" \\"2021年净增完成度\\" \\"趋势\\" \\"2022\\"
\\"数值\\" \\"数值\\" \\"环比\\" \\"同比\\" \\"数值\\" \\"环比\\" \\"数值\\" \\"环比\\" \\"同比\\" \\"净增完成度\\" \\"趋势\\" \\"数值\\" \\"环比\\"
" \\"日期\\" \\"2022-09\\" \\"2022-10\\" \\"2022-11\\" \\"2021年净增完成度\\" \\"趋势\\" \\"2022\\"
\\"数值\\" \\"数值\\" \\"环比\\" \\"同比\\" \\"数值\\" \\"环比\\" \\"数值\\" \\"环比\\" \\"同比\\" \\"净增完成度\\" \\"趋势\\" \\"数值\\" \\"环比\\"
\\"自定义节点A\\"
\\"自定义节点A\\" \\"指标A\\" \\"377\\" \\"3877\\" \\"4324\\" \\"0.42\\" \\"377\\"
\\"自定义节点A\\" \\"指标A\\" \\"指标B\\" \\"377\\" \\"324\\" \\"377\\" \\"324\\" \\"-0.02\\" \\"377\\" \\"324\\"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,21 @@ describe('<StrategySheet/> Tests', () => {
expect(result).toMatchSnapshot();
expect(detailRow).toEqual([`"自定义节点A"`, `"指标A"`, '', '', '']);
});

test('should export correct headers when label have array and string', () => {
const result = copyData(s2, '\t');
const rows = result.split('\n');
expect(rows[0].split('\t')[8]).toEqual('"2022-11"');
expect(rows[0].split('\t')[11]).toEqual('"2021年净增完成度"');
expect(rows[0].split('\t')[12]).toEqual('"趋势"');
expect(rows[0].split('\t')[13]).toEqual('"2022"');
expect(rows[1].split('\t')[8]).toEqual('"数值"');
expect(rows[1].split('\t')[9]).toEqual('"环比"');
expect(rows[1].split('\t')[10]).toEqual('"同比"');
expect(rows[1].split('\t')[11]).toEqual('"净增完成度"');
expect(rows[1].split('\t')[12]).toEqual('"趋势"');
expect(rows[1].split('\t')[13]).toEqual('"数值"');
});
});

describe('StrategySheet Interaction Tests', () => {
Expand Down

1 comment on commit ec62409

@vercel
Copy link

@vercel vercel bot commented on ec62409 Dec 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

antvis-s2 – ./

antvis-s2-antv-s2.vercel.app
antvis-s2-git-master-antv-s2.vercel.app
antvis-s2.vercel.app

Please sign in to comment.