-
Notifications
You must be signed in to change notification settings - Fork 276
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
docs(grid): [grid] add updateFooter demo #2755
Conversation
WalkthroughThe pull request introduces comprehensive updates to the grid component across multiple files, primarily focusing on expanding mobile-first support and enhancing footer functionality. The changes involve updating method signatures, modifying footer calculation logic, and adding new demo components that showcase grid footer interactions. The modifications aim to improve the grid's responsiveness and provide more flexible data presentation options. Changes
Possibly related PRs
Suggested Labels
Suggested Reviewers
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Walkthrough: This PR introduces a new demo for updating the footer in the grid component. It includes changes to support both PC and mobile-first modes, and adds new examples and tests for the updateFooter functionality. Changes:
|
]) | ||
|
||
function handleChange() { | ||
gridRef.value.updateFooter() |
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.
Ensure that gridRef.value
is properly initialized before calling updateFooter()
to avoid potential runtime errors.
}, | ||
methods: { | ||
handleChange() { | ||
this.$refs.grid.updateFooter() |
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.
Ensure that this.$refs.grid
is properly initialized before calling updateFooter()
to avoid potential runtime errors.
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.
Actionable comments posted: 2
🧹 Nitpick comments (2)
examples/sites/demos/pc/app/grid/footer/update-footer.spec.ts (1)
3-11
: Test could be more comprehensiveWhile the test covers the basic functionality, consider adding more test cases:
- Decrease operation
- Multiple updates
- Edge cases (e.g., empty data)
test('表尾合并行或列', async ({ page }) => { page.on('pageerror', (exception) => expect(exception).toBeNull()) const demo = page.locator('#update-footer') await page.goto('grid-footer#update-footer') await expect(demo.getByRole('cell', { name: '5310' })).toBeVisible() await demo.getByRole('cell', { name: '1300' }).click() await demo.locator('.tiny-numeric__increase').click() await expect(demo.getByRole('cell', { name: '5311' })).toBeVisible() + // Test decrease operation + await demo.locator('.tiny-numeric__decrease').click() + await expect(demo.getByRole('cell', { name: '5310' })).toBeVisible() + + // Test multiple updates + await demo.locator('.tiny-numeric__increase').click() + await demo.locator('.tiny-numeric__increase').click() + await expect(demo.getByRole('cell', { name: '5312' })).toBeVisible() }) + +test('表尾合并行或列 - 边缘情况', async ({ page }) => { + // Test with empty data + // Implementation details depend on how empty state is triggered +})examples/sites/demos/pc/app/grid/footer/update-footer-composition-api.vue (1)
82-84
: Consider debouncing the updateFooter callFor better performance, consider debouncing the updateFooter call when handling frequent changes.
+import { ref, onMounted } from 'vue' + +const debounceTimer = ref(null) + function handleChange() { - gridRef.value.updateFooter() + if (debounceTimer.value) clearTimeout(debounceTimer.value) + debounceTimer.value = setTimeout(() => { + gridRef.value.updateFooter() + }, 300) } + +onMounted(() => { + return () => { + if (debounceTimer.value) clearTimeout(debounceTimer.value) + } +})
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
examples/sites/demos/apis/grid.js
(133 hunks)examples/sites/demos/pc/app/grid/footer/footer-row-or-column-span-composition-api.vue
(2 hunks)examples/sites/demos/pc/app/grid/footer/footer-row-or-column-span.vue
(2 hunks)examples/sites/demos/pc/app/grid/footer/update-footer-composition-api.vue
(1 hunks)examples/sites/demos/pc/app/grid/footer/update-footer.spec.ts
(1 hunks)examples/sites/demos/pc/app/grid/footer/update-footer.vue
(1 hunks)examples/sites/demos/pc/app/grid/webdoc/grid-footer.js
(1 hunks)
👮 Files not reviewed due to content moderation or server errors (3)
- examples/sites/demos/pc/app/grid/footer/footer-row-or-column-span.vue
- examples/sites/demos/pc/app/grid/footer/update-footer.vue
- examples/sites/demos/apis/grid.js
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (2)
examples/sites/demos/pc/app/grid/webdoc/grid-footer.js (1)
33-43
: LGTM! Well-documented demo entryThe demo entry is well-structured with clear descriptions in both languages and proper references to the implementation file.
examples/sites/demos/pc/app/grid/footer/update-footer-composition-api.vue (1)
86-88
: LGTM! Good handling of empty data caseThe empty data case is properly handled with a default footer value.
if (columnIndex === 2) { | ||
return data.map((item) => item.employees).reduce((acc, item) => acc + item) | ||
} | ||
|
||
return null | ||
}), | ||
columns.map((column, columnIndex) => { | ||
if (columnIndex === 0) { | ||
return null | ||
} | ||
|
||
if (column.property === 'employees') { | ||
return null | ||
} | ||
|
||
return null | ||
}) | ||
columns.map(() => null) |
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.
🛠️ Refactor suggestion
Consider using column property instead of index
Using column indices makes the code brittle to column reordering. Consider using column properties for more maintainable code.
- if (columnIndex === 2) {
+ if (column.property === 'employees') {
return data.map((item) => item.employees).reduce((acc, item) => acc + item)
}
- return null
+ return ''
Committable suggestion skipped: line range outside the PR's diff.
if (column.property === 'employees') { | ||
return data.map((item) => item[column.property]).reduce((acc, item) => acc + item) | ||
} |
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.
🛠️ Refactor suggestion
Add error handling for the reduce operation
The reduce operation could throw if any employee value is non-numeric. Consider adding error handling and type safety.
if (column.property === 'employees') {
- return data.map((item) => item[column.property]).reduce((acc, item) => acc + item)
+ try {
+ return data
+ .map((item) => Number(item[column.property]) || 0)
+ .reduce((acc, item) => acc + item, 0)
+ } catch (error) {
+ console.error('Error calculating employee sum:', error)
+ return 0
+ }
}
📝 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.
if (column.property === 'employees') { | |
return data.map((item) => item[column.property]).reduce((acc, item) => acc + item) | |
} | |
if (column.property === 'employees') { | |
try { | |
return data | |
.map((item) => Number(item[column.property]) || 0) | |
.reduce((acc, item) => acc + item, 0) | |
} catch (error) { | |
console.error('Error calculating employee sum:', error) | |
return 0 | |
} | |
} |
PR
新增表格updateFooter文档
updateFooter这个API一直存在,但是缺少文档说明与demo。
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
close #2078
Summary by CodeRabbit
Release Notes
New Features
Improvements
Testing
These updates improve the grid component's responsiveness and provide more flexible data management capabilities.