Skip to content

Commit

Permalink
fix: 修复明细表在 dataCfg 为空, 同时开启序号列时, 错误的渲染了占位符的问题 (#3042)
Browse files Browse the repository at this point in the history
* fix: 修复明细表在 dataCfg 为空, 同时开启序号列时, 错误的渲染了占位符的问题

* docs: 更新文档
  • Loading branch information
lijinke666 authored Dec 20, 2024
1 parent b3a83e7 commit feab43f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
49 changes: 26 additions & 23 deletions packages/s2-core/__tests__/spreadsheet/table-sheet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,29 +431,32 @@ describe('TableSheet normal spec', () => {
await expectEmptyPlaceholder(s2);
});

test('should not render empty placeholder if all fields is empty', async () => {
const s2 = new TableSheet(
getContainer(),
{ ...dataCfg, fields: {}, data: [] },
{
...options,
frozen: {},
seriesNumber: {
enable: false,
test.each([{ showSeriesNumber: true }, { showSeriesNumber: false }])(
'should not render empty placeholder if all fields is empty for %o',
async ({ showSeriesNumber }) => {
const s2 = new TableSheet(
getContainer(),
{ ...dataCfg, fields: {}, data: [] },
{
...options,
frozen: {},
seriesNumber: {
enable: showSeriesNumber,
},
},
},
);

await s2.render();
const [rect, icon, text] = (s2.facet as TableFacet).emptyPlaceholderGroup
.children;

expect(
(s2.facet as TableFacet).emptyPlaceholderGroup.children,
).toHaveLength(0);
expect(rect).not.toBeDefined();
expect(icon).not.toBeDefined();
expect(text).not.toBeDefined();
});
);

await s2.render();
const [rect, icon, text] = (s2.facet as TableFacet)
.emptyPlaceholderGroup.children;

expect(
(s2.facet as TableFacet).emptyPlaceholderGroup.children,
).toHaveLength(0);
expect(rect).not.toBeDefined();
expect(icon).not.toBeDefined();
expect(text).not.toBeDefined();
},
);
});
});
9 changes: 9 additions & 0 deletions packages/s2-core/src/facet/table-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ export class TableFacet extends FrozenFacet {
this.initEmptyPlaceholderGroup();
}

protected shouldRender(): boolean {
const { fields } = this.spreadsheet.dataSet;
const isOnlyContainedSeriesNumber = fields?.columns?.every(
(field) => field === SERIES_NUMBER_FIELD,
);

return super.shouldRender() && !isOnlyContainedSeriesNumber;
}

public render() {
if (!this.shouldRender()) {
return;
Expand Down
1 change: 1 addition & 0 deletions s2-site/docs/common/development.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ pnpm react:test -- -u
pnpm lint

# 本地启动官网
pnpm build # 首次运行官网需要先执行一次
pnpm site:start
```

0 comments on commit feab43f

Please sign in to comment.