mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-06 16:06:28 +08:00
feat(table-filter): support custom Empty (#49613)
* fix: Table empty node in filter dropdown not following ConfigProvider renderEmpty (#49548) * 修复自定义全局组件,过滤里面没有生效 * 新增测试用例 * 重新提交测试用例 * 测试用例添加断言判断 * update Table.filter.test.tsx * commit snapshot * update Table.filter.test.tsx * update Table.filter.test.tsx * update Table.filter.test.tsx (cherry picked from commit7790934b0b
) * chore: update case * feat(table-filter): support custom Empty * chore(type): improve TS type definition (#49602) (cherry picked from commita15fcfa1dc
) * fixup! feat(table-filter): support custom Empty * Squashed commit of the following: commit1b9706f22d
Merge:e76e386966
cc54bef826
Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed Jun 26 10:10:48 2024 +0000 chore: auto merge branches (#49609) chore: sync master to feature commitcc54bef826
Author: 照明胧 <25151442+mmmml-zhao@users.noreply.github.com> Date: Wed Jun 26 14:19:22 2024 +0800 fix: The emptyText field of the table (#49599) * fix: The emptyText field of the table when emptyText is null * test: update test case(#49599) commitff7fea18f3
Author: afc163 <afc163@gmail.com> Date: Wed Jun 26 12:40:24 2024 +0800 Revert "bug: fix-table-bug ref filters" (#49600) This reverts commit7790934b0b
. commita15fcfa1dc
Author: 红 <wxh1220@gmail.com> Date: Wed Jun 26 12:40:11 2024 +0800 chore(type): improve TS type definition (#49602) commit9ce5cbcf64
Author: Andrey <aaa144855@gmail.com> Date: Wed Jun 26 06:05:39 2024 +0300 fix: remove redundant transformations in ```UploadList```, which led to decrease in performance (#49598) * fix: remove unnecessary transformations for upload list with previews * chore: revert miss convert --------- Co-authored-by: 二货机器人 <smith3816@gmail.com> commit4145305b16
Author: MadCcc <madccc@foxmail.com> Date: Tue Jun 25 16:59:30 2024 +0800 docs: fix site FOUC (#49595) commit44e96b7b06
Author: enhongchen <106970098+enhongchen@users.noreply.github.com> Date: Tue Jun 25 14:24:14 2024 +0800 docs: Update use-with-rsbuild.zh-CN.md (#49592) https://ant.design/docs/react/use-with-rsbuild-cn?theme=happy-work#%E5%AE%89%E8%A3%85%E5%92%8C%E5%88%9D%E5%A7%8B%E5%8C%96 Signed-off-by: enhongchen <106970098+enhongchen@users.noreply.github.com> commit6a0af781d1
Author: 红 <wxh1220@gmail.com> Date: Tue Jun 25 13:34:28 2024 +0800 chore: improve tabs demo (#49590) ref: https://docs.dndkit.com/presets/sortable#collision-detection-algorithm commit7127603b76
Author: Tantatorn Suksangwarn <timefear007@gmail.com> Date: Tue Jun 25 12:32:59 2024 +0700 fix: add missing Thai translations (#49588) commit7790934b0b
Author: duqigit <916475145@qq.com> Date: Tue Jun 25 10:44:43 2024 +0800 fix: Table empty node in filter dropdown not following ConfigProvider renderEmpty (#49548) * 修复自定义全局组件,过滤里面没有生效 * 新增测试用例 * 重新提交测试用例 * 测试用例添加断言判断 * update Table.filter.test.tsx * commit snapshot * update Table.filter.test.tsx * update Table.filter.test.tsx * update Table.filter.test.tsx commitb09913db06
Author: lijianan <574980606@qq.com> Date: Tue Jun 25 10:42:19 2024 +0800 test: update test case code (#49585) commitb420c57354
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue Jun 25 10:39:47 2024 +0800 chore(deps): bump oven-sh/setup-bun from 1 to 2 (#49578) Bumps [oven-sh/setup-bun](https://github.com/oven-sh/setup-bun) from 1 to 2. - [Release notes](https://github.com/oven-sh/setup-bun/releases) - [Commits](https://github.com/oven-sh/setup-bun/compare/v1...v2) --- updated-dependencies: - dependency-name: oven-sh/setup-bun dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> commita81603d720
Author: afc163 <afc163@gmail.com> Date: Mon Jun 24 13:33:56 2024 +0800 docs: fix nav menu cannot click (#49569) * chore: remove * test: add more unit test * chore: lint * chore: fix legacy16 bug * chore: update logic * test: update unit test --------- Co-authored-by: duqigit <916475145@qq.com>
This commit is contained in:
parent
09b86845a7
commit
800c3fcbdb
@ -0,0 +1,438 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`renderEmpty should render Cascader empty 1`] = `
|
||||
<div
|
||||
class="ant-empty ant-empty-normal ant-empty-small"
|
||||
>
|
||||
<div
|
||||
class="ant-empty-image"
|
||||
>
|
||||
<svg
|
||||
height="41"
|
||||
viewBox="0 0 64 41"
|
||||
width="64"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<title>
|
||||
Simple Empty
|
||||
</title>
|
||||
<g
|
||||
fill="none"
|
||||
fill-rule="evenodd"
|
||||
transform="translate(0 1)"
|
||||
>
|
||||
<ellipse
|
||||
cx="32"
|
||||
cy="33"
|
||||
fill="#f5f5f5"
|
||||
rx="32"
|
||||
ry="7"
|
||||
/>
|
||||
<g
|
||||
fill-rule="nonzero"
|
||||
stroke="#d9d9d9"
|
||||
>
|
||||
<path
|
||||
d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"
|
||||
/>
|
||||
<path
|
||||
d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z"
|
||||
fill="#fafafa"
|
||||
/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<div
|
||||
class="ant-empty-description"
|
||||
>
|
||||
No data
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`renderEmpty should render List empty 1`] = `
|
||||
<div
|
||||
class="ant-empty ant-empty-normal"
|
||||
>
|
||||
<div
|
||||
class="ant-empty-image"
|
||||
>
|
||||
<svg
|
||||
height="41"
|
||||
viewBox="0 0 64 41"
|
||||
width="64"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<title>
|
||||
Simple Empty
|
||||
</title>
|
||||
<g
|
||||
fill="none"
|
||||
fill-rule="evenodd"
|
||||
transform="translate(0 1)"
|
||||
>
|
||||
<ellipse
|
||||
cx="32"
|
||||
cy="33"
|
||||
fill="#f5f5f5"
|
||||
rx="32"
|
||||
ry="7"
|
||||
/>
|
||||
<g
|
||||
fill-rule="nonzero"
|
||||
stroke="#d9d9d9"
|
||||
>
|
||||
<path
|
||||
d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"
|
||||
/>
|
||||
<path
|
||||
d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z"
|
||||
fill="#fafafa"
|
||||
/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<div
|
||||
class="ant-empty-description"
|
||||
>
|
||||
No data
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`renderEmpty should render Mentions empty 1`] = `
|
||||
<div
|
||||
class="ant-empty ant-empty-normal ant-empty-small"
|
||||
>
|
||||
<div
|
||||
class="ant-empty-image"
|
||||
>
|
||||
<svg
|
||||
height="41"
|
||||
viewBox="0 0 64 41"
|
||||
width="64"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<title>
|
||||
Simple Empty
|
||||
</title>
|
||||
<g
|
||||
fill="none"
|
||||
fill-rule="evenodd"
|
||||
transform="translate(0 1)"
|
||||
>
|
||||
<ellipse
|
||||
cx="32"
|
||||
cy="33"
|
||||
fill="#f5f5f5"
|
||||
rx="32"
|
||||
ry="7"
|
||||
/>
|
||||
<g
|
||||
fill-rule="nonzero"
|
||||
stroke="#d9d9d9"
|
||||
>
|
||||
<path
|
||||
d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"
|
||||
/>
|
||||
<path
|
||||
d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z"
|
||||
fill="#fafafa"
|
||||
/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<div
|
||||
class="ant-empty-description"
|
||||
>
|
||||
No data
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`renderEmpty should render Select empty 1`] = `
|
||||
<div
|
||||
class="ant-empty ant-empty-normal ant-empty-small"
|
||||
>
|
||||
<div
|
||||
class="ant-empty-image"
|
||||
>
|
||||
<svg
|
||||
height="41"
|
||||
viewBox="0 0 64 41"
|
||||
width="64"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<title>
|
||||
Simple Empty
|
||||
</title>
|
||||
<g
|
||||
fill="none"
|
||||
fill-rule="evenodd"
|
||||
transform="translate(0 1)"
|
||||
>
|
||||
<ellipse
|
||||
cx="32"
|
||||
cy="33"
|
||||
fill="#f5f5f5"
|
||||
rx="32"
|
||||
ry="7"
|
||||
/>
|
||||
<g
|
||||
fill-rule="nonzero"
|
||||
stroke="#d9d9d9"
|
||||
>
|
||||
<path
|
||||
d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"
|
||||
/>
|
||||
<path
|
||||
d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z"
|
||||
fill="#fafafa"
|
||||
/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<div
|
||||
class="ant-empty-description"
|
||||
>
|
||||
No data
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`renderEmpty should render Table empty 1`] = `
|
||||
<div
|
||||
class="ant-empty ant-empty-normal"
|
||||
>
|
||||
<div
|
||||
class="ant-empty-image"
|
||||
>
|
||||
<svg
|
||||
height="41"
|
||||
viewBox="0 0 64 41"
|
||||
width="64"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<title>
|
||||
Simple Empty
|
||||
</title>
|
||||
<g
|
||||
fill="none"
|
||||
fill-rule="evenodd"
|
||||
transform="translate(0 1)"
|
||||
>
|
||||
<ellipse
|
||||
cx="32"
|
||||
cy="33"
|
||||
fill="#f5f5f5"
|
||||
rx="32"
|
||||
ry="7"
|
||||
/>
|
||||
<g
|
||||
fill-rule="nonzero"
|
||||
stroke="#d9d9d9"
|
||||
>
|
||||
<path
|
||||
d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"
|
||||
/>
|
||||
<path
|
||||
d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z"
|
||||
fill="#fafafa"
|
||||
/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<div
|
||||
class="ant-empty-description"
|
||||
>
|
||||
No data
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`renderEmpty should render Table.filter empty 1`] = `null`;
|
||||
|
||||
exports[`renderEmpty should render Transfer empty 1`] = `
|
||||
<div
|
||||
class="ant-empty ant-empty-normal ant-empty-small"
|
||||
>
|
||||
<div
|
||||
class="ant-empty-image"
|
||||
>
|
||||
<svg
|
||||
height="41"
|
||||
viewBox="0 0 64 41"
|
||||
width="64"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<title>
|
||||
Simple Empty
|
||||
</title>
|
||||
<g
|
||||
fill="none"
|
||||
fill-rule="evenodd"
|
||||
transform="translate(0 1)"
|
||||
>
|
||||
<ellipse
|
||||
cx="32"
|
||||
cy="33"
|
||||
fill="#f5f5f5"
|
||||
rx="32"
|
||||
ry="7"
|
||||
/>
|
||||
<g
|
||||
fill-rule="nonzero"
|
||||
stroke="#d9d9d9"
|
||||
>
|
||||
<path
|
||||
d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"
|
||||
/>
|
||||
<path
|
||||
d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z"
|
||||
fill="#fafafa"
|
||||
/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<div
|
||||
class="ant-empty-description"
|
||||
>
|
||||
No data
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`renderEmpty should render TreeSelect empty 1`] = `
|
||||
<div
|
||||
class="ant-empty ant-empty-normal ant-empty-small"
|
||||
>
|
||||
<div
|
||||
class="ant-empty-image"
|
||||
>
|
||||
<svg
|
||||
height="41"
|
||||
viewBox="0 0 64 41"
|
||||
width="64"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<title>
|
||||
Simple Empty
|
||||
</title>
|
||||
<g
|
||||
fill="none"
|
||||
fill-rule="evenodd"
|
||||
transform="translate(0 1)"
|
||||
>
|
||||
<ellipse
|
||||
cx="32"
|
||||
cy="33"
|
||||
fill="#f5f5f5"
|
||||
rx="32"
|
||||
ry="7"
|
||||
/>
|
||||
<g
|
||||
fill-rule="nonzero"
|
||||
stroke="#d9d9d9"
|
||||
>
|
||||
<path
|
||||
d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"
|
||||
/>
|
||||
<path
|
||||
d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z"
|
||||
fill="#fafafa"
|
||||
/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<div
|
||||
class="ant-empty-description"
|
||||
>
|
||||
No data
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`renderEmpty should return empty when componentName is not matched 1`] = `
|
||||
<div
|
||||
class="ant-empty"
|
||||
>
|
||||
<div
|
||||
class="ant-empty-image"
|
||||
>
|
||||
<svg
|
||||
height="152"
|
||||
viewBox="0 0 184 152"
|
||||
width="184"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<title>
|
||||
empty image
|
||||
</title>
|
||||
<g
|
||||
fill="none"
|
||||
fill-rule="evenodd"
|
||||
>
|
||||
<g
|
||||
transform="translate(24 31.67)"
|
||||
>
|
||||
<ellipse
|
||||
cx="67.797"
|
||||
cy="106.89"
|
||||
fill="#F5F5F7"
|
||||
fill-opacity=".8"
|
||||
rx="67.797"
|
||||
ry="12.668"
|
||||
/>
|
||||
<path
|
||||
d="M122.034 69.674L98.109 40.229c-1.148-1.386-2.826-2.225-4.593-2.225h-51.44c-1.766 0-3.444.839-4.592 2.225L13.56 69.674v15.383h108.475V69.674z"
|
||||
fill="#AEB8C2"
|
||||
/>
|
||||
<path
|
||||
d="M101.537 86.214L80.63 61.102c-1.001-1.207-2.507-1.867-4.048-1.867H31.724c-1.54 0-3.047.66-4.048 1.867L6.769 86.214v13.792h94.768V86.214z"
|
||||
fill="url(#linearGradient-1)"
|
||||
transform="translate(13.56)"
|
||||
/>
|
||||
<path
|
||||
d="M33.83 0h67.933a4 4 0 0 1 4 4v93.344a4 4 0 0 1-4 4H33.83a4 4 0 0 1-4-4V4a4 4 0 0 1 4-4z"
|
||||
fill="#F5F5F7"
|
||||
/>
|
||||
<path
|
||||
d="M42.678 9.953h50.237a2 2 0 0 1 2 2V36.91a2 2 0 0 1-2 2H42.678a2 2 0 0 1-2-2V11.953a2 2 0 0 1 2-2zM42.94 49.767h49.713a2.262 2.262 0 1 1 0 4.524H42.94a2.262 2.262 0 0 1 0-4.524zM42.94 61.53h49.713a2.262 2.262 0 1 1 0 4.525H42.94a2.262 2.262 0 0 1 0-4.525zM121.813 105.032c-.775 3.071-3.497 5.36-6.735 5.36H20.515c-3.238 0-5.96-2.29-6.734-5.36a7.309 7.309 0 0 1-.222-1.79V69.675h26.318c2.907 0 5.25 2.448 5.25 5.42v.04c0 2.971 2.37 5.37 5.277 5.37h34.785c2.907 0 5.277-2.421 5.277-5.393V75.1c0-2.972 2.343-5.426 5.25-5.426h26.318v33.569c0 .617-.077 1.216-.221 1.789z"
|
||||
fill="#DCE0E6"
|
||||
/>
|
||||
</g>
|
||||
<path
|
||||
d="M149.121 33.292l-6.83 2.65a1 1 0 0 1-1.317-1.23l1.937-6.207c-2.589-2.944-4.109-6.534-4.109-10.408C138.802 8.102 148.92 0 161.402 0 173.881 0 184 8.102 184 18.097c0 9.995-10.118 18.097-22.599 18.097-4.528 0-8.744-1.066-12.28-2.902z"
|
||||
fill="#DCE0E6"
|
||||
/>
|
||||
<g
|
||||
fill="#FFF"
|
||||
transform="translate(149.65 15.383)"
|
||||
>
|
||||
<ellipse
|
||||
cx="20.654"
|
||||
cy="3.167"
|
||||
rx="2.849"
|
||||
ry="2.815"
|
||||
/>
|
||||
<path
|
||||
d="M5.698 5.63H0L2.898.704zM9.259.704h4.985V5.63H9.259z"
|
||||
/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<div
|
||||
class="ant-empty-description"
|
||||
>
|
||||
No data
|
||||
</div>
|
||||
</div>
|
||||
`;
|
30
components/config-provider/__tests__/renderEmpty.test.tsx
Normal file
30
components/config-provider/__tests__/renderEmpty.test.tsx
Normal file
@ -0,0 +1,30 @@
|
||||
import React from 'react';
|
||||
import RenderEmpty from '../defaultRenderEmpty';
|
||||
import { render } from '../../../tests/utils';
|
||||
|
||||
describe('renderEmpty', () => {
|
||||
it.each([
|
||||
'Table',
|
||||
'Table.filter' /* 👈 5.19.0+ */,
|
||||
'List',
|
||||
'Select',
|
||||
'TreeSelect',
|
||||
'Cascader',
|
||||
'Transfer',
|
||||
'Mentions',
|
||||
])('should render %s empty', (componentName: any) => {
|
||||
const { container } = render(<RenderEmpty componentName={componentName} />);
|
||||
expect(container.firstChild).toMatchSnapshot();
|
||||
});
|
||||
|
||||
// https://github.com/ant-design/ant-design/pull/49613#issuecomment-2198857047
|
||||
it('should return false when componentName is `Table.filter`', () => {
|
||||
const { container } = render(<RenderEmpty componentName="Table.filter" />);
|
||||
expect(container.firstChild).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should return empty when componentName is not matched', () => {
|
||||
const { container } = render(<RenderEmpty componentName={`not_match` as any} />);
|
||||
expect(container.firstChild).toMatchSnapshot();
|
||||
});
|
||||
});
|
@ -6,6 +6,7 @@ import Empty from '../empty';
|
||||
|
||||
type ComponentName =
|
||||
| 'Table'
|
||||
| 'Table.filter' /* 👈 5.19.0+ */
|
||||
| 'List'
|
||||
| 'Select'
|
||||
| 'TreeSelect'
|
||||
@ -31,7 +32,14 @@ const DefaultRenderEmpty: React.FC<EmptyProps> = (props) => {
|
||||
case 'Transfer':
|
||||
case 'Mentions':
|
||||
return <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} className={`${prefix}-small`} />;
|
||||
/* istanbul ignore next */
|
||||
/**
|
||||
* This type of component should satisfy the nullish coalescing operator(??) on the left-hand side.
|
||||
* to let the component itself implement the logic.
|
||||
* For example `Table.filter`.
|
||||
*/
|
||||
case 'Table.filter':
|
||||
// why `null`? legacy react16 node type `undefined` is not allowed.
|
||||
return null;
|
||||
default:
|
||||
// Should never hit if we take all the component into consider.
|
||||
return <Empty />;
|
||||
|
@ -5,7 +5,7 @@ import React, { useEffect, useState } from 'react';
|
||||
import type { ColumnGroupType, ColumnType, TableProps } from '..';
|
||||
import Table from '..';
|
||||
import { resetWarned } from '../../_util/warning';
|
||||
import { act, fireEvent, render, waitFor } from '../../../tests/utils';
|
||||
import { act, fireEvent, render, waitFakeTimer, waitFor } from '../../../tests/utils';
|
||||
import Button from '../../button';
|
||||
import ConfigProvider from '../../config-provider';
|
||||
import Input from '../../input';
|
||||
@ -2947,4 +2947,66 @@ describe('Table.filter', () => {
|
||||
fireEvent.click(container.querySelector('.ant-dropdown-trigger')!);
|
||||
expect(handleChange).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
/**
|
||||
* https://github.com/ant-design/ant-design/issues/49542
|
||||
* https://github.com/ant-design/ant-design/discussions/49603
|
||||
*/
|
||||
describe('empty state', () => {
|
||||
const TestDemo = ({ renderEmpty }: any) => (
|
||||
<ConfigProvider renderEmpty={renderEmpty}>
|
||||
<Table
|
||||
dataSource={[{ name: 'John Brown' }]}
|
||||
columns={[
|
||||
{
|
||||
title: 'Name',
|
||||
key: 'name',
|
||||
filters: [], // empty filters
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</ConfigProvider>
|
||||
);
|
||||
|
||||
it('should return custom content', async () => {
|
||||
const mockTableFilterRenderEmpty = jest.fn();
|
||||
|
||||
function renderEmpty(...args: any[]) {
|
||||
if (args[0] === 'Table.filter') {
|
||||
mockTableFilterRenderEmpty(...args);
|
||||
return 'foo';
|
||||
}
|
||||
return 'bar';
|
||||
}
|
||||
|
||||
const { container } = render(<TestDemo renderEmpty={renderEmpty} />);
|
||||
|
||||
// Open Filter
|
||||
fireEvent.click(container.querySelector('span.ant-dropdown-trigger')!);
|
||||
act(() => {
|
||||
jest.runAllTimers();
|
||||
});
|
||||
|
||||
await waitFakeTimer();
|
||||
|
||||
expect(container.querySelector('.ant-table-filter-dropdown')).toHaveTextContent('foo');
|
||||
|
||||
expect(mockTableFilterRenderEmpty).toHaveBeenCalled();
|
||||
expect(mockTableFilterRenderEmpty.mock.calls[0][0]).toEqual('Table.filter');
|
||||
});
|
||||
|
||||
it('allow `false` to not render empty states', async () => {
|
||||
const { container } = render(
|
||||
<TestDemo renderEmpty={(name: any) => (name === 'Table.filter' ? false : 'bar')} />,
|
||||
);
|
||||
|
||||
// Open Filter
|
||||
fireEvent.click(container.querySelector('span.ant-dropdown-trigger')!);
|
||||
|
||||
await waitFakeTimer();
|
||||
|
||||
expect(container.querySelector('.ant-table-filter-dropdown .ant-empty')).toBeNull();
|
||||
expect(container.querySelector('.ant-table-filter-dropdown')!.childNodes).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -350,6 +350,8 @@ function FilterDropdown<RecordType>(props: FilterDropdownProps<RecordType>) {
|
||||
|
||||
let dropdownContent: React.ReactNode;
|
||||
|
||||
const { direction, renderEmpty } = React.useContext(ConfigContext);
|
||||
|
||||
if (typeof column.filterDropdown === 'function') {
|
||||
dropdownContent = column.filterDropdown({
|
||||
prefixCls: `${dropdownPrefixCls}-custom`,
|
||||
@ -368,7 +370,7 @@ function FilterDropdown<RecordType>(props: FilterDropdownProps<RecordType>) {
|
||||
} else {
|
||||
const selectedKeys = getFilteredKeysSync() || [];
|
||||
const getFilterComponent = () => {
|
||||
const empty = (
|
||||
const empty = renderEmpty?.('Table.filter') ?? (
|
||||
<Empty
|
||||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||
description={locale.filterEmptyText}
|
||||
@ -524,8 +526,6 @@ function FilterDropdown<RecordType>(props: FilterDropdownProps<RecordType>) {
|
||||
filterIcon = <FilterFilled />;
|
||||
}
|
||||
|
||||
const { direction } = React.useContext(ConfigContext);
|
||||
|
||||
return (
|
||||
<div className={`${prefixCls}-column`}>
|
||||
<span className={`${tablePrefixCls}-column-title`}>{children}</span>
|
||||
|
Loading…
Reference in New Issue
Block a user