Skip to content

chore: Refactoring code by taking out the common logic for re-using it on other IDEs#39577

Merged
hetunandu merged 3 commits intoreleasefrom
chore/refactor-for-package-ide-tabs
Mar 6, 2025
Merged

chore: Refactoring code by taking out the common logic for re-using it on other IDEs#39577
hetunandu merged 3 commits intoreleasefrom
chore/refactor-for-package-ide-tabs

Conversation

@ankitakinger
Copy link
Contributor

@ankitakinger ankitakinger commented Mar 5, 2025

Description

Refactoring code by taking out the common logic for re-using it on other IDEs

Fixes #38904

Automation

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

🔍 Cypress test results

Caution

🔴 🔴 🔴 Some tests have failed.
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/13692417401
Commit: caef1fa
Cypress dashboard.
Tags: @tag.All
Spec:
The following are new failures, please fix them before merging the PR:

  1. cypress/e2e/Regression/ServerSide/GenerateCRUD/Postgres2_Spec.ts
List of identified flaky tests.
Thu, 06 Mar 2025 07:19:07 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced navigation flow with improved tab management during item removal.
  • Bug Fixes

    • Resolved issues that could lead to execution interruptions, ensuring smoother interactions.
  • Refactor

    • Streamlined internal logic for grouping, sorting, and navigation, resulting in improved stability and performance.

@ankitakinger ankitakinger added the ok-to-test Required label for CI label Mar 5, 2025
@ankitakinger ankitakinger requested a review from hetunandu March 5, 2025 14:37
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2025

Walkthrough

This pull request refactors several modules by updating type definitions and function signatures to use generics, enhancing flexibility. It also improves robustness in the block execution hook with optional chaining. Additionally, it removes outdated tab management and redirection logic from the saga file and replaces it with new helper functions in dedicated utility files. Import statements have been updated to reflect these changes.

Changes

File(s) Change Summary
app/client/src/IDE/utils/groupAndSortEntitySegmentList.ts Updated EditorSegmentList and groupAndSortEntitySegmentList to use generics (<T>).
app/client/src/ce/PluginActionEditor/hooks/useBlockExecution.ts Added optional chaining to safely access actionConfiguration.path.
app/client/src/sagas/IDESaga.tsx Removed functions (getUpdatedTabs, getNextEntityAfterRemove), enum, and interface related to tab and redirection logic.
app/client/src/IDE/utils/getNextEntityAfterRemove.ts
app/client/src/IDE/utils/getUpdatedTabs.ts
Introduced new helper functions and related types to manage redirection and tab updates.
app/client/src/IDE/utils/getNextEntityAfterRemove.test.ts Updated imports from the old saga file to the new helper module.

Sequence Diagram(s)

sequenceDiagram
    participant U as User Action
    participant S as IDE Saga
    participant R as Redirect Helper
    U->>S: Remove entity (removedId)
    S->>R: getNextEntityAfterRemove(removedId, tabs)
    R-->>S: Return RedirectAction (NA, LIST, or ITEM)
    S->>U: Redirect based on action
Loading
sequenceDiagram
    participant U as User Action
    participant S as Tab Manager
    participant T as Tab Helper
    U->>S: Create entity (newId)
    S->>T: getUpdatedTabs(newId, currentTabs)
    T-->>S: Return updated tab list
    S->>U: Update UI with new tabs
Loading

Possibly related PRs

Suggested reviewers

  • AmanAgarwal041
  • sagar-qa007
  • hetunandu

Poem

In structured code the changes bloom,
Generics rise to clear the room.
Tabs and redirects find a new way,
With helpers guiding what’s done today.
Cheers to refactor and a brighter display!
🎉✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 0168713 and caef1fa.

📒 Files selected for processing (2)
  • app/client/src/IDE/utils/getNextEntityAfterRemove.test.ts (1 hunks)
  • app/client/src/sagas/IDESaga.tsx (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • app/client/src/IDE/utils/getNextEntityAfterRemove.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-build / client-build
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-prettier / prettier-check
🔇 Additional comments (7)
app/client/src/sagas/IDESaga.tsx (7)

2-2: Good practice separating type and value imports.

The separation of type imports (line 1) from value imports (line 2) is a good TypeScript practice that improves code clarity.


30-34: Good refactoring to improve reusability.

Moving the utility functions to dedicated files aligns with the PR objective of extracting common logic for reuse across different IDEs. This improves modularity and maintainability.

The refactored code maintains the same function signatures, ensuring backward compatibility while enabling reuse in other contexts.


45-48: Function call to refactored utility works correctly.

The saga correctly uses the imported getUpdatedTabs function with the same parameters as before. Integration appears seamless.


55-58: Consistent usage of refactored utility.

The implementation for query tabs is consistent with the JS tabs implementation, showing good symmetry in the codebase.


64-65: Clean integration with refactored redirect logic.

The getNextEntityAfterRemove function is used correctly with the same parameters, maintaining consistent behavior after refactoring.


67-82: Switch statement correctly uses imported enum.

The switch statement properly uses the imported RedirectAction enum. No changes needed to the implementation logic.

🧰 Tools
🪛 Biome (1.9.4)

[error] 78-78: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


87-105: Consistent implementation for query entity redirection.

The query entity redirection follows the same pattern as JS entity redirection, showing good code consistency.

🧰 Tools
🪛 Biome (1.9.4)

[error] 101-101: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)


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

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 IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product potential-duplicate This label marks issues that are potential duplicates of already open issues Task A simple Todo skip-changelog Adding this label to a PR prevents it from being listed in the changelog labels Mar 5, 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 c0e6c3c and 61ce974.

📒 Files selected for processing (5)
  • app/client/src/IDE/utils/groupAndSortEntitySegmentList.ts (1 hunks)
  • app/client/src/ce/PluginActionEditor/hooks/useBlockExecution.ts (1 hunks)
  • app/client/src/sagas/IDESaga.tsx (2 hunks)
  • app/client/src/sagas/getNextEntityAfterRemove.test.ts (1 hunks)
  • app/client/src/sagas/helper.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • app/client/src/sagas/getNextEntityAfterRemove.test.ts
🧰 Additional context used
🪛 Biome (1.9.4)
app/client/src/sagas/helper.ts

[error] 330-336: This generator function doesn't contain yield.

(lint/correctness/useYield)

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • 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-build / client-build
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-prettier / prettier-check
🔇 Additional comments (8)
app/client/src/ce/PluginActionEditor/hooks/useBlockExecution.ts (1)

24-24: Good safeguard against undefined configuration
Using optional chaining effectively prevents a potential null reference error here.

app/client/src/IDE/utils/groupAndSortEntitySegmentList.ts (4)

2-2: Efficient lodash usage
The import appears correct and consistent with established patterns.


4-4: Updated type definition is beneficial
Declaring EditorSegmentList as generic enhances reusability across various entity types.


6-6: Good extension of the generic parameter
Allowing items to be typed as T[] solidifies type safety for future usage.


9-11: Generic function improves flexibility
Converting groupAndSortEntitySegmentList to a generic function is a solid step toward making this utility more reusable.

app/client/src/sagas/helper.ts (1)

338-401: Navigation logic for entity removal looks solid
Centralizing removal handling and redirect decisions in this helper clarifies responsibilities and simplifies maintenance.

app/client/src/sagas/IDESaga.tsx (2)

2-2: Explicit import
Clear indication of using FocusEntity from the same file, maintaining code clarity.


31-34: Refactored imports
Importing tab and redirect utilities from the helper module streamlines the saga and improves maintainability.

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/IDE/utils/getUpdatedTabs.ts (1)

1-7: Add JSDoc comments and return type annotation.

The function logic is correct, but it would benefit from JSDoc comments explaining its purpose and parameters. Also, explicitly define the return type for better maintainability.

-export function getUpdatedTabs(newId: string, currentTabs: string[]) {
+/**
+ * Updates the tabs array to include the new tab ID if it doesn't already exist
+ * @param newId The ID of the tab to add
+ * @param currentTabs Current array of tab IDs
+ * @returns Updated array of tab IDs
+ */
+export function getUpdatedTabs(newId: string, currentTabs: string[]): string[] {
app/client/src/IDE/utils/getNextEntityAfterRemove.ts (1)

38-66: Consider simplifying the redirection logic.

The switch statement implementation works correctly, but could be simplified. Also, the TODO comment on lines 48-49 indicates potential design changes needed.

  const indexOfTab = tabs.findIndex((item) => item.key === removedId);

- switch (indexOfTab) {
-   case -1:
-     // If no other action is remaining, navigate to the creation url
-     return {
-       action: RedirectAction.LIST,
-     };
-   case 0:
-     // if the removed item is first item, then if tabs present, tabs + 1
-     // else otherItems[0] -> TODO: consider changing this logic after discussion with
-     // design team. May be new listing UI for side by side
-     if (tabs.length > 1) {
-       return {
-         action: RedirectAction.ITEM,
-         payload: tabs[1],
-       };
-     } else {
-       return {
-         action: RedirectAction.LIST,
-       };
-     }
-   default:
-     return {
-       action: RedirectAction.ITEM,
-       payload: tabs[indexOfTab - 1],
-     };
- }
+ // If tab not found or it's the last remaining tab, go to list view
+ if (indexOfTab === -1 || tabs.length <= 1) {
+   return {
+     action: RedirectAction.LIST,
+   };
+ }
+ 
+ // Choose next tab if available, otherwise previous tab
+ const nextTabIndex = indexOfTab === 0 ? 1 : indexOfTab - 1;
+ return {
+   action: RedirectAction.ITEM,
+   payload: tabs[nextTabIndex],
+ };

Note: Resolve the TODO comment (lines 48-49) after discussion with the design team.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 61ce974 and 0168713.

📒 Files selected for processing (2)
  • app/client/src/IDE/utils/getNextEntityAfterRemove.ts (1 hunks)
  • app/client/src/IDE/utils/getUpdatedTabs.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • 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-prettier / prettier-check
  • GitHub Check: client-build / client-build
🔇 Additional comments (2)
app/client/src/IDE/utils/getNextEntityAfterRemove.ts (2)

1-20: Well-structured enum and interface implementation with proper documentation.

The implementation of the RedirectAction enum and RedirectActionDescription interface is clean and well-documented. Good use of generic typing for flexibility.


22-37: Strong implementation of redirection logic with proper type safety.

The function correctly determines whether navigation is required based on the currently selected entity. Good use of generics with the EntityItem constraint.

@hetunandu hetunandu merged commit 943e7f2 into release Mar 6, 2025
83 of 85 checks passed
@hetunandu hetunandu deleted the chore/refactor-for-package-ide-tabs branch March 6, 2025 07:52
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 potential-duplicate This label marks issues that are potential duplicates of already open issues 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.

[Task]: Implement Entity tabs for Package IDE

2 participants