Skip to content

Commit

Permalink
fix: 修复在维值缺失场景下导出数据占位符未解析的问题 (#3027)
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 authored Dec 13, 2024
1 parent 0a7977c commit 6e63b97
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ exports[`Miss Dimension Values Tests should replace empty dimension value placeh

exports[`Miss Dimension Values Tests should replace empty dimension value placeholder when copy original data 1`] = `
"first second third number
总计 $$empty_field_value$$ $$empty_field_value$$ 1732771
总计 - - 1732771
维值-1 维值-2 维度-3 12222
维值-1 维值-3 维值-3 11111
维值-1 维值-3 维度-3 11111
维值-1 维值-3 小计
维值-1 小计 456
测试-1 测试-2 维度-3 4444567
测试-1 测试-3 $$empty_field_value$$ 785222
测试-1 测试-3 - 785222
测试-1 测试-4 维度-3 6455644
测试-1 测试-5 维度-3 1111
测试-1 小计 125555
测试-6 测试-x $$empty_field_value$$ 111111
测试-6 测试-7 $$empty_field_value$$ 67878
测试-6 测试-8 $$empty_field_value$$ 456.464
测试-6 测试-x - 111111
测试-6 测试-7 - 67878
测试-6 测试-8 - 456.464
测试-6 小计 123.416"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
totalData as drillDownTotalData,
} from 'tests/data/mock-drill-down-dataset.json';
import { assembleDataCfg } from 'tests/util';
import { EMPTY_FIELD_VALUE } from '../../../src';

jest.mock('@/sheet-type');

Expand Down Expand Up @@ -510,6 +511,7 @@ describe('Pivot Dataset Test', () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
expect(dataSet.getFieldName(['1'])).toEqual(['1']);
expect(dataSet.getFieldName(EMPTY_FIELD_VALUE)).toStrictEqual('-');
});

test('should return correct field meta', () => {
Expand Down
19 changes: 18 additions & 1 deletion packages/s2-core/__tests__/unit/utils/text-spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ELLIPSIS_SYMBOL } from '@/common';
import { ELLIPSIS_SYMBOL, EMPTY_FIELD_VALUE } from '@/common';
import {
drawCustomContent,
getCellWidth,
Expand All @@ -8,6 +8,7 @@ import {
isUnchangedValue,
isUpDataValue,
isZeroOrEmptyValue,
replaceEmptyFieldValue,
} from '@/utils/text';
import {
createFakeSpreadSheet,
Expand Down Expand Up @@ -385,3 +386,19 @@ describe('getDisplayText', () => {
expect(getDisplayText(value, '@')).toEqual(result);
});
});

describe('replaceEmptyFieldValue', () => {
test.each`
value | result
${'value'} | ${'value'}
${EMPTY_FIELD_VALUE} | ${'-'}
${undefined} | ${undefined}
${0} | ${0}
${NaN} | ${NaN}
`(
'should get correct empty field display value for $value',
({ value, result }) => {
expect(replaceEmptyFieldValue(value)).toEqual(result);
},
);
});
8 changes: 6 additions & 2 deletions packages/s2-core/src/data-set/base-data-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ import {
} from '../utils/condition/state-controller';
import { generateExtraFieldMeta } from '../utils/dataset/pivot-data-set';
import type { Indexes } from '../utils/indexes';
import { getDisplayText, getEmptyPlaceholder } from '../utils/text';
import {
getDisplayText,
getEmptyPlaceholder,
replaceEmptyFieldValue,
} from '../utils/text';
import type { GetCellMultiDataParams } from './index';
import type { GetCellDataParams, Query } from './interface';

Expand Down Expand Up @@ -145,7 +149,7 @@ export abstract class BaseDataSet {
return get(
this.getFieldMeta(realField, this.meta),
'name',
defaultValue ?? realDefaultValue,
replaceEmptyFieldValue(defaultValue ?? realDefaultValue),
);
}

Expand Down
4 changes: 3 additions & 1 deletion packages/s2-core/src/utils/export/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import type { Node } from '../../facet/layout/node';
import type { SpreadSheet } from '../../sheet-type';
import { resolveNillString } from '../layout';
import { replaceEmptyFieldValue } from '../text';

export function keyEqualTo(key: string, compareKey: string) {
if (!key || !compareKey) {
Expand Down Expand Up @@ -64,8 +65,9 @@ export const getHeaderMeasureFieldNames = (
}

// https://github.com/antvis/S2/issues/2688
// https://github.com/antvis/S2/pull/2829
if (!formatHeader) {
return resolveNillString(field);
return replaceEmptyFieldValue(resolveNillString(field)!);
}

return spreadsheet.dataSet.getFieldName(field);
Expand Down

0 comments on commit 6e63b97

Please sign in to comment.