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(drawer): [drawer] modify the problem that the before-close method is triggered upon page loading is solved #2364

Merged
merged 2 commits into from
Oct 24, 2024

Conversation

James-9696
Copy link
Collaborator

@James-9696 James-9696 commented Oct 23, 2024

PR

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

Summary by CodeRabbit

  • New Features

    • The drawer will now close by default when the close method is invoked, enhancing usability.
  • Improvements

    • Enhanced drag interactions with a debounce mechanism for smoother performance.
    • Added functions for managing scrollbar visibility, improving the user interface during drawer interactions.
  • Tests

    • Updated test script for the drawer component to simplify message element identification and assertion checks.

Copy link

coderabbitai bot commented Oct 23, 2024

Walkthrough

The changes in this pull request primarily involve modifications to the close method within the drawer component, specifically altering its default parameter from false to true. This adjustment ensures that the drawer closes by default unless otherwise specified. Additional functions related to the drawer's dimensions and event handling remain unchanged in logic but are structured to support drag interactions and scrollbar management.

Changes

File Path Change Summary
packages/renderless/src/drawer/index.ts - Updated close method default parameter from false to true.
- computedWidth and computedHeight functions remain unchanged.
- Event handling functions (mousedown, mousemove, mouseup) are structured for drag state management.
- mousemove function includes a debounce mechanism for smoother interactions.
- Added showScrollbar and hideScrollbar functions for scrollbar visibility management.
examples/sites/demos/pc/app/drawer/before-close.spec.ts - Updated locator for modal message from .tiny-modal.type__message to .tiny-modal__text.
- Simplified expectation check for message text in the test.

Possibly related PRs

Suggested reviewers

  • zzcr

🐰 In the drawer where we play,
The close now defaults to sway.
With dimensions set just right,
Dragging brings pure delight!
Scrollbars hide, then show with glee,
A happy home for you and me! 🎉


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.

@github-actions github-actions bot added the bug Something isn't working label Oct 23, 2024
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: 0

🧹 Outside diff range and nitpick comments (3)
packages/renderless/src/drawer/index.ts (3)

36-38: Add test coverage for the modified close behavior.

The change in default behavior needs test coverage to verify:

  1. The fix for unwanted beforeClose triggers during page load
  2. Existing close functionality still works when force is explicitly set to false
  3. The interaction with maskClosable and beforeClose props

Would you like me to help create test cases for these scenarios?


36-38: Document the behavior change in component documentation.

This change modifies the default behavior of the drawer's close method. Please update the component's documentation to reflect that:

  1. beforeClose is now bypassed by default
  2. To maintain the previous behavior, force parameter needs to be explicitly set to false

Would you like me to help draft the documentation updates?


Line range hint 52-67: Consider refactoring handleClose for better maintainability.

The current implementation mixes multiple concerns:

  1. Force close handling
  2. Mask close handling
  3. beforeClose validation
  4. Event emission

Consider splitting these into separate methods for better maintainability and testing.

Here's a suggested refactor:

const shouldPreventClose = ({ type, force, maskClosable, beforeClose }) => {
  if (force) return false
  if (type === 'mask' && !maskClosable) return true
  return typeof beforeClose === 'function' && beforeClose(type) === false
}

const emitCloseEvents = ({ type, emit }) => {
  emit('update:visible', false)
  emit(['close', 'confirm'].includes(type) ? type : 'close')
}

export const handleClose = 
  ({ emit, props, state }: Pick<IDrawerRenderlessParams, 'emit' | 'props' | 'state'>) =>
  (type: string, force?: boolean) => {
    if (shouldPreventClose({ type, force, ...props })) return
    
    if (state.visible) {
      state.visible = false
      setTimeout(() => emitCloseEvents({ type, emit }), 200)
    }
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 124e50a and 7c71c1a.

📒 Files selected for processing (1)
  • packages/renderless/src/drawer/index.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
packages/renderless/src/drawer/index.ts (1)

36-38: Verify the impact of changing the default force parameter.

While this change fixes the unwanted trigger of beforeClose during page load, it represents a significant behavior change that might affect existing implementations.

Let's verify the usage patterns in the codebase:

✅ Verification successful

Based on the search results, I can make the following observations:

  1. Direct calls to close() method:

    • Most calls are either with no arguments or with explicit boolean values
    • In drawer-specific examples:
      • examples/sites/demos/pc/app/drawer/before-close.vue and before-close-composition-api.vue explicitly pass true
      • Other drawer usages don't pass any argument
  2. Event handlers:

    • Many components use @close event handlers
    • No evidence of code relying on the default false behavior

Let me generate a final response:

The change to default force=true appears safe to implement

The codebase analysis shows that:

  • Explicit calls to drawer's close method either pass no arguments or explicitly pass true
  • The examples demonstrating beforeClose functionality explicitly pass the force parameter
  • No code patterns were found that rely on the default false behavior

This change aligns with the common usage patterns in the codebase and should successfully fix the unwanted trigger of beforeClose during page load without breaking existing implementations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for direct calls to drawer close method
rg -A 2 "\.close\(" 

# Search for drawer close event handlers
rg -A 2 "@close|v-on:close|:on-close"

Length of output: 34382

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

🧹 Outside diff range and nitpick comments (1)
examples/sites/demos/pc/app/drawer/before-close.spec.ts (1)

Line range hint 1-33: Test coverage appears incomplete for the reported bug.

While this test covers the drawer's close behavior, it doesn't specifically test the reported bug where the "before-close" method was being triggered during page load.

Consider adding a test case that specifically verifies the "before-close" method is not triggered during page load. I can help draft this test case. Here's a suggested implementation:

test('before-close should not trigger on page load', async ({ page }) => {
  let beforeCloseCalled = false
  await page.exposeFunction('logBeforeClose', () => {
    beforeCloseCalled = true
  })
  
  // Navigate and wait for page load
  await page.goto('drawer#before-close')
  await page.waitForLoadState('networkidle')
  
  // Verify before-close wasn't called during load
  expect(beforeCloseCalled).toBe(false)
})

Would you like me to create a GitHub issue to track this test addition?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7c71c1a and b1371b6.

📒 Files selected for processing (1)
  • examples/sites/demos/pc/app/drawer/before-close.spec.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
examples/sites/demos/pc/app/drawer/before-close.spec.ts (2)

15-15: Verify the simplified assertion maintains test robustness.

The removal of .nth(1) suggests the DOM structure was simplified. Let's ensure this doesn't reduce test coverage.

#!/bin/bash
# Description: Check for other instances of nth() usage with modal messages
# Expected: Consistent handling of modal message assertions

# Search for other tests using nth() with modal messages
echo "Checking for other nth() usage with modal messages..."
rg -A 3 -B 3 'message.*nth\(' 'examples/sites/demos/pc/'

8-8: Verify the reliability of the new selector.

The change from .tiny-modal.type__message to .tiny-modal__text suggests a DOM structure change. Let's verify this selector is consistently used across the codebase.

✅ Verification successful

Let me generate new shell scripts to better verify the selector changes.

This should help us understand:

  1. The actual DOM structure in templates
  2. How modal selectors are used across test files
  3. Specific usage in the drawer component context

Based on the search results, I can now generate a final response regarding the selector change:

The selector change is part of a consistent modal implementation pattern

The search results show that .tiny-modal__text is used specifically in the drawer component's context, while the general modal pattern across the codebase uses variations like:

  • .tiny-modal__box for general modal boxes
  • .tiny-modal__body for modal content
  • .tiny-modal__text for text content

The change from .tiny-modal.type__message to .tiny-modal__text aligns with the component's BEM-style naming convention and is more specific to the text content being tested.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistency in modal text selectors
# Expected: All modal text selectors should use the same pattern

# Search for both old and new selectors to ensure complete migration
echo "Checking for old selector usage..."
rg -l "tiny-modal.type__message"

echo "Checking for new selector usage..."
rg -l "tiny-modal__text"

# Check for any other similar modal text selectors
echo "Checking for other modal text selector patterns..."
rg -l "tiny-modal.*text"

Length of output: 1153


Script:

#!/bin/bash
# Search for modal-related class names in template files
echo "Checking modal-related classes in template files..."
rg -A 3 -B 3 'class=.*tiny-modal' --type html

# Search for modal-related selectors in test files
echo "Checking modal-related selectors in test files..."
rg -A 3 -B 3 'locator\(.*(tiny-modal)' --type ts

# Search specifically in the drawer component directory
echo "Checking drawer component files..."
fd -e vue -e ts -e js drawer$ -x rg -l "tiny-modal"

Length of output: 49348

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants