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(table-sheet): 明细表数据为空时错误的展示一行空数据 close #2255 #2357

Merged
merged 5 commits into from
Oct 11, 2023
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
Expand Up @@ -158,6 +158,10 @@ describe('Pivot Dataset Test', () => {
getDimensionsWithoutPathPre(sortedDimensionValues[EXTRA_FIELD]),
).toEqual(['number', 'number', 'number', 'number']);
});

test('should get correctly empty dataset result', () => {
expect(dataSet.isEmpty()).toBeFalsy();
});
});

describe('test for query data', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ describe('Table Mode Dataset Test', () => {
test('should get correct meta data', () => {
expect(dataSet.meta).toEqual(expect.objectContaining([]));
});

test('should get correctly empty dataset result', () => {
expect(dataSet.isEmpty()).toBeFalsy();
});
});

describe('test for query data', () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/s2-core/__tests__/unit/facet/table-facet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import { getFrozenLeafNodesCount } from '@/facet/utils';
import { SpreadSheet } from '@/sheet-type';
import { getTheme } from '@/theme';

const actualDataSet = jest.requireActual(
'@/data-set/base-data-set',
).BaseDataSet;

jest.mock('@/sheet-type', () => {
const container = new Canvas({
width: 100,
Expand Down Expand Up @@ -59,6 +61,9 @@
interaction: {
clearHoverTimer: jest.fn(),
},
dataSet: {
isEmpty: jest.fn(),
},
};
}),
};
Expand All @@ -77,6 +82,7 @@
getCellData: () => 1,
getFieldMeta: jest.fn(),
getFieldFormatter: actualDataSet.prototype.getFieldFormatter,
isEmpty: jest.fn(),
};
}),
};
Expand Down Expand Up @@ -764,7 +770,7 @@
});

test('should get correct col layout with frozen col', () => {
const { width } = facet.spreadsheet.options;

Check warning on line 773 in packages/s2-core/__tests__/unit/facet/table-facet-spec.ts

View workflow job for this annotation

GitHub Actions / lint (18)

'width' is assigned a value but never used
const { frozenColCount } = facet.cfg;
const { colNodes } = facet.layoutResult;
const topLevelNodes = colNodes.filter((node) => node.parent.id === 'root');
Expand Down
1 change: 1 addition & 0 deletions packages/s2-core/src/cell/table-col-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class TableColCell extends ColCell {
y,
};
}

return {
x: position.x + x - scrollX,
y: position.y + y,
Expand Down
5 changes: 5 additions & 0 deletions packages/s2-core/src/data-set/base-data-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
find,
get,
identity,
isEmpty,
isNil,
map,
max,
Expand Down Expand Up @@ -117,6 +118,10 @@ export abstract class BaseDataSet {
return this.displayData;
}

public isEmpty() {
return isEmpty(this.getDisplayDataSet());
}

public getValueRangeByField(field: string): ValueRange {
const cacheRange = getValueRangeState(this.spreadsheet, field);
if (cacheRange) {
Expand Down
21 changes: 12 additions & 9 deletions packages/s2-core/src/facet/table-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
getFrozenRowsForGrid,
getRowsForGrid,
} from '../utils/grid';
import type { PanelIndexes } from '../utils/indexes';
import type { Indexes, PanelIndexes } from '../utils/indexes';
import { getValidFrozenOptions } from '../utils/layout/frozen';
import { BaseFacet } from './base-facet';
import { CornerBBox } from './bbox/cornerBBox';
Expand Down Expand Up @@ -1129,14 +1129,17 @@ export class TableFacet extends BaseFacet {
}
}

const indexes = calculateInViewIndexes(
scrollX,
scrollY,
this.viewCellWidths,
this.viewCellHeights,
finalViewport,
this.getRealScrollX(this.cornerBBox.width),
);
// https://github.com/antvis/S2/issues/2255
const indexes = this.spreadsheet.dataSet.isEmpty()
? ([] as unknown as Indexes)
: calculateInViewIndexes(
scrollX,
scrollY,
this.viewCellWidths,
this.viewCellHeights,
finalViewport,
this.getRealScrollX(this.cornerBBox.width),
);

this.panelScrollGroupIndexes = indexes;

Expand Down
1 change: 1 addition & 0 deletions packages/s2-core/src/sheet-type/table-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export class TableSheet extends SpreadSheet {
}
return new TableDataCell(facet, this);
};

return {
...this.options,
...fields,
Expand Down
1 change: 1 addition & 0 deletions s2-site/docs/api/basic-class/base-data-set.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ s2.dataSet.getFieldName('type')
| getCellData | 获取单个的单元格数据 | (params: [CellDataParams](#celldataparams)) => [DataType[]](#datatype) | |
| getMultiData | 获取批量的单元格数据 | (query: [DataType](#datatype), isTotals?: boolean, isRow?: boolean, drillDownFields?: string[]) => [DataType[]](#datatype) | |
| moreThanOneValue | 是否超过 1 个数值 | () => [ViewMeta](#viewmeta) | |
| isEmpty | 是否为空数据集 | () => `boolean` | `@antv/s2-v1.51.1` |

### DataType

Expand Down
Loading