Skip to content

Conversation

zanyuki-jd
Copy link
Contributor

@zanyuki-jd zanyuki-jd commented Jun 27, 2024

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • 新功能

    • 添加了 Demo14 组件以展示表格组件的自定义行渲染逻辑。
    • 更新了 TableDemo 组件中的翻译字符串,支持自定义行功能。
  • 改进

    • 在表格组件中添加了对 rowRender 函数的条件检查,以支持自定义行渲染逻辑。
  • 导出声明

    • 导出了 TableColumnProps 类型以便于表格列配置。

Copy link

coderabbitai bot commented Jun 27, 2024

Walkthrough

该更改主要新增了一个名为Demo14的演示组件,并在现有TableDemo组件中更新了自定义行的翻译字符串。此外,还对Table组件的indexindex.taro文件进行了类型导出更新,并添加了针对rowRender函数的条件检查。

Changes

文件路径 更改摘要
.../table/demo.taro.tsx 添加Demo14组件导入以及更新TableDemo组件的翻译字符串。
.../table/demos/h5/demo14.tsx 新增Demo14组件,使用@nutui/nutui-react中的Table组件,并自定义行渲染。
.../table/demos/taro/demo14.tsx 新增Demo14组件,使用@nutui/nutui-react-taro中的Table组件,并自定义行渲染。
.../table/index.taro.ts 更新类型导出,添加TableColumnProps的导出。
.../table/index.ts 更新了类型导出,添加了TableColumnProps
.../table/table.taro.tsx renderBodyTds函数中添加rowRender条件检查。
.../table/table.tsx renderBodyTds函数中添加rowRender条件检查。

Poem

代码如诗舞,
新增功能齐齐来。
十四号演示新姿态,
自定义行行精彩。
数据列间传导航,
优雅流畅无阻碍。
Nutui如风在,
编码世界乐开怀。


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3f9b0bc and 99fbfe0.

Files selected for processing (1)
  • src/packages/table/demos/taro/demo14.tsx (1 hunks)
Additional comments not posted (3)
src/packages/table/demos/taro/demo14.tsx (3)

5-19: 优化列定义

columns 数组是常量,不需要使用 useState 来定义。可以直接定义为常量数组以减少不必要的状态管理复杂性。


21-65: 优化数据定义

data 数组是常量,不需要使用 useState 来定义。可以直接定义为常量数组以减少不必要的状态管理复杂性。


30-53: 优化自定义组件的实现

data 数组中定义的自定义组件提取到外部,以增强代码的可读性和可维护性。


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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 (3)
src/packages/table/table.tsx (1)

Line range hint 79-79: 建议使用可选链来提高代码安全性。

- defaultProps.noData = locale.noData
+ defaultProps.noData = locale?.noData
src/packages/table/table.taro.tsx (2)

Line range hint 82-82: 优化建议:使用可选链

静态分析工具建议在此处使用可选链以增强代码的安全性和可读性。例如,item.sorter && !sortedMapping.current[item.key] 可以改为 item.sorter?.(!sortedMapping.current[item.key])

- if (item.sorter && !sortedMapping.current[item.key]) {
+ if (item.sorter?.(!sortedMapping.current[item.key])) {

Line range hint 103-112: 增强键盘访问性

为了支持仅使用键盘的用户导航,建议在使用鼠标事件的同时增加对应的键盘事件。这不仅是一个好的实践,也是无障碍设计的要求。

<div
  className={classNames(
    `${headerClassPrefix}-th`,
    cellClasses(item),
    getStickyClass(item.key)
  )}
  key={item.key}
  onClick={() => handleSorterClick(item)}
+ onKeyUp={() => handleSorterClick(item)}
  style={getStickyStyle(item.key)}
>
  {item.title}&nbsp;
  {item.sorter &&
    (sorterIcon || <ArrowDown width="12px" height="12px" />)}
</div>

import Demo11 from './demos/taro/demo11'
import Demo12 from './demos/taro/demo12'
import Demo13 from './demos/taro/demo13'
import Demo14 from './demos/h5/demo14'
Copy link

Choose a reason for hiding this comment

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

导入路径错误,应从 Taro 特定的目录导入。

- import Demo14 from './demos/h5/demo14'
+ import Demo14 from './demos/taro/demo14'
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import Demo14 from './demos/h5/demo14'
import Demo14 from './demos/taro/demo14'

Comment on lines +125 to +128
const { rowRender } = item
if (rowRender && typeof rowRender === 'function') {
return rowRender(item, rowIndex)
}
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

需要增加键盘访问性支持。

在文件 src/packages/table/table.tsx 中,发现存在 onClick 事件,但缺少相应的键盘事件处理程序(如 onKeyUponKeyDownonKeyPress)。为了确保组件的可访问性,请添加这些键盘事件处理程序。

  • onClick 事件位置:
    • onClick={() => handleSorterClick(item)}
Analysis chain

自定义行渲染逻辑正确。

但需要增加键盘访问性支持。

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the onClick event in the table has corresponding keyboard event handlers.

# Test: Search for onClick events in the file. Expect: Corresponding onKeyUp, onKeyDown, or onKeyPress events.
rg --type typescript $'onClick' src/packages/table/table.tsx

Length of output: 94



Script:

#!/bin/bash
# Description: Verify the onClick event in the table has corresponding keyboard event handlers.

# Test: Search for onClick events in the file. Expect: Corresponding onKeyUp, onKeyDown, or onKeyPress events.
rg 'onClick' src/packages/table/table.tsx

Length of output: 91



Script:

#!/bin/bash
# Description: Verify the presence of keyboard event handlers corresponding to the onClick event in the table component.

# Test: Search for onKeyUp, onKeyDown, or onKeyPress events in the file.
rg 'on(KeyUp|KeyDown|KeyPress)' src/packages/table/table.tsx

Length of output: 62

@oasis-cloud oasis-cloud linked an issue Jun 27, 2024 that may be closed by this pull request
Copy link

codecov bot commented Jun 27, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 85.98%. Comparing base (7fc969f) to head (99fbfe0).

Files Patch % Lines
src/packages/table/table.tsx 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #2390      +/-   ##
==========================================
- Coverage   85.99%   85.98%   -0.01%     
==========================================
  Files         217      217              
  Lines       22823    22827       +4     
  Branches     2539     2540       +1     
==========================================
+ Hits        19626    19628       +2     
- Misses       3192     3194       +2     
  Partials        5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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: 3

Comment on lines +5 to +19
const [columns] = useState<Array<TableColumnProps>>([
{
title: '姓名',
key: 'name',
align: 'center',
},
{
title: '性别',
key: 'gender',
},
{
title: '学历',
key: 'record',
},
])
Copy link

Choose a reason for hiding this comment

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

优化列定义

columns 数组是常量,不需要使用 useState 来定义。可以直接定义为常量数组以减少不必要的状态管理复杂性。

-  const [columns] = useState<Array<TableColumnProps>>([
+  const columns: Array<TableColumnProps> = [
...
-  ])
+  ]
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const [columns] = useState<Array<TableColumnProps>>([
{
title: '姓名',
key: 'name',
align: 'center',
},
{
title: '性别',
key: 'gender',
},
{
title: '学历',
key: 'record',
},
])
const columns: Array<TableColumnProps> = [
{
title: '姓名',
key: 'name',
align: 'center',
},
{
title: '性别',
key: 'gender',
},
{
title: '学历',
key: 'record',
},
]

Comment on lines 28 to 53
height: '100px',
text: '这里是自定义行',
Component: (props: any) => {
return (
<div style={{ height: props.height }}>
<div
style={{
position: 'absolute',
height: props.height,
width: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
borderBottom:
'1px solid var(--nutui-table-border-color, var(--nutui-black-3, rgba(0, 0, 0, 0.06)))',
}}
>
{props.text}
</div>
</div>
)
},
rowRender: (item: any) => {
const { Component, ...rest } = item
return <Component {...rest} />
},
Copy link

Choose a reason for hiding this comment

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

优化自定义组件的实现

data 数组中定义的自定义组件提取到外部,以增强代码的可读性和可维护性。

+ const CustomRow = (props: any) => (
+   <div style={{ height: props.height }}>
+     <div
+       style={{
+         position: 'absolute',
+         height: props.height,
+         width: '100%',
+         display: 'flex',
+         justifyContent: 'center',
+         alignItems: 'center',
+         borderBottom: '1px solid var(--nutui-table-border-color, var(--nutui-black-3, rgba(0, 0, 0, 0.06)))',
+       }}
+     >
+       {props.text}
+     </div>
+   </div>
+ )
...
-      Component: (props: any) => {
-        return (
-          <div style={{ height: props.height }}>
-            <div
-              style={{
-                position: 'absolute',
-                height: props.height,
-                width: '100%',
-                display: 'flex',
-                justifyContent: 'center',
-                alignItems: 'center',
-                borderBottom:
-                  '1px solid var(--nutui-table-border-color, var(--nutui-black-3, rgba(0, 0, 0, 0.06)))',
-              }}
-            >
-              {props.text}
-            </div>
-          </div>
-        )
-      },
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
height: '100px',
text: '这里是自定义行',
Component: (props: any) => {
return (
<div style={{ height: props.height }}>
<div
style={{
position: 'absolute',
height: props.height,
width: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
borderBottom:
'1px solid var(--nutui-table-border-color, var(--nutui-black-3, rgba(0, 0, 0, 0.06)))',
}}
>
{props.text}
</div>
</div>
)
},
rowRender: (item: any) => {
const { Component, ...rest } = item
return <Component {...rest} />
},
height: '100px',
text: '这里是自定义行',
Component: CustomRow,
rowRender: (item: any) => {
const { Component, ...rest } = item
return <Component {...rest} />
},
```
```tsx
const CustomRow = (props: any) => (
<div style={{ height: props.height }}>
<div
style={{
position: 'absolute',
height: props.height,
width: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
borderBottom: '1px solid var(--nutui-table-border-color, var(--nutui-black-3, rgba(0, 0, 0, 0.06)))',
}}
>
{props.text}
</div>
</div>
)

Comment on lines 21 to 65
const [data] = useState([
{
name: 'Tom',
gender: '男',
record: '小学',
},
{
height: '100px',
text: '这里是自定义行',
Component: (props: any) => {
return (
<div style={{ height: props.height }}>
<div
style={{
position: 'absolute',
height: props.height,
width: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
borderBottom:
'1px solid var(--nutui-table-border-color, var(--nutui-black-3, rgba(0, 0, 0, 0.06)))',
}}
>
{props.text}
</div>
</div>
)
},
rowRender: (item: any) => {
const { Component, ...rest } = item
return <Component {...rest} />
},
},
{
name: 'Lucy',
gender: '女',
record: '本科',
},
{
name: 'Jack',
gender: '男',
record: '高中',
},
])
Copy link

Choose a reason for hiding this comment

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

优化数据定义

data 数组是常量,不需要使用 useState 来定义。可以直接定义为常量数组以减少不必要的状态管理复杂性。

-  const [data] = useState([
+  const data = [
...
-  ])
+  ]
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const [data] = useState([
{
name: 'Tom',
gender: '男',
record: '小学',
},
{
height: '100px',
text: '这里是自定义行',
Component: (props: any) => {
return (
<div style={{ height: props.height }}>
<div
style={{
position: 'absolute',
height: props.height,
width: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
borderBottom:
'1px solid var(--nutui-table-border-color, var(--nutui-black-3, rgba(0, 0, 0, 0.06)))',
}}
>
{props.text}
</div>
</div>
)
},
rowRender: (item: any) => {
const { Component, ...rest } = item
return <Component {...rest} />
},
},
{
name: 'Lucy',
gender: '女',
record: '本科',
},
{
name: 'Jack',
gender: '男',
record: '高中',
},
])
const data = [
{
name: 'Tom',
gender: '男',
record: '小学',
},
{
height: '100px',
text: '这里是自定义行',
Component: (props: any) => {
return (
<div style={{ height: props.height }}>
<div
style={{
position: 'absolute',
height: props.height,
width: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
borderBottom:
'1px solid var(--nutui-table-border-color, var(--nutui-black-3, rgba(0, 0, 0, 0.06)))',
}}
>
{props.text}
</div>
</div>
)
},
rowRender: (item: any) => {
const { Component, ...rest } = item
return <Component {...rest} />
},
},
{
name: 'Lucy',
gender: '女',
record: '本科',
},
{
name: 'Jack',
gender: '男',
record: '高中',
},
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR]: Table新增自定义行功能

2 participants