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: update block filters UI in materials #914

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

Conversation

gene9831
Copy link
Collaborator

@gene9831 gene9831 commented Nov 28, 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

在物料插件里面的添加区块页面中,原来的区块筛选器是checkbox group的形式。如果checkbox数量很多,则会显示得很凌乱。现优化成select组件

What is the current behavior?

image

What is the new behavior?

image

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a conditional rendering mechanism for filter components, enhancing user interaction with checkboxes and selection options.
    • Added a new property usingSelect to filters, allowing for a selection interface on specific filters.
  • Bug Fixes

    • Improved error handling for the block addition process, ensuring users are informed of any issues.
  • Style

    • Adjusted layout and spacing for the new select component and modified the footer toolbar for better alignment.

@github-actions github-actions bot added enhancement New feature or request refactor-main refactor/develop branch feature labels Nov 28, 2024
Copy link
Contributor

coderabbitai bot commented Nov 28, 2024

Walkthrough

The changes introduce a conditional rendering mechanism in the BlockGroupFilters.vue component based on the usingSelect property of filter objects. When usingSelect is false, a checkbox group is displayed; when true, a select component is rendered. The BlockGroupPanel.vue component has been updated to include the usingSelect property for specific filters and improve error handling in the addBlocks method. These modifications enhance the filtering interface and error management within the application.

Changes

File Path Change Summary
.../BlockGroupFilters.vue - Introduced conditional rendering for filter components based on usingSelect.
- Updated @change event handlers for checkbox and select components.
- Added selectOptions variable and modified getFilters method signature.
- Added TinySelect and TinyOption components.
- Adjusted styling for layout.
.../BlockGroupPanel.vue - Added usingSelect property to author and tag filters.
- Updated addBlocks method to return a promise for better error handling.
.../BlockGroupArrange.vue - Added a new CSS rule to adjust the right margin of the footer toolbar.

Possibly related PRs

  • fix: add block panel can't open #827: The changes in BlockGroupPanel.vue introduce the usingSelect property, which is directly related to the conditional rendering of filter components in BlockGroupFilters.vue based on the same property.
  • fix: fix materials panel #909: The modifications in the materials panel include event emissions that enhance interactivity, which aligns with the updates in BlockGroupFilters.vue that also involve event handling for filter changes.

Suggested labels

ready_for_review

Suggested reviewers

  • hexqi
  • chilingling

🐇 In the meadow, filters play,
With checkboxes bright, they lead the way.
A select for choices, so easy to see,
Enhancing our blocks, oh what glee!
With promises strong, errors kept at bay,
Hopping along, we code and we play! 🐇


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

🧹 Outside diff range and nitpick comments (4)
packages/plugins/materials/src/meta/block/src/BlockGroupFilters.vue (3)

54-61: Consider adding type validation for filter IDs

The state initialization looks good but could be more robust with validation.

Consider this enhancement:

 const state = reactive({
   checkGroup: props.filters.reduce(
     (result, filter) => ({
       ...result,
-      [filter.id]: []
+      [filter.id]: filter.id ? [] : console.warn(`Filter missing ID: ${filter.name}`)
     }),
     {}
   )
 })

63-74: Translate Chinese comment and enhance documentation

The implementation is correct, but the comment should be in English for consistency.

Consider replacing the comment with:

- // 这里重新计算selectOptions的原因:tiny-option的value属性如果是一个对象,那么此对象内部需要有value属性
+ // Compute selectOptions to ensure each option object contains a 'value' property,
+ // which is required by tiny-option when its value prop is an object

77-89: Consider using type guards for better type safety

The type checking logic works but could be more explicit.

Consider this enhancement:

- if (typeof checked.at(0) === 'string') {
+ // Type guard for checkbox group values
+ if (Array.isArray(checked) && typeof checked[0] === 'string') {
packages/plugins/materials/src/meta/block/src/BlockGroupPanel.vue (1)

Line range hint 1-1: Consider adding documentation for the new filter behavior.

Since this is a UI enhancement that changes how filters behave, it would be beneficial to:

  1. Update the component's documentation to explain the usingSelect property
  2. Add comments explaining when to use select vs. checkbox group filters
  3. Update any relevant UI/UX guidelines

Would you like me to help draft the documentation for these changes?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 49f68c3 and 88cef0b.

📒 Files selected for processing (2)
  • packages/plugins/materials/src/meta/block/src/BlockGroupFilters.vue (4 hunks)
  • packages/plugins/materials/src/meta/block/src/BlockGroupPanel.vue (1 hunks)
🔇 Additional comments (3)
packages/plugins/materials/src/meta/block/src/BlockGroupFilters.vue (2)

7-13: LGTM: Checkbox group implementation looks correct

The conditional rendering and data binding for the checkbox group is properly implemented.


14-28: Verify the UX of hover-expand behavior

The select component implementation looks good, but the hover-expand prop might affect usability with multiple selections. Please verify that:

  1. The dropdown remains open while making multiple selections
  2. The hover behavior doesn't interfere with selection of multiple items
packages/plugins/materials/src/meta/block/src/BlockGroupPanel.vue (1)

100-101: LGTM! The filter configuration changes align with the UI enhancement goals.

The addition of usingSelect: true to the author and tag filters is a clean way to implement the UI enhancement, allowing these filters to render as select components instead of checkbox groups. This change will help manage large numbers of filter options more effectively.

Also applies to: 106-107

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 (4)
packages/plugins/materials/src/meta/block/src/BlockGroupFilters.vue (4)

7-27: Consider enhancing accessibility for the select component.

While the implementation is functionally correct, consider adding ARIA labels and aria-describedby attributes to improve accessibility for screen readers.

 <tiny-select
   v-else
   v-model="state.checkGroup[filter.id]"
   size="mini"
   multiple
+  :aria-label="filter.name"
+  :aria-describedby="`${filter.id}-description`"
   @change="getFilters($event, filter.id)"
 >

62-73: Translate Chinese comment to English for better maintainability.

The Chinese comment explains an important implementation detail about the value property requirement for tiny-option.

-    // 这里重新计算selectOptions的原因:tiny-option的value属性如果是一个对象,那么此对象内部需要有value属性
+    // Recalculating selectOptions because when tiny-option's value is an object, that object must have a 'value' property

76-89: Enhance type checking in getFilters method.

The current type checking using typeof checked.at(0) could be more robust. Consider checking for object type explicitly and handling empty arrays.

-      if (typeof checked.at(0) === 'string') {
+      if (!checked.length) {
+        return emit('search', null, filters)
+      }
+      if (!checked.some(item => typeof item === 'object')) {

Line range hint 44-49: Add prop validation for filters array items.

The filters prop type is defined as Array but lacks validation for the required properties (id, name, children, usingSelect).

 filters: {
   type: Array,
-  default: () => []
+  default: () => [],
+  validator(value) {
+    return value.every(filter => 
+      typeof filter.id === 'string' &&
+      typeof filter.name === 'string' &&
+      Array.isArray(filter.children) &&
+      typeof filter.usingSelect === 'boolean'
+    )
+  }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 88cef0b and 0133742.

📒 Files selected for processing (2)
  • packages/plugins/materials/src/meta/block/src/BlockGroupArrange.vue (1 hunks)
  • packages/plugins/materials/src/meta/block/src/BlockGroupFilters.vue (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/plugins/materials/src/meta/block/src/BlockGroupArrange.vue
🔇 Additional comments (1)
packages/plugins/materials/src/meta/block/src/BlockGroupFilters.vue (1)

141-143: Browser compatibility concern with :has() selector.

The CSS :has() selector might not be supported in all browsers. Consider using a class-based approach instead.

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 (4)
packages/plugins/materials/src/meta/block/src/BlockGroupFilters.vue (4)

53-60: Simplify state initialization

The current implementation using reduce could be simplified for better readability.

Consider this alternative:

-      checkGroup: props.filters.reduce(
-        (result, filter) => ({
-          ...result,
-          [filter.id]: []
-        }),
-        {}
-      )
+      checkGroup: Object.fromEntries(props.filters.map(filter => [filter.id, []]))

62-62: Translate Chinese comment to English

For better international collaboration, comments should be in English.

- // 这里重新计算selectOptions的原因:tiny-option的value属性如果是一个对象,那么此对象内部需要有value属性
+ // Recalculating selectOptions because tiny-option's value property requires an internal value property when it's an object

79-87: Improve type checking robustness

The current type checking using typeof checked.at(0) === 'string' could be more robust.

Consider this improvement:

-      if (typeof checked.at(0) === 'string') {
+      if (Array.isArray(checked) && checked.length > 0 && typeof checked[0] === 'string') {

141-143: Remove duplicate selector in deep selector

The selector .tiny-select.tiny-select contains a duplicate class name.

-      :deep(.tiny-select.tiny-select .tiny-select__tags .tiny-tag) {
+      :deep(.tiny-select .tiny-select__tags .tiny-tag) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0133742 and 62c7bde.

📒 Files selected for processing (1)
  • packages/plugins/materials/src/meta/block/src/BlockGroupFilters.vue (4 hunks)
🔇 Additional comments (2)
packages/plugins/materials/src/meta/block/src/BlockGroupFilters.vue (2)

17-17: Verify size prop consistency across components

The size="mini" prop is used here. Let's ensure this matches the design system guidelines.

✅ Verification successful

Size prop "mini" is consistently used across components

The size="mini" prop is used consistently across multiple components in the codebase, particularly in similar UI contexts like form inputs, radio groups, and selectors. The usage aligns with the following components:

  • NumberConfigurator
  • FileSelector
  • SettingPanel
  • BlockGroupFilters
  • NumericSelect
  • BlockGroup

The codebase also shows a consistent pattern of size values, mainly using "mini" and "small" for different UI contexts, where "mini" is typically used for form controls and filters.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check size prop usage across components
rg 'size="mini"' --type vue

Length of output: 57


Script:

#!/bin/bash
# Check size prop usage across components with ripgrep, without file type filter
rg 'size="mini"'

Length of output: 784


Script:

#!/bin/bash
# Check for other size prop values in the codebase
rg 'size="[^"]+"'

Length of output: 3958


Script:

#!/bin/bash
# Find component files to understand the component structure
fd -e vue

Length of output: 16774


10-10: Inconsistent event handler parameter passing between components

The checkbox group passes filter children to getFilters, while the select component doesn't. This inconsistency could lead to maintenance issues.

Let's verify if this difference is intentional by checking other similar components:

Also applies to: 19-19

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

🧹 Outside diff range and nitpick comments (4)
packages/plugins/materials/src/meta/block/src/BlockGroupFilters.vue (4)

7-27: Consider unifying event handler signatures.

The event handlers for checkbox and select components have different parameter patterns:

  • Checkbox: @change="getFilters($event, filter.id, filter.children)"
  • Select: @change="getFilters($event, filter.id)"

This inconsistency could make maintenance more challenging.

Consider unifying the handlers by moving the children lookup into the getFilters method:

- @change="getFilters($event, filter.id, filter.children)"
+ @change="getFilters($event, filter.id)"

Then update the method to get children from props when needed.


14-27: Enhance accessibility for the select component.

The select component could benefit from additional accessibility attributes.

Add aria labels and placeholder text:

 <tiny-select
   v-else
   v-model="state.checkGroup[filter.id]"
   size="mini"
   multiple
+  :aria-label="filter.name"
+  :placeholder="'Select ' + filter.name"
   @change="getFilters($event, filter.id)"
 >

62-73: Translate Chinese comment to English for better maintainability.

The Chinese comment explains an important implementation detail about tiny-option's value property requirements.

Replace the Chinese comment with English:

- // 这里重新计算selectOptions的原因:tiny-option的value属性如果是一个对象,那么此对象内部需要有value属性
+ // Recomputing selectOptions because tiny-option's value property requires an object with an internal value property

141-146: Avoid using !important in CSS rules.

The !important declaration in max-width calculation could make future style overrides difficult.

Consider increasing selector specificity instead:

- :deep(.tiny-select.tiny-select .tiny-select__tags) {
-   max-width: calc(100% - 24px) !important;
+ :deep(.tiny-select.tiny-select:not(.is-disabled) .tiny-select__tags) {
+   max-width: calc(100% - 24px);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 62c7bde and 05fe922.

📒 Files selected for processing (1)
  • packages/plugins/materials/src/meta/block/src/BlockGroupFilters.vue (4 hunks)

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.

1 participant