Skip to content

Commit

Permalink
fix: 修复数值单元格 tooltip 内的指标名展示错误 (#2941)
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 authored Oct 25, 2024
1 parent 523b2cc commit a426a46
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,32 @@ Object {
}
`;

exports[`Tooltip Utils Tests Tooltip Get Data Tests should get correctly data cell details 1`] = `
Object {
"description": undefined,
"details": Array [
Object {
"name": "number",
"value": 7789,
},
],
"headInfo": Object {
"cols": Array [],
"rows": Array [
Object {
"name": undefined,
"value": "-",
},
],
},
"infos": undefined,
"interpretation": undefined,
"name": null,
"summaries": Array [],
"tips": undefined,
}
`;

exports[`Tooltip Utils Tests Tooltip Get Data Tests should get custom tree row cell summary data 1`] = `
Object {
"description": "指标1描述",
Expand Down
24 changes: 24 additions & 0 deletions packages/s2-core/__tests__/unit/utils/tooltip-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,30 @@ describe('Tooltip Utils Tests', () => {
expect(tooltipData).toEqual(defaultTooltipData);
});

test('should get correctly data cell details', () => {
s2 = createPivotSheet();

const cell = createMockCellInfo('test-a');
const tooltipData = getTooltipData({
cellInfos: [
getCellData(7789, false, {
sub_type: '桌子',
type: '家具',
}),
],
options: {
enableFormat: true,
isTotals: false,
hideSummary: true,
onlyShowCellText: false,
},
targetCell: cell.mockCell,
spreadsheet: s2,
});

expect(tooltipData).toMatchSnapshot();
});

test.each([
{ count: 1, isTotalCell: true, name: '单选' },
{ count: 4, isTotalCell: false, name: '多选' },
Expand Down
8 changes: 5 additions & 3 deletions packages/s2-core/src/utils/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,11 @@ export const getListItem = (
targetCell?: S2CellType;
},
): TooltipDetailListItem => {
const name =
spreadsheet?.dataSet.getCustomRowFieldName(targetCell!) ||
spreadsheet?.dataSet?.getFieldName(field);
const defaultFieldName = spreadsheet?.dataSet?.getFieldName(field);
const name = spreadsheet.isCustomRowFields()
? spreadsheet?.dataSet.getCustomRowFieldName(targetCell!) ||
defaultFieldName
: defaultFieldName;

const formatter = spreadsheet?.dataSet?.getFieldFormatter(field);

Expand Down

0 comments on commit a426a46

Please sign in to comment.