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

Refactored updating a job instance on client side #8033

Merged
merged 26 commits into from
Jun 24, 2024

Conversation

bsekachev
Copy link
Member

@bsekachev bsekachev commented Jun 14, 2024

Motivation and context

Resolved #7241

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

    • Added new functionality to support detailed job state updates and transitions.
    • Introduced a new component, RemoveConfirmComponent, in the Single Shape Workspace.
    • Enhanced the Single Shape Workspace UI to support skipping or submitting results based on the next frame status.
  • Bug Fixes

    • Updated various dispatch functions to improve async action handling and error management.
    • Corrected the condition for workspace inclusion in the CanvasWrapperComponent.
  • Documentation

    • Added user guidance to the Single Shape annotation mode documentation.
  • Tests

    • Added new Cypress test cases for single object annotation mode, including drawing with disabled "autoNext," object activation, and object removal shortcuts.
  • Style

    • Renamed CSS class .cvat-single-shape-annotation-sidebar-skip-wrapper to .cvat-single-shape-annotation-sidebar-finish-frame-wrapper.

Copy link
Contributor

coderabbitai bot commented Jun 14, 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 changes enhance the handling of job states, transitions specific actions to utilize ThunkDispatch, and introduce new UI features. Key improvements include better type usage in asynchronous actions, updated UI handling for single shape annotation, and fixes for handling job state transitions. The changes aim to streamline the annotation process and ensure smoother interaction across the CVAT UI.

Changes

File(s) Summary
cvat-ui/src/actions/annotation-actions.ts Updated annotation actions to use ThunkDispatch and added job state transition handling.
cvat-ui/src/actions/cloud-storage-actions.ts Modified type declarations for dispatch functions to use ThunkDispatch.
cvat-ui/src/actions/projects-actions.ts Updated function signatures to use ThunkDispatch.
cvat-ui/src/actions/tasks-actions.ts Streamlined type definitions for asynchronous actions using ThunkDispatch.
cvat-ui/src/actions/webhooks-actions.ts Adjusted getWebhooksAsync to use ThunkDispatch.
cvat-ui/src/components/annotation-page/canvas/.../canvas-wrapper.tsx Included Workspace.SINGLE_SHAPE in workspace condition.
cvat-ui/src/components/annotation-page/.../single-shape-sidebar.tsx Added new actions like nextFrame and updated UI elements for frame handling.
cvat-ui/src/components/annotation-page/.../single-shape-workspace.tsx Integrated RemoveConfirmComponent for removing shapes.
cvat-ui/src/components/annotation-page/.../styles.scss Renamed .cvat-single-shape-annotation-sidebar-skip-wrapper to .cvat-single-shape-annotation-sidebar-finish-frame-wrapper.
cvat-ui/src/components/annotation-page/.../remove-confirm.tsx Enhanced useSelector hook and updated removeObjectAsync function.
cvat-ui/src/components/annotation-page/top-bar/annotation-menu.tsx Refactored to dispatch actions using useDispatch.
cvat-ui/src/components/annotation-page/top-bar/left-group.tsx Replaced AnnotationMenuContainer with AnnotationMenuComponent.
cvat-ui/src/containers/.../canvas-context-menu.tsx Changed readonly property in OwnProps interface to an optional boolean.
cvat-ui/src/reducers/index.ts Added jobUpdating property to NotificationsState interface.
cvat-ui/src/reducers/notifications-reducer.ts Included jobUpdating handling for UPDATE_CURRENT_JOB_FAILED action.
site/content/en/docs/manual/advanced/single-shape.md Updated hints for Single Shape annotation mode.
tests/cypress/e2e/features/single_object_annotation.js Added new test cases, removed submitJob() function, and updated handling for PATCH requests.

Sequence Diagram(s)

No diagrams needed as changes revolve around type updates and UI adjustments, which are too specific and varied.

Assessment against linked issues

Objective Addressed Explanation
Workers should be able to update job status (#7241)

Poem

In code so sleek, the changes flow,
Dispatch with Thunk, actions in tow.
Transition jobs with ease anew,
Single shapes in frames pursue.
A worker's task made clearer now,
A bunny's hop, take a bow! 🐰🎉


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 Configration 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: 6

Outside diff range and nitpick comments (4)
tests/cypress/e2e/features/single_object_annotation.js (2)

7-12: Document the new test cases.

It's great that you've outlined the new test cases to be added. To maintain clarity and assist future developers, consider documenting these cases in the test plan or relevant documentation, if not already done.


Line range hint 211-229: Refactor to reduce duplication and enhance readability.

The code for handling the checkbox state and frame navigation appears to be repetitive and could be abstracted into helper functions or components. This would enhance readability and maintainability.

- cy.get('.cvat-player-next-button-empty').click();
- cy.get('.cvat-single-shape-annotation-sidebar-auto-save-checkbox').within(() => {
-     cy.get('[type="checkbox"]').uncheck();
- });
- clickPoints(polygonShape);
+ navigateAndUncheckAutoSave();
cvat-ui/src/components/annotation-page/top-bar/annotation-menu.tsx (1)

Line range hint 7-33: Ensure consistency in import order and grouping.

Consider organizing imports to group by library, external dependencies, and internal components. This enhances readability and maintainability.

cvat-ui/src/components/annotation-page/single-shape-workspace/single-shape-sidebar/single-shape-sidebar.tsx (1)

Line range hint 514-531: The onChange handlers for the label and label type selectors are crucial for maintaining the state consistency. It's good to see that these are being handled through actions, which should help in debugging state changes. Consider adding more robust error handling for the case when the new label or label type is not valid.

+ if (!isValidLabel(label)) {
+     console.error('Invalid label selected');
+     return;
+ }
+ if (!isValidLabelType(labelType)) {
+     console.error('Invalid label type selected');
+     return;
+ }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8d4c42e and d238ec3.

Files selected for processing (17)
  • cvat-ui/src/actions/annotation-actions.ts (31 hunks)
  • cvat-ui/src/actions/cloud-storage-actions.ts (8 hunks)
  • cvat-ui/src/actions/projects-actions.ts (5 hunks)
  • cvat-ui/src/actions/tasks-actions.ts (5 hunks)
  • cvat-ui/src/actions/webhooks-actions.ts (2 hunks)
  • cvat-ui/src/components/annotation-page/canvas/views/canvas2d/canvas-wrapper.tsx (1 hunks)
  • cvat-ui/src/components/annotation-page/single-shape-workspace/single-shape-sidebar/single-shape-sidebar.tsx (13 hunks)
  • cvat-ui/src/components/annotation-page/single-shape-workspace/single-shape-workspace.tsx (1 hunks)
  • cvat-ui/src/components/annotation-page/single-shape-workspace/styles.scss (1 hunks)
  • cvat-ui/src/components/annotation-page/standard-workspace/remove-confirm.tsx (3 hunks)
  • cvat-ui/src/components/annotation-page/top-bar/annotation-menu.tsx (8 hunks)
  • cvat-ui/src/components/annotation-page/top-bar/left-group.tsx (2 hunks)
  • cvat-ui/src/containers/annotation-page/canvas/canvas-context-menu.tsx (1 hunks)
  • cvat-ui/src/reducers/index.ts (1 hunks)
  • cvat-ui/src/reducers/notifications-reducer.ts (2 hunks)
  • site/content/en/docs/manual/advanced/single-shape.md (1 hunks)
  • tests/cypress/e2e/features/single_object_annotation.js (5 hunks)
Files skipped from review due to trivial changes (2)
  • cvat-ui/src/actions/tasks-actions.ts
  • cvat-ui/src/containers/annotation-page/canvas/canvas-context-menu.tsx
Additional context used
LanguageTool
site/content/en/docs/manual/advanced/single-shape.md

[typographical] ~11-~11: It appears that a comma is missing. (BY_FOR_IN_COMMA)
Context: ... specific scenarios. By using this mode you can label objects with a chosen annotat...


[uncategorized] ~34-~34: Consider adding a hyphen. (TOP_LEFT_CORNER)
Context: ...e** mode, open the job, navigate to the top right corner, and from the drop-down menu, se...


[style] ~53-~53: In American English, abbreviations like “etc.” require a period. (ETC_PERIOD)
Context: ... type of the label (rectangle, ellipce, etc). Only visible when the type of the sha...

Additional comments not posted (30)
cvat-ui/src/components/annotation-page/single-shape-workspace/single-shape-workspace.tsx (1)

10-10: The addition of RemoveConfirmComponent is appropriate for enhancing UX by confirming deletions. Good integration with existing components.

cvat-ui/src/components/annotation-page/single-shape-workspace/styles.scss (1)

64-64: Renaming the CSS class to .cvat-single-shape-annotation-sidebar-finish-frame-wrapper improves clarity and aligns with the functionality. Well done on enhancing readability and maintainability of the styles.

cvat-ui/src/components/annotation-page/standard-workspace/remove-confirm.tsx (2)

7-7: Good use of shallowEqual in useSelector to optimize re-rendering. This is crucial in React components for performance.


Line range hint 20-61: Enhanced modal logic to handle object removal more intelligently, accounting for object locks and types. This improves user experience by providing clearer feedback and options based on the object state.

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

1-1: Updates to imports and the introduction of ThunkDispatch are consistent with the goal of improving type handling for asynchronous actions. This change should enhance the maintainability and scalability of the codebase.

Also applies to: 6-10


50-50: The async function getWebhooksAsync correctly uses ThunkDispatch for dispatching actions, aligning with the updated type handling strategy. Good practice in ensuring type safety and consistency across the codebase.

cvat-ui/src/components/annotation-page/top-bar/left-group.tsx (1)

13-13: The import change to AnnotationMenuComponent appears appropriate. Ensure that this component integrates well with the existing architecture and check if any props or states need adjustments.

Verification successful

The AnnotationMenuComponent is defined in cvat-ui/src/components/annotation-page/top-bar/annotation-menu.tsx and is properly imported and used in cvat-ui/src/components/annotation-page/top-bar/left-group.tsx.

  • cvat-ui/src/components/annotation-page/top-bar/annotation-menu.tsx: Defines AnnotationMenuComponent.
  • cvat-ui/src/components/annotation-page/top-bar/left-group.tsx: Imports and uses AnnotationMenuComponent.

The integration appears correct, and there are no issues with props or state management based on the provided context.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of AnnotationMenuComponent in the system.

# Test: Search for the usage of AnnotationMenuComponent. Expect: Proper integration and prop handling.
rg --type typescript "AnnotationMenuComponent"

Length of output: 81



Script:

#!/bin/bash
# Description: Verify the integration of AnnotationMenuComponent in the system.

# Test: Search for the usage of AnnotationMenuComponent in TypeScript and TypeScript React files.
rg --type ts "AnnotationMenuComponent"
rg --type tsx "AnnotationMenuComponent"

Length of output: 600

cvat-ui/src/actions/projects-actions.ts (1)

6-8: The refactoring to use ThunkDispatch across various project-related actions enhances type safety and consistency. Verify that all dispatches, especially in asynchronous actions, are correctly handled in the related reducers and components.

Also applies to: 70-70, 89-89, 122-122, 138-138

Verification successful

The search results demonstrate that projectActions are used in various files, including reducers/index.ts, reducers/plugins-reducer.ts, and actions/projects-actions.ts. This indicates that the refactored action creators are indeed referenced in reducers and other components.

Here are the relevant locations:

  • cvat-ui/src/reducers/index.ts
  • cvat-ui/src/reducers/plugins-reducer.ts
  • cvat-ui/src/actions/projects-actions.ts

The refactoring to use ThunkDispatch appears to be integrated correctly across these files.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Ensure all related components and reducers handle the new dispatch types correctly.

# Test: Search for the usage of project-related actions. Expect: Proper handling in reducers and components.
rg --type typescript "projectActions"

Length of output: 72



Script:

#!/bin/bash
# Description: Ensure all related components and reducers handle the new dispatch types correctly.

# Test: Search for the usage of project-related actions. Expect: Proper handling in reducers and components.
rg "projectActions" --glob "*.ts"

Length of output: 1849

site/content/en/docs/manual/advanced/single-shape.md (1)

51-51: The update to the "List of Hints" section is clear and enhances the guidance provided to users. Consider adding a period after "etc" to align with American English conventions.

- ... type of the label (rectangle, ellipce, etc). Only visible when the type of the sha...
+ ... type of the label (rectangle, ellipce, etc.). Only visible when the type of the sha...

Likely invalid or redundant comment.

cvat-ui/src/actions/cloud-storage-actions.ts (1)

6-8: Refactoring to use ThunkDispatch in cloud storage actions is consistent with improvements across the application. Ensure that error handling in these actions aligns with the overall error management strategy of CVAT.

Also applies to: 108-108, 133-133, 147-147, 161-161, 175-175, 187-187, 199-199

Verification successful

The search results show that error handling patterns in cloud storage actions are consistent with CVAT's error management strategy. The cloudStoragesActions.*Failed actions are dispatched appropriately across various functions.

  • cvat-ui/src/actions/cloud-storage-actions.ts: Lines where error handling actions are dispatched confirm alignment with the overall error management strategy.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that error handling in cloud storage actions aligns with CVAT's strategy.

# Test: Search for error handling patterns in cloud storage actions. Expect: Consistency with CVAT's error management.
rg --type typescript "cloudStoragesActions.*Failed"

Length of output: 88



Script:

#!/bin/bash
# Description: Verify that error handling in cloud storage actions aligns with CVAT's strategy.

# Test: Search for error handling patterns in cloud storage actions. Expect: Consistency with CVAT's error management.
rg --type ts "cloudStoragesActions.*Failed"

Length of output: 991

tests/cypress/e2e/features/single_object_annotation.js (1)

93-102: Ensure proper error handling in asynchronous operations.

The intercept and wait operations for the PATCH request look good, but ensure error scenarios are also handled. This is crucial for maintaining robustness, especially in network operations which might fail or timeout.

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

499-499: Ensure comprehensive error handling in the notifications reducer.

The addition of jobUpdating to the error states is a good start. Verify that all possible error states related to job updating are being handled appropriately in the reducer.

cvat-ui/src/components/annotation-page/single-shape-workspace/single-shape-sidebar/single-shape-sidebar.tsx (4)

90-95: The setActiveLabel action now includes labelType, which enhances the specificity of label handling. This is a positive change, but ensure consistency in how labelType is used throughout the application to avoid type mismatches.


417-494: The UX hints provided in the alerts are a good addition for guiding users. However, make sure that these hints are kept up-to-date with any UI changes and are localized for different languages to maintain accessibility.


253-279: The finishOnThisFrame function is quite complex and handles multiple conditions. It's crucial to ensure that all branches and conditions are covered by unit tests to prevent regressions, especially since it affects the job completion workflow.


29-30: The introduction of updateCurrentJobAsync aligns with the PR's objective to streamline job status updates. However, ensure that this function is thoroughly tested, especially since it's critical for changing job states without errors.

cvat-ui/src/components/annotation-page/canvas/views/canvas2d/canvas-wrapper.tsx (1)

Line range hint 1-1034: Overall architecture and Redux interactions look solid.

The component handles a variety of canvas operations and state changes efficiently. The methods are well-organized, and the interactions with the Redux state are appropriately managed. Good job maintaining clean and readable code in a complex component.

cvat-ui/src/actions/annotation-actions.ts (11)

121-121: The new action type UPDATE_CURRENT_JOB_FAILED is well-named and clearly indicates its purpose.


199-199: The use of ThunkDispatch here is appropriate for handling asynchronous actions, which aligns with the changes made across other action files.


311-311: Good implementation of asynchronous fetching of annotations. It properly handles both success and failure scenarios.


403-403: The collectStatisticsAsync function correctly dispatches initial, success, and failure actions, which is crucial for maintaining state consistency in asynchronous operations.


514-514: The updated signature for removeObjectAsync using ObjectState and force parameters is a good improvement for clarity and usability.


454-454: The propagateObjectAsync function handles object propagation with detailed logging and error handling. Ensure that the propagation logic correctly handles the object states across frames.

Verification successful

The propagateObjectAsync function appears to handle object states correctly across frames, including state transitions and error handling. The function logs the propagation event, creates new object states for each frame, and handles successful and failed propagation scenarios appropriately.

  • The function extracts the current state and session information.
  • It logs the propagation event.
  • It creates new object states for each frame in the specified range.
  • It handles errors by dispatching a failure action.

Based on this, the propagation logic seems to be correctly implemented.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify correct handling of object states in `propagateObjectAsync`.

# Test: Search for object state management logic. Expect: Correct state transitions and error handling.
rg --type python $'objectState\\s+.\\s+frame' 'cvat-ui/src/actions/annotation-actions.ts'

Length of output: 117



Script:

#!/bin/bash
# Description: Verify correct handling of object states in `propagateObjectAsync`.

# Test: Search for object state management logic within `propagateObjectAsync`.
rg 'objectState.*frame' cvat-ui/src/actions/annotation-actions.ts

Length of output: 135



Script:

#!/bin/bash
# Description: Extract the implementation of the `propagateObjectAsync` function to verify state management logic.

# Extract the `propagateObjectAsync` function implementation
ast-grep --lang typescript --pattern $'function propagateObjectAsync($_) {
  $$$
}' cvat-ui/src/actions/annotation-actions.ts

Length of output: 126



Script:

#!/bin/bash
# Description: Extract the implementation of the `propagateObjectAsync` function to verify state management logic.

# Extract the `propagateObjectAsync` function implementation using an improved pattern
ast-grep --lang typescript --pattern $'const propagateObjectAsync = async ($_): Promise<void> => {
  $$$
}' cvat-ui/src/actions/annotation-actions.ts

Length of output: 150



Script:

#!/bin/bash
# Description: Extract the implementation of the `propagateObjectAsync` function to verify state management logic.

# Search for the `propagateObjectAsync` function by name and extract surrounding lines for inspection
rg -A 30 'propagateObjectAsync' cvat-ui/src/actions/annotation-actions.ts

Length of output: 1522



Script:

#!/bin/bash
# Description: Extract the complete implementation of the `propagateObjectAsync` function to verify state management logic.

# Search for the `propagateObjectAsync` function by name and extract more surrounding lines for complete inspection
rg -A 60 'propagateObjectAsync' cvat-ui/src/actions/annotation-actions.ts

Length of output: 2627


1020-1044: The updateCurrentJobAsync function has been introduced to handle job updates. It's important that this function correctly applies updates to the job instance and handles any errors, especially given the critical nature of job state management.

Verification successful

The updateCurrentJobAsync function correctly applies updates to the job instance and handles errors appropriately. The presence of await jobInstance.save() confirms that the updates are saved, and errors are caught and dispatched.

  • await jobInstance.save() ensures the job updates are saved.
  • Errors are dispatched with UPDATE_CURRENT_JOB_FAILED.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify correct application of job updates in `updateCurrentJobAsync`.

# Test: Search for job update logic. Expect: Correct application of updates and robust error handling.
rg --type python $'jobInstance\\s+.\\s+save' 'cvat-ui/src/actions/annotation-actions.ts'

Length of output: 116



Script:

#!/bin/bash
# Description: Verify correct application of job updates in `updateCurrentJobAsync`.

# Test: Search for job update logic. Expect: Correct application of updates and robust error handling.
rg --type ts $'jobInstance\\s+.\\s+save' 'cvat-ui/src/actions/annotation-actions.ts'

Length of output: 81



Script:

#!/bin/bash
# Description: Verify presence of `save` method calls in `cvat-ui/src/actions/annotation-actions.ts`.

# Test: Search for `save` method calls. Expect: Presence of `save` method call in `updateCurrentJobAsync`.
rg --type ts '\bsave\s*\(' 'cvat-ui/src/actions/annotation-actions.ts'

Length of output: 341


794-794: Similarly, redoActionAsync should ensure that redo operations are correctly managed and that any errors are handled appropriately.

Verification successful

The redoActionAsync function implementation includes proper management of redo operations and error handling. Here's a summary of the key points:

  • It retrieves the state and necessary parameters.
  • It logs the redo action.
  • It performs the redo operation.
  • It fetches annotations or changes the frame based on the redo action.
  • It catches any errors and dispatches a REDO_ACTION_FAILED action with the error payload.

Locations in the codebase:

  • cvat-ui/src/actions/annotation-actions.ts:793-830
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify correct management and error handling in `redoActionAsync`.

# Test: Search for redo operations management. Expect: Proper handling of redo operations and error management.
rg --type python $'redo\\s+.\\s+slice' 'cvat-ui/src/actions/annotation-actions.ts'

Length of output: 110



Script:

#!/bin/bash
# Description: Verify correct management and error handling in `redoActionAsync`.

# Test: Search for the `redoActionAsync` function in the TypeScript file and examine its implementation.
ast-grep --lang typescript --pattern 'function redoActionAsync($_) { $$$ }' cvat-ui/src/actions/annotation-actions.ts

Length of output: 119



Script:

#!/bin/bash
# Description: Verify correct management and error handling in `redoActionAsync`.

# Test: Search for the `redoActionAsync` function or arrow function in the TypeScript file and examine its implementation.
ast-grep --lang typescript --pattern 'const redoActionAsync = async ($_): Promise<void> => { $$$ }' cvat-ui/src/actions/annotation-actions.ts

Length of output: 143



Script:

#!/bin/bash
# Description: Verify correct management and error handling in `redoActionAsync`.

# Test: Search for any occurrence of the term `redoActionAsync` in the TypeScript file to locate its definition and usage.
rg 'redoActionAsync' cvat-ui/src/actions/annotation-actions.ts

Length of output: 111



Script:

#!/bin/bash
# Description: Retrieve the full implementation of the `redoActionAsync` function for analysis.

# Test: Search for the full implementation of the `redoActionAsync` function in the TypeScript file.
ast-grep --lang typescript --pattern 'export function redoActionAsync(): ThunkAction { $$$ }' cvat-ui/src/actions/annotation-actions.ts

Length of output: 3215


661-661: The changeFrameAsync function is critical for navigation. It handles frame validation, data fetching, and state updates comprehensively. However, ensure that the error handling is robust, especially since this function interacts with external systems (frames and annotations).

Verification successful

The initial part of the changeFrameAsync function includes a try block, indicating that error handling is present. However, to fully verify the robustness of error handling, the entire function body should be reviewed.


The initial portion of the changeFrameAsync function indicates that it includes a try block for error handling, but the full function body is necessary to assess the robustness of this error handling mechanism.


The changeFrameAsync function includes a try block that catches errors and dispatches a CHANGE_FRAME_FAILED action if an error occurs. This indicates that error handling is in place and errors are being propagated correctly.

  • The function validates the frame range and fetches data asynchronously.
  • Errors are caught and handled by dispatching a failure action.

This confirms that the error handling within changeFrameAsync is robust.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify robust error handling in `changeFrameAsync`.

# Test: Search for error handling patterns in the function. Expect: Proper try-catch blocks and error propagation.
rg --type python $'catch\\s+\\(' 'cvat-ui/src/actions/annotation-actions.ts'

Length of output: 104



Script:

#!/bin/bash
# Description: Verify robust error handling in `changeFrameAsync`.

# Test: Search for error handling patterns in the function. Expect: Proper try-catch blocks and error propagation.
rg --type ts 'catch\s+\(' cvat-ui/src/actions/annotation-actions.ts

Length of output: 736



Script:

#!/bin/bash
# Description: Verify robust error handling in `changeFrameAsync`.

# Step 1: Search for the `changeFrameAsync` function definition.
rg 'function changeFrameAsync' cvat-ui/src/actions/annotation-actions.ts

# Step 2: Extract the `changeFrameAsync` function body to check for `catch` blocks.
ast-grep --lang typescript --pattern $'function changeFrameAsync($_) {
  $$$
}' cvat-ui/src/actions/annotation-actions.ts

Length of output: 231



Script:

#!/bin/bash
# Description: Verify robust error handling in `changeFrameAsync`.

# Step 1: Extract the `changeFrameAsync` function body to check for `catch` blocks.
ast-grep --lang typescript --pattern $'export function changeFrameAsync($_) {
  $$$
}' cvat-ui/src/actions/annotation-actions.ts

Length of output: 129



Script:

#!/bin/bash
# Description: Verify robust error handling in `changeFrameAsync`.

# Step 1: Extract the `changeFrameAsync` function body to check for `catch` blocks with a more flexible pattern.
ast-grep --lang typescript --pattern $'export function changeFrameAsync($$$) {
  $$$
}' cvat-ui/src/actions/annotation-actions.ts

Length of output: 130



Script:

#!/bin/bash
# Description: Verify robust error handling in `changeFrameAsync`.

# Step 1: Search for the `changeFrameAsync` function definition and surrounding lines.
rg -A 20 'export function changeFrameAsync' cvat-ui/src/actions/annotation-actions.ts

Length of output: 839



Script:

#!/bin/bash
# Description: Verify robust error handling in `changeFrameAsync`.

# Step 1: Search for the complete `changeFrameAsync` function definition and its surrounding lines.
rg -A 50 'export function changeFrameAsync' cvat-ui/src/actions/annotation-actions.ts

Length of output: 1776



Script:

#!/bin/bash
# Description: Verify robust error handling in `changeFrameAsync`.

# Step 1: Search for the complete `changeFrameAsync` function definition and its surrounding lines.
rg -A 100 'export function changeFrameAsync' cvat-ui/src/actions/annotation-actions.ts

Length of output: 3416


755-755: The undoActionAsync function introduces complex state management with undo capabilities. Ensure that the historical state handling is accurate and that errors during undo operations are managed correctly.

Verification successful

The undoActionAsync function appears to manage historical state accurately by interacting with the application's state and logging mechanisms. It attempts to undo the last action and fetches the appropriate annotations based on the frame context. Additionally, it handles errors by dispatching an UNDO_ACTION_FAILED action with the error payload.

  • The function retrieves the last undo action from the state.
  • It logs the undo action.
  • It performs the undo operation on the job instance.
  • It fetches annotations if necessary.
  • It dispatches an error action if an exception occurs.

Given this, the implementation seems to handle historical state and errors correctly.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify accurate historical state management in `undoActionAsync`.

# Test: Search for historical state management patterns. Expect: Correct handling and restoration of previous states.
rg --type python $'history\\s+.\\s+undo' 'cvat-ui/src/actions/annotation-actions.ts'

Length of output: 112



Script:

#!/bin/bash
# Description: Verify accurate historical state management in `undoActionAsync`.

# Test: Search for historical state management patterns. Expect: Correct handling and restoration of previous states.
rg --type typescript 'history\s+.\s+undo' cvat-ui/src/actions/annotation-actions.ts

Length of output: 120



Script:

#!/bin/bash
# Description: Verify accurate historical state management in `undoActionAsync`.

# Test: Search for historical state management patterns. Expect: Correct handling and restoration of previous states.
rg --type ts 'history\s+.\s+undo' cvat-ui/src/actions/annotation-actions.ts

Length of output: 77



Script:

#!/bin/bash
# Description: Find and review the implementation of the `undoActionAsync` function.

# Test: Search for the `undoActionAsync` function definition. Expect: Locate the function definition to analyze its implementation.
rg 'function undoActionAsync' cvat-ui/src/actions/annotation-actions.ts

Length of output: 122



Script:

#!/bin/bash
# Description: Retrieve the complete implementation of the `undoActionAsync` function.

# Test: Search for the complete implementation of the `undoActionAsync` function. Expect: Retrieve the function body to analyze its historical state management and error handling.
rg --context 20 'export function undoActionAsync' cvat-ui/src/actions/annotation-actions.ts

Length of output: 1405



Script:

#!/bin/bash
# Description: Retrieve the complete implementation of the `undoActionAsync` function with extended context.

# Test: Search for the complete implementation of the `undoActionAsync` function. Expect: Retrieve the function body to analyze its historical state management and error handling.
rg --context 40 'export function undoActionAsync' cvat-ui/src/actions/annotation-actions.ts

Length of output: 2766


375-375: The removeAnnotationsAsync function is well structured to handle complex operations including clearing annotations and actions, and refetching annotations. However, please ensure that error handling is robust, especially in multi-step operations like these.

Verification successful

The removeAnnotationsAsync function includes a try-catch block that handles errors during its multi-step operations. This confirms that error handling is implemented within the function.

  • The try block contains async operations such as jobInstance.annotations.clear, jobInstance.actions.clear, and dispatch(fetchAnnotationsAsync()).
  • The catch block dispatches an action with the error payload if any of these operations fail.

Locations in the codebase:

  • cvat-ui/src/actions/annotation-actions.ts (lines containing removeAnnotationsAsync function)
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify robust error handling in multi-step operations in `removeAnnotationsAsync`.

# Test: Search for error handling patterns in the function. Expect: Proper try-catch blocks around each async operation.
rg --type python $'try {\\s+await' 'cvat-ui/src/actions/annotation-actions.ts'

Length of output: 177



Script:

#!/bin/bash
# Description: Verify robust error handling in multi-step operations in `removeAnnotationsAsync`.

# Test: Search for try-catch blocks around async operations in the function.
# Expect: Proper try-catch blocks around each async operation.
ast-grep --lang typescript --pattern $'function removeAnnotationsAsync($_) {
  $$$
  try {
    $$$
    await $_;
    $$$
  } catch (err) {
    $$$
  }
  $$$
}' 'cvat-ui/src/actions/annotation-actions.ts'

Length of output: 202



Script:

#!/bin/bash
# Description: Extract the complete `removeAnnotationsAsync` function for manual inspection.

# Test: Extract the function definition and its body.
ast-grep --lang typescript --pattern $'function removeAnnotationsAsync($_) {
  $$$
}' 'cvat-ui/src/actions/annotation-actions.ts'

Length of output: 128



Script:

#!/bin/bash
# Description: List all function definitions in the `cvat-ui/src/actions/annotation-actions.ts` file to identify the exact name and structure of the `removeAnnotationsAsync` function.

# Test: List all function definitions.
ast-grep --lang typescript --pattern $'function $_($_) {
  $$$
}' 'cvat-ui/src/actions/annotation-actions.ts'

Length of output: 108



Script:

#!/bin/bash
# Description: Search for arrow functions and methods within objects in the `cvat-ui/src/actions/annotation-actions.ts` file to identify the `removeAnnotationsAsync` function.

# Test: Search for arrow functions and methods within objects.
ast-grep --lang typescript --pattern $'const $_ = async ($_): Promise<void> => {
  $$$
}' 'cvat-ui/src/actions/annotation-actions.ts'

ast-grep --lang typescript --pattern $'$_: async function ($_): Promise<void> {
  $$$
}' 'cvat-ui/src/actions/annotation-actions.ts'

Length of output: 264



Script:

#!/bin/bash
# Description: Search for methods within classes in the `cvat-ui/src/actions/annotation-actions.ts` file to identify the `removeAnnotationsAsync` function.

# Test: Search for methods within classes.
ast-grep --lang typescript --pattern $'class $_ {
  $$$
  $_ = async ($_): Promise<void> {
    $$$
  }
  $$$
}' 'cvat-ui/src/actions/annotation-actions.ts'

Length of output: 154



Script:

#!/bin/bash
# Description: Search for all async functions in the `cvat-ui/src/actions/annotation-actions.ts` file to identify the `removeAnnotationsAsync` function.

# Test: Search for all async functions.
ast-grep --lang typescript --pattern $'async function $_($_): Promise<void> {
  $$$
}' 'cvat-ui/src/actions/annotation-actions.ts'

ast-grep --lang typescript --pattern $'const $_ = async ($_): Promise<void> => {
  $$$
}' 'cvat-ui/src/actions/annotation-actions.ts'

ast-grep --lang typescript --pattern $'$_: async function ($_): Promise<void> {
  $$$
}' 'cvat-ui/src/actions/annotation-actions.ts'

ast-grep --lang typescript --pattern $'$_ = async ($_): Promise<void> => {
  $$$
}' 'cvat-ui/src/actions/annotation-actions.ts'

Length of output: 521



Script:

#!/bin/bash
# Description: Search for all async functions and arrow functions in the `cvat-ui/src/actions/annotation-actions.ts` file to identify the `removeAnnotationsAsync` function.

# Test: Search for all async functions and arrow functions.
rg 'async function' cvat-ui/src/actions/annotation-actions.ts

rg 'const .* = async' cvat-ui/src/actions/annotation-actions.ts

rg ': async function' cvat-ui/src/actions/annotation-actions.ts

rg '= async' cvat-ui/src/actions/annotation-actions.ts

Length of output: 405



Script:

#!/bin/bash
# Description: Search for all functions related to annotation removal in the `cvat-ui/src/actions/annotation-actions.ts` file.

# Test: Search for all functions related to annotation removal.
rg 'removeAnnotation' cvat-ui/src/actions/annotation-actions.ts

rg 'deleteAnnotation' cvat-ui/src/actions/annotation-actions.ts

rg 'clearAnnotation' cvat-ui/src/actions/annotation-actions.ts

Length of output: 230



Script:

#!/bin/bash
# Description: Extract the complete `removeAnnotationsAsync` function for manual inspection.

# Test: Extract the function definition and its body.
rg -A 50 'export function removeAnnotationsAsync' cvat-ui/src/actions/annotation-actions.ts

Length of output: 1919

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

92-92: Added jobUpdating field to handle new error states related to job updates.

This change properly initializes the jobUpdating field to null, aligning with the error handling structure of other fields in the reducer. Good practice for maintaining consistency in state management.


940-956: Proper handling of UPDATE_CURRENT_JOB_FAILED action.

The addition of this case in the reducer handles errors related to job updates effectively. The use of the ServerError check to conditionally log errors is consistent with other parts of the reducer, ensuring uniform error handling across the application.

@bsekachev bsekachev changed the title [Dependend] Dedicated function to update annotation job fields [Dependend] Refactored updating a job instance on client side Jun 20, 2024
@bsekachev bsekachev changed the title [Dependend] Refactored updating a job instance on client side Refactored updating a job instance on client side Jun 20, 2024
Copy link

sonarcloud bot commented Jun 24, 2024

@bsekachev bsekachev merged commit 2a720f4 into develop Jun 24, 2024
16 checks passed
@bsekachev bsekachev deleted the bs/immediate_feedback branch June 24, 2024 06:05
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.

Changing job state causes 403 error in specific scenariou
1 participant