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 disabling the requests, improved notification links #8197

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

klakhov
Copy link
Contributor

@klakhov klakhov commented Jul 18, 2024

Motivation and context

The pr adresses two problems:

  1. If we download something from requests page, the card will be disabled. But if we go to another page after it, it will be enabled again. The pr adds storing of disabled requests to global store
  2. Improved links that are shown by requests notifications. We render them as buttons that operate with react router instead of plain <a> tags, using which reloads the page.

How has this been tested?

Manual

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

    • Introduced a new action to disable requests, expanding request management functionality.
    • Added a new CVATMarkdown component for improved rendering of markdown content in error notifications.
  • Enhancements

    • Replaced ReactMarkdown with CVATMarkdown across various components for consistent error message formatting.
    • Added a disabled prop to RequestCard component to manage interactive states.
  • Bug Fixes

    • Improved notification message formatting by adding punctuation to the end of sentences.
  • Styles

    • Added a new CSS class for better styling of notification links.

Copy link
Contributor

coderabbitai bot commented Jul 18, 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

This series of changes enhances the CVAT application's handling of requests by introducing a new action for disabling requests and updating various components to use a custom markdown renderer. The updates improve error message formatting and state management, incorporating new props for better functionality. Overall, these modifications aim to streamline request management and enhance user notifications within the application.

Changes

Files Change Summary
cvat-ui/src/actions/requests-actions.ts Added DISABLE_REQUEST action type and disableRequest method for request management.
cvat-ui/src/components/annotation-page/standard-workspace/... Replaced ReactMarkdown with CVATMarkdown for consistent error message rendering.
cvat-ui/src/components/common/cvat-markdown.tsx Introduced CVATMarkdown component for custom markdown rendering with link handling.
cvat-ui/src/components/cvat-app.tsx Replaced ReactMarkdown with CVATMarkdown for notifications and error messages.
cvat-ui/src/components/export-backup/export-backup-modal.tsx Updated to use CVATMarkdown with history prop for navigation in notifications.
cvat-ui/src/components/export-dataset/export-dataset-modal.tsx Added history prop to CVATMarkdown for enhanced navigation capabilities.
cvat-ui/src/components/import-dataset/import-dataset-modal.tsx Replaced ReactMarkdown with CVATMarkdown and initialized history for routing.
cvat-ui/src/components/requests-page/request-card.tsx Added disabled prop to RequestCard component for controlling interactivity.
cvat-ui/src/reducers/index.ts Updated RequestsState to rename urls to disabled.
cvat-ui/src/reducers/requests-reducer.ts Modified defaultState to include disabled array and handle new action type.
cvat-ui/src/styles.scss Introduced new CSS class .cvat-notification-link for styling links in notifications.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant RequestsActions
    participant RequestsReducer

    User->>App: Trigger request disable
    App->>RequestsActions: Dispatch DISABLE_REQUEST
    RequestsActions-->>RequestsReducer: Update state to disable request
    RequestsReducer-->>App: New state with disabled request
    App-->>User: Show updated request status
Loading

🐰 In a meadow lush and wide,
I hop and dance, my changes glide.
Requests now disabled with a cheer,
With markdown links that bring us near.
So celebrate, both big and small,
For CVAT shines, we'll have a ball! 🎉


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.

@klakhov klakhov marked this pull request as ready for review July 19, 2024 07:47
@klakhov klakhov requested a review from bsekachev as a code owner July 19, 2024 07:47
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

Outside diff range, codebase verification and nitpick comments (1)
cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/tools-control.tsx (1)

790-790: Integration of CVATMarkdown is missing in opencv-control.tsx.

The checkTrackedStates function in tools-control.tsx is correctly updated to use CVATMarkdown. However, the opencv-control.tsx file does not integrate CVATMarkdown at all. Please ensure that CVATMarkdown is used consistently for error handling in both files.

  • opencv-control.tsx needs to be updated to use CVATMarkdown similarly to tools-control.tsx.
Analysis chain

LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all instances of checkTrackedStates are updated to handle the new CVATMarkdown component correctly.


Let's correct the file type and re-run the search to verify the usage of checkTrackedStates.


To ensure that CVATMarkdown is correctly integrated with checkTrackedStates, let's search for CVATMarkdown usage within the opencv-control.tsx and tools-control.tsx files.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all instances of `checkTrackedStates` in the codebase.

# Test: Search for the function usage. Expect: Instances of `checkTrackedStates` to be updated.
rg --type python -A 5 $'checkTrackedStates'

Length of output: 73


Script:

#!/bin/bash
# Description: Verify all instances of `checkTrackedStates` in the codebase.

# Test: Search for the function usage. Expect: Instances of `checkTrackedStates` to be updated.
rg --type ts -A 5 'checkTrackedStates'

Length of output: 3049


Script:

#!/bin/bash
# Description: Verify the usage of `CVATMarkdown` in the relevant files.

# Test: Search for `CVATMarkdown` usage in the specified files.
rg 'CVATMarkdown' cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/opencv-control.tsx cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/tools-control.tsx

Length of output: 1414

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 511a2d9 and 9a054c1.

Files selected for processing (13)
  • cvat-ui/src/actions/requests-actions.ts (2 hunks)
  • cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/tools-control.tsx (7 hunks)
  • cvat-ui/src/components/common/cvat-markdown.tsx (1 hunks)
  • cvat-ui/src/components/cvat-app.tsx (6 hunks)
  • cvat-ui/src/components/export-backup/export-backup-modal.tsx (4 hunks)
  • cvat-ui/src/components/export-dataset/export-dataset-modal.tsx (4 hunks)
  • cvat-ui/src/components/import-dataset/import-dataset-modal.tsx (4 hunks)
  • cvat-ui/src/components/requests-page/request-card.tsx (6 hunks)
  • cvat-ui/src/components/requests-page/requests-list.tsx (1 hunks)
  • cvat-ui/src/reducers/index.ts (1 hunks)
  • cvat-ui/src/reducers/notifications-reducer.ts (2 hunks)
  • cvat-ui/src/reducers/requests-reducer.ts (2 hunks)
  • cvat-ui/src/styles.scss (1 hunks)
Files skipped from review due to trivial changes (2)
  • cvat-ui/src/reducers/notifications-reducer.ts
  • cvat-ui/src/styles.scss
Additional comments not posted (28)
cvat-ui/src/components/common/cvat-markdown.tsx (4)

1-4: LGTM! Import statements are appropriate.

The import statements include necessary libraries and components.


6-6: LGTM! Type definition is clear and correct.

The type alias UseHistoryType is defined correctly.


8-27: LGTM! Higher-order component implementation is clear and correct.

The HOC RouterLinkHOC correctly handles internal and external links.


29-41: LGTM! Function implementation is clear and correct.

The function CVATMarkdown correctly integrates custom link handling with ReactMarkdown.

cvat-ui/src/reducers/requests-reducer.ts (2)

14-14: LGTM! State changes are clear and correct.

The addition of the disabled array in defaultState aligns with the new functionality.


36-42: LGTM! Reducer changes are clear and correct.

The new case for DISABLE_REQUEST correctly updates the disabled array in the state.

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

36-36: LGTM! State usage changes are clear and correct.

The disabled state property is correctly retrieved from the Redux store.


39-44: LGTM! Request rendering changes are clear and correct.

The RequestCard component correctly receives a disabled prop based on the disabled state property.

cvat-ui/src/actions/requests-actions.ts (2)

24-24: LGTM! New action type DISABLE_REQUEST added to RequestsActionsTypes.

The addition follows the existing pattern and enhances the set of actions for request management.


48-50: LGTM! New action creator disableRequest added to requestsActions.

The addition follows the existing pattern and correctly uses the createAction function.

cvat-ui/src/components/export-backup/export-backup-modal.tsx (2)

Line range hint 8-18:
LGTM! Import statements updated to use CVATMarkdown and useHistory hook.

The changes follow the existing pattern and enhance the component's functionality.


105-109: LGTM! Notification logic updated to use CVATMarkdown with history prop.

The changes follow the existing pattern and enhance the component's functionality.

cvat-ui/src/components/export-dataset/export-dataset-modal.tsx (2)

Line range hint 9-20:
LGTM! Import statements updated to use CVATMarkdown and useHistory hook.

The changes follow the existing pattern and enhance the component's functionality.


126-126: LGTM! Notification logic updated to use CVATMarkdown with history prop.

The changes follow the existing pattern and enhance the component's functionality.

cvat-ui/src/components/requests-page/request-card.tsx (6)

23-23: LGTM!

The import statement for requestsActions is appropriate and necessary for the new functionality.


28-28: LGTM!

The addition of the disabled prop to the Props interface is appropriate and aligns with the new functionality.


141-141: LGTM!

Destructuring the disabled prop from props is necessary and correctly implemented.


156-158: LGTM!

Adjusting the style object based on the disabled state is a good approach to visually indicate the disabled state.


170-170: LGTM!

Dispatching the requestsActions.disableRequest(request) action after downloading is appropriate and necessary.


182-182: LGTM!

Dispatching the requestsActions.disableRequest(request) action after canceling is appropriate and necessary.

cvat-ui/src/reducers/index.ts (1)

956-956: LGTM!

Renaming the urls property to disabled in the RequestsState interface is appropriate and aligns with the new functionality.

cvat-ui/src/components/import-dataset/import-dataset-modal.tsx (3)

9-9: LGTM!

The import statements for useHistory and CVATMarkdown are appropriate and necessary for the new functionality.

Also applies to: 22-22


282-282: LGTM!

Using the useHistory hook to get the history object is appropriate and necessary for navigation purposes.


471-471: LGTM!

Using the CVATMarkdown component to render the notification description is appropriate and likely provides additional functionality or styling specific to the CVAT application.

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

361-369: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all instances of showMessages are updated to handle the new CVATMarkdown component correctly.

Verification successful

Let's correct the file type and function name, and re-run the script to verify the usage of showMessage in the codebase.


Let's update the script to search within both ts and tsx files to verify the usage of showMessage in the codebase.


The showMessage function is correctly used in the codebase.

The function showMessage is defined and utilized appropriately within cvat-ui/src/components/cvat-app.tsx. Other instances found in the codebase are related to a different function (showMessageWithPause) and do not impact the showMessage function.

  • cvat-ui/src/components/cvat-app.tsx
  • cvat-core/src/annotations-actions.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all instances of `showMessages` in the codebase.

# Test: Search for the function usage. Expect: Instances of `showMessages` to be updated.
rg --type python -A 5 $'showMessages'

Length of output: 67


Script:

#!/bin/bash
# Description: Verify all instances of `showMessage` in the codebase.

# Test: Search for the function usage. Expect: Instances of `showMessage` to be updated.
rg --type tsx -A 5 'showMessage'

Length of output: 60


Script:

#!/bin/bash
# Description: Verify all instances of `showMessage` in the codebase.

# Test: Search for the function usage. Expect: Instances of `showMessage` to be updated.
rg --type-add 'ts:*.{ts,tsx}' -A 5 'showMessage'

Length of output: 2836


Line range hint 392-408:
LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all instances of showErrors are updated to handle the new CVATMarkdown component correctly.

Verification successful

LGTM! All instances of showErrors have been updated to handle the new CVATMarkdown component correctly.

  • cvat-ui/src/components/cvat-app.tsx: The showErrors function is defined and used within this file, and it correctly utilizes the CVATMarkdown component.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all instances of `showErrors` in the codebase.

# Test: Search for the function usage. Expect: Instances of `showErrors` to be updated.
rg --type python -A 5 $'showErrors'

Length of output: 65


Script:

#!/bin/bash
# Description: Verify all instances of `showErrors` in the codebase.

# Test: Search for the function usage. Expect: Instances of `showErrors` to be updated.
rg --type ts,tsx -A 5 $'showErrors'

Length of output: 65


Script:

#!/bin/bash
# Description: Verify all instances of `showErrors` in the codebase.

# Test: Search for the function usage. Expect: Instances of `showErrors` to be updated.
rg --type typescript,tsx -A 5 $'showErrors'

Length of output: 81


Script:

#!/bin/bash
# Description: Verify all instances of `showErrors` in the codebase.

# Test: Search for the function usage. Expect: Instances of `showErrors` to be updated.
rg --type ts,tsx -A 5 'showErrors'

Length of output: 65


Script:

#!/bin/bash
# Description: Verify all instances of `showErrors` in the codebase.

# Test: Search for the function usage. Expect: Instances of `showErrors` to be updated.
rg --type-add 'typescript:*.ts' --type-add 'tsx:*.tsx' -t typescript -t tsx -A 5 'showErrors'

Length of output: 1049

cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/tools-control.tsx (2)

443-443: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all instances of runInteractionRequest are updated to handle the new CVATMarkdown component correctly.

Verification successful

Verification successful.

All instances of runInteractionRequest are correctly updated to handle the new CVATMarkdown component within the same file.

  • cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/tools-control.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all instances of `runInteractionRequest` in the codebase.

# Test: Search for the function usage. Expect: Instances of `runInteractionRequest` to be updated.
rg --type python -A 5 $'runInteractionRequest'

Length of output: 76


Script:

#!/bin/bash
# Description: Verify all instances of `runInteractionRequest` in the codebase.

# Test: Search for the function usage. Expect: Instances of `runInteractionRequest` to be updated.
rg --type tsx -A 5 $'runInteractionRequest'

Length of output: 70


Script:

#!/bin/bash
# Description: Verify all instances of `runInteractionRequest` in the codebase.

# Test: Search for the function usage. Expect: Instances of `runInteractionRequest` to be updated.
rg 'runInteractionRequest' --glob '*.tsx' -A 5

Length of output: 2612


536-536: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all instances of onTracking are updated to handle the new CVATMarkdown component correctly.

@codecov-commenter
Copy link

codecov-commenter commented Jul 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.38%. Comparing base (715d41b) to head (4f250d1).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8197   +/-   ##
========================================
  Coverage    83.37%   83.38%           
========================================
  Files          388      388           
  Lines        41315    41319    +4     
  Branches      3855     3856    +1     
========================================
+ Hits         34447    34452    +5     
+ Misses        6868     6867    -1     
Components Coverage Δ
cvat-ui 79.67% <100.00%> (+<0.01%) ⬆️
cvat-server 86.70% <ø> (+<0.01%) ⬆️

@klakhov klakhov requested a review from nmanovic as a code owner July 19, 2024 10:30
Copy link

sonarcloud bot commented Jul 24, 2024

@@ -0,0 +1,41 @@
import Button from 'antd/lib/button';
Copy link
Member

Choose a reason for hiding this comment

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

License header?


const RouterLinkHOC = (history?: UseHistoryType) => (
function (props: { children: React.ReactNode, href?: string }): JSX.Element {
const { href, children } = props;
Copy link
Member

Choose a reason for hiding this comment

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

Why not put useHistory here?
In this case, in external components we do not need to have history.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that would be better. But we cant use useHistoty(its undefined). The notifications rendered by antd notification module are outside of our Router. It seems thats because its created using React.render docs

Copy link
Member

Choose a reason for hiding this comment

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

okay, I see

@@ -33,10 +33,17 @@ function RequestsList(props: Props): JSX.Element {
const dispatch = useDispatch();
const { query, count } = props;
const { page } = query;
const { requests } = useSelector((state: CombinedState) => state.requests);
const { requests, disabled } = useSelector((state: CombinedState) => state.requests);
Copy link
Member

Choose a reason for hiding this comment

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

useSelector((state: CombinedState) => { requests: state.requests, disabled: state.disabled }, shallowEqual);

would be more optimized as state.requests may change more often than state.requests.requests and state.requests.disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants