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

feat: form support reverse action buttons #5108

Merged
merged 2 commits into from
Dec 11, 2024

Conversation

mynetfan
Copy link
Collaborator

@mynetfan mynetfan commented Dec 11, 2024

Description

添加翻转表单操作按钮的属性,用于控制提交按钮和重置按钮的前后位置。
close #5103

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

    • Added a new property actionButtonsReverse to control the order of action buttons in the Vben Form component.
    • Introduced a button in the UI to toggle the action button positioning.
  • Documentation

    • Updated documentation for the Vben Form component to include details about the new actionButtonsReverse property and dynamic field interactions.
  • Bug Fixes

    • Enhanced rendering logic for action buttons to accommodate the new property without altering existing functionalities.

@mynetfan mynetfan requested review from anncwb, vince292007 and a team as code owners December 11, 2024 07:08
Copy link

changeset-bot bot commented Dec 11, 2024

⚠️ No Changeset found

Latest commit: f7dd1fe

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 Dec 11, 2024

Caution

Review failed

The pull request is closed.

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/@core/ui-kit/form-ui/src/components/form-actions.vue

Oops! Something went wrong! :(

ESLint: 9.16.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/node_modules/@vben/eslint-config/dist/index.mjs' imported from /eslint.config.mjs
at finalizeResolution (node:internal/modules/esm/resolve:257:11)
at moduleResolve (node:internal/modules/esm/resolve:914:10)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

Walkthrough

The pull request introduces enhancements to the Vben Form component documentation and its associated functionality. A new property, actionButtonsReverse, is added to allow users to control the order of action buttons in the form. The documentation is updated to clarify the usage of this property, as well as the return values of the useVbenForm function and the dependencies property. Additionally, modifications in the form-actions.vue component and the api.vue file implement the new functionality, allowing for dynamic button positioning based on user interaction.

Changes

File Path Change Summary
docs/src/components/common-ui/vben-form.md Updated documentation to include actionButtonsReverse property, expanded API section, and detailed dependencies property.
packages/@core/ui-kit/form-ui/src/components/form-actions.vue Added conditional rendering for action buttons based on actionButtonsReverse, modified button classes.
packages/@core/ui-kit/form-ui/src/types.ts Added optional property actionButtonsReverse to VbenFormProps interface.
playground/src/views/examples/form/api.vue Introduced isReverseActionButtons variable, updated handleClick method, and added button to toggle action buttons' position.

Assessment against linked issues

Objective Addressed Explanation
Control the order of action buttons in the form (#[5103])
Enhance documentation for form functionalities (#[5103])

Possibly related PRs

Suggested reviewers

  • vince292007

Poem

🐰 In the form where buttons play,
A new way to arrange the fray.
With a flip, they dance and sway,
Action buttons lead the way!
Click to change, it’s fun, hooray!
Forms are now a brighter day! 🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 06968cd and f7dd1fe.

📒 Files selected for processing (1)
  • packages/@core/ui-kit/form-ui/src/components/form-actions.vue (1 hunks)

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. (Experiment)
  • @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: 0

🧹 Outside diff range and nitpick comments (2)
packages/@core/ui-kit/form-ui/src/components/form-actions.vue (1)

145-158: Consider refactoring duplicated submit button template.

The submit button template is duplicated with only minor differences. Consider extracting it into a separate template or component to improve maintainability.

+ <!-- Extract to a separate template -->
+ <template #submit-button="{ class = '' }">
+   <component
+     :is="COMPONENT_MAP.PrimaryButton"
+     v-if="submitButtonOptions.show"
+     :class="class"
+     type="button"
+     @click="handleSubmit"
+     v-bind="submitButtonOptions"
+   >
+     {{ submitButtonOptions.content }}
+   </component>
+ </template>

  <template v-if="rootProps.actionButtonsReverse">
    <slot name="submit-before"></slot>
-   <component
-     :is="COMPONENT_MAP.PrimaryButton"
-     v-if="submitButtonOptions.show"
-     type="button"
-     @click="handleSubmit"
-     v-bind="submitButtonOptions"
-   >
-     {{ submitButtonOptions.content }}
-   </component>
+   <template v-slot:submit-button></template>
  </template>

  <!-- ... -->

  <template v-if="!rootProps.actionButtonsReverse">
    <slot name="submit-before"></slot>
-   <component
-     :is="COMPONENT_MAP.PrimaryButton"
-     v-if="submitButtonOptions.show"
-     class="ml-3"
-     type="button"
-     @click="handleSubmit"
-     v-bind="submitButtonOptions"
-   >
-     {{ submitButtonOptions.content }}
-   </component>
+   <template v-slot:submit-button="{ class: 'ml-3' }"></template>
  </template>

Also applies to: 174-188

docs/src/components/common-ui/vben-form.md (1)

310-310: Enhance the documentation for actionButtonsReverse property.

While the property is well-documented with its basic attributes, consider adding:

  • An example usage scenario
  • Visual representation of button positions (before/after)
  • Impact on form submission behavior
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 43adc94 and 06968cd.

📒 Files selected for processing (4)
  • docs/src/components/common-ui/vben-form.md (1 hunks)
  • packages/@core/ui-kit/form-ui/src/components/form-actions.vue (1 hunks)
  • packages/@core/ui-kit/form-ui/src/types.ts (1 hunks)
  • playground/src/views/examples/form/api.vue (5 hunks)
🔇 Additional comments (7)
packages/@core/ui-kit/form-ui/src/types.ts (1)

310-313: LGTM! Clean type definition with good documentation.

The new actionButtonsReverse property is well-defined and documented, following the existing interface patterns.

packages/@core/ui-kit/form-ui/src/components/form-actions.vue (1)

166-166: LGTM! Correct margin adjustment for the new layout.

The margin class change from mr-3 to ml-3 is appropriate for maintaining consistent spacing in both normal and reversed button layouts.

playground/src/views/examples/form/api.vue (3)

10-14: LGTM! Clean state management implementation.

The reactive state management for actionButtonsReverse is well-implemented and properly initialized in the form configuration.


168-172: LGTM! Consistent handler implementation.

The new case for reverseActionButtons follows the existing pattern and properly updates both the local state and form configuration.


242-244: LGTM! Clear and consistent UI implementation.

The new button for reversing action buttons is well-integrated into the existing UI layout.

docs/src/components/common-ui/vben-form.md (2)

Line range hint 1-24: Documentation structure is well-organized and comprehensive.

The documentation follows best practices with:

  • Clear section hierarchy
  • Detailed API documentation
  • Comprehensive type definitions

Line range hint 310-400: Verify the completeness of type definitions for new features.

Let's ensure all new properties are properly typed in the codebase.

✅ Verification successful

Type definitions and usage are properly implemented

The verification shows that:

  • The actionButtonsReverse property is properly typed as boolean in the interface definition (packages/@core/ui-kit/form-ui/src/types.ts)
  • The property is correctly used in the component implementation:
    • Utilized in form-actions component logic (packages/@core/ui-kit/form-ui/src/components/form-actions.vue)
    • Demonstrated in example usage (playground/src/views/examples/form/api.vue)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify type definitions for actionButtonsReverse property

# Check if the property is properly typed in the component interface
ast-grep --pattern 'interface $interface {
  $$$
  actionButtonsReverse?: boolean;
  $$$
}'

# Check if the property is used in component implementation
rg "actionButtonsReverse.*=.*" -t vue

Length of output: 161


Script:

#!/bin/bash
# Let's try a different approach to verify the type definitions and usage

# Search for actionButtonsReverse in all TypeScript files
rg "actionButtonsReverse" -t ts

# Search for interface or type definitions containing form props
ast-grep --pattern 'interface $interface {
  $$$
  submitButtonOptions?: $_
  $$$
}'

# Also search for any .vue files (without file type filter)
rg "actionButtonsReverse" --type-add 'vue:*.vue' -t vue

Length of output: 702

@mynetfan mynetfan merged commit 7c4dfdc into vbenjs:main Dec 11, 2024
13 checks passed
@mynetfan mynetfan deleted the feat/form-actions-reverse branch December 11, 2024 07:29
@anncwb anncwb added the feature label Dec 12, 2024
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.

FEATURE: 希望同步兼容vxe版本以及form表单中部分小功能的期望
2 participants