Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复维值带有 '-' 时刷选复制无法复制表头 close #2684 #2691

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`PivotSheet Special Dimension Values Copy Tests should correctly copy data with header 1`] = `
" 两片罐事业部 宝翼制罐 河北制罐 成都制罐 哈尔滨制罐
dq dq dq dq dq
2018年-三月 53332
2019年-三月 53332
2023年-三月 53332 67456 53332 66293.333333 97192.090909
2023年-四月 67454 0 70442.733333 56665 100535.760606
2023年-五月 23566 -10000 73786.40303 65554 103879.430303
2023年-六月 67456 22222 77130.072727 53332 107223.1
2023年-七月 0 39998 80473.742424 70442.733333 61292.833333
2023年-八月 0 48877 83817.412121 73786.40303 66293.333333
2023年-九月 22222 49999 87161.081818 77130.072727 56665"
`;
60 changes: 60 additions & 0 deletions packages/s2-core/__tests__/bugs/issue-2684-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* 透视表维值含有 "-", 复制数据时表头缺失
* @description spec for issue #2684
* https://github.com/antvis/S2/issues/2684
*/

import { isEmpty } from 'lodash';
import { InteractionStateName } from '../../src';
import { getSelectedData } from '../../src/utils/export/copy';
import * as mockDataConfig from '../data/data-issue-2684.json';
import { createPivotSheet } from '../util/helpers';
import type { S2Options, SpreadSheet } from '@/index';

const s2Options: S2Options = {
width: 600,
height: 480,
interaction: {
enableCopy: true,
copyWithHeader: true,
copyWithFormat: true,
brushSelection: {
data: true,
row: true,
col: true,
},
multiSelection: true,
},
};

describe('PivotSheet Special Dimension Values Copy Tests', () => {
let s2: SpreadSheet;

beforeEach(() => {
s2 = createPivotSheet(s2Options);
s2.setDataCfg(mockDataConfig);
s2.render();
});

test('should correctly copy data with header', () => {
const { rowLeafNodes, colLeafNodes } = s2.facet.layoutResult;
const cells = s2.interaction.getPanelGroupAllDataCells().map((cell) => {
const meta = cell.getMeta();
const colId = String(colLeafNodes[meta.colIndex].id);
const rowId = isEmpty(rowLeafNodes)
? String(meta.rowIndex)
: String(rowLeafNodes[meta.rowIndex].id);

return { ...meta, colId, rowId };
});

s2.interaction.changeState({
cells,
stateName: InteractionStateName.SELECTED,
});

const data = getSelectedData(s2);

expect(data).toMatchSnapshot();
});
});
Loading
Loading