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

feat: showSizeChanger accept SelectProps #597

Conversation

prakashks20
Copy link
Contributor

@prakashks20 prakashks20 commented Jul 25, 2024

Ant Design Pagination enhanced feature added in ant-design/ant-design#46757 depends on this PR changes

Summary by CodeRabbit

  • 新功能
    • 更新了分页组件的API文档,增强了可读性和一致性,特别是对showSizeChanger参数的详细描述。
    • 新增了showSizeChanger功能的演示文档和示例组件,展示了如何在用户界面中实现可调整页面大小的分页。
    • Options组件现在集成了showSizeChanger功能,支持条件显示搜索输入和通知外部组件大小变化。
  • 测试
    • 添加了针对具有大小变化功能的Pagination组件的单元测试,确保其正常工作。

Copy link

vercel bot commented Jul 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
pagination ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 22, 2024 0:48am

@prakashmallow
Copy link
Contributor

prakashmallow commented Jul 31, 2024

Waiting for the code review of this pull request. This pull request depends on fixing the Ant Design pagination issue

src/interface.ts Outdated Show resolved Hide resolved
src/interface.ts Outdated Show resolved Hide resolved
src/interface.ts Outdated Show resolved Hide resolved
@prakashmallow
Copy link
Contributor

@afc163 Code review changes have been addressed. Please review these changes.

@prakashks20
Copy link
Contributor Author

@afc163 @MadCcc @zombieJ Waiting for the changes in this pull request to fix the Antd pagination size selector issue. Could you please review it as soon as possible?

src/Pagination.tsx Outdated Show resolved Hide resolved
src/Pagination.tsx Outdated Show resolved Hide resolved
src/Options.tsx Outdated Show resolved Hide resolved
src/Options.tsx Show resolved Hide resolved
@afc163 afc163 force-pushed the feature/development/pageSizeChanger-option-for-pagination branch from 4194f22 to af3e072 Compare September 22, 2024 09:05
Copy link

socket-security bot commented Sep 22, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@testing-library/[email protected] Transitive: environment, eval +21 3.6 MB testing-library-bot
npm/[email protected] filesystem Transitive: environment +40 30.1 MB simenb
npm/[email protected] Transitive: environment, filesystem, shell +26 6.13 MB sindresorhus
npm/[email protected] environment, filesystem Transitive: eval, shell, unsafe +62 10.3 MB eslintbot
npm/[email protected] Transitive: environment, eval, filesystem, network, shell, unsafe +273 578 MB yifankakaxi
npm/[email protected] filesystem, shell Transitive: environment +22 944 kB tschaub
npm/[email protected] None +1 510 kB isaacs
npm/[email protected] environment, filesystem, shell 0 4.03 kB typicode
npm/[email protected] None 0 8.38 kB keyanzhang
npm/[email protected] eval, filesystem Transitive: environment +2 2.91 MB matthew-dean
npm/[email protected] Transitive: environment, filesystem, shell +13 540 kB okonet
npm/[email protected] Transitive: environment, filesystem, shell +24 2.07 MB sindresorhus
npm/[email protected] environment, filesystem, unsafe 0 7.7 MB prettier-bot
npm/[email protected] None +1 448 kB afc163, chenshuai2144, madccc, ...6 more
npm/[email protected] environment, filesystem Transitive: eval, shell, unsafe +75 14.7 MB zombiej
npm/[email protected] environment +1 265 kB zombiej
npm/[email protected] environment 0 4.51 MB react-bot
npm/[email protected] environment 0 318 kB react-bot

View full report↗︎

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range and nitpick comments (5)
tests/options.test.tsx (1)

15-16: 添加 showSizeChanger 属性是个好的改进

这个改动符合 PR 的目标,将分页大小选择器的属性进行分组。

为了更好的可读性和明确性,建议显式设置属性值:

- showSizeChanger
+ showSizeChanger={true}

这样可以让代码的意图更加清晰,特别是对于不熟悉 JSX 语法的开发者来说。

package.json (1)

53-53: 新增的测试依赖项将提升测试质量

添加 @testing-library/user-event 依赖项是一个很好的决定。这个库能够模拟用户交互,有助于编写更真实和全面的测试用例,特别是对于分页组件这样的交互性组件。

考虑在项目的测试文件中充分利用这个新的依赖项,特别是在测试分页大小选择器的交互时。这将有助于确保新功能的可靠性和用户体验的一致性。

tests/sizer.test.tsx (3)

87-94: 测试结构组织得很好

新增的 describe 块很好地组织了与 showSizeChanger 相关的测试。options 数组的定义也很全面。

建议:考虑将 options 数组定义为常量,并移到 describe 块外部。这样可以提高其重用性,并使测试更加清晰。

const PAGE_SIZE_OPTIONS = [
  { value: '10', label: '10 条每页' },
  { value: '25', label: '25 条每页' },
  { value: '50', label: '50 条每页' },
  { value: '75', label: '75 条每页' },
  { value: '100', label: '100 条每页' },
];

describe('Pagination with showSizeChanger', () => {
  // 使用 PAGE_SIZE_OPTIONS
});

95-120: 页面大小更改测试案例设计合理

这个测试案例很好地覆盖了更改页面大小的基本功能。它正确地模拟了用户交互并验证了 onChange 回调的调用及其参数。

建议:考虑添加一个额外的断言,以确保选择新的页面大小后,分页组件的状态也相应更新。例如:

expect(container.querySelector('.rc-select-selection-item')).toHaveTextContent('25 条每页');

这将确保 UI 也正确反映了更改。


122-155: 搜索功能测试案例设计全面

这个测试案例很好地覆盖了通过搜索更改页面大小的功能。使用 userEvent 模拟输入是一个很好的做法,能更真实地模拟用户行为。测试全面检查了 UI 更新和 onChange 回调。

建议:考虑添加一个测试场景,验证当用户输入一个不存在的页面大小时的行为。例如:

await userEvent.type(container.querySelector('input'), '999');
expect(container.querySelectorAll('.rc-select-item-option-content')).toHaveLength(0);

这将确保组件在无效输入时的行为符合预期。

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 68aa2fe and ab723a5.

Files ignored due to path filters (1)
  • tests/__snapshots__/demo.test.tsx.snap is excluded by !**/*.snap
Files selected for processing (7)
  • README.md (1 hunks)
  • docs/examples/showSizeChanger.tsx (1 hunks)
  • package.json (1 hunks)
  • src/Options.tsx (5 hunks)
  • src/Pagination.tsx (3 hunks)
  • tests/options.test.tsx (2 hunks)
  • tests/sizer.test.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • docs/examples/showSizeChanger.tsx
  • src/Options.tsx
Additional context used
LanguageTool
README.md

[grammar] ~66-~66: Comparison requires “than”, not ‘then’ nor ‘as’.
Context: ...ect.tsx#L112) | false when total less then totalBoundaryShowSizeChanger, true ...

(COMP_THAN)

GitHub Check: codecov/patch
src/Pagination.tsx

[warning] 193-193: src/Pagination.tsx#L193
Added line #L193 was not covered by tests

Additional comments not posted (7)
README.md (2)

55-57: 代码格式和表格结构改进

添加的 prettier-ignore 注释有助于保持一致的格式,这是一个很好的做法。表格的标题和对齐方式已经标准化,提高了可读性。


Line range hint 1-84: 整体文档改进

README 文件的整体结构和内容有了显著改善。API 文档更加清晰和详细,特别是对于 showSizeChanger 等参数的描述。这些更改将有助于开发者更好地理解和使用该分页组件。

建议在未来的更新中考虑添加一些使用示例,以进一步提高文档的实用性。

Tools
LanguageTool

[grammar] ~66-~66: Comparison requires “than”, not ‘then’ nor ‘as’.
Context: ...ect.tsx#L112) | false when total less then totalBoundaryShowSizeChanger, true ...

(COMP_THAN)

tests/sizer.test.tsx (2)

3-3: 导入 userEvent 是个好主意!

引入 userEvent 可以更真实地模拟用户交互,这对于测试分页组件的交互行为非常有用。这是一个很好的改进。


Line range hint 1-156: 总体评价:测试用例质量高,覆盖全面

这些新增的测试用例显著提高了对 showSizeChanger 功能的覆盖率。它们不仅测试了直接选择页面大小的情况,还包括了基于搜索选择页面大小的场景,这些都是关键的用户交互。测试结构良好,使用了适当的测试库和方法。

建议:

  1. 考虑添加对边缘情况的测试,如处理无效输入或异常情况。
  2. 可以探索使用 test.each 来参数化测试,减少代码重复。
  3. 确保这些测试与组件的其他功能(如页面切换)集成良好,可能需要添加一些集成测试。

总的来说,这些测试用例为 Pagination 组件的 showSizeChanger 功能提供了强有力的质量保证。

src/Pagination.tsx (3)

66-66: 优化了 showSizeChanger 属性的默认值设置

这个改动通过使用 totaltotalBoundaryShowSizeChanger 来动态设置 showSizeChanger 的默认值,提高了组件的灵活性和易用性。这种方法可以根据数据总量自动决定是否显示页面大小选择器,减少了使用者的配置负担。


590-595: 优化了 Options 组件的属性传递

这些改动简化了属性传递逻辑,提高了代码的一致性和可维护性:

  1. changeSize 属性现在始终设置为 changePageSize 函数,消除了之前的条件判断。
  2. 新增了 showSizeChanger 属性的传递,使 Options 组件能够更精确地控制其行为。

这些变更使得组件之间的交互更加清晰和可预测。


192-194: 改进了 changePageSize 函数的逻辑

添加的守卫语句提高了函数的效率和逻辑一致性。当 showSizeChanger 为 false 时,函数会立即返回,避免不必要的计算。

建议为这个新添加的守卫语句添加测试用例,以确保代码覆盖率和功能正确性。可以使用以下命令来查找现有的测试文件:

然后在相应的测试文件中添加新的测试用例,确保当 showSizeChanger 为 false 时,changePageSize 函数不会执行后续逻辑。

Tools
GitHub Check: codecov/patch

[warning] 193-193: src/Pagination.tsx#L193
Added line #L193 was not covered by tests

tests/options.test.tsx Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@afc163 afc163 changed the title Pagination size selector props are grouped with the pageSizeChanger prop on rc-pagination feat: showSizeChanger accept SelectProps Sep 22, 2024
@afc163 afc163 merged commit f4b851f into react-component:master Sep 22, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants