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: TinyGrid slot children can not operate #1100

Open
wants to merge 1 commit into
base: refactor/develop
Choose a base branch
from

Conversation

chilingling
Copy link
Member

@chilingling chilingling commented Feb 7, 2025

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

修复 TinyGrid 组件列插槽拖入内容保存后,再次选中无法进行操作的 bug

【问题描述】
打开 TinyGrid 组件的列插槽,拖入内容,保存,再次选中插槽里面拖入的内容,发现无法对插槽里面的内容进行操作。

【问题分析】

  1. v2.1 版本引入的 bug。
  2. 新版画布通信的过程中,构建 nodesMap 的时候没有处理节点在 props 里面的场景。导致如果节点在 props 属性里面,而不是 children 里面的话,无法构建到 nodesMap 中。
  3. 选中节点后,会根据节点 id 往 nodesMap 查找 schema,此时由于 2 步骤中没有往 nodesMap 集成对应的 schema,查找失败,进而导致无法进行任何操作

【修复方案】
临时方案(本次PR 代码):兼容 TinyGrid 节点在 props 的场景。
长期方案:需要调研是否可以将 props 中含有节点的场景,下放到 children 节点中。

What is the current behavior?

Issue Number: #1098

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features
    • Enhanced canvas functionality for improved management of grid elements and their associated properties.
    • Added mechanisms to automatically assign unique identifiers to grid items, ensuring consistent and structured layouts.

修复 TinyGrid 组件列插槽拖入内容保存后,再次选中无法进行操作的 bug
Copy link
Contributor

coderabbitai bot commented Feb 7, 2025

Walkthrough

This change introduces two new functions to enhance node management in the canvas API. The function handleTinyGridColumnsSlots processes a node’s columns by iterating through its slots, assigns unique IDs, and updates the nodesMap. The second function, handleNodesInProps, invokes the grid-specific logic when the node represents a TinyGrid component. Additionally, generateNodesMap now integrates these new functions when processing nodes, ensuring that grid column slots are handled appropriately without altering the overall API structure.

Changes

File Change Summary
packages/canvas/.../useCanvas.js Added new functions: handleTinyGridColumnsSlots and handleNodesInProps; updated generateNodesMap to incorporate new node handling for TinyGrid columns.

Sequence Diagram(s)

sequenceDiagram
    participant Node as Canvas Node
    participant GNM as generateNodesMap
    participant HNP as handleNodesInProps
    participant HTG as handleTinyGridColumnsSlots

    Node->>GNM: Process node
    GNM->>HNP: Call handleNodesInProps(node)
    HNP->>Node: Check componentName ("TinyGrid")
    alt Node is TinyGrid
        HNP->>HTG: Call handleTinyGridColumnsSlots(node)
        HTG->>Node: Process columns & assign unique IDs
    end
    HTG-->>GNM: Return updated mapping
Loading

Suggested labels

bug, refactor-main

Suggested reviewers

  • hexqi
  • rhlin

Poem

I’m a bunny with a keen eye,
Hopping through the canvas sky.
New functions sprout like carrots so bright,
Guiding nodes with unique IDs just right.
Enjoy the code hop, a joyous delight!
🥕🐇

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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. (Beta)
  • @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 bug Something isn't working refactor-main refactor/develop branch feature labels Feb 7, 2025
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

🧹 Nitpick comments (1)
packages/canvas/DesignCanvas/src/api/useCanvas.js (1)

76-99: LGTM! The implementation correctly handles TinyGrid slot children.

The function properly processes columns and their slots, ensuring each item has a unique ID and is correctly mapped in the nodesMap.

Consider moving the eslint-disable comment to the line it affects.

The eslint-disable comment on line 92 should be moved to line 93 to be more specific and maintain better code clarity.

-            // eslint-disable-next-line no-use-before-define
-            generateNodesMap(item.children, item)
+            generateNodesMap(item.children, item) // eslint-disable-line no-use-before-define
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3c8ba63 and a73706a.

📒 Files selected for processing (1)
  • packages/canvas/DesignCanvas/src/api/useCanvas.js (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: push-check
🔇 Additional comments (2)
packages/canvas/DesignCanvas/src/api/useCanvas.js (2)

101-105: LGTM! Clean and focused implementation.

The function is well-designed with a single responsibility and is correctly integrated into the node generation process.

Also applies to: 118-118


76-99: Add tests to prevent regression.

The changes look good and address the PR objective. However, to prevent regression, consider adding tests that verify:

  1. TinyGrid slot children get unique IDs
  2. They are properly added to nodesMap
  3. They can be operated on after save and re-select

Here's a script to help verify the current test coverage:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working refactor-main refactor/develop branch feature
Projects
None yet
1 participant