Skip to content

Commit

Permalink
fix: 修复总计小计被意外 format 的问题 (#2209)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjgogogo authored May 15, 2023
1 parent 1a404e1 commit 6e98291
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
30 changes: 30 additions & 0 deletions packages/s2-core/__tests__/unit/cell/header-cell-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,36 @@ describe('header cell formatter test', () => {
expect(rowCell.getFieldValue()).toBe('杭州1');
});

test('should not format pivot col and row total cell', () => {
const colNode = new Node({
id: `root[&]总计`,
key: '',
value: '总计',
parent: root,
label: '总计',
isTotals: true,
});
const rowNode = new Node({
id: `root[&]杭州[&]小计`,
key: '',
value: '小计',
parent: root,
label: '小计',
isTotals: true,
});

const formatter: Formatter = (value) => {
return `${value}1`;
};
jest.spyOn(s2.dataSet, 'getFieldFormatter').mockReturnValue(formatter);

const colCell = new ColCell(colNode, s2);
const rowCell = new RowCell(rowNode, s2);

expect(colCell.getFieldValue()).toBe('总计');
expect(rowCell.getFieldValue()).toBe('小计');
});

test('pivot corner cell not formatter', () => {
const formatter: Formatter = (value) => {
return `${value}1`;
Expand Down
7 changes: 4 additions & 3 deletions packages/s2-core/src/cell/header-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,17 @@ export abstract class HeaderCell extends BaseCell<Node> {
}

protected getFormattedFieldValue(): FormatResult {
const { label } = this.meta;
const { label, isTotals } = this.meta;

const formatter = this.spreadsheet.dataSet.getFieldFormatter(
this.meta.field,
);

const isTableMode = this.spreadsheet.isTableMode();
// 如果是 总计/小计 文字单元格,不需要被格式化
// 如果是 table mode,列头不需要被格式化
const isTableMode = this.spreadsheet.isTableMode();
const formattedValue =
formatter && !isTableMode
formatter && !isTableMode && !isTotals
? formatter(label, undefined, this.meta)
: label;

Expand Down

1 comment on commit 6e98291

@vercel
Copy link

@vercel vercel bot commented on 6e98291 May 15, 2023

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-git-master-antv-s2.vercel.app
antvis-s2.vercel.app
antvis-s2-antv-s2.vercel.app

Please sign in to comment.