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: ADS Entity List Tree #38493

Open
wants to merge 59 commits into
base: release
Choose a base branch
from
Open

feat: ADS Entity List Tree #38493

wants to merge 59 commits into from

Conversation

hetunandu
Copy link
Member

@hetunandu hetunandu commented Jan 6, 2025

Description

Introduces the List Tree component in ADS that is built on top of Entity Item component.
Uses feature flags to update the UI List Tree using this component

Fixes #37770

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/12707788731
Commit: 3bc67d9
Cypress dashboard.
Tags: @tag.IDE
Spec:


Fri, 10 Jan 2025 11:05:24 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a new EntityListTree component for hierarchical entity management.
    • Introduced a new widget tree view with enhanced navigation and interaction.
    • Implemented a feature flag for new widget tree functionality.
    • Added a context menu for widgets with actions like renaming and deletion.
    • Introduced new hooks for managing widget deletion and navigation.
    • Added a new UIEntityListTree component for rendering UI entities.
    • Introduced a WidgetContextMenu component for widget actions.
    • Added a new OldWidgetEntityList component for legacy widget rendering.
    • Introduced a new hook for validating entity names.
  • Improvements

    • Enhanced widget explorer with improved name editing and validation.
    • Refined entity name editing experience.
    • Improved styling and layout for entity explorer components.
    • Streamlined rendering logic for entity items and controls.
  • Performance

    • Optimized widget tree rendering and state management.
    • Introduced memoization for tree-related operations.
  • Bug Fixes

    • Improved widget deletion logic.
    • Fixed issues with widget name editing and validation.

hetunandu and others added 27 commits January 1, 2025 14:36
Copy link
Contributor

coderabbitai bot commented Jan 6, 2025

Walkthrough

This pull request introduces a comprehensive implementation of the EntityListTree component in the design system, focusing on creating a reusable, interactive tree-like structure for displaying hierarchical entities. The changes span multiple files across the client application, introducing new components, hooks, and utilities to support a flexible and feature-rich entity explorer interface.

Changes

File Path Change Summary
.../EntityListTree/* Added new component with stories, styles, types, and index exports
.../FeatureFlag.ts Introduced new feature flag release_ads_entity_item_enabled
.../Explorer/Widgets/* Added new widget list tree implementation and supporting components
.../EditableName/* Enhanced name validation and editing hooks

Assessment against linked issues

Objective Addressed Explanation
Reusable tree component with passed items
Collapsible icon with toggle functionality
Selective expansion and selection
Hover, active, error states
Left padding override
Nested item spacing calculation
No descriptions support

Possibly related PRs

Suggested Labels

Design System Product, ADS Components

Suggested Reviewers

  • ankitakinger
  • sagar-qa007

Poem

🌳 Behold the EntityListTree so bright,
Branches of code, expanding with might!
Widgets dance, icons sway,
In this digital forest, components play! 🎉


📜 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 4f80a9a and 560ff97.

📒 Files selected for processing (1)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.test.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.test.tsx
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • 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-build / client-build
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: chromatic-deployment
  • GitHub Check: chromatic-deployment
  • GitHub Check: storybook-tests

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.

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 IDE Pod Issues that new developers face while exploring the IDE labels Jan 6, 2025
…ilities (#38541)

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: [email protected] <[email protected]>
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

🧹 Nitpick comments (7)
app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/UIEntityListTree.types.ts (1)

14-17: Add JSDoc comments for configuration flags

The boolean flags in WidgetTreeConfig would benefit from documentation explaining their purpose and impact.

Add JSDoc comments like this:

 export interface WidgetTreeConfig {
+  /** Determines if the user has permissions to manage pages */
   canManagePages: boolean;
+  /** Controls whether this feature is enabled for the user */
   isFeatureEnabled: boolean;
 }
app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/hooks/useWidgetTreeState.ts (1)

5-21: Consider adding error boundaries and validation

While the implementation is solid, consider adding:

  1. Type validation for the Redux selector result
  2. Error handling for invalid widget IDs
  3. Maximum limit for expanded widgets to prevent memory issues

Example implementation:

 export const useWidgetTreeState = () => {
   const widgetsToExpand = useSelector(getEntityExplorerWidgetsToExpand);
-  const [expandedWidgets, setExpandedWidgets] = useState<string[]>(widgetsToExpand);
+  const [expandedWidgets, setExpandedWidgets] = useState<string[]>(
+    Array.isArray(widgetsToExpand) ? widgetsToExpand.slice(0, 100) : []
+  );

   const handleExpand = useCallback((id: string) => {
+    if (typeof id !== 'string' || id.trim() === '') return;
     setExpandedWidgets((prev) =>
       prev.includes(id)
         ? prev.filter((widgetId) => widgetId !== id)
-        : [...prev, id],
+        : prev.length >= 100 ? prev : [...prev, id],
     );
   }, []);
app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/hooks/useWidgetTreeHandlers.ts (2)

3-3: Remove unused import

The WidgetType import is not used in this file.

-import type { WidgetType } from "constants/WidgetConstants";

13-25: Consider debouncing double-click handler

The current implementation might cause both click and double-click handlers to fire when double-clicking. Consider adding debounce to prevent this.

+import debounce from "lodash/debounce";

 export const useWidgetTreeHandlers = (config: HandlerConfig) => {
   const { enterEditMode, switchToWidget } = config;

   const handleClick = useCallback(
     (_e: MouseEvent, widgetId: string) => {
+      if (_e.detail === 1) { // Only handle single clicks
         switchToWidget(widgetId);
+      }
     },
     [switchToWidget],
   );

   const handleDoubleClick = useCallback(
-    (widgetId: string) => {
+    debounce((widgetId: string) => {
       enterEditMode(widgetId);
-    },
+    }, 250),
     [enterEditMode],
   );
app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/utils/treeEnhancer.ts (1)

10-15: Add input validation for enhanceWidgetTree

The function assumes valid input array. Consider adding validation for null/undefined items.

 export const enhanceWidgetTree = (
   items: CanvasStructure[],
   config: TreeEnhancementConfig,
 ): EntityListTreeItem[] => {
+  if (!items?.length) return [];
   return items.map((item) => enhanceWidgetTreeItem(item, config));
 };
app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/UIEntityListTree.tsx (2)

73-88: Optimize enhancedItems memoization

The enhancedItems memo depends on too many variables. Consider breaking it down into smaller memoized parts.

+ const baseItems = useMemo(
+   () => treeItems.map((item) => ({
+     ...item,
+     rightControlVisibility: "hover" as const,
+   })),
+   [treeItems]
+ );

  const enhancedItems = useMemo(() => {
-   return treeItems.map((item) => ({
+   return baseItems.map((item) => ({
-     ...item,
-     rightControlVisibility: "hover" as const,
      onClick: (e: React.MouseEvent) => handleClick(e, item.id),
      onDoubleClick: () => handleDoubleClick(item.id),
      rightControl: (
        <WidgetContextMenu
          canManagePages={canManagePages}
          widgetId={item.id}
        />
      ),
      nameEditorConfig: handleNameEditor(item.id),
    }));
  }, [baseItems, handleClick, handleDoubleClick, canManagePages, handleNameEditor]);

90-97: Add error boundary for tree rendering

The tree rendering could fail if the data structure is malformed. Consider wrapping it in an error boundary.

+ import { ErrorBoundary } from "components/editorComponents/ErrorBoundary";

  return (
+   <ErrorBoundary>
      <EntityListTree
        className={className}
        items={enhancedItems}
        onItemExpand={handleExpand}
      />
+   </ErrorBoundary>
  );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c5e5b7b and 064ad76.

📒 Files selected for processing (8)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/UIEntityListTree.tsx (1 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/UIEntityListTree.types.ts (1 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/hooks/index.ts (1 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/hooks/useWidgetNameEditor.ts (1 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/hooks/useWidgetTreeHandlers.ts (1 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/hooks/useWidgetTreeState.ts (1 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/index.ts (1 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/utils/treeEnhancer.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-build / client-build
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: chromatic-deployment
  • GitHub Check: chromatic-deployment
  • GitHub Check: storybook-tests
🔇 Additional comments (3)
app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/hooks/index.ts (1)

1-5: Clean and well-organized hook exports

The barrel export pattern provides a clean interface for consuming components. The separation of hooks into individual files promotes maintainability.

app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/hooks/useWidgetNameEditor.ts (1)

21-25: Consider adding payload for exitEditMode action

The exitEditMode action doesn't include any payload about which widget's edit mode is being exited. This could lead to state inconsistencies if multiple widgets are in edit mode.

Let's verify if multiple widgets can be in edit mode simultaneously:

app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/index.ts (1)

1-2: LGTM!

Clean barrel file implementation with named exports.

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

🧹 Nitpick comments (5)
app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/utils/enhanceTree.ts (1)

4-16: Consider adding input validation.

The implementation is clean and functional. However, consider adding validation for the input parameters to handle edge cases.

 export const enhanceItemsTree = (
   items: CanvasStructure[],
   enhancer: (item: CanvasStructure) => EntityListTreeItem,
 ) => {
+  if (!Array.isArray(items)) {
+    return [];
+  }
+  if (typeof enhancer !== 'function') {
+    throw new Error('Enhancer must be a function');
+  }
   return items.map((child): EntityListTreeItem => {
app/client/src/selectors/explorerSelector.ts (1)

37-38: Add JSDoc documentation for consistency.

Other selectors in this file have JSDoc documentation. Consider adding documentation for this new selector to maintain consistency.

+/**
+ * returns the currently editing entity name
+ *
+ * @param state
+ * @returns
+ */
 export const getEditingEntityName = (state: AppState) =>
   state.ui.explorer.entity.editingEntityName;
app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/UIEntityListTree.tsx (3)

43-43: Consider providing widget name for validation initialization.

The useValidateEntityName hook is initialized with an empty object. Consider providing initial values for better type safety and validation context.

- const validateName = useValidateEntityName({});
+ const validateName = useValidateEntityName({ entityType: "widget" });

47-70: Consider memoizing the tree enhancement callback.

The enhancement callback function is recreated on every render. Consider memoizing it with useCallback to optimize performance.

+ const enhanceWidget = useCallback(
+   (widget) => ({
+     id: widget.widgetId,
+     title: widget.widgetName,
+     // ... rest of the enhancement logic
+   }),
+   [canManagePages, selectedWidgets, expandedWidgets, switchToWidget, enterEditMode, 
+    updatingEntity, editingEntity, handleNameSave, exitEditMode, validateName]
+ );

- const items = enhanceItemsTree(widgets?.children || [], (widget) => ({
+ const items = enhanceItemsTree(widgets?.children || [], enhanceWidget);

72-72: Consider memoizing items prop.

The items array is recreated on every render. Consider memoizing it with useMemo to prevent unnecessary re-renders of EntityListTree.

+ const memoizedItems = useMemo(() => items, [items]);
- return <EntityListTree items={items} onItemExpand={handleExpand} />;
+ return <EntityListTree items={memoizedItems} onItemExpand={handleExpand} />;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 064ad76 and 38705a5.

📒 Files selected for processing (9)
  • app/client/src/IDE/Components/EditableName/index.ts (1 hunks)
  • app/client/src/IDE/index.ts (1 hunks)
  • app/client/src/ce/selectors/entitiesSelector.ts (0 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/UIEntityListTree.tsx (1 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/hooks/useWidgetTreeExpandedState.ts (1 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/index.ts (1 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/utils/enhanceTree.ts (1 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/hooks/useNameEditorState.ts (1 hunks)
  • app/client/src/selectors/explorerSelector.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • app/client/src/ce/selectors/entitiesSelector.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-unit-tests / client-unit-tests
  • 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: storybook-tests
  • GitHub Check: chromatic-deployment
🔇 Additional comments (3)
app/client/src/IDE/Components/EditableName/index.ts (1)

4-4: LGTM! Clean export addition.

The new export follows the established pattern and groups related functionality together.

app/client/src/pages/Editor/IDE/EditorPane/hooks/useNameEditorState.ts (1)

10-36: LGTM! Well-structured custom hook implementation.

The hook follows React best practices with proper dependency management and clear separation of concerns.

app/client/src/IDE/index.ts (1)

51-51: LGTM! Export addition follows existing pattern.

The new export maintains the established organization of the file.

Copy link

github-actions bot commented Jan 9, 2025

🔴🔴🔴 Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 3, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

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

🧹 Nitpick comments (7)
app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.tsx (1)

Line range hint 49-53: Consider making dimensions configurable

While using CSS variables for background color is good, consider making the height and padding values configurable through props or theme variables for better flexibility.

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

42-57: Simplify children check with optional chaining

Consider using optional chaining for a more concise check.

-            {item.children && item.children.length ? (
+            {item.children?.length ? (
🧰 Tools
🪛 Biome (1.9.4)

[error] 42-42: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

app/client/src/sagas/selectors.tsx (1)

Line range hint 133-133: Consider addressing the TODO comments with eslint-disable directives.

There are two instances of eslint-disable comments marked as TODO. These represent technical debt that should be addressed by properly typing the variables.

The affected areas are:

  1. dataTree in getDataTreeForActionCreator
  2. acc in getPluginIdToImageLocation

Also applies to: 185-185

app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/hooks/useDeleteWidget.ts (3)

20-22: Enhance the comment to better explain the tab deletion logic.

The current comment could be more descriptive about why tabs require special handling.

-    // If the widget is a tab we are updating the `tabs` of the property of the widget
-    // This is similar to deleting a tab from the property pane
+    // Special handling for tab widgets:
+    // When deleting a tab, we need to update the parent TABS_WIDGET's `tabs` property
+    // instead of directly deleting the widget. This ensures proper cleanup and state management
+    // similar to when deleting a tab through the property pane.

30-38: Improve error handling for tab deletion.

The current implementation could be more robust with proper error handling and logging.

-      if (widget?.parentId && !!filteredTabs.length) {
+      if (!widget?.tabId) {
+        console.error('Failed to delete tab: Missing tabId');
+        return;
+      }
+
+      if (widget?.parentId && filteredTabs.length) {
         dispatch({
           type: ReduxActionTypes.WIDGET_DELETE_TAB_CHILD,
-          payload: { ...tabsObj[widget?.tabId] },
+          payload: { ...tabsObj[widget.tabId] },
         });
       }

40-47: Consider adding error handling for widget deletion.

The default widget deletion case could benefit from some basic validation.

+    if (!widget) {
+      console.error('Failed to delete widget: Widget not found');
+      return;
+    }
+
     dispatch({
       type: WidgetReduxActionTypes.WIDGET_DELETE,
       payload: {
         widgetId,
-        parentId: widget?.parentId,
+        parentId: widget.parentId,
       },
     });
app/client/src/pages/Editor/IDE/EditorPane/UI/List.tsx (1)

90-93: Consider consolidating overflow properties

The overflow properties could be consolidated into a single overflow property for better maintainability.

-          overflowX="hidden"
-          overflowY="auto"
+          overflow="hidden auto"
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 38705a5 and 9a8d80f.

📒 Files selected for processing (7)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.tsx (3 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.styles.ts (1 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.tsx (1 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/List.tsx (3 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/WidgetContextMenu.tsx (1 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/hooks/useDeleteWidget.ts (1 hunks)
  • app/client/src/sagas/selectors.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/WidgetContextMenu.tsx
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.styles.ts
🧰 Additional context used
🪛 Biome (1.9.4)
app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.tsx

[error] 42-42: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-build / client-build
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: storybook-tests
  • GitHub Check: chromatic-deployment
  • GitHub Check: chromatic-deployment
🔇 Additional comments (9)
app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.tsx (2)

35-42: Clean implementation of startIcon with loading state

Good use of useMemo for performance optimization and clean handling of loading state.


81-88: Well-implemented rightControl visibility logic

Clean implementation with proper memoization and clear conditional rendering.

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

15-26: Well-implemented expand click handler

Good use of useCallback and proper event handling with clear documentation.


62-68: Clean implementation of recursive tree rendering

Good handling of depth and expansion state. Consider adding a maximum depth limit to prevent potential stack overflow with deeply nested structures.

app/client/src/sagas/selectors.tsx (1)

66-68: LGTM! Type safety improvement.

The explicit return type annotation enhances type safety and makes the API contract clearer.

However, let's verify that this change doesn't break any existing usage:

✅ Verification successful

Return type change is safe and properly handled

The explicit undefined type is already accounted for in existing usage patterns through optional chaining and null-safe operations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all usages of getWidgetByID to ensure they handle the undefined case
rg "getWidgetByID\(" -A 2

Length of output: 4392

app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/hooks/useDeleteWidget.ts (2)

1-11: LGTM! Well-organized imports and constant definition.

The imports are logically grouped and demonstrate good separation of concerns.


13-17: LGTM! Clean hook setup with proper Redux integration.

The hook signature and state setup demonstrate good practices with proper typing and Redux hook usage.

app/client/src/pages/Editor/IDE/EditorPane/UI/List.tsx (2)

6-6: Clean import organization!

The new imports are well-organized and follow the project's import structure.

Also applies to: 14-15


94-98: Clean feature toggle implementation!

The conditional rendering between old and new implementations is well-structured and maintainable.

Copy link

🔴🔴🔴 Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 3, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

Copy link

🔴🔴🔴 Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 3, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

@hetunandu
Copy link
Member Author

/build-deploy-preview

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12704712525.
Workflow: On demand build Docker image and deploy preview.
skip-tests: . env: .
PR: 38493.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-38493.dp.appsmith.com

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

🧹 Nitpick comments (2)
app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.tsx (2)

43-58: Consider using optional chaining

The condition item.children && item.children.length could be simplified.

-{item.children && item.children.length ? (
+{item.children?.length ? (
🧰 Tools
🪛 Biome (1.9.4)

[error] 43-43: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


63-69: Consider memoizing recursive component

The recursive rendering of EntityListTree could benefit from memoization to prevent unnecessary re-renders in large trees.

Consider wrapping the component with React.memo:

export const EntityListTree = React.memo(function EntityListTree(props: EntityListTreeProps) {
  // ... existing implementation
});
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9a8d80f and d566221.

📒 Files selected for processing (10)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EmptyState/EmptyState.tsx (1 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EmptyState/EmptyState.types.ts (1 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.styles.ts (1 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.tsx (4 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.styles.ts (1 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.tsx (1 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/ExplorerContainer/ExplorerContainer.tsx (1 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/NoSearchResults/NoSearchResults.tsx (1 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/SearchAndAdd/SearchAndAdd.styles.tsx (1 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/SearchAndAdd/SearchAndAdd.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/SearchAndAdd/SearchAndAdd.styles.tsx
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.styles.ts
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/NoSearchResults/NoSearchResults.tsx
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EmptyState/EmptyState.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.tsx
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.styles.ts
🧰 Additional context used
🪛 Biome (1.9.4)
app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.tsx

[error] 43-43: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: perform-test / client-build / client-build
  • 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-build / client-build
  • GitHub Check: chromatic-deployment
  • GitHub Check: chromatic-deployment
  • GitHub Check: storybook-tests
🔇 Additional comments (5)
app/client/packages/design-system/ads/src/Templates/EntityExplorer/ExplorerContainer/ExplorerContainer.tsx (2)

2-3: LGTM! Import paths are now more direct and maintainable.

The refactored imports improve code organization by using direct paths.


Line range hint 6-19: Well-structured component with proper TypeScript typing.

The component follows React best practices with:

  • Proper prop typing
  • Consistent use of the Flex component
  • Clean prop spreading
app/client/packages/design-system/ads/src/Templates/EntityExplorer/EmptyState/EmptyState.types.ts (1)

1-2: LGTM! Improved import organization

The split imports provide better clarity on the source of each type.

app/client/packages/design-system/ads/src/Templates/EntityExplorer/SearchAndAdd/SearchAndAdd.tsx (1)

3-3: LGTM! Aligned with design system structure

Import path updated to use relative path within the design system.

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

16-27: LGTM! Well-implemented event handler

The useCallback optimization and event propagation handling are correctly implemented.

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

🧹 Nitpick comments (5)
app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.test.tsx (1)

81-112: Add test coverage for disabled state and selection behavior.

The test suite should verify:

  • Disabled items cannot be expanded/selected
  • Selection state is correctly managed
  • Name editor interactions work as expected
app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/hooks/useWidgetTreeExpandedState.ts (1)

22-25: Optimize array operations for better performance.

Consider using Set for better performance with large arrays:

-      setExpandedWidgets((prev) => [
-        ...prev,
-        ...widgetsToExpand.filter((widgetId) => !prev.includes(widgetId)),
-      ]);
+      setExpandedWidgets((prev) => {
+        const prevSet = new Set(prev);
+        widgetsToExpand.forEach(id => prevSet.add(id));
+        return Array.from(prevSet);
+      });
app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.tsx (1)

51-64: Optimize conditional rendering with optional chaining.

Use optional chaining for cleaner code:

-            {item.children && item.children.length ? (
+            {item.children?.length ? (
🧰 Tools
🪛 Biome (1.9.4)

[error] 51-51: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/UIEntityListTree.tsx (2)

19-31: Consider memoizing selector results

The selected widgets and permissions checks could be expensive operations. Consider memoizing these values using useMemo to prevent unnecessary recalculations.

-  const widgets = useSelector(selectWidgetsForCurrentPage);
-  const selectedWidgets = useSelector(getSelectedWidgets);
+  const widgets = useSelector(selectWidgetsForCurrentPage, React.memo);
+  const selectedWidgets = useSelector(getSelectedWidgets, React.memo);

47-73: Optimize item enhancement to prevent unnecessary re-renders

The enhancement function and its callbacks are recreated on every render. Consider memoizing both the enhancement function and its callbacks.

+ const handleClick = useCallback((e, widget) => switchToWidget(e, widget), [switchToWidget]);
+ const handleDoubleClick = useCallback((widgetId) => enterEditMode(widgetId), [enterEditMode]);

+ const enhanceWidget = useCallback((widget) => ({
+   id: widget.widgetId,
+   title: widget.widgetName,
+   startIcon: <WidgetTypeIcon type={widget.type} />,
+   isSelected: selectedWidgets.includes(widget.widgetId),
+   isExpanded: expandedWidgets.includes(widget.widgetId),
+   onClick: (e) => handleClick(e, widget),
+   onDoubleClick: () => handleDoubleClick(widget.widgetId),
+   // ... rest of the enhancement logic
+ }), [selectedWidgets, expandedWidgets, handleClick, handleDoubleClick]);

- const items = enhanceItemsTree(widgets?.children || [], (widget) => ({
+ const items = useMemo(() => 
+   enhanceItemsTree(widgets?.children || [], enhanceWidget),
+ [widgets?.children, enhanceWidget]);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d566221 and 6bafb5e.

📒 Files selected for processing (5)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.test.tsx (1 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.tsx (1 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/UIEntityListTree.tsx (1 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/WidgetTypeIcon.tsx (1 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/hooks/useWidgetTreeExpandedState.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.tsx

[error] 51-51: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-build / client-build
  • GitHub Check: chromatic-deployment
  • GitHub Check: storybook-tests
  • GitHub Check: chromatic-deployment
🔇 Additional comments (5)
app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/WidgetTypeIcon.tsx (1)

5-21: LGTM! Well-structured component with proper optimization.

The implementation includes:

  • Clear TypeScript interfaces
  • Performance optimization with React.memo
  • Proper fallback handling
app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/hooks/useWidgetTreeExpandedState.ts (1)

10-16: ⚠️ Potential issue

Add setExpandedWidgets to useCallback dependencies.

The handleExpand callback should include setExpandedWidgets in its dependency array.

-}, []);
+}, [setExpandedWidgets]);

Likely invalid or redundant comment.

app/client/src/pages/Editor/IDE/EditorPane/UI/UIEntityListTree/UIEntityListTree.tsx (3)

1-18: LGTM! Well-organized imports

The imports are logically grouped and all dependencies are relevant to the component's functionality.


33-44: LGTM! Well-implemented name editing logic

The name editing handlers are properly memoized and follow React's best practices.


45-46: LGTM! Clean tree state management

The tree state is managed efficiently using a custom hook.

Comment on lines 45 to 48
it("renders the EntityListTree component", () => {
render(<EntityListTree {...defaultProps} />);
expect(screen.getByRole("tree")).toBeInTheDocument();
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Add keyboard navigation implementation and tests

The component implements ARIA attributes but lacks keyboard navigation handlers required for tree view accessibility. Add keyboard support for:

  • Arrow keys for navigation
  • Enter/Space for selection
  • Home/End for first/last item
  • Expand/Collapse with arrow keys
🔗 Analysis chain

Add test coverage for keyboard navigation and accessibility.

The component implements ARIA attributes but lacks tests for keyboard navigation and accessibility features.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for keyboard event handlers in the component
rg -A 2 'onKeyDown|onKeyPress|onKeyUp' app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/

Length of output: 123


Script:

#!/bin/bash
# Check component implementation and imports
ast-grep --pattern 'export const EntityListTree = $_' app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.tsx

# Look for accessibility-related code
rg -i "aria-|role=" app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.tsx

Length of output: 485


Script:

#!/bin/bash
# Check for imports and component inheritance
rg -A 3 "^import.*from" app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityListTree/EntityListTree.tsx

# Check if there's a base tree component being used
ast-grep --pattern '<$_Tree'

Length of output: 74527

Comment on lines +32 to +81
return (
<Flex
flex="1"
flexDirection="column"
role={currentDepth == 0 ? "tree" : undefined}
>
{props.items.map((item) => (
<Flex flex="1" flexDirection="column" key={item.id}>
<EntityItemWrapper
alignItems="center"
aria-expanded={item.isExpanded}
aria-level={currentDepth}
aria-selected={item.isSelected}
data-depth={currentDepth}
data-disabled={item.isDisabled || false}
data-selected={item.isSelected}
flexDirection="row"
role="treeitem"
>
{item.children && item.children.length ? (
<CollapseWrapper
data-itemid={item.id}
data-testid="entity-item-expand-icon"
onClick={handleOnExpandClick}
>
<Icon
name={
item.isExpanded ? "arrow-down-s-line" : "arrow-right-s-line"
}
size="md"
/>
</CollapseWrapper>
) : (
<CollapseSpacer />
)}
<PaddingOverrider>
<EntityItem {...item} />
</PaddingOverrider>
</EntityItemWrapper>
{item.children && item.isExpanded ? (
<EntityListTree
depth={childrenDepth}
items={item.children}
onItemExpand={onItemExpand}
/>
) : null}
</Flex>
))}
</Flex>
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Implement keyboard navigation for accessibility.

Add keyboard navigation handlers for:

  • Arrow keys for tree traversal
  • Home/End for first/last item
  • Enter/Space for selection

Would you like me to provide the implementation for keyboard navigation handlers?

🧰 Tools
🪛 Biome (1.9.4)

[error] 51-51: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

@hetunandu
Copy link
Member Author

/build-deploy-preview

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12707067301.
Workflow: On demand build Docker image and deploy preview.
skip-tests: . env: .
PR: 38493.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-38493.dp.appsmith.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request 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 Task A simple Todo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create EntityListTree component
2 participants