-
-
Notifications
You must be signed in to change notification settings - Fork 621
feat: add forceRender api #1386
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -31,6 +31,7 @@ export interface BodyRowProps<RecordType> { | |||||
| colSpan: number; | ||||||
| sticky: number; | ||||||
| }; | ||||||
| forceRender?: boolean | ((record: RecordType, index: number) => boolean); | ||||||
| } | ||||||
|
Comment on lines
+34
to
35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain统一
export interface BodyRowProps<RecordType> {
- forceRender?: boolean | ((record: RecordType, index: number) => boolean);
+ // 与对外 API / Context 对齐,index 可选
+ forceRender?: boolean | ((record: RecordType, index?: number) => boolean);
}
@@
- if (process.env.NODE_ENV !== 'production') {
- devRenderTimes(props);
- }
+ // 调试渲染计数仅保留一次调用
@@
- const shouldForceRender = () => {
+ const shouldForceRender = () => {
if (typeof forceRender === 'function') {
- return forceRender(record, index);
+ return forceRender(record, index);
}
return !!forceRender;
};
@@
- if (rowSupportExpand && (expandedRef.current || expanded || shouldForceRender?.())) {
+ if (rowSupportExpand && (expandedRef.current || expanded || shouldForceRender())) {另需在文档中说明回调的 Also applies to: 142-143, 162-168, 236-237 🏁 Script executed: #!/bin/bash
# Gather information about BodyRow.tsx and related type definitions
echo "=== Checking BodyRow.tsx content (key lines) ==="
cat src/Body/BodyRow.tsx | head -250
echo -e "\n=== Searching for devRenderTimes calls ==="
rg -n "devRenderTimes" src/Body/BodyRow.tsx
echo -e "\n=== Searching for TableContext definition ==="
fd -e ts -e tsx | xargs grep -l "TableContext" | head -5
echo -e "\n=== Searching for ExpandableConfig definition ==="
fd -e ts -e tsx | xargs grep -l "ExpandableConfig" | head -5Length of output: 7681 🏁 Script executed: #!/bin/bash
# Search for forceRender definitions in TableContext and ExpandableConfig
echo "=== TableContext definition for forceRender ==="
rg -n "forceRender" src/context/TableContext.tsx -A 2 -B 2
echo -e "\n=== ExpandableConfig definition ==="
rg -n "ExpandableConfig" src/interface.ts -A 10 -B 2
echo -e "\n=== Expand hook definition ==="
rg -n "forceRender" src/hooks/useExpand.ts -A 2 -B 2
echo -e "\n=== Table.tsx for forceRender ==="
rg -n "forceRender" src/Table.tsx -A 2 -B 2Length of output: 1405 🏁 Script executed: #!/bin/bash
# Verify what index parameter represents and check ExpandableConfig for forceRender
echo "=== Check if ExpandableConfig has forceRender ==="
rg -n "interface ExpandableConfig" src/interface.ts -A 25
echo -e "\n=== Verify index usage context in BodyRow ==="
rg -n "index" src/Body/BodyRow.tsx | head -20Length of output: 1847 统一 验证结果确认以下问题:
export interface BodyRowProps<RecordType> {
- forceRender?: boolean | ((record: RecordType, index: number) => boolean);
+ forceRender?: boolean | ((record: RecordType, index?: number) => boolean);
}
@@ (行 123-125)
- if (process.env.NODE_ENV !== 'production') {
- devRenderTimes(props);
- }
+ // 调试渲染计数仅保留一次调用
@@ (行 167-172)
const shouldForceRender = () => {
if (typeof forceRender === 'function') {
return forceRender(record, index);
}
return !!forceRender;
};
@@ (行 237)
- if (rowSupportExpand && (expandedRef.current || expanded || shouldForceRender?.())) {
+ if (rowSupportExpand && (expandedRef.current || expanded || shouldForceRender())) {建议同步更新
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| // ================================================================================== | ||||||
|
|
@@ -138,6 +139,7 @@ const BodyRow = <RecordType extends { children?: readonly RecordType[] }>( | |||||
| cellComponent, | ||||||
| scopeCellComponent, | ||||||
| expandedRowInfo, | ||||||
| forceRender, | ||||||
| } = props; | ||||||
|
|
||||||
| const rowInfo = useRowInfo(record, rowKey, index, indent); | ||||||
|
|
@@ -157,6 +159,13 @@ const BodyRow = <RecordType extends { children?: readonly RecordType[] }>( | |||||
| const expandedRef = React.useRef(false); | ||||||
| expandedRef.current ||= expanded; | ||||||
|
|
||||||
| const shouldForceRender = () => { | ||||||
| if (typeof forceRender === 'function') { | ||||||
| return forceRender(record, index); | ||||||
| } | ||||||
| return !!forceRender; | ||||||
| }; | ||||||
|
|
||||||
| if (process.env.NODE_ENV !== 'production') { | ||||||
| devRenderTimes(props); | ||||||
| } | ||||||
|
|
@@ -224,7 +233,7 @@ const BodyRow = <RecordType extends { children?: readonly RecordType[] }>( | |||||
|
|
||||||
| // ======================== Expand Row ========================= | ||||||
| let expandRowNode: React.ReactElement<ExpandedRowProps>; | ||||||
| if (rowSupportExpand && (expandedRef.current || expanded)) { | ||||||
| if (rowSupportExpand && (expandedRef.current || expanded || shouldForceRender?.())) { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The optional chaining
Suggested change
|
||||||
| const expandContent = expandedRowRender(record, index, indent + 1, expanded); | ||||||
|
|
||||||
| expandRowNode = ( | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -892,6 +892,7 @@ const Table = <RecordType extends DefaultRecordType>( | |
| expandableType, | ||
| expandRowByClick: expandableConfig.expandRowByClick, | ||
| expandedRowRender: expandableConfig.expandedRowRender, | ||
| forceRender: expandableConfig.forceRender, | ||
| expandedRowOffset: expandableConfig.expandedRowOffset, | ||
| onTriggerExpand, | ||
| expandIconColumnIndex: expandableConfig.expandIconColumnIndex, | ||
|
|
@@ -953,6 +954,8 @@ const Table = <RecordType extends DefaultRecordType>( | |
| onTriggerExpand, | ||
| expandableConfig.expandIconColumnIndex, | ||
| expandableConfig.indentSize, | ||
| expandableConfig.forceRender, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| expandableConfig, | ||
| emptyNode, | ||
|
|
||
| // Column | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -53,6 +53,7 @@ export interface TableContextProps<RecordType = any> { | |||||||||
| expandableType: ExpandableType; | ||||||||||
| expandRowByClick: boolean; | ||||||||||
| expandedRowRender: ExpandedRowRender<RecordType>; | ||||||||||
| forceRender?: boolean | ((record: RecordType) => boolean); | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type for
Suggested change
|
||||||||||
| expandIcon: RenderExpandIcon<RecordType>; | ||||||||||
|
Comment on lines
+56
to
57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major 上下文类型与对外接口对齐(允许可选 index) 为与 - forceRender?: boolean | ((record: RecordType) => boolean);
+ forceRender?: boolean | ((record: RecordType, index?: number) => boolean);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| onTriggerExpand: TriggerEventHandler<RecordType>; | ||||||||||
| expandIconColumnIndex: number; | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -267,6 +267,7 @@ export interface ExpandableConfig<RecordType> { | |||||||||||
| columnWidth?: number | string; | ||||||||||||
| fixed?: FixedType; | ||||||||||||
| expandedRowOffset?: number; | ||||||||||||
| forceRender?: boolean|((record: RecordType) => boolean); | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type definition for
Suggested change
|
||||||||||||
| } | ||||||||||||
|
Comment on lines
+270
to
271
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major 对外 API 的函数签名需要统一(建议允许可选 index 参数) 当前 - forceRender?: boolean|((record: RecordType) => boolean);
+ // 与 BodyRow / TableContext 对齐,允许按行下标做条件判断
+ forceRender?: boolean | ((record: RecordType, index?: number) => boolean);同时顺便对联合类型两侧加空格,保持代码风格一致。 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
|
|
||||||||||||
| // =================== Render =================== | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This arrow function can be simplified to a single line for better readability.