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

docs(grid): [grid] add updateFooter demo #2755

Merged
merged 1 commit into from
Jan 8, 2025
Merged

Conversation

gimmyhehe
Copy link
Member

@gimmyhehe gimmyhehe commented Jan 7, 2025

PR

新增表格updateFooter文档

updateFooter这个API一直存在,但是缺少文档说明与demo。

image

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

close #2078

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced grid component with mobile-first support
    • Added ability to manually update footer data in grid
  • Improvements

    • Expanded grid method compatibility across platforms
    • Simplified footer calculation logic
    • Added dynamic footer updates for grid components
  • Testing

    • Introduced new test case for footer row and column merging

These updates improve the grid component's responsiveness and provide more flexible data management capabilities.

Copy link

coderabbitai bot commented Jan 7, 2025

Walkthrough

The 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

File Change Summary
examples/sites/demos/apis/grid.js Updated method signatures for grid component, expanding mode from ['pc'] to ['pc', 'mobile-first']
examples/sites/demos/pc/app/grid/footer/footer-row-or-column-span-composition-api.vue Simplified footer method logic, focusing on column indices
examples/sites/demos/pc/app/grid/footer/footer-row-or-column-span.vue Modified footer method calculations and column span handling
examples/sites/demos/pc/app/grid/footer/update-footer-composition-api.vue Added new component for dynamic grid footer with reactive data
examples/sites/demos/pc/app/grid/footer/update-footer.spec.ts Added new test case for footer row/column merging functionality
examples/sites/demos/pc/app/grid/footer/update-footer.vue Introduced new grid component with dynamic footer calculations
examples/sites/demos/pc/app/grid/webdoc/grid-footer.js Added new demo entry for manually updating footer data

Possibly related PRs

Suggested Labels

documentation

Suggested Reviewers

  • zzcr

Poem

🐰 Grid dancing, mobile and neat,
Rows and columns now complete,
Footer leaps with data's might,
Responsive magic takes its flight!
CodeRabbit's grid, a joyful sight! 🌈


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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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

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:

Files Summary
examples/sites/demos/apis/grid.js Updated to support 'mobile-first' mode alongside 'pc' mode.
examples/sites/demos/pc/app/grid/footer/footer-row-or-column-span-composition-api.vue
examples/sites/demos/pc/app/grid/footer/footer-row-or-column-span.vue
Modified logic for calculating employee totals and row/column spans.
examples/sites/demos/pc/app/grid/footer/update-footer-composition-api.vue
examples/sites/demos/pc/app/grid/footer/update-footer.vue
Added new demo files for the updateFooter functionality.
examples/sites/demos/pc/app/grid/footer/update-footer.spec.ts Added tests for the updateFooter functionality.
examples/sites/demos/pc/app/grid/webdoc/grid-footer.js Documentation updated to include the new updateFooter demo.

])

function handleChange() {
gridRef.value.updateFooter()

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()

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.

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

🧹 Nitpick comments (2)
examples/sites/demos/pc/app/grid/footer/update-footer.spec.ts (1)

3-11: Test could be more comprehensive

While the test covers the basic functionality, consider adding more test cases:

  1. Decrease operation
  2. Multiple updates
  3. 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 call

For 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6e29e24 and b5d50f3.

📒 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 entry

The 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 case

The empty data case is properly handled with a default footer value.

Comment on lines +88 to +94
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)
Copy link

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.

Comment on lines +96 to +98
if (column.property === 'employees') {
return data.map((item) => item[column.property]).reduce((acc, item) => acc + item)
}
Copy link

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.

Suggested change
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
}
}

@zzcr zzcr merged commit 2be6d13 into dev Jan 8, 2025
14 of 21 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.

✨ [Feature]: 合计行重算方法
2 participants