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: 修复明细表在 dataCfg 为空, 同时开启序号列时, 错误的渲染了占位符的问题 #3042

Merged
merged 2 commits into from
Dec 20, 2024
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
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(
Copy link
Member Author

@lijinke666 lijinke666 Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

dataCfg 为空时, 明细表开启序号, columns 会添加 SERIES_NUMBER_FIELD, 所以 shouldRender() 没有拦截到, 这种情况不应该渲染

(field) => field === SERIES_NUMBER_FIELD,
);

return super.shouldRender() && !isOnlyContainedSeriesNumber;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shouldRender method ensures that the placeholder is not rendered when only the series number column is present. This is a logical fix to prevent unnecessary rendering.

}

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
```
Loading