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: add confirmDisabled for Dialog #4959

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

mynetfan
Copy link
Collaborator

@mynetfan mynetfan commented Nov 27, 2024

Description

Dialog添加confirmDisabled属性用于控制提交按钮的禁用状态。在一些类似表单弹窗的场景下,可以在不满足提交条件时自行禁用提交按钮。
close #4946

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

    • Introduced a new property confirmDisabled for the modal, allowing users to disable the confirm button.
    • Enhanced modal configuration options for better user interaction control.
  • Documentation

    • Updated documentation to include the new confirmDisabled property and its functionality.

@mynetfan mynetfan requested review from anncwb, vince292007 and a team as code owners November 27, 2024 02:49
Copy link

changeset-bot bot commented Nov 27, 2024

⚠️ No Changeset found

Latest commit: 9d12cf4

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 Nov 27, 2024

Walkthrough

The pull request introduces a new property, confirmDisabled, to the Vben Modal component, allowing users to disable the confirm button. This property is added to multiple files, including the modal's API, props interface, and the documentation. The changes enhance the modal's configurability without altering existing functionalities, ensuring that the confirm button's visibility and behavior can be dynamically managed.

Changes

File Path Change Summary
docs/src/components/common-ui/vben-modal.md Updated documentation to include confirmDisabled property and its details in the API section.
packages/@core/ui-kit/popup-ui/src/modal/modal-api.ts Added confirmDisabled property to defaultState in ModalApi class, initialized to false.
packages/@core/ui-kit/popup-ui/src/modal/modal.ts Introduced confirmDisabled as an optional property in ModalProps interface.
packages/@core/ui-kit/popup-ui/src/modal/modal.vue Integrated confirmDisabled into modal's props and bound it to the confirm button's :disabled attribute.
playground/src/views/examples/modal/auto-height-demo.vue Updated handleUpdate function to manage confirmDisabled state during loading processes.

Assessment against linked issues

Objective Addressed Explanation
Add confirmDisabled property to the modal component and allow dynamic modification (#4946)

Possibly related issues

Possibly related PRs

Suggested labels

feature

Suggested reviewers

  • vince292007
  • anncwb

Poem

In the modal's cozy space,
A button waits with grace.
With confirmDisabled now in sight,
We control its state, just right!
A toggle here, a toggle there,
User joy is in the air! 🐇✨

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/popup-ui/src/modal/modal-api.ts

Oops! Something went wrong! :(

ESLint: 9.15.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)


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: 0

🧹 Outside diff range and nitpick comments (5)
playground/src/views/examples/modal/auto-height-demo.vue (1)

25-29: Consider adding error handling for robustness

The async operation could benefit from error handling to ensure the modal states are properly reset even when errors occur.

Consider updating the implementation like this:

 function handleUpdate(len: number) {
   modalApi.setState({ confirmDisabled: true, loading: true });
-  setTimeout(() => {
-    list.value = Array.from({ length: len }, (_v, k) => k + 1);
-    modalApi.setState({ confirmDisabled: false, loading: false });
-  }, 2000);
+  const DEMO_TIMEOUT = 2000;
+  setTimeout(() => {
+    try {
+      list.value = Array.from({ length: len }, (_v, k) => k + 1);
+    } catch (error) {
+      console.error('Failed to update list:', error);
+    } finally {
+      modalApi.setState({ confirmDisabled: false, loading: false });
+    }
+  }, DEMO_TIMEOUT);
 }
packages/@core/ui-kit/popup-ui/src/modal/modal.ts (1)

38-41: Enhance JSDoc documentation for the new property.

While the implementation is correct, the documentation could be more comprehensive to match the style of other properties.

Apply this diff to improve the documentation:

  /**
-  * 禁用确认按钮
+  * 是否禁用确认按钮。用于控制确认按钮的禁用状态,常用于表单验证等场景
+  * @default false
   */
  confirmDisabled?: boolean;
packages/@core/ui-kit/popup-ui/src/modal/modal-api.ts (1)

44-44: Implementation satisfies dynamic state management requirement.

The integration with the existing state management system (setState, batchStore, and store's onUpdate) provides robust support for dynamically controlling the confirm button's disabled state, which directly addresses the requirements in issue #4946.

Usage example for dynamic updates:

// Single update
modalApi.setState({ confirmDisabled: true });

// Batch updates
modalApi.batchStore(() => {
  modalApi.setState({ confirmDisabled: true });
  modalApi.setState({ confirmLoading: true });
});
docs/src/components/common-ui/vben-modal.md (2)

96-96: Enhance the property description with use cases.

The confirmDisabled property documentation could be more helpful by including common use cases. Consider expanding the description to mention scenarios like form validation or data loading states.

-| confirmDisabled | 禁用确认按钮 | `boolean` | `false` |
+| confirmDisabled | 禁用确认按钮,常用于表单验证、数据加载等场景 | `boolean` | `false` |

Line range hint 1-150: Add usage example for the confirmDisabled property.

To help developers understand how to use this new feature effectively, consider adding a demo that showcases:

  1. Dynamic control of the confirm button's disabled state
  2. Integration with table selections (as mentioned in issue FEATURE: 能否增加弹框确认按钮的disabled属性,并且能动态修改 #4946)
  3. Form validation scenarios

This could be added as a new section similar to existing examples like "基础用法" or "自动计算高度".

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f85badf and 9d12cf4.

📒 Files selected for processing (5)
  • docs/src/components/common-ui/vben-modal.md (1 hunks)
  • packages/@core/ui-kit/popup-ui/src/modal/modal-api.ts (1 hunks)
  • packages/@core/ui-kit/popup-ui/src/modal/modal.ts (1 hunks)
  • packages/@core/ui-kit/popup-ui/src/modal/modal.vue (2 hunks)
  • playground/src/views/examples/modal/auto-height-demo.vue (1 hunks)
🔇 Additional comments (6)
playground/src/views/examples/modal/auto-height-demo.vue (1)

25-25: Well-implemented state management for the new confirmDisabled property!

The implementation correctly manages both the confirmDisabled and loading states atomically, preventing user interaction during the update process. This is a good practice that ensures UI consistency.

Also applies to: 28-28

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

38-41: Verify integration with modal state management.

The property is correctly added to ModalProps, but we should verify its integration with the modal system.

✅ Verification successful

Property is properly integrated with modal system

The confirmDisabled property is correctly integrated across the modal system:

  • It's initialized in the default state in modal-api.ts
  • It's properly bound to the confirm button in the modal template using :disabled="confirmDisabled"
  • The state management through ModalApi and useModal correctly handles the property
  • The template correctly applies the disabled state to the confirm button component
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new property is properly integrated across the modal system

# Check if the property is properly handled in related files
echo "Checking modal-related files for proper integration..."

# Look for modal state management files
rg -l "ModalState|ModalApi" --type ts

# Check for proper initialization in default state
ast-grep --pattern 'defaultState = {
  $$$
  confirmDisabled: $_,
  $$$
}'

# Verify the property is used in the template
rg "confirmDisabled|:disabled" --type vue

Length of output: 534


Script:

#!/bin/bash
# Let's check the actual implementation and usage of confirmDisabled

# First, let's see the modal implementation
echo "=== Modal Implementation ==="
rg -A 5 "confirmDisabled" packages/@core/ui-kit/popup-ui/src/modal/modal.ts

# Check use-modal.ts for state management
echo "=== Modal State Management ==="
cat packages/@core/ui-kit/popup-ui/src/modal/use-modal.ts

# Check modal-api.ts for API handling
echo "=== Modal API ==="
cat packages/@core/ui-kit/popup-ui/src/modal/modal-api.ts

# Look for template files with .tsx extension since Vue might be using TSX
echo "=== Template Usage ==="
rg "confirmDisabled|:disabled" --type ts

Length of output: 7241


Script:

#!/bin/bash
# Let's check the modal.vue template to see how the confirmDisabled is used
echo "=== Modal Template ==="
cat packages/@core/ui-kit/popup-ui/src/modal/modal.vue

# Also check for any test files that might verify this functionality
echo "=== Modal Tests ==="
cat "packages/@core/ui-kit/popup-ui/src/modal/__tests__/modal-api.test.ts"

Length of output: 11764

packages/@core/ui-kit/popup-ui/src/modal/modal-api.ts (2)

44-44: LGTM! The implementation aligns with PR objectives.

The addition of confirmDisabled with a default value of false is well-integrated into the existing state management pattern and maintains backward compatibility.


44-44: Verify type definitions for ModalState.

Please ensure that the confirmDisabled property is properly defined in the ModalState type interface.

✅ Verification successful

Let me search for ModalProps definition since ModalState extends it, and the confirmDisabled property might be defined there.


Type definition for confirmDisabled is properly defined

The confirmDisabled property is correctly defined in the ModalProps interface (line 41), which is extended by ModalState. The property is defined as an optional boolean with proper documentation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify ModalState type definition includes confirmDisabled property
# Expected: Find type definition with confirmDisabled property

# Search for ModalState type definition
ast-grep --pattern 'interface ModalState {
  $$$
  confirmDisabled$_
  $$$
}'

# Alternatively, search using ripgrep
rg -A 20 'interface\s+ModalState'

Length of output: 1592


Script:

#!/bin/bash
# Search for ModalProps interface definition
ast-grep --pattern 'interface ModalProps {
  $$$
}'

# Also search with ripgrep for better context
rg -A 20 'interface\s+ModalProps'

Length of output: 8815

packages/@core/ui-kit/popup-ui/src/modal/modal.vue (2)

62-62: LGTM! Property addition aligns with existing patterns

The confirmDisabled property is correctly integrated into the component's prop system using the usePriorityValues utility, maintaining consistency with other modal control properties.


289-289: LGTM! Verify interaction between disabled and loading states

The disabled binding is correctly implemented. However, it's good practice to verify the interaction between the disabled and loading states.

Let's verify the component's usage patterns:

✅ Verification successful

Based on the search results, I can see that the modal component is used in various scenarios, and there's a clear example in playground/src/views/examples/modal/auto-height-demo.vue where both confirmDisabled and loading states are used together correctly. Let me verify the implementation further with one more search:


Let me try one more search to verify the implementation:


Implementation verified through usage patterns

Based on the search results, particularly from playground/src/views/examples/modal/auto-height-demo.vue, we can see that both states (confirmDisabled and loading) are used together correctly in real implementations. The example shows proper state management where both states are toggled simultaneously:

modalApi.setState({ confirmDisabled: true, loading: true });
// ... async operation ...
modalApi.setState({ confirmDisabled: false, loading: false });

This demonstrates that the disabled binding works well alongside the loading state, and the implementation is being used as intended.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for existing usages of the modal component to understand common patterns
# and ensure the new disabled state works well with existing implementations

# Look for modal usage patterns
rg -A 5 "modalApi\.setState|confirmLoading.*true" 

# Look for potential edge cases in modal state management
ast-grep --pattern 'modalApi?.setState((prev) => { $$$
  return { $$$, confirmLoading: true, $$$ };
})'

Length of output: 5755


Script:

#!/bin/bash
# Look for the modal component's implementation to verify the disabled and loading state handling
rg -A 10 "confirmDisabled.*loading" packages/@core/ui-kit/popup-ui/src/modal/

Length of output: 79


Script:

#!/bin/bash
# Look for the modal component's implementation focusing on the button props
rg -A 5 ":disabled.*:loading|:loading.*:disabled" packages/@core/ui-kit/popup-ui/src/modal/

Length of output: 93

@vince292007 vince292007 merged commit dedba18 into vbenjs:main Nov 27, 2024
14 checks passed
@mynetfan mynetfan deleted the feat/dialog-confirmDisabled branch November 27, 2024 04:27
@github-actions github-actions bot locked and limited conversation to collaborators Dec 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FEATURE: 能否增加弹框确认按钮的disabled属性,并且能动态修改
2 participants