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

fix: table internal search collspaed configuration does not take effect #4585

Merged
merged 2 commits into from
Oct 7, 2024

Conversation

anncwb
Copy link
Collaborator

@anncwb anncwb commented Oct 7, 2024

Description

fixed #4584

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • New Features
    • Enhanced form functionality within the grid component, allowing users to toggle the visibility of the form's collapse button.
    • Added a new toolbar button for toggling the form's collapse state.
  • Improvements
    • Improved reactivity in the grid component to ensure state synchronization with updated handling of component properties.
    • Enhanced state management in the form component for a more comprehensive approach.
  • Bug Fixes
    • Resolved issues with form reset and data reload processes.
  • Documentation
    • Clarified handling of form options and initialization logic for better user understanding.

@anncwb anncwb added the bug Something isn't working label Oct 7, 2024
@anncwb anncwb requested a review from vince292007 as a code owner October 7, 2024 08:01
Copy link

changeset-bot bot commented Oct 7, 2024

⚠️ No Changeset found

Latest commit: 79a9ae1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Oct 7, 2024

Walkthrough

The changes in this pull request involve modifications to the useVbenForm and useVbenVxeGrid functions, enhancing their state management capabilities. The api.setState method now merges props and attrs, improving how component states are managed. Additionally, reactivity checks have been updated to observe the entire options object, while the onBeforeUnmount lifecycle hook remains unchanged. These adjustments aim to refine the functionality of form and grid components within the application.

Changes

File Path Change Summary
packages/@core/ui-kit/form-ui/src/use-vben-form.ts Modified useVbenForm to merge props and attrs into state; updated reactivity checks for options.
packages/effects/plugins/src/vxe-table/use-vxe-grid.ts Removed commented variable; merged props and attrs in api.setState; uncommented reactivity support.

Assessment against linked issues

Objective Addressed Explanation
Ensure the collapse button functions correctly when using useVbenVxeGrid (4584) The changes do not explicitly address the collapse button functionality described in the issue.

Possibly related PRs

Suggested reviewers

  • vince292007

Poem

🐰 In the meadow, forms do play,
With buttons bright, they lead the way.
Collapsing down, then up they spring,
A joyful dance, oh what they bring!
With every click, the grid will cheer,
For rabbit's changes, now so clear! 🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f9c3a8d and 79a9ae1.

📒 Files selected for processing (2)
  • packages/@core/ui-kit/form-ui/src/use-vben-form.ts (1 hunks)
  • packages/effects/plugins/src/vxe-table/use-vxe-grid.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/@core/ui-kit/form-ui/src/use-vben-form.ts
  • packages/effects/plugins/src/vxe-table/use-vxe-grid.ts

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 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
Contributor

@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: 1

🧹 Outside diff range and nitpick comments (7)
packages/@core/ui-kit/form-ui/src/use-vben-form.ts (2)

29-29: LGTM with a suggestion for improvement

The change to include both props and attrs in the state is good for consistency. However, consider the order of spreading to ensure intended overriding behavior.

Consider changing the order of spreading to prioritize props over attrs:

-api.setState({ ...props, ...attrs });
+api.setState({ ...attrs, ...props });

This ensures that props values take precedence over attrs if there are any conflicting keys.


43-43: Approved, with a suggestion for robustness

Updating the state with the entire options object is consistent with watching the whole object. This ensures all changes in options are reflected in the state.

However, to prevent accidentally overwriting existing state that's not part of the options, consider merging the new options with the existing state:

-api.setState(options);
+api.setState(prevState => ({ ...prevState, ...options }));

This approach preserves any additional state that might have been set elsewhere while still updating with the new options.

packages/@core/ui-kit/form-ui/src/vben-use-form.vue (1)

Line range hint 60-65: LGTM: FormActions implementation with minor suggestion

The FormActions component is correctly implemented with conditional rendering and proper bindings for the collapsed state. This change addresses the core issue of the collapse functionality not working as intended.

Consider using the shorthand v-model syntax for better readability:

- :model-value="state.collapsed"
- @update:model-value="handleUpdateCollapsed"
+ v-model="state.collapsed"

This change would simplify the code while maintaining the same functionality.

playground/src/views/examples/vxe-table/form.vue (3)

6-6: LGTM! Consider removing unused imports.

The Button import is correctly added and used in the template. However, the message import is not used in the visible code. If it's not used elsewhere in the component, consider removing it to keep the imports clean.


97-106: Function looks good, but there's a typo in the name.

The toggleFormCollspae function correctly implements the form collapse functionality, addressing the issue described in #4584. It resets the form and toggles the visibility of the collapse button as intended.

However, there's a typo in the function name:

-function toggleFormCollspae() {
+function toggleFormCollapse() {

Also, ensure to update any references to this function name in the template or elsewhere in the code.


111-117: LGTM! Consider internationalization for button text.

The addition of the toolbar with a button to toggle form collapse is well-implemented and aligns with the PR objectives. The button is correctly placed and linked to the toggleFormCollspae function.

However, consider the following suggestions:

  1. Update the function name in the template to match the corrected name (after fixing the typo):
-<Button type="primary" @click="toggleFormCollspae">
+<Button type="primary" @click="toggleFormCollapse">
  1. Consider using an internationalization approach for the button text to support multiple languages if required:
-切换表单折叠按钮
+{{ t('toggleFormCollapseButton') }}

Replace with your preferred i18n method if different.

packages/effects/plugins/src/vxe-table/use-vxe-grid.ts (1)

11-11: Use camelCase for variable naming

Consider renaming IS_REACTIVE to isReactiveOption to adhere to JavaScript naming conventions. Uppercase names are typically reserved for constants, while camelCase is used for variables.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f0edad8 and f9c3a8d.

📒 Files selected for processing (6)
  • packages/@core/ui-kit/form-ui/src/components/form-actions.vue (1 hunks)
  • packages/@core/ui-kit/form-ui/src/use-vben-form.ts (2 hunks)
  • packages/@core/ui-kit/form-ui/src/vben-use-form.vue (1 hunks)
  • packages/effects/plugins/src/vxe-table/use-vxe-grid.ts (3 hunks)
  • packages/effects/plugins/src/vxe-table/use-vxe-grid.vue (1 hunks)
  • playground/src/views/examples/vxe-table/form.vue (2 hunks)
🧰 Additional context used
🔇 Additional comments (13)
packages/@core/ui-kit/form-ui/src/use-vben-form.ts (2)

Line range hint 1-53: Summary: Changes align with PR objectives and improve form handling

The modifications in this file enhance the reactivity and state management of the form component, which aligns well with the PR objectives of fixing issues with form configuration. The changes to watch the entire options object and update the state accordingly should address the problems with formOptions not taking effect as mentioned in the linked issue #4584.

Key improvements:

  1. More comprehensive state management by including both props and attrs.
  2. Enhanced reactivity by watching the entire options object.
  3. Consistent state updates with the full options object.

These changes should help resolve the issue where showCollapseButton and collapsed properties were not functioning as intended. However, to fully verify the fix:

#!/bin/bash
# Description: Verify the implementation of showCollapseButton and collapsed properties

# Search for usage of showCollapseButton and collapsed in formOptions
rg --type typescript -e 'formOptions.*showCollapseButton' -e 'formOptions.*collapsed'

# Search for the implementation of collapse functionality
ast-grep --lang typescript --pattern $'function $_($_, $_) {
  $$$
  showCollapseButton
  $$$
  collapsed
  $$$
}'

This script will help identify where and how these properties are used, allowing us to confirm that the changes in this file properly propagate to the collapse functionality implementation.


41-41: Approved, but consider performance implications

Watching the entire options object provides more comprehensive reactivity. This change allows the component to respond to changes in any part of the options, which is generally good for maintaining consistency.

However, this might lead to unnecessary re-renders if properties that don't affect the form are changed. To verify the impact, we can check how often the options object is modified:

If the results show frequent modifications to properties that don't affect the form, consider using a more granular watch or implementing shouldUpdate logic to optimize performance.

packages/@core/ui-kit/form-ui/src/vben-use-form.vue (4)

Line range hint 30-32: LGTM: Addition of handleUpdateCollapsed function

The new handleUpdateCollapsed function correctly updates the collapsed state of the form using the formApi.setState method. This addition aligns with the PR objective of fixing the collapse functionality issue.


42-42: LGTM: Addition of collapsed binding

The new binding :collapsed="state.collapsed" correctly connects the Form component's collapsed prop to the state.collapsed value. This change ensures that the form's collapsed state is always in sync and reactive, which addresses the core issue described in the PR objectives.


Line range hint 1-70: Summary: Effective implementation of collapse functionality

The changes in this file successfully address the issue described in the PR objectives. The implementation now provides a complete cycle for managing the form's collapsed state:

  1. The handleUpdateCollapsed function allows updating the state.
  2. The Form component is bound to the collapsed state.
  3. The FormActions component provides user interaction to toggle the state.

These changes should resolve the reported bug where the "Expand" button was not displayed and had no effect when clicked.

To ensure the changes are comprehensive, let's check if there are any other files that might need similar updates:

#!/bin/bash
# Search for other files that might use similar form collapse functionality
rg -l 'showCollapseButton|collapsed.*formOptions'

This will help us verify if the fix has been applied consistently across the codebase.


Line range hint 3-3: Query: Removal of watch function

The watch function for form.values has been commented out. Can you provide more context on why this change was made? Removing this watch might affect how the component reacts to form value changes.

To understand the impact, let's check if handleValuesChange is used elsewhere in the codebase:

Also applies to: 5-5, 7-7

✅ Verification successful

**Verification Successful: No unintended layout changes detected.**  
All padding adjustments in `use-vxe-grid.vue` are isolated and consistent with existing patterns in the codebase.



</details>

<details>
<summary>🏁 Scripts executed</summary>

The following scripts were executed for the analysis:

Script:

```shell
#!/bin/bash
# Description: Check for any unintended layout changes in other components using similar classes

# Test: Search for other components using pb-6 class that might need similar updates
rg --type vue 'class="[^"]*pb-6'

# Test: Verify the consistency of bottom padding across similar form containers
rg --type vue 'class="[^"]*relative rounded py-3 pb-[46]'

Length of output: 150


Script:

#!/bin/bash
# Description: Check for any unintended layout changes in other components using similar classes

# Test: Search for other components using pb-6 class that might need similar updates
rg 'class="[^"]*pb-6' --type-add 'vue:*.vue' --type vue

# Test: Verify the consistency of bottom padding across similar form containers
rg 'class="[^"]*relative rounded py-3 pb-\[46\]' --type-add 'vue:*.vue' --type vue

Length of output: 227


Script:

#!/bin/bash
# Description: Check for any unintended layout changes in other components using similar padding classes

# Test: Search for other components using pb-6 class that might need similar updates
rg 'class="[^"]*pb-6' --type-add 'vue:*.vue' --type vue

# Test: Search for components using pb-4 class to ensure consistency
rg 'class="[^"]*pb-4' --type-add 'vue:*.vue' --type vue

Length of output: 453

packages/effects/plugins/src/vxe-table/use-vxe-grid.ts (2)

3-3: Appropriate import of 'watch' from 'vue'

The addition of watch to the import statement is necessary for implementing reactivity support in the code.


23-23: Synchronizing API state with props and attrs

Merging props and attrs into api.setState ensures that the API state reflects the current component properties and attributes. This practice keeps the API state consistent with the component's external interface.

packages/effects/plugins/src/vxe-table/use-vxe-grid.ts Outdated Show resolved Hide resolved
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: 使用useVbenVxeGrid创建表格,配置formOptions中的收缩表单错误
1 participant