Skip to content

chore: Update Entity Tree implementation for better composition#39488

Merged
hetunandu merged 8 commits intoreleasefrom
fix/app-ide-ui-tree
Mar 3, 2025
Merged

chore: Update Entity Tree implementation for better composition#39488
hetunandu merged 8 commits intoreleasefrom
fix/app-ide-ui-tree

Conversation

@hetunandu
Copy link
Member

@hetunandu hetunandu commented Feb 28, 2025

Description

Make EntityListTree component accept a ItemRender component instead of rendering the EntityItem component itself to improve composibility

Fixes #39491

Automation

/ok-to-test tags="@tag.IDE"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/13612177606
Commit: 5d915d1
Cypress dashboard.
Tags: @tag.IDE
Spec:


Sun, 02 Mar 2025 05:19:40 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enabled customizable rendering for hierarchical list items, allowing a tailored display of widget information.
    • Introduced a dedicated widget item for improved in-place editing and management within the widget tree.
  • Refactor

    • Simplified the widget tree view to focus on core functionalities.
    • Enhanced name validation logic by removing unnecessary dependencies.
    • Restructured component logic for improved clarity and maintainability.

@hetunandu hetunandu requested a review from a team as a code owner February 28, 2025 09:55
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 28, 2025

Walkthrough

The pull request introduces a customizable item rendering mechanism for the EntityListTree component. It now accepts an ItemComponent prop to render items, which is recursively propagated for nested entries. The type definitions have been updated to include new properties such as isSelected, isDisabled, and id. Additionally, the name validation logic in the EditableName hook has been tightened by making the entity name required and adding an optional entity ID. The UI tree components have been simplified by removing unused hooks and dispatch actions and by introducing a new WidgetTreeItem for rendering.

Changes

File(s) Change Summary
app/client/.../EntityListTree/EntityListTree.tsx
app/client/.../EntityListTree/EntityListTree.types.ts
Updated EntityListTree to accept an ItemComponent prop for custom rendering. Modified type definitions by removing inheritance from EntityItemProps and adding new properties (isSelected, isDisabled?, id).
app/client/src/IDE/Components/EditableName/useValidateEntityName.ts Changed entityName from optional to required, added an optional entityId, and updated the validation callback logic to compare directly against entityName.
app/client/src/pages/AppIDE/components/UIEntityListTree/UIEntityListTree.tsx
app/client/src/pages/AppIDE/components/UIEntityListTree/WidgetTreeItem.tsx
app/client/src/pages/AppIDE/components/UIEntityListTree/hooks/useSwitchToWidget.ts
Simplified the UI tree by removing Redux, feature flags, and extra widget logic. Introduced a new WidgetTreeItem component for rendering and updated the widget switch hook to use a more specific widget object.
app/client/.../EntityListTree/EntityListTree.stories.tsx Restructured story definitions to encapsulate rendering logic within a new EntityItemComponent, simplifying the tree item configuration and enhancing modularity.
app/client/.../EntityListTree/EntityListTree.test.tsx Updated test setup to reflect changes in item rendering and validation logic, including the introduction of a new ItemComponent and modifications to test IDs.
app/client/src/pages/AppIDE/components/JSEntityItem/JSEntityItem.tsx
app/client/src/pages/AppIDE/components/QueryEntityItem/QueryEntityItem.tsx
Modified the validateName function to remove the dependency on item.title, simplifying the validation logic.

Possibly related PRs

Suggested labels

Enhancement, IDE Product, Task, IDE Pod, ok-to-test

Suggested reviewers

  • ankitakinger
  • alex-golovanov

Poem

In the code garden new features bloom,
Custom renderers now dispel the gloom.
Tree items flex in a dance so neat,
With props and hooks all in one beat.
Innovation thrives in every line—
A digital symphony so fine!
🎉


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ddc381e and 5d915d1.

📒 Files selected for processing (3)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.test.tsx (3 hunks)
  • app/client/src/pages/AppIDE/components/JSEntityItem/JSEntityItem.tsx (1 hunks)
  • app/client/src/pages/AppIDE/components/QueryEntityItem/QueryEntityItem.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-build / client-build
  • GitHub Check: chromatic-deployment
  • GitHub Check: chromatic-deployment
  • GitHub Check: storybook-tests
🔇 Additional comments (8)
app/client/src/pages/AppIDE/components/QueryEntityItem/QueryEntityItem.tsx (1)

102-102: Updated validateName function call to match the hook's expected parameters.

The change correctly simplifies the validateName function call by removing the redundant item.title parameter. This is appropriate since the entity name is already provided when initializing the hook at line 47-49.

app/client/src/pages/AppIDE/components/JSEntityItem/JSEntityItem.tsx (1)

86-86: Updated validateName function call to match the hook's expected parameters.

The change simplifies the validateName function call by removing the redundant item.title parameter, which is already provided when initializing the hook at line 36-38. This modification keeps the component consistent with the QueryEntityItem implementation.

app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.test.tsx (6)

4-7: Good use of type imports.

The import statement has been properly updated to use the type keyword, keeping the import statements clean and making it explicit that these are type imports.


11-19: Cleaner data structure for name mapping.

Good replacement of the previous mock configuration with a simple key-value mapping for entity names. This approach is more maintainable and easier to understand.


21-23: Well-implemented ItemComponent.

The ItemComponent is nicely implemented as a functional component with proper typing. The fallback to item.id when a name isn't found in the mapping is a good defensive coding practice.


25-27: Clean props update.

The defaultProps has been correctly updated to include the new ItemComponent while removing unnecessary mock configurations.


55-55: Test ID naming convention update.

The test ID has been updated to follow the "t--" prefix naming convention, making it consistent with other test IDs in the codebase.


76-76: Test ID naming convention update.

The test ID update here maintains consistency with the convention change applied earlier.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
  • @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.

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.

@hetunandu hetunandu requested review from alex-golovanov and ankitakinger and removed request for a team February 28, 2025 09:55
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Feb 28, 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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 213ebf9 and df63a8f.

📒 Files selected for processing (6)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.tsx (3 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.types.ts (1 hunks)
  • app/client/src/IDE/Components/EditableName/useValidateEntityName.ts (1 hunks)
  • app/client/src/pages/AppIDE/components/UIEntityListTree/UIEntityListTree.tsx (1 hunks)
  • app/client/src/pages/AppIDE/components/UIEntityListTree/WidgetTreeItem.tsx (1 hunks)
  • app/client/src/pages/AppIDE/components/UIEntityListTree/hooks/useSwitchToWidget.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-build / client-build
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: chromatic-deployment
  • GitHub Check: chromatic-deployment
  • GitHub Check: storybook-tests
🔇 Additional comments (19)
app/client/src/pages/AppIDE/components/UIEntityListTree/hooks/useSwitchToWidget.ts (2)

9-9: Clean import addition for type safety.

The addition of the WidgetType import improves type safety by providing explicit typing for the widget parameter.


17-20: Improved parameter typing enhances API clarity.

The parameter type has been updated from a generic CanvasStructure to a more specific object type with exactly the properties needed by the function. This makes the API requirements more explicit and removes potential dependencies on unused properties.

This change aligns well with the composability improvements mentioned in the PR objectives, as it allows for more flexible component integration by clearly defining the minimal interface required.

app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.tsx (4)

13-13: Good addition of ItemComponent parameter for improved composability.

This change allows the EntityListTree to accept a custom component for rendering items, making it more flexible and reusable.


53-53: Prefix added to data-testid attribute.

The data-testid attribute has been updated with a "t--" prefix, which is likely for test selector consistency.


66-66: Improved component composition with ItemComponent.

The direct rendering of a specific component has been replaced with the provided ItemComponent prop, enabling better component composition patterns.


70-70: Properly propagating ItemComponent to nested tree instances.

Good practice to pass the ItemComponent to nested EntityListTree instances, ensuring consistent rendering throughout the tree.

app/client/src/pages/AppIDE/components/UIEntityListTree/UIEntityListTree.tsx (3)

1-8: Well-executed simplification of imports.

The component now has focused imports, removing unnecessary dependencies that have been moved to the WidgetTreeItem component.


16-20: Simplified tree item configuration.

The tree item configuration has been streamlined to only include essential properties needed for rendering, with the rest moved to the WidgetTreeItem component.


22-28: Clean implementation of component composition pattern.

The component now leverages the new ItemComponent prop from EntityListTree, using WidgetTreeItem as the renderer. This is a good application of component composition.

app/client/src/pages/AppIDE/components/UIEntityListTree/WidgetTreeItem.tsx (5)

1-15: Well-structured imports for the new component.

The imports are organized logically, bringing in the necessary dependencies for rendering, state management, and user interactions.


16-37: Good implementation of widget-specific functionality.

The component properly retrieves widget data and sets up the necessary state and callbacks for managing widget names and interactions.


38-48: Proper name validation implementation.

Good use of the validateName hook with the appropriate parameters, including the widget name and ID.


50-68: Well-organized memoization of nameEditorConfig.

The nameEditorConfig is properly memoized with the correct dependencies to prevent unnecessary re-renders.


69-106: Comprehensive item rendering setup.

The component includes all necessary callbacks and UI elements for a fully functional widget tree item, including click handlers, icons, and context menus.

app/client/src/IDE/Components/EditableName/useValidateEntityName.ts (4)

12-15: Good type definition improvements.

Making entityName required and adding optional entityId enhances the type safety and functionality of the validation hook.


22-26: Improved prop destructuring with defaults.

The destructuring now properly handles the entityId with a sensible default value.


28-31: Enhanced selector usage with entityId.

The selector now receives the entityId parameter, allowing for more accurate validation against used entity names.


33-42: Simplified validation logic.

The validation callback has been streamlined by removing the redundant oldName parameter and directly using entityName for comparison.

app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.types.ts (1)

12-12: New ItemComponent prop enables better composition.

Adding ItemComponent as a required prop enables better component composition and customization of item rendering. This follows React best practices by delegating rendering responsibility to the parent component rather than hard-coding it.

This change aligns well with the PR's objective of "better composition" and improves the component's flexibility. The typing ensures type safety when implementing custom renderers.

ankitakinger
ankitakinger previously approved these changes Feb 28, 2025
@ankitakinger ankitakinger self-requested a review February 28, 2025 10:18
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)
app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.stories.tsx (1)

133-133: Simplify boolean expression

The Boolean call is redundant since negation already coerces values to boolean.

- setExpanded((prev) => ({ ...prev, [id]: !Boolean(prev[id]) }));
+ setExpanded((prev) => ({ ...prev, [id]: !prev[id] }));
🧰 Tools
🪛 Biome (1.9.4)

[error] 133-133: Avoid redundant Boolean call

It is not necessary to use Boolean call when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant Boolean call

(lint/complexity/noExtraBooleanCast)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ea02d7f and ddc381e.

📒 Files selected for processing (1)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.stories.tsx (4 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.stories.tsx

[error] 133-133: Avoid redundant Boolean call

It is not necessary to use Boolean call when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant Boolean call

(lint/complexity/noExtraBooleanCast)

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-build / client-build
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: chromatic-deployment
  • GitHub Check: storybook-tests
  • GitHub Check: chromatic-deployment
🔇 Additional comments (3)
app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.stories.tsx (3)

31-38: Good addition of centralized naming map

This approach separates data from presentation by mapping IDs to display names, making the code more maintainable.


90-117: Well-structured component extraction

The EntityItemComponent effectively encapsulates the item rendering logic and state management. This demonstrates the composability pattern being implemented in this PR.


146-150: Good implementation of the composability pattern

The updated EntityListTree usage properly demonstrates how to use the new ItemComponent prop, which is the main objective of this PR.

@hetunandu hetunandu added the ok-to-test Required label for CI label Mar 2, 2025
@hetunandu hetunandu merged commit 3f2972e into release Mar 3, 2025
57 checks passed
@hetunandu hetunandu deleted the fix/app-ide-ui-tree branch March 3, 2025 01:31
@github-actions github-actions bot added IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product Task A simple Todo labels Mar 3, 2025
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Apr 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog Task A simple Todo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: UI List tree does not validate Tab Widget renames

2 participants