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: support checking all blocks in material add block panel #923

Open
wants to merge 3 commits into
base: refactor/develop
Choose a base branch
from

Conversation

gene9831
Copy link
Collaborator

@gene9831 gene9831 commented Dec 5, 2024

English | 简体中文

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)
  • Built its own designer, fully self-validated

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:

Background and solution

物料插件-区块分组-添加区块,区块列表没有全选功能

改动点:

  • 给区块列表添加全选功能
  • 抽取了一个 SelectAll 组件到 common

What is the current behavior?

What is the new behavior?

image
image

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a Select All component for bulk selection in the block list.
    • Enhanced block selection functionality with new methods for selecting and deselecting all items.
  • Bug Fixes

    • Improved error handling in the addBlocks method to ensure selection state resets after operations.
  • Style

    • Updated styling for checkboxes and various components to enhance visual representation and user experience.
  • Documentation

    • Updated event emissions for better interaction management within the block list components.

Copy link
Contributor

coderabbitai bot commented Dec 5, 2024

Walkthrough

The changes introduce a new SelectAll component in PluginBlockList.vue to enable users to select or deselect all items in a block list. This functionality is supported by new methods and events for managing selections. The useBlock.js composable has been updated with methods to handle block selection, while several components, including BlockGroupPanel.vue and BlockList.vue, have been modified to integrate the new selection features. Additionally, styling updates are made to enhance the visual representation of checkboxes and other components.

Changes

File Path Change Summary
packages/common/component/PluginBlockList.vue Added select-all component; updated emits for checkAll and cancelCheckAll; new methods added.
packages/common/component/SelectAll.vue Introduced new component for selecting/deselecting all items; includes props and computed properties.
packages/common/component/index.js Exported new SelectAll component.
packages/plugins/block/src/composable/useBlock.js Added checkAll and cancelCheckAll methods for block selection management.
packages/plugins/materials/src/meta/block/src/BlockGroupPanel.vue Integrated cancelCheckAll into addBlocks method for selection reset.
packages/plugins/materials/src/meta/block/src/BlockGroupTransfer.vue Integrated SelectAll component; updated useBlock methods for selection management.
packages/plugins/materials/src/meta/block/src/BlockList.vue Added event listeners for checkAll and cancelCheckAll; updated emits and methods.
packages/theme/base/src/component-common.less Updated styles for checkbox states and various components for improved UI consistency.

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • hexqi
  • chilingling

🐇 In the block list, a checkbox appears,
To select all items, it cheers and cheers!
With a click, all are chosen,
Or with a flick, they're frozen.
A hop, a skip, a joyful leap,
Managing blocks is now a breeze, oh so sweet! 🐇


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 enhancement New feature or request refactor-main refactor/develop branch feature labels Dec 5, 2024
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 (8)
packages/common/component/SelectAll.vue (3)

12-19: Add TypeScript type definitions for array props

The items and selected props would benefit from explicit type definitions for better type safety and developer experience.

   items: {
     type: Array,
+    type: Array as PropType<unknown[]>,
     default: () => []
   },
   selected: {
     type: Array,
+    type: Array as PropType<unknown[]>,
     default: () => []
   },

1-42: Add unit tests and documentation for the SelectAll component

The component looks well-implemented, but it's missing:

  1. Unit tests to verify the component's behavior
  2. Documentation explaining props, events, and usage examples

Would you like me to help create:

  1. Unit tests covering key functionality?
  2. Documentation in JSDoc format?

28-39: Consider adding error handling for edge cases

The selectedAll computed property's setter should handle edge cases:

  1. When items array is empty
  2. When items contain duplicates
 const selectedAll = computed({
   get() {
-    return props.items.length > 0 && props.items.length === props.selected.length
+    return props.items.length > 0 && props.selected.length === new Set(props.items).size
   },
   set(value) {
+    if (props.items.length === 0) return
     if (value) {
-      emit('selectAll', props.items)
+      emit('selectAll', [...new Set(props.items)])
     } else {
       emit('deselectAll')
     }
   }
 })
packages/plugins/materials/src/meta/block/src/BlockGroupTransfer.vue (2)

4-11: Add accessibility attributes to SelectAll component

Enhance accessibility by adding an aria-label to the SelectAll component.

       <select-all
         v-if="state.displayType === 'grid'"
         class="block-select-all"
+        aria-label="Select all blocks"
         :items="state.blockList"
         :selected="selectedBlockArray"
         @select-all="checkAll"
         @deselect-all="cancelCheckAll"
       ></select-all>

9-10: Consider normalizing event names for consistency

The events select-all/deselect-all from SelectAll component don't match the handler names checkAll/cancelCheckAll. Consider normalizing these for better maintainability.

Either update the SelectAll component:

-  @select-all="checkAll"
-  @deselect-all="cancelCheckAll"
+  @checkAll="checkAll"
+  @cancelCheckAll="cancelCheckAll"

Or update the handlers to match the events:

-  @select-all="checkAll"
-  @deselect-all="cancelCheckAll"
+  @select-all="handleSelectAll"
+  @deselect-all="handleDeselectAll"
packages/plugins/materials/src/meta/block/src/BlockList.vue (1)

19-20: Use consistent event handler binding pattern

The event handlers use different binding patterns - arrow function for checkAll but direct method reference for cancelCheckAll. Consider using the same pattern for both for consistency.

-    @checkAll="(items) => checkAll(items)"
-    @cancelCheckAll="cancelCheckAll"
+    @checkAll="checkAll"
+    @cancelCheckAll="cancelCheckAll"
packages/plugins/block/src/composable/useBlock.js (1)

702-704: Consider defensive copying for selectedBlockArray

The direct assignment of blockList could lead to unexpected behavior if the source array is mutated externally. Consider creating a new array to prevent external mutations.

-  selectedBlockArray.value = blockList
+  selectedBlockArray.value = [...blockList]
packages/common/component/PluginBlockList.vue (1)

374-380: Consider adding type safety to the handler methods.

While the implementation is correct, consider adding TypeScript or JSDoc type annotations for better maintainability and IDE support.

-    const handleSelectAll = (items) => {
+    /**
+     * @param {Array} items - The items to be selected
+     */
+    const handleSelectAll = (items) => {
      emit('checkAll', items)
    }

-    const handleDeselectAll = () => {
+    /**
+     * Handles deselection of all items
+     */
+    const handleDeselectAll = () => {
      emit('cancelCheckAll')
    }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between dee65eb and 4c3ae20.

📒 Files selected for processing (8)
  • packages/common/component/PluginBlockList.vue (7 hunks)
  • packages/common/component/SelectAll.vue (1 hunks)
  • packages/common/component/index.js (1 hunks)
  • packages/plugins/block/src/composable/useBlock.js (2 hunks)
  • packages/plugins/materials/src/meta/block/src/BlockGroupPanel.vue (2 hunks)
  • packages/plugins/materials/src/meta/block/src/BlockGroupTransfer.vue (7 hunks)
  • packages/plugins/materials/src/meta/block/src/BlockList.vue (4 hunks)
  • packages/theme/base/src/component-common.less (1 hunks)
🔇 Additional comments (12)
packages/common/component/index.js (1)

38-38: LGTM!

The export follows the established pattern in the file.

packages/plugins/materials/src/meta/block/src/BlockGroupTransfer.vue (1)

29-30: Verify event handler implementation in BlockList component

The BlockList component now receives new events @checkAll and @cancelCheckAll. Let's verify their implementation.

✅ Verification successful

Let me gather more information to verify the implementation of these event handlers.


Event handlers are properly implemented in BlockList component

The verification shows that both checkAll and cancelCheckAll events are:

  • Correctly declared in the component's emits option
  • Properly implemented as methods that emit the corresponding events
  • Appropriately bound in the template
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for checkAll/cancelCheckAll event implementations in BlockList
ast-grep --pattern 'emit("checkAll", $$$)' || ast-grep --pattern 'emit("cancelCheckAll", $$$)'

# Search for event declarations
rg -A 5 'emits.*checkAll.*cancelCheckAll' 

Length of output: 1321


Script:

#!/bin/bash
# Search for checkAll/cancelCheckAll method implementations in BlockList
ast-grep --pattern 'function checkAll() {
  $$$
}' || ast-grep --pattern 'const checkAll = () => {
  $$$
}'

ast-grep --pattern 'function cancelCheckAll() {
  $$$
}' || ast-grep --pattern 'const cancelCheckAll = () => {
  $$$
}'

# Search for any usage of these events in the file
rg -A 3 'checkAll|cancelCheckAll' packages/plugins/materials/src/meta/block/src/BlockList.vue

Length of output: 794

packages/plugins/materials/src/meta/block/src/BlockList.vue (1)

Line range hint 201-219: LGTM: Clean implementation of selection methods

The implementation is clean and follows Vue 3 composition API patterns correctly.

packages/plugins/materials/src/meta/block/src/BlockGroupPanel.vue (2)

80-80: LGTM: Proper import of new functionality

The cancelCheckAll method is correctly destructured from useBlock composable.


158-160: LGTM: Good error handling practice

Excellent use of the finally block to ensure selection state is cleaned up regardless of whether the block addition succeeds or fails.

packages/plugins/block/src/composable/useBlock.js (2)

706-708: LGTM: Clean implementation of cancelCheckAll

The implementation correctly resets the selection state by assigning a new empty array.


748-749: LGTM: Proper export of new functionality

The new methods are correctly exported from the composable.

packages/theme/base/src/component-common.less (1)

524-525: LGTM: Checkbox styling supports the new select-all feature.

The added styles properly handle both checked and indeterminate states of checkboxes using theme variables, maintaining consistency with the design system.

packages/common/component/PluginBlockList.vue (4)

3-11: LGTM: SelectAll component integration is well-implemented.

The component is properly integrated with:

  • Conditional rendering based on showCheckbox prop
  • Correct prop bindings for items and selected state
  • Proper event handling

154-154: LGTM: Component registration follows best practices.

The SelectAll component is properly imported and registered in the components section.

Also applies to: 172-173


247-247: LGTM: Events are properly declared.

The emits array correctly includes the new events 'checkAll' and 'cancelCheckAll'.


469-473: LGTM: Checkbox column styling is well-structured.

The styling:

  • Uses flexbox for proper alignment
  • Maintains consistency with existing styles
  • Is scoped appropriately

packages/common/component/SelectAll.vue Outdated Show resolved Hide resolved
packages/common/component/SelectAll.vue Outdated Show resolved Hide resolved
packages/common/component/SelectAll.vue Outdated Show resolved Hide resolved
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 (1)
packages/common/component/PluginBlockList.vue (1)

368-374: Simplify the event handler implementation.

The event handler can be simplified by using object destructuring and early return pattern.

Consider this more concise implementation:

-const handleSelectAll = (items) => {
-  if (Array.isArray(items)) {
-    emit('checkAll', items)
-  } else {
-    emit('cancelCheckAll')
-  }
-}
+const handleSelectAll = (items) => {
+  if (!Array.isArray(items)) {
+    return emit('cancelCheckAll')
+  }
+  emit('checkAll', items)
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4c3ae20 and a97dc74.

📒 Files selected for processing (3)
  • packages/common/component/PluginBlockList.vue (7 hunks)
  • packages/common/component/SelectAll.vue (1 hunks)
  • packages/plugins/materials/src/meta/block/src/BlockGroupTransfer.vue (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/common/component/SelectAll.vue
  • packages/plugins/materials/src/meta/block/src/BlockGroupTransfer.vue
🔇 Additional comments (5)
packages/common/component/PluginBlockList.vue (5)

148-148: LGTM: Component registration is properly implemented.

The SelectAll component is correctly imported and registered in the components section.

Also applies to: 166-167


241-241: LGTM: Event emits are properly declared.

The new events 'checkAll' and 'cancelCheckAll' are correctly added to the emits array.


4-4: Simplify the event binding syntax.

The event binding can be simplified as noted in the previous review.

Apply this change:

-<select-all :allItems="data" :selected="checked" :hidden-label="true" @select-all="(items) => handleSelectAll(items)"></select-all>
+<select-all :allItems="data" :selected="checked" :hidden-label="true" @select-all="handleSelectAll"></select-all>

462-466: LGTM: Checkbox styling is properly implemented.

The checkbox styling uses flex layout appropriately for alignment.


4-4: Verify the SelectAll component's contract.

Ensure that the SelectAll component's contract (props and events) aligns with its usage here.

✅ Verification successful

Let me gather more specific information about the SelectAll component's implementation.


Based on the SelectAll component's implementation, I can now provide the final verification response:

The SelectAll component's contract matches its usage correctly

The component implementation shows that all props and events used in PluginBlockList.vue are properly defined:

  • Props:
    • allItems: Array (matches data)
    • selected: Array (matches checked)
    • hiddenLabel: Boolean (matches hidden-label)
  • Events:
    • selectAll event is properly defined and emitted (matches @select-all)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the SelectAll component's implementation
# Look for the SelectAll component's implementation to verify its contract

# Search for the SelectAll component file
echo "Searching for SelectAll component file..."
fd -e vue -e js SelectAll

# Search for the component's props and emits
echo "Checking component's contract..."
ast-grep --pattern 'defineProps({
  $$$
})' 

ast-grep --pattern 'defineEmits([
  $$$
])'

Length of output: 330


Script:

#!/bin/bash
# Get the content of the SelectAll component
echo "Content of SelectAll.vue:"
cat packages/common/component/SelectAll.vue

# Search for any usage patterns of SelectAll in the codebase
echo -e "\nUsage patterns of SelectAll:"
rg -A 2 "<select-all" --type vue

Length of output: 1185

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactor-main refactor/develop branch feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants