Skip to content

feat: modal and drawer locking - #5648

Merged
mynetfan merged 4 commits into
vbenjs:mainfrom
mynetfan:feat/drawer-lock
Mar 4, 2025
Merged

mynetfan merged 4 commits into
vbenjs:mainfrom
mynetfan:feat/drawer-lock

Conversation

@mynetfan

@mynetfan mynetfan commented Mar 4, 2025 •

Copy link
Copy Markdown
Collaborator

Description

  • 改进Modal的lock方法;
  • 新增unlock方法用作lock(false)的别名;
  • 为Drawer新增lock和unlock方法

fix: #5645

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 modals and drawers now feature a temporary submission lock that disables close and cancel actions while showing a loading state, helping prevent duplicate submissions.
    • Additional UI improvements include optional auto-focus and customizable cancel button visibility, ensuring a smoother interaction during critical operations.
  • Documentation

    • Updated guides now clearly explain the new locking functionality and its availability with specific version requirements.

@mynetfan
mynetfan requested review from a team, anncwb and vince292007 as code owners March 4, 2025 13:45
@changeset-bot

changeset-bot Bot commented Mar 4, 2025 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 90de32a

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

@coderabbitai

coderabbitai Bot commented Mar 4, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request introduces new lock and unlock functionalities for both drawer and modal components. It adds corresponding API methods, state properties, and updates documentation along with demo examples. The changes ensure that components can enter a submission state where user interactions are controlled consistently through a locking mechanism, with version restrictions starting from >5.5.3.

Changes

File(s) Change Summary
docs/src/components/common-ui/vben-drawer.md, docs/src/components/common-ui/vben-modal.md Updated documentation for drawerApi and modalApi to include new lock/unlock methods with version restrictions and usage explanations.
packages/@core/ui-kit/popup-ui/src/drawer/drawer-api.ts, .../drawer/drawer.ts, .../drawer/drawer.vue Added a submitting state and implemented lock and unlock methods in the drawer API. Modified props and UI logic to disable closing actions during submission.
packages/@core/ui-kit/popup-ui/src/modal/modal-api.ts, .../modal/modal.vue, packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogContent.vue Introduced unlock in the Modal API and adjusted modal/dialog properties to manage close actions during a submission state.
playground/src/views/examples/drawer/base-demo.vue, playground/src/views/examples/modal/base-demo.vue Added demo functions (lockDrawer and lockModal) and buttons to showcase the temporary locking behavior for drawer and modal components.

Sequence Diagram(s)

sequenceDiagram
  participant User as User
  participant Demo as Drawer Demo
  participant DrawerApi as Drawer API

  User->>Demo: Click "锁定抽屉状态" button
  Demo->>DrawerApi: Call lock(true)
  DrawerApi->>DrawerApi: Set submitting = true (lock drawer)
  Note over DrawerApi: Drawer UI shows loading state and disables close actions
  Demo->>DrawerApi: After 3000ms, call lock(false)
  DrawerApi->>DrawerApi: Set submitting = false (unlock drawer)
  Note over DrawerApi: Drawer returns to normal state
Loading
sequenceDiagram
  participant User as User
  participant Demo as Modal Demo
  participant ModalApi as Modal API

  User->>Demo: Click button to lock modal
  Demo->>ModalApi: Call lock(true)
  ModalApi->>ModalApi: Set locked state (prevent close actions)
  Note over ModalApi: Modal reflects a loading/submission state
  Demo->>ModalApi: After 3000ms, call unlock()
  ModalApi->>ModalApi: Set locked state to false (unlock modal)
  Note over ModalApi: Modal returns to normal state
Loading

Possibly related PRs

Suggested labels

feature

Suggested reviewers

  • anncwb
  • vince292007

Poem

I’m a rabbit with a codey beat,
Hopping through APIs so neat.
Lock and unlock, a rhythmic tune,
Keeping submissions safe by noon.
With a twitchy nose and joyful cheer,
CodeRabbit celebrates changes here!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
  • @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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/@core/ui-kit/popup-ui/src/modal/modal.vue (1)

203-209: Improved modal close button control with better separation of concerns.

The changes to DialogContent properties improve the control flow:

  • :show-close="closable" now directly determines if the close button is visible
  • :close-disabled="submitting" allows the button to remain visible but disabled when submitting

This is a better separation of concerns than the previous implementation which conflated visibility with disabled state.

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

142-147: Need to fix table column count inconsistency.

The table row for "setState" has only 3 columns while the header has 4 columns. This causes a formatting issue that should be fixed for better readability.

-| setState | 动态设置弹窗状态属性 | `(((prev: ModalState) => Partial<ModalState>)\| Partial<ModalState>)=>drawerApi` |
+| setState | 动态设置弹窗状态属性 | `(((prev: ModalState) => Partial<ModalState>)\| Partial<ModalState>)=>drawerApi` | --- |
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

142-142: Table column count
Expected: 4; Actual: 3; Too few cells, row will be missing data

(MD056, table-column-count)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between decd9c5 and 90de32a.

📒 Files selected for processing (10)
  • docs/src/components/common-ui/vben-drawer.md (1 hunks)
  • docs/src/components/common-ui/vben-modal.md (1 hunks)
  • packages/@core/ui-kit/popup-ui/src/drawer/drawer-api.ts (3 hunks)
  • packages/@core/ui-kit/popup-ui/src/drawer/drawer.ts (3 hunks)
  • packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue (8 hunks)
  • packages/@core/ui-kit/popup-ui/src/modal/modal-api.ts (1 hunks)
  • packages/@core/ui-kit/popup-ui/src/modal/modal.vue (1 hunks)
  • packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogContent.vue (2 hunks)
  • playground/src/views/examples/drawer/base-demo.vue (2 hunks)
  • playground/src/views/examples/modal/base-demo.vue (2 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
docs/src/components/common-ui/vben-drawer.md

142-142: Table column count
Expected: 4; Actual: 3; Too few cells, row will be missing data

(MD056, table-column-count)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: post-update (windows-latest)
🔇 Additional comments (30)
packages/@core/ui-kit/popup-ui/src/modal/modal-api.ts (1)

183-190: Good addition of the unlock method as an alias for lock(false)

This is a well-implemented addition that provides a more semantically clear way to release the modal's lock state. The method properly returns the result of this.lock(false) to maintain the fluent interface pattern used throughout the class.

playground/src/views/examples/modal/base-demo.vue (3)

4-4: Appropriate import for the new Button component

The import statement correctly includes the Button component from ant-design-vue which is needed for the new locking functionality demo.


22-27: Good implementation of the lockModal function

This function demonstrates a practical use case for the new lock/unlock API. The implementation correctly locks the modal and then unlocks it after a 3-second delay, providing a clear example of the API usage.


32-32: Well-integrated button for demonstrating the lock functionality

The button is properly integrated into the template and includes the appropriate primary type and click handler to demonstrate the modal locking functionality.

playground/src/views/examples/drawer/base-demo.vue (3)

4-4: Appropriate import for the new Button component

The import statement correctly includes the Button component from ant-design-vue which is needed for the new locking functionality demo.


19-24: Good implementation of the lockDrawer function

The function demonstrates the drawer lock/unlock API in a consistent manner with the modal example. It correctly locks the drawer and then unlocks it after a 3-second delay, providing a clear example of how to use this functionality.


30-30: Well-integrated button for demonstrating the drawer lock functionality

The button is properly positioned in the template with the appropriate primary type and click handler to demonstrate the drawer locking functionality.

packages/@core/ui-kit/shadcn-ui/src/ui/dialog/DialogContent.vue (3)

26-27: Good addition of the closeDisabled prop

Adding this prop is necessary for supporting the locking mechanism and controlling the close button's state. The prop follows the component's naming conventions and is well-integrated with the existing props structure.


34-35: Proper default value for closeDisabled

Setting the default value to false ensures backward compatibility with existing code that doesn't explicitly set this prop, maintaining the component's previous behavior.


112-113: Correct binding of the closeDisabled prop to the DialogClose component

The disabled attribute is properly bound to the closeDisabled prop, allowing the close button to be conditionally disabled when the dialog is in a locked state.

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

158-158: Documentation added for new unlock method.

The new unlock method documentation provides a clear and consistent API for unlocking modals that have been locked, serving as a more semantically meaningful alternative to lock(false).


162-162: Updated lock method documentation to include unlock references.

The documentation update for the lock method now correctly references the new unlock method as an alternative way to release the locked state, improving the clarity and completeness of the API documentation.

packages/@core/ui-kit/popup-ui/src/drawer/drawer.ts (1)

108-111: Added submitting state property to DrawerProps.

The addition of the submitting property with proper JSDoc comments aligns the drawer component with the modal component, enabling consistent locking behavior across all popup components in the framework.

packages/@core/ui-kit/popup-ui/src/drawer/drawer-api.ts (4)

55-55: Added submitting state to drawer default state.

The default state now includes submitting: false, which is necessary for the new locking functionality to work properly.


96-100: Improved close method to reset submitting state.

The close method now explicitly resets the submitting state to false when closing the drawer, ensuring proper cleanup and preventing potential state issues if the drawer is reopened.


108-115: Added lock method to drawer API.

The lock method implementation with proper JSDoc documentation allows users to lock the drawer during submission processes, preventing unwanted interactions and providing consistent behavior with the modal component.


175-181: Added unlock method to drawer API.

The unlock method serves as a semantic alias for lock(false), providing a more intuitive API for releasing the locked state of a drawer. The implementation and documentation are clear and consistent with the modal component.

packages/@core/ui-kit/popup-ui/src/drawer/drawer.vue (10)

39-39: Good implementation of the submitting prop.

The default value of false is appropriate for this feature as it ensures backward compatibility with existing code.


77-77: Good priority handling for the submitting state.

Correctly including the submitting state in the usePriorityValues function ensures consistency between props and internal state.


96-97: Properly enhanced modal interaction safety.

Adding the submitting.value check prevents unwanted modal dismissal during form submission, which is a good UX practice to prevent data loss.


101-103: Escape key prevention works correctly during submission.

The implementation properly prevents the escape key from closing the drawer when in submitting state, consistent with the locking mechanism.


109-114: Comprehensive pointer event handling.

The condition now properly accounts for the submitting state, ensuring consistent behavior across all dismissal methods. The logical ordering of conditions is also good - checking submitting first makes the code more readable.


178-179: Properly disabled close button during submission.

Disabling the close button when submitting is active prevents users from inadvertently canceling operations in progress.


219-220: Consistent treatment of both close buttons.

Both close buttons (left and right) are treated consistently with respect to the submitting state, which ensures a predictable user experience.


244-248: Enhanced loading state visibility.

Showing the loading indicator during both standard loading operations and submission states provides clear visual feedback to the user.


268-269: Appropriately disabled cancel button during submission.

Disabling the cancel button during submission prevents users from accidentally canceling an operation in progress.


279-280: Good loading state for confirmation button.

The confirm button now correctly shows its loading state when either confirmLoading or submitting is true, providing appropriate visual feedback for both scenarios.

docs/src/components/common-ui/vben-drawer.md (3)

140-141: Table structure improved with version information.

Adding the version column is helpful for users to understand when specific features were introduced. This improves documentation clarity.


148-149: Well-documented new lock and unlock methods.

The documentation for the new lock and unlock methods is clear and informative. The version restriction information is also helpful to indicate when these features became available.


151-155: Excellent detailed explanation of the lock functionality.

The info block provides a comprehensive explanation of the lock method, its purpose, and its behavior. This helps developers understand when and how to use this feature effectively.

@mynetfan
mynetfan merged commit f380452 into vbenjs:main Mar 4, 2025
@mynetfan
mynetfan deleted the feat/drawer-lock branch March 4, 2025 14:00
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FEATURE: drawer 可以跟 modal 一样 增加lock 方法吗?

1 participant