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: Selected item in State Inspector #38955

Merged
merged 2 commits into from
Feb 4, 2025
Merged

Conversation

hetunandu
Copy link
Member

@hetunandu hetunandu commented Feb 3, 2025

Description

fixes the selected item being lost in state inspector by refactoring the logic

  • Keeps only the selected item id in state
  • separates the data tree fetch in a different hook

Fixes #38875

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/13111881263
Commit: f64e20f
Cypress dashboard.
Tags: @tag.IDE
Spec:


Mon, 03 Feb 2025 11:26:14 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Improved the debugger state inspector to compute and display dynamic data based on the selected item for a more responsive experience.
  • Refactor

    • Simplified state management by switching from complex item objects to straightforward identifier strings.
    • Updated tests and internal logic to ensure consistent selection behavior and data processing.

Copy link
Contributor

coderabbitai bot commented Feb 3, 2025

Walkthrough

This pull request refactors how the State Inspector manages the selected item. The changes switch from using a complex GenericEntityItem object to a simple string identifier across actions, hooks, utilities, reducers, and selectors. Additionally, a new hook, useGetDisplayData, is introduced to compute display data based on the selected item’s title. Tests and state management logic have been updated accordingly without altering the overall control flow.

Changes

File(s) Change Summary
app/client/src/actions/debuggerActions.ts Updated setDebuggerStateInspectorSelectedItem parameter type from GenericEntityItem to string.
app/client/src/components/editorComponents/Debugger/StateInspector/StateInspector.test.tsx
app/client/src/components/editorComponents/Debugger/StateInspector/StateInspector.tsx
Integrated new hook useGetDisplayData and updated tests to reflect the new display data structure.
app/client/src/components/editorComponents/Debugger/StateInspector/hooks/* Added new hook useGetDisplayData; updated useStateInspectorItems (renamed variable to selectedItemId and adjusted return types) and useStateInspectorState (now returns string identifier) in line with the simplified item representation.
app/client/src/components/editorComponents/Debugger/StateInspector/utils.ts Modified enhanceItemForListItem to accept selectedItemId and update selection logic accordingly.
app/client/src/reducers/uiReducers/debuggerReducer.ts Changed action type to ReduxAction<string> and renamed state property from selectedItem to selectedItemId.
app/client/src/selectors/debuggerSelectors.tsx Updated selector to retrieve selectedItemId instead of selectedItem.

Sequence Diagram(s)

sequenceDiagram
    participant SI as StateInspector Component
    participant GD as useGetDisplayData Hook
    participant RS as Redux Store
    SI->>GD: Call useGetDisplayData(selectedItemName)
    GD->>RS: Retrieve dataTree, configTree, jsActions
    RS-->>GD: Return state data
    GD-->>SI: Return computed display data
Loading

Assessment against linked issues

Objective Addressed Explanation
#38875: Selection is lost when renaming an entity

Suggested labels

Bug, Medium, IDE Product, Needs Triaging, ok-to-test, IDE Pod, Query Forms

Suggested reviewers

  • ankitakinger
  • albinAppsmith

Poem

In our code, a new dawn greets the day,
IDs now guide the selection’s way.
With hooks refreshed and tests aligned,
The Debugger’s state is redefined.
Cheers to refactor magic underway! 🚀

✨ 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.

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 Debugger Product Issues related to the debugger High This issue blocks a user from building or impacts a lot of users IDE Pod Issues that new developers face while exploring the IDE Low An issue that is neither critical nor breaks a user flow labels Feb 3, 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 (2)
app/client/src/components/editorComponents/Debugger/StateInspector/hooks/useGetDisplayData.ts (1)

7-25: Consider adding error boundary for robust error handling.

While the hook handles missing data gracefully, consider wrapping the filterInternalProperties call in a try-catch block to handle potential runtime errors.

 export function useGetDisplayData(selectedItemName: string) {
   const dataTree = useSelector(getDataTree);
   const configTree = useSelector(getConfigTree);
   const jsActions = useSelector(getJSCollections);

   return useMemo(() => {
     if (selectedItemName in dataTree && selectedItemName in configTree) {
+      try {
         return filterInternalProperties(
           selectedItemName,
           dataTree[selectedItemName],
           jsActions,
           dataTree,
           configTree,
         );
+      } catch (error) {
+        console.error("Error filtering properties:", error);
+        return "";
+      }
     }

     return "";
   }, [configTree, dataTree, jsActions, selectedItemName]);
 }
app/client/src/components/editorComponents/Debugger/StateInspector/hooks/useStateInspectorItems.ts (1)

22-45: Consider memoizing selectedItem transformation separately.

The selectedItem transformation could be memoized separately from groups to avoid unnecessary object creation when only groups change.

-  const [groups, selectedItem] = useMemo(() => {
+  const groups = useMemo(() => {
     const allGroups = [queries, jsItems, uiItems, globalItems];
 
     const processedGroups = allGroups
       .filter((groupedItems) => groupedItems.items.length > 0)
       .map((groupedItems) => ({
         group: groupedItems.group,
         items: groupedItems.items.map((item) =>
           enhanceItemForListItem(item, selectedItemId, setSelectedItem),
         ),
       }));
 
+    return processedGroups;
+  }, [globalItems, jsItems, queries, selectedItemId, setSelectedItem, uiItems]);
+
+  const selectedItem = useMemo(() => {
     const selectedItemFromGroups = processedGroups
       .flatMap((group) => group.items)
       .find((item) => item.id === selectedItemId);
 
-    const selectedItem: GenericEntityItem | undefined = {
+    return selectedItemFromGroups ? {
       key: selectedItemFromGroups?.id || "",
       title: selectedItemFromGroups?.title || "",
       icon: selectedItemFromGroups?.startIcon,
-    };
-
-    return [processedGroups, selectedItem];
-  }, [globalItems, jsItems, queries, selectedItemId, setSelectedItem, uiItems]);
+    } : undefined;
+  }, [groups, selectedItemId]);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2a35c93 and f64e20f.

📒 Files selected for processing (10)
  • app/client/src/actions/debuggerActions.ts (1 hunks)
  • app/client/src/components/editorComponents/Debugger/StateInspector/StateInspector.test.tsx (7 hunks)
  • app/client/src/components/editorComponents/Debugger/StateInspector/StateInspector.tsx (2 hunks)
  • app/client/src/components/editorComponents/Debugger/StateInspector/hooks/index.ts (1 hunks)
  • app/client/src/components/editorComponents/Debugger/StateInspector/hooks/useGetDisplayData.ts (1 hunks)
  • app/client/src/components/editorComponents/Debugger/StateInspector/hooks/useStateInspectorItems.ts (1 hunks)
  • app/client/src/components/editorComponents/Debugger/StateInspector/hooks/useStateInspectorState.ts (1 hunks)
  • app/client/src/components/editorComponents/Debugger/StateInspector/utils.ts (1 hunks)
  • app/client/src/reducers/uiReducers/debuggerReducer.ts (2 hunks)
  • app/client/src/selectors/debuggerSelectors.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • app/client/src/components/editorComponents/Debugger/StateInspector/hooks/index.ts
🔇 Additional comments (11)
app/client/src/components/editorComponents/Debugger/StateInspector/utils.ts (1)

4-15: LGTM! Clean refactor to use string IDs.

The changes simplify the state management by using string IDs instead of complex objects while maintaining the same functionality.

app/client/src/components/editorComponents/Debugger/StateInspector/hooks/useStateInspectorState.ts (1)

5-18: LGTM! Consistent type changes.

The hook's signature changes align with the refactoring to use string IDs, maintaining consistency across the codebase.

app/client/src/components/editorComponents/Debugger/StateInspector/hooks/useStateInspectorItems.ts (1)

47-56: LGTM! Clean effect implementation.

The useEffect implementation for handling unselected state is clean and has proper dependencies.

app/client/src/components/editorComponents/Debugger/StateInspector/StateInspector.tsx (1)

12-12: LGTM! Good separation of concerns.

Moving the display data computation to a separate hook improves code organization and maintainability.

Also applies to: 21-22

app/client/src/actions/debuggerActions.ts (1)

151-156: LGTM! Simplified action payload.

Using a string ID instead of a complex object type makes the action more maintainable and reduces unnecessary data passing.

app/client/src/components/editorComponents/Debugger/StateInspector/StateInspector.test.tsx (1)

17-18: LGTM! Comprehensive test coverage.

The mock setup for the new hook is well-structured and consistent across all test cases.

Also applies to: 37-38

app/client/src/selectors/debuggerSelectors.tsx (2)

188-189: LGTM! Consistent with the new ID-based approach.

The selector change maintains consistency with the broader refactoring to use string IDs.


1-1: Verify complete migration to ID-based approach.

Let's ensure all related files have been updated to use the new ID-based approach.

✅ Verification successful

Migration to ID-based approach verified.
No references to the old patterns were found in the Debugger StateInspector files, confirming that the updates are complete.

  • No occurrences of GenericEntityItem.*selectedItem were detected.
  • All references to .selectedItem now include the Id suffix.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining references to GenericEntityItem in state inspector related files
rg -l "GenericEntityItem.*selectedItem" "app/client/src/components/editorComponents/Debugger/StateInspector"

# Search for any old selectedItem references that might have been missed
rg -l "\.selectedItem(?!Id)" "app/client/src/components/editorComponents/Debugger/StateInspector"

Length of output: 444


Script:

#!/bin/bash
# Re-run the search commands using the --pcre2 flag to enable lookahead functionality

# Search for any remaining references to GenericEntityItem using selectedItem within StateInspector files
echo "Searching for 'GenericEntityItem.*selectedItem'..."
rg --pcre2 -l "GenericEntityItem.*selectedItem" "app/client/src/components/editorComponents/Debugger/StateInspector"

# Search for any old selectedItem references that might have been missed (i.e. not suffixed with 'Id')
echo "Searching for occurrences of '.selectedItem' not followed by 'Id'..."
rg --pcre2 -l "\.selectedItem(?!Id)" "app/client/src/components/editorComponents/Debugger/StateInspector"

Length of output: 498

app/client/src/reducers/uiReducers/debuggerReducer.ts (3)

191-191: LGTM! Good simplification of the action payload type.

The change from GenericEntityItem to string aligns with best practices by maintaining minimal state representation.


196-196: LGTM! Clear and consistent state property naming.

The property name selectedItemId accurately reflects its content and maintains consistency with the action type change.


214-214: LGTM! Type-safe interface update.

The interface correctly reflects the state structure changes while maintaining nullability behavior.

@hetunandu hetunandu added the ok-to-test Required label for CI label Feb 3, 2025
@hetunandu hetunandu merged commit ce416df into release Feb 4, 2025
47 checks passed
@hetunandu hetunandu deleted the fix/state-inspector-selection branch February 4, 2025 07:24
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Debugger Product Issues related to the debugger High This issue blocks a user from building or impacts a lot of users IDE Pod Issues that new developers face while exploring the IDE Low An issue that is neither critical nor breaks a user flow ok-to-test Required label for CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: [State Inspector] Selection is lost when renaming an entity
2 participants