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: fixed back button to redirect to applications page #35900

Merged

Conversation

saicharan-zemoso
Copy link
Contributor

@saicharan-zemoso saicharan-zemoso commented Aug 27, 2024

added the changes to redirect to application pages instead of going back in the history.

issue: #34431

fixed the navigation to not go back in history
The navigation of the back button used to go back in history. Now it will be redirected to the expected page.

added the test for profile page:
image

added the tests for settings page:
image

video:

back.button.fix.mp4

Automation

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

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/10659602683
Commit: 23f2285
Cypress dashboard.
Tags: @tag.All
Spec:


Mon, 02 Sep 2024 04:52:56 UTC

Summary by CodeRabbit

  • New Features

    • Enhanced navigation for the BackButton in both UserProfile and Settings components, directing users to the applications page and specific workspace pages, respectively.
  • Bug Fixes

    • Improved test coverage for BackButton interactions in both UserProfile and Settings components, ensuring correct navigation behavior is verified.
  • Tests

    • Expanded test suite for UserProfile and Settings components, incorporating better routing and interaction simulations.

Copy link
Contributor

coderabbitai bot commented Aug 27, 2024

Walkthrough

The changes enhance the UserProfile and Settings components by modifying the BackButton to include a goTo prop for improved navigation. Additionally, the testing suites have been updated to include new test cases that validate the navigation functionality and enhance mock setups for routing, ensuring a more comprehensive simulation of user interactions.

Changes

Files Change Summary
app/client/src/pages/UserProfile/index.test.tsx Expanded imports for testing, updated mock setup for react-router-dom with useHistory, and added a test case for the "Back" button navigation functionality.
app/client/src/pages/UserProfile/index.tsx Modified the BackButton to include a goTo prop set to "/applications" for improved navigation.
app/client/src/pages/workspace/__tests__/settings.test.tsx Wrapped component in BrowserRouter, added navigation mock function, and included a test case for the "Back" button behavior.
app/client/src/pages/workspace/settings.tsx Updated BackButton to include a goTo prop that constructs a URL using workspaceId for dynamic navigation.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UserProfile
    participant Settings
    participant Router

    User->>UserProfile: Click "Back"
    UserProfile->>Router: Call history.push("/applications")
    Router-->>UserProfile: Navigate to applications page
    User->>Settings: Click "Back"
    Settings->>Router: Call history.push("/workspace")
    Router-->>Settings: Navigate to workspace page
Loading

Poem

In a world of clicks and paths so bright,
The BackButton leads with guiding light.
From profiles to workspaces, it deftly flows,
Navigating journeys, where the user goes.
With tests that ensure each click's delight,
Our code dances smoothly, day and night! 🌟


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.
Early access features: disabled

We are currently testing the following features in early access:

  • Anthropic claude-3-5-sonnet for code reviews: Anthropic claims that the new Claude model has stronger code understanding and code generation capabilities than their previous models. Note: Our default code review model was also updated late last week. Please compare the quality of the reviews between the two models by toggling the early access feature.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues on the discussion post.

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

Commits

Files that changed from the base of the PR and between cfab57f and 2a1877a.

Files selected for processing (4)
  • app/client/src/pages/UserProfile/index.test.tsx (3 hunks)
  • app/client/src/pages/UserProfile/index.tsx (1 hunks)
  • app/client/src/pages/workspace/tests/settings.test.tsx (3 hunks)
  • app/client/src/pages/workspace/settings.tsx (1 hunks)
Additional comments not posted (11)
app/client/src/pages/UserProfile/index.tsx (1)

59-59: Good job!

The goTo prop is correctly added to the BackButton to redirect users to the /applications page. This change aligns with the PR objective to improve navigation.

The code changes are approved.

app/client/src/pages/UserProfile/index.test.tsx (3)

3-3: Nice addition!

The screen and fireEvent imports from @testing-library/react are correctly added to facilitate the new test case.

The code changes are approved.


95-102: Well done!

The mocked useHistory hook is correctly implemented to simulate navigation actions within the tests.

The code changes are approved.


145-159: Excellent test case!

The new test case is correctly implemented to verify that clicking the "Back" button triggers a call to history.push with the expected path (/applications). This enhances the test coverage.

The code changes are approved.

app/client/src/pages/workspace/settings.tsx (1)

130-130: Great enhancement!

The goTo prop is correctly added to the BackButton to dynamically construct a URL using the workspaceId. This change enhances the navigation functionality by providing a direct link that is contextually relevant to the user's current settings.

The code changes are approved.

app/client/src/pages/workspace/__tests__/settings.test.tsx (6)

4-4: Good job importing BrowserRouter!

This ensures that the routing functionality is properly tested.

This change is approved.


6-10: Great addition of fireEvent!

This enables interaction simulation within the tests, which is crucial for testing user interactions.

This change is approved.


13-14: Nice use of redux-mock-store!

This helps in creating a mock store for testing purposes.

This change is approved.


162-163: Good introduction of mockHistoryPush!

This mock function is essential for simulating navigation in your tests.

This change is approved.


164-165: Well done configuring the mock store!

This is necessary for providing a mock Redux store to the component during tests.

This change is approved.


169-171: Excellent job mocking useHistory!

This ensures that the push function is correctly tested.

This change is approved.

Comment on lines +209 to +222
it("should redirect to workspace page if user wants to go back", () => {
testRender(
<BrowserRouter>
<Provider store={mockStore(mockWorkspaceData)}>
<Settings />
</Provider>
</BrowserRouter>,
);
const backBtn = testScreen.getByText("Back");
fireEvent.click(backBtn);
expect(mockHistoryPush).toHaveBeenCalledWith(
`/applications?workspaceId=${mockWorkspaceData.id}`,
);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Great addition of the back button test case!

This test case ensures that the back button redirects to the correct page, improving the robustness of your tests. However, consider adding a comment to explain the purpose of this test case for future maintainers.

Add a comment to explain the purpose of this test case:

  it("should redirect to workspace page if user wants to go back", () => {
+   // This test case ensures that clicking the back button redirects to the workspace page.
    testRender(
      <BrowserRouter>
        <Provider store={mockStore(mockWorkspaceData)}>
          <Settings />
        </Provider>
      </BrowserRouter>,
    );
    const backBtn = testScreen.getByText("Back");
    fireEvent.click(backBtn);
    expect(mockHistoryPush).toHaveBeenCalledWith(
      `/applications?workspaceId=${mockWorkspaceData.id}`,
    );
  });
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it("should redirect to workspace page if user wants to go back", () => {
testRender(
<BrowserRouter>
<Provider store={mockStore(mockWorkspaceData)}>
<Settings />
</Provider>
</BrowserRouter>,
);
const backBtn = testScreen.getByText("Back");
fireEvent.click(backBtn);
expect(mockHistoryPush).toHaveBeenCalledWith(
`/applications?workspaceId=${mockWorkspaceData.id}`,
);
});
it("should redirect to workspace page if user wants to go back", () => {
// This test case ensures that clicking the back button redirects to the workspace page.
testRender(
<BrowserRouter>
<Provider store={mockStore(mockWorkspaceData)}>
<Settings />
</Provider>
</BrowserRouter>,
);
const backBtn = testScreen.getByText("Back");
fireEvent.click(backBtn);
expect(mockHistoryPush).toHaveBeenCalledWith(
`/applications?workspaceId=${mockWorkspaceData.id}`,
);
});

@ankitakinger
Copy link
Contributor

/build-deploy-preview skip-tests=true

Copy link

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

@ankitakinger
Copy link
Contributor

@saicharan-zemoso Could you please check and fix the checks that are failing? You will be able to see the errors when you click "Details" for the specific check.

Copy link

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

@saicharan-zemoso
Copy link
Contributor Author

Ok I will check why they are failing

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2a1877a and 1e2a4de.

Files selected for processing (1)
  • app/client/src/pages/UserProfile/index.test.tsx (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/src/pages/UserProfile/index.test.tsx

@ankitakinger
Copy link
Contributor

@saicharan-zemoso There are still some failures in prettier and lint checks.

@saicharan-zemoso
Copy link
Contributor Author

Hello @ankitakinger ,
it is suggisting to insert "." but we cannot add it there
image
for the code:
image

and is it ok to add a line to make prettier ignore this Or is there any other way to solve this as we cannot add a "." in that line.

@ankitakinger
Copy link
Contributor

ankitakinger commented Aug 30, 2024

@saicharan-zemoso It's actually not a dot but a single space. If you are using VSCode as your editor, you can install "ESLint" and "Prettier - Code formatter" extensions and that will take care of fixing these errors.
image
image

If you're using any other editor, I'm sure there would be a way to get this done automatically on save, you'll just have to search for the same.

The space there needs to be added before />

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1e2a4de and 0b59ba7.

Files selected for processing (2)
  • app/client/src/pages/UserProfile/index.tsx (1 hunks)
  • app/client/src/pages/workspace/settings.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • app/client/src/pages/UserProfile/index.tsx
  • app/client/src/pages/workspace/settings.tsx

@ankitakinger ankitakinger added the ok-to-test Required label for CI label Sep 2, 2024
Copy link
Contributor

@ankitakinger ankitakinger left a comment

Choose a reason for hiding this comment

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

LGTM

@abhvsn abhvsn merged commit 420dc9b into appsmithorg:release Sep 4, 2024
24 of 26 checks passed
ankitakinger added a commit that referenced this pull request Sep 9, 2024
ankitakinger added a commit that referenced this pull request Sep 9, 2024
…e" (#36191)

Reverts #35900

## Automation

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

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10778653732>
> Commit: b0516d0
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10778653732&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`
> Spec:
> <hr>Mon, 09 Sep 2024 18:26:51 UTC
<!-- end of auto-generated comment: Cypress test results  -->



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Simplified navigation with the `BackButton` component, now relying on
default behavior instead of a specified route in the `UserProfile` and
`Settings` components.
  
- **Bug Fixes**
- Refined testing strategy by removing outdated navigation-related tests
and imports for the `UserProfile` and `Settings` components,
streamlining the test suite.

- **Documentation**
- Updated comments and documentation to reflect changes in navigation
behavior and testing focus.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants