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

Fixed "Back" button redirection #8277

Merged
merged 10 commits into from
Aug 19, 2024
Merged

Fixed "Back" button redirection #8277

merged 10 commits into from
Aug 19, 2024

Conversation

klakhov
Copy link
Contributor

@klakhov klakhov commented Aug 8, 2024

Motivation and context

Resolved #8257

The problem is in hashing system we use to save the opened tab. It clutters the history and we cant really go back using it. There are two ways to improve that. We eighter save the actual link to go back somewhere in our application or pass it as a state when moving to analytics page history.push(/analytics, { from: somewhere}). From my perspective the first way is more elegant

TODO:

  • Analytics page
  • Check Guide page

How has this been tested?

Checklist

  • I submit my changes into the develop branch
  • I have created a changelog fragment
  • [ ] I have updated the documentation accordingly
  • [ ] I have added tests to cover my changes
  • I have linked related issues (see GitHub docs)
  • I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

Summary by CodeRabbit

  • New Features

    • Enhanced navigation functionality with a configurable back link for the AnalyticsPage component.
    • Introduced a dynamic back navigation experience across analytics routes.
    • Improved the GoBackButton component to accept custom back links.
  • Bug Fixes

    • Fixed navigation flow issues by ensuring the previous pathname is accurately stored and used.
  • Documentation

    • Updated documentation to reflect changes in component props and improved navigation logic.

@klakhov klakhov requested a review from bsekachev as a code owner August 8, 2024 07:24
Copy link
Contributor

coderabbitai bot commented Aug 8, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The recent updates to the CVAT UI enhance navigation functionality, particularly for the AnalyticsPage component. Key changes include the introduction of a backLink prop for more flexible back navigation, improved state management to store previous paths, and updates to the useGoBack hook to allow custom back links. These enhancements aim to ensure users return to the correct previous page when using the "Back" button.

Changes

Files Change Summary
.../analytics-page.tsx Added Props interface with optional backLink for AnalyticsPage, enabling flexible navigation links.
.../common/go-back-button.tsx Introduced Props interface to accept backLink, enhancing its functionality for more flexible navigation.
.../cvat-app.tsx Modified CVATApplication to manage goBackLink for improved routing between analytics and project pages.
.../hooks.ts Updated useGoBack to accept an optional backLink, enhancing navigation capabilities based on context.

Assessment against linked issues

Objective Addressed Explanation
Return to the project page from analytics (8257)
Flexible navigation using backLink (8257)

🐇 In the code, I hopped with glee,
A backLink here, a backLink free!
No more lost paths, just joy in the flow,
Navigation's smooth, as we swiftly go!
With each little change, our journey's refined,
A rabbit's delight, in the code we find! 🌟


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

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

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 UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ff50b46 and 7eb3434.

Files selected for processing (4)
  • cvat-ui/src/components/analytics-page/analytics-page.tsx (2 hunks)
  • cvat-ui/src/components/common/go-back-button.tsx (1 hunks)
  • cvat-ui/src/components/cvat-app.tsx (4 hunks)
  • cvat-ui/src/utils/hooks.ts (1 hunks)
Additional comments not posted (11)
cvat-ui/src/components/common/go-back-button.tsx (2)

11-13: LGTM: Props interface is well-defined.

The Props interface correctly defines an optional backLink property, enhancing the flexibility of the GoBackButton component.


15-18: LGTM: GoBackButton function changes.

The GoBackButton function now accepts a backLink prop, enhancing navigation flexibility. The use of React.memo is appropriate for performance optimization.

Ensure that the GoBackButton is used correctly across the codebase with the new backLink prop.

cvat-ui/src/utils/hooks.ts (1)

65-70: LGTM: useGoBack function changes.

The useGoBack function now accepts a backLink parameter, enhancing navigation flexibility. The use of useCallback is appropriate for performance optimization.

Consider verifying the handling of invalid backLink values to ensure robust navigation.

cvat-ui/src/components/analytics-page/analytics-page.tsx (2)

82-84: LGTM: Props interface is well-defined.

The Props interface correctly defines an optional backLink property, enhancing the flexibility of the AnalyticsPage component.


86-87: LGTM: AnalyticsPage function changes.

The AnalyticsPage function now accepts a backLink prop, enhancing navigation flexibility. The use of React.memo is appropriate for performance optimization.

Ensure that the AnalyticsPage is used correctly across the codebase with the new backLink prop.

Verification successful

Verified: Correct usage of AnalyticsPage with backLink prop

The AnalyticsPage component is used correctly with the backLink prop in cvat-ui/src/components/cvat-app.tsx, ensuring navigation flexibility is implemented as intended.

  • Location: cvat-ui/src/components/cvat-app.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `AnalyticsPage` with the new `backLink` prop.

# Test: Search for the usage of `AnalyticsPage`. Expect: Usage with the `backLink` prop.
rg --type tsx -A 5 $'<AnalyticsPage'

Length of output: 65


Script:

#!/bin/bash
# Description: Verify the usage of `AnalyticsPage` with the new `backLink` prop.

# Test: Search for the usage of `AnalyticsPage`. Expect: Usage with the `backLink` prop.
rg -A 5 '<AnalyticsPage'

Length of output: 2170

cvat-ui/src/components/cvat-app.tsx (6)

131-131: Addition of goBackLink is appropriate.

The introduction of goBackLink in the CVATAppState interface is a suitable enhancement for managing navigation state.


139-140: Initialization of goBackLink is appropriate.

The constructor correctly initializes goBackLink to undefined, which is consistent with its intended use.


521-524: Render logic for AnalyticsPage is appropriate.

Passing goBackLink as a prop to AnalyticsPage ensures dynamic back navigation, aligning with the PR objectives.


531-535: Render logic for task analytics is appropriate.

The update to pass goBackLink as a prop ensures consistent navigation behavior across analytics pages.


542-546: Render logic for job analytics is appropriate.

Passing goBackLink as a prop ensures consistent navigation behavior across all analytics pages.


178-182: Logic for setting goBackLink is appropriate.

The history.listen update correctly captures the previous pathname for analytics page navigation, enhancing the back navigation feature.

Ensure that the condition logic accurately reflects the intended navigation paths.

Verification successful

Let's refine our approach to verify the condition logic for setting goBackLink by correctly identifying JavaScript files and searching for analytics routes.


Let's broaden our search to ensure we capture any analytics-related routes or components by looking for more general routing patterns and keywords.


Logic for setting goBackLink is consistent with analytics route handling.

The search results confirm that analytics routes are managed within the application, as indicated by the regex pattern in webpack.config.js. This supports the logic implemented in cvat-app.tsx for setting the goBackLink when navigating to an analytics page.

  • Relevant file: cvat-ui/webpack.config.js contains a regex pattern that includes analytics.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the condition logic for setting `goBackLink`.

# Test: Search for analytics page routes and ensure the logic is consistent.
rg --type javascript 'path=.*analytics'

Length of output: 76


Script:

#!/bin/bash
# Find all JavaScript files and search for analytics routes
fd -e js -e jsx | xargs rg 'path=.*analytics'

Length of output: 47


Script:

#!/bin/bash
# Search for any route definitions or analytics-related keywords in JavaScript files
fd -e js -e jsx | xargs rg -i 'route|analytics'

Length of output: 2831

@klakhov klakhov changed the title [WIP] Fixed "Back" button redirection Fixed "Back" button redirection Aug 13, 2024
@klakhov klakhov requested a review from nmanovic as a code owner August 13, 2024 08:53
@klakhov klakhov removed the request for review from nmanovic August 13, 2024 08:56
@klakhov klakhov added the ui/ux label Aug 13, 2024
@codecov-commenter
Copy link

codecov-commenter commented Aug 13, 2024

Codecov Report

Attention: Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.

Project coverage is 83.34%. Comparing base (3f9083b) to head (66c6721).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8277      +/-   ##
===========================================
- Coverage    83.35%   83.34%   -0.01%     
===========================================
  Files          391      393       +2     
  Lines        41556    41582      +26     
  Branches      3839     3844       +5     
===========================================
+ Hits         34639    34658      +19     
- Misses        6917     6924       +7     
Components Coverage Δ
cvat-ui 79.58% <94.73%> (-0.01%) ⬇️
cvat-server 86.68% <ø> (-0.01%) ⬇️

Copy link

sonarcloud bot commented Aug 16, 2024

@klakhov
Copy link
Contributor Author

klakhov commented Aug 16, 2024

@bsekachev
Implemented solution with location in state, as we discussed

@klakhov klakhov merged commit afbb143 into develop Aug 19, 2024
33 checks passed
@klakhov klakhov deleted the kl/fix-go-back branch August 20, 2024 07:22
@cvat-bot cvat-bot bot mentioned this pull request Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong redirection from analytics page
3 participants