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: App card routing #38798

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

fix: App card routing #38798

wants to merge 4 commits into from

Conversation

hetunandu
Copy link
Member

@hetunandu hetunandu commented Jan 22, 2025

Description

fixes an issue where App card click causing the whole app to remount and init all redux state

The performance of opening an app in edit has improved drastically post this change

Screen.Recording.2025-01-23.at.11.04.00.AM.mov

Reverts code back to #15168
Changed with https://github.com/appsmithorg/appsmith/pull/27223/files#diff-d346c04dfdbc5fc695a1c5e7308754cd2c676a6ea31e1783b28792d7c3895dd3R461

Precursor for #37648

Automation

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

🔍 Cypress test results

Caution

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

  1. cypress/e2e/Regression/ClientSide/OtherUIFeatures/Widget_Error_spec.js
List of identified flaky tests.
Mon, 27 Jan 2025 09:17:41 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

Summary by CodeRabbit

  • Refactor

    • Updated event handling for application launch and edit functions.
    • Simplified prop access within the application card component.
    • Enhanced application selection and editing functionality in the HomePage class.
    • Modified navigation mechanism in the AppsmithLink component.
  • Bug Fixes

    • Improved event handling to prevent default actions and support opening links in new tabs.
    • Refined visibility checks for UI components after application creation and editing.
  • New Features

    • Added a method to select an application for editing in the HomePage class.
    • Introduced a validation step to check the visibility of the application name after launching.

Copy link
Contributor

coderabbitai bot commented Jan 22, 2025

Walkthrough

The pull request modifies the ApplicationCard.tsx file, focusing on refactoring to use the application prop directly instead of accessing it through props.application. The method signatures for launchApp, editApp, and launchMobileApp have been updated to include an event parameter, enabling better event handling. Additionally, default actions are prevented, and navigation logic has been refined to enhance the management of application states throughout the component. Changes to the HomePage.ts and WorkspaceCommands.js files introduce new methods and assertions to improve application editing and visibility checks.

Changes

File Change Summary
app/client/src/pages/Applications/ApplicationCard.tsx - Refactored to use application prop directly
- Updated method signatures to accept event parameters
- Added e.preventDefault() and e.stopPropagation()
- Modified navigation logic for opening URLs
app/client/cypress/support/Pages/HomePage.ts - Added method SelectAppToEdit(index: number = 0) to select and edit applications
- Updated visibility assertion in CreateAppInWorkspace method
app/client/cypress/support/WorkspaceCommands.js - Added constant appSettings from ObjectsRegistry
- Added visibility assertion for application name in launchApp command
app/client/src/pages/Editor/AppsmithLink.tsx - Added handleOnClick function for programmatic navigation using history.push
- Updated StyledLink usage to utilize onClick prop

Possibly related PRs

Suggested labels

Enhancement, High, Production, Needs Triaging, IDE Product, IDE Pod

Suggested reviewers

  • AmanAgarwal041
  • albinAppsmith
  • ankitakinger
  • sagar-qa007

Poem

🎉 In the code where functions play,
Props now shine in a clearer way,
Events are caught, no actions stray,
ApplicationCard leads the way!
Refactored paths, bright as day! 🌈


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 the Bug Something isn't working label Jan 22, 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 (3)
app/client/src/pages/Applications/ApplicationCard.tsx (3)

480-489: Add TypeScript event type annotation.

The event parameter should be properly typed for better type safety.

-  const launchApp = useCallback(
-    (e) => {
+  const launchApp = useCallback(
+    (e: React.MouseEvent<HTMLElement>) => {

491-500: Add TypeScript event type annotation.

The event parameter should be properly typed for better type safety.

-  const editApp = useCallback(
-    (e) => {
+  const editApp = useCallback(
+    (e: React.MouseEvent<HTMLElement>) => {

502-511: Optimize dependencies and add type annotation.

  1. The dependency array includes redundant dependencies that are already covered by viewModeURL.
  2. The event parameter should be properly typed.
-  const launchMobileApp = useCallback(
-    (e) => {
+  const launchMobileApp = useCallback(
+    (e: React.MouseEvent<HTMLElement>) => {
       e.preventDefault();
       e.stopPropagation();
       setURLParams();
       history.push(viewModeURL);
       dispatch(getCurrentUser());
     },
-    [dispatch, props.application.defaultBasePageId, setURLParams, viewerParams],
+    [dispatch, viewModeURL, setURLParams],
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 704e473 and 0eff745.

📒 Files selected for processing (1)
  • app/client/src/pages/Applications/ApplicationCard.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • 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
🔇 Additional comments (1)
app/client/src/pages/Applications/ApplicationCard.tsx (1)

480-511: Implementation effectively addresses the remounting issue.

The changes successfully prevent default navigation behavior and implement controlled routing through history.push, which should resolve the application remounting issue.

@hetunandu hetunandu added the ok-to-test Required label for CI label Jan 22, 2025
@hetunandu
Copy link
Member Author

/build-deploy-preview

Copy link

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

Copy link

Deploy-Preview-URL: https://ce-38798.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: 0

🧹 Nitpick comments (1)
app/client/src/pages/Applications/ApplicationCard.tsx (1)

211-227: Consider memoizing permission checks.

These permission checks are computed on every render. Consider using useMemo to optimize performance.

-  const hasEditPermission = isPermitted(
-    application.userPermissions ?? [],
-    PERMISSION_TYPE.MANAGE_APPLICATION,
-  );
+  const hasEditPermission = useMemo(() => 
+    isPermitted(
+      application.userPermissions ?? [],
+      PERMISSION_TYPE.MANAGE_APPLICATION,
+    ),
+    [application.userPermissions]
+  );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0eff745 and 45bb2fc.

📒 Files selected for processing (1)
  • app/client/src/pages/Applications/ApplicationCard.tsx (12 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • 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-prettier / prettier-check
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-build / client-build
🔇 Additional comments (6)
app/client/src/pages/Applications/ApplicationCard.tsx (6)

79-90: LGTM! Well-structured styles using design system variables.


165-172: LGTM! Proper color initialization with fallback.


445-470: LGTM! Well-structured URL params management with proper dependencies.


488-533: New tab functionality is enhanced, not removed.

Contrary to the previous review comment, this change actually enhances the new tab functionality by adding support for Ctrl/Cmd+Click. This is a more standard approach that aligns with user expectations.


551-552: LGTM! Proper test ID updates.


313-314: Handle potential edge case in initials generation.

The current implementation assumes the application name has at least one character. Consider adding a length check before accessing the second character.

-  if (initials.length < 2 && application.name.length > 1) {
-    initials += application.name[1].toUpperCase() || "";
+  if (initials.length < 2 && application.name?.length > 1) {
+    initials += application.name[1]?.toUpperCase() || "";

@hetunandu
Copy link
Member Author

/build-deploy-preview

Copy link

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

Copy link

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

ankitakinger
ankitakinger previously approved these changes Jan 23, 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 (5)
app/client/cypress/support/WorkspaceCommands.js (1)

66-66: Validate locator usage for best practices.
While asserting element visibility here is helpful, confirm that appSettings.locators._applicationName references a data-* attribute rather than a CSS or XPath selector. Adhering to data-* attributes aligns with Cypress best practices for stable element targeting.

app/client/cypress/support/Pages/HomePage.ts (4)

135-135: Consider verifying the active Apps tab for stability.
A quick assertion after navigating can confirm the tab switch and guard against flaky tests.

  public SwitchToAppsTab() {
    this.agHelper.GetNClick(this._homeTab);
+   this.agHelper.AssertElementVisibility(".t--applications-container");
  }

328-328: Use data-test attributes for targeted element visibility checks.
Replacing classes with data-* attributes often yields more robust tests.


802-802: Avoid forcing clicks if not necessary.
“force: true” bypasses Cypress’s actionability checks and can mask real UI issues. Use it only when absolutely needed.


812-816: Offer a method to select an application by name alongside index.
Index-based selection can be brittle; consider adding a companion method that locates the app by name or data-test attribute.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 45bb2fc and 4c2484e.

📒 Files selected for processing (2)
  • app/client/cypress/support/Pages/HomePage.ts (5 hunks)
  • app/client/cypress/support/WorkspaceCommands.js (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
app/client/cypress/support/WorkspaceCommands.js (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
app/client/cypress/support/Pages/HomePage.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
⏰ 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-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-build / client-build
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-prettier / prettier-check
🔇 Additional comments (3)
app/client/cypress/support/WorkspaceCommands.js (1)

15-15: Solid introduction for referencing app settings.
This new constant centralizes the usage of application settings, maintaining better consistency with other helper objects.

app/client/cypress/support/Pages/HomePage.ts (2)

6-6: No relevant code change here.


811-811: No meaningful code change here.

ankitakinger
ankitakinger previously approved these changes Jan 24, 2025
@dvj1988
Copy link
Contributor

dvj1988 commented Jan 27, 2025

@hetunandu Is it correct to assume that the entire page was re-rendering because we were passing the href to the "Edit" and "Launch" CTAs on the Application card?
If we are using React Router to navigate to the application's edit and view modes, do we still need to pass the href to these CTAs? From the code, it appears that we are passing the href but then preventing the default behaviour, which would otherwise navigate to the new URL.

@hetunandu
Copy link
Member Author

@dvj1988 is correct here @vsvamsi1

href causes the React Router / Browser to load the App.tsx to mount again instead just the sub route.

I am preventing default unless the user attempts to open the App in a new tab / window cause that anyways needs a full App mount.

there still is a href passed which makes it a link. I think this helps in browser understanding it is a link but if needed we can remove that as well.

@hetunandu
Copy link
Member Author

/build-deploy-preview

Copy link

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

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/src/pages/Applications/ApplicationCard.tsx (1)

445-470: Consider simplifying URL params dependency array

The current implementation has a large dependency array that could potentially cause unnecessary re-renders.

Consider extracting the page-related data into a useMemo:

+const defaultPage = useMemo(
+  () => application.pages.find((page) => page.id === application.defaultPageId),
+  [application.pages, application.defaultPageId]
+);

 const setURLParams = useCallback(() => {
-  const page: ApplicationPagePayload | undefined = application.pages.find(
-    (page) => page.id === application.defaultPageId,
-  );
+  if (!defaultPage) return;

   urlBuilder.updateURLParams(
     {
       applicationSlug: application.slug,
       applicationVersion: application.applicationVersion,
       baseApplicationId: application.baseId,
     },
     application.pages.map((page) => ({
       pageSlug: page.slug,
       customSlug: page.customSlug,
       basePageId: page.baseId,
     })),
   );
-}, [
-  application.applicationVersion,
-  application.baseId,
-  application.defaultPageId,
-  application.pages,
-  application.slug,
-]);
+}, [application, defaultPage]);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4c2484e and daf90eb.

📒 Files selected for processing (2)
  • app/client/src/pages/Applications/ApplicationCard.tsx (12 hunks)
  • app/client/src/pages/Editor/AppsmithLink.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • 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-unit-tests / client-unit-tests
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-build / client-build
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
🔇 Additional comments (5)
app/client/src/pages/Applications/ApplicationCard.tsx (3)

79-90: LGTM: Icon styling follows design system guidelines

The styling implementation correctly uses CSS variables for theming and maintains consistency with the design system.


Line range hint 104-128: LGTM: Improved prop access pattern

Direct access to the application prop with proper type safety through optional chaining improves code readability and reliability.


488-516: LGTM: Improved navigation handling prevents app remounting

The implementation now correctly:

  1. Prevents app remounting by using React Router for navigation
  2. Maintains new tab functionality through ctrl/cmd + click
  3. Sets URL params before navigation

Let's verify that all application card click handlers are consistently implemented:

✅ Verification successful

✅ Click handlers are consistently implemented

Both Edit and Launch buttons in ApplicationCard.tsx follow the same navigation pattern, with proper handling of ctrl/cmd + click and React Router navigation. No other click handlers require updates.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for click handlers in application card components
ast-grep --pattern 'onClick={$_}'

Length of output: 35


Script:

#!/bin/bash
# First, find all application card related files
echo "=== Finding Application Card files ==="
fd -e tsx -e ts -e js "Application.*Card"

echo -e "\n=== Searching for click handlers ==="
# Search for onClick handlers with context
rg -U "onClick={.*?}" -g "*Application*Card*" -A 2 -B 2

Length of output: 558


Script:

#!/bin/bash
# Search for onClick handlers in the application card files
echo "=== Searching ApplicationCard.tsx ==="
rg "onClick=" app/client/src/pages/Applications/ApplicationCard.tsx -A 5 -B 5

echo -e "\n=== Searching ApplicationCardList files ==="
rg "onClick=" app/client/src/ee/pages/Applications/ApplicationCardList.tsx app/client/src/ce/pages/Applications/ApplicationCardList.tsx -A 5 -B 5

Length of output: 951

app/client/src/pages/Editor/AppsmithLink.tsx (2)

1-1: LGTM! Good use of useCallback for performance optimization.

The implementation correctly memoizes the click handler and uses programmatic navigation.

Also applies to: 7-7, 27-29


Line range hint 33-38: Verify the navigation behavior change.

The switch from declarative routing (to prop) to programmatic navigation (onClick) aligns with the PR objective to prevent full app remounts. However, we should verify this doesn't break keyboard navigation or accessibility.

Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working ok-to-test Required label for CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants