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

Do not block canvas navigation when frame is being fetched #8284

Merged
merged 8 commits into from
Aug 9, 2024

Conversation

bsekachev
Copy link
Member

@bsekachev bsekachev commented Aug 9, 2024

Motivation and context

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

    • Updated version numbers for cvat-canvas and cvat-ui packages, indicating minor improvements and bug fixes.
    • Enhanced image loading management in the canvas, improving user interaction responsiveness.
  • Bug Fixes

    • Refined logic in CanvasWrapperComponent to prevent errors related to undefined states.
    • Streamlined state handling in annotation-reducer, ensuring more predictable updates.
  • Improvements

    • Removed unnecessary conditions in the top bar actions, potentially improving interface responsiveness.

Copy link
Contributor

coderabbitai bot commented Aug 9, 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 enhance the functionality and performance of the CVAT application by incrementing version numbers and refining logic within key components. Notable improvements include better image loading state management, streamlined event handling, and clearer control flows in annotation management. These changes aim to optimize user interaction, improve responsiveness, and maintain robust state management, ensuring a smoother experience during image annotation tasks.

Changes

Files Change Summary
cvat-canvas/package.json, cvat-ui/package.json Version updates from 2.20.6 to 2.20.7 and from 1.64.3 to 1.64.4, indicating minor improvements and bug fixes.
cvat-canvas/src/typescript/canvasModel.ts, cvat-canvas/src/typescript/canvasView.ts Enhanced image handling and notifications in CanvasModelImpl, and added isImageLoading state management in CanvasViewImpl for better user experience.
cvat-ui/src/components/annotation-page/canvas/views/canvas2d/canvas-wrapper.tsx, cvat-ui/src/containers/annotation-page/top-bar/top-bar.tsx Improved conditional logic in CanvasWrapperComponent and removed canvasIsReady checks in AnnotationTopBarContainer for streamlined action handling.
cvat-ui/src/reducers/annotation-reducer.ts Refined reducer logic for ACTIVATE_OBJECT, DELETE_FRAME_SUCCESS, and RESTORE_FRAME_SUCCESS actions, simplifying state updates and improving clarity.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CanvasViewImpl
    participant CanvasModelImpl
    participant AnnotationReducer

    User->>CanvasViewImpl: Load Image
    CanvasViewImpl-->>CanvasModelImpl: Set isImageLoading(true)
    CanvasModelImpl-->>CanvasViewImpl: Notify image loading
    CanvasViewImpl-->>User: Display loading state
    CanvasModelImpl->>CanvasModelImpl: Check image existence
    CanvasModelImpl-->>CanvasViewImpl: Set isImageLoading(false)
    CanvasViewImpl-->>User: Display image
Loading

🐰 In a world where pixels dance,
The rabbit hops and takes a stance.
With loading states and logic bright,
Annotations made with pure delight!
So let’s rejoice, both near and far,
For smoother paths in this canvas bazaar! 🌟


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

Outside diff range, codebase verification and nitpick comments (1)
cvat-ui/src/containers/annotation-page/top-bar/top-bar.tsx (1)

Reintroduce canvasIsReady Check in onPrevFrame Method

The canvasIsReady state is crucial for ensuring that frame navigation and other canvas-dependent actions occur only when the canvas is fully loaded. Its removal from the onPrevFrame method could lead to unexpected behavior. Consider reintroducing this check to maintain stability and prevent errors.

  • File: cvat-ui/src/containers/annotation-page/top-bar/top-bar.tsx
  • Method: onPrevFrame
Analysis chain

Line range hint 374-385: Verify the impact of removing canvasIsReady check in onPrevFrame.

The method now navigates frames based on other conditions. Ensure that the removal of canvasIsReady does not lead to unexpected behavior when the canvas is not ready.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `canvasIsReady` in conjunction with frame navigation methods across the codebase.

# Test: Search for conditions involving `canvasIsReady` and frame navigation. Expect: Ensure proper handling when canvas is not ready.
rg --type js --type ts 'canvasIsReady.*frame'

Length of output: 164


Script:

#!/bin/bash
# Search for the `onPrevFrame` method definition and its usage across the codebase to understand its context and conditions.
ast-grep --lang ts --pattern 'onPrevFrame($_) { $$$ }'

# Additionally, search for invocations of `onPrevFrame` to see how it is used.
rg 'onPrevFrame'

Length of output: 1744


Script:

#!/bin/bash
# Search for canvas-related state management to understand how canvas readiness is ensured in the codebase.
rg 'canvasIsReady'

Length of output: 3558

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 79ec6a1 and e09cb5b.

Files selected for processing (7)
  • cvat-canvas/package.json (1 hunks)
  • cvat-canvas/src/typescript/canvasModel.ts (2 hunks)
  • cvat-canvas/src/typescript/canvasView.ts (5 hunks)
  • cvat-ui/package.json (1 hunks)
  • cvat-ui/src/components/annotation-page/canvas/views/canvas2d/canvas-wrapper.tsx (2 hunks)
  • cvat-ui/src/containers/annotation-page/top-bar/top-bar.tsx (13 hunks)
  • cvat-ui/src/reducers/annotation-reducer.ts (2 hunks)
Files skipped from review due to trivial changes (2)
  • cvat-canvas/package.json
  • cvat-ui/package.json
Additional comments not posted (20)
cvat-ui/src/containers/annotation-page/top-bar/top-bar.tsx (9)

Line range hint 354-363: Verify the impact of removing canvasIsReady check in onBackward.

The method now navigates frames based on other conditions. Ensure that the removal of canvasIsReady does not lead to unexpected behavior when the canvas is not ready.


298-300: Verify the impact of removing canvasIsReady check in undo.

The undo method now only checks if the frame can be changed and if there is an undoAction. Ensure that this change does not lead to issues when the canvas is not ready.


306-308: Verify the impact of removing canvasIsReady check in redo.

The redo method now only checks if the frame can be changed and if there is a redoAction. Ensure that this change does not lead to issues when the canvas is not ready.


466-470: Verify the impact of removing canvasIsReady check in searchAnnotations.

The method now searches annotations based on other conditions. Ensure that the removal of canvasIsReady does not lead to unexpected behavior when the canvas is not ready.


Line range hint 403-413: Verify the impact of removing canvasIsReady check in onNextFrame.

The method now navigates frames based on other conditions. Ensure that the removal of canvasIsReady does not lead to unexpected behavior when the canvas is not ready.


338-343: Verify the impact of removing canvasIsReady check in onFirstFrame.

The method now navigates frames based on other conditions. Ensure that the removal of canvasIsReady does not lead to unexpected behavior when the canvas is not ready.

Verification successful

Removal of canvasIsReady from onFirstFrame is unlikely to cause issues.

The canvasIsReady check is still used in other parts of the code to control frame navigation and playback, ensuring that actions are only performed when the canvas is ready. This suggests that the change does not introduce unexpected behavior.

  • The canvasIsReady condition is used in conjunction with playing and frameFetching to control frame navigation.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `canvasIsReady` in conjunction with frame navigation methods across the codebase.

# Test: Search for conditions involving `canvasIsReady` and frame navigation. Expect: Ensure proper handling when canvas is not ready.
rg --type js --type ts 'canvasIsReady.*frame'

Length of output: 164


Script:

#!/bin/bash
# Description: Explore the usage of `canvasIsReady` throughout the file to understand its role in frame navigation.

# Test: Search for all occurrences of `canvasIsReady` in the file to analyze its usage context.
rg --type ts 'canvasIsReady' cvat-ui/src/containers/annotation-page/top-bar/top-bar.tsx -A 5 -B 5

Length of output: 1710


559-561: Verify the impact of removing canvasIsReady check in onDeleteFrame.

The method now deletes frames based on the job type. Ensure that the removal of canvasIsReady does not lead to unexpected behavior when the canvas is not ready.


451-456: Verify the impact of removing canvasIsReady check in onLastFrame.

The method now navigates frames based on other conditions. Ensure that the removal of canvasIsReady does not lead to unexpected behavior when the canvas is not ready.


Line range hint 431-440: Verify the impact of removing canvasIsReady check in onForward.

The method now navigates frames based on other conditions. Ensure that the removal of canvasIsReady does not lead to unexpected behavior when the canvas is not ready.

Verification successful

Verification of canvasIsReady Removal in onForward:

The removal of the canvasIsReady check from the onForward method does not directly impact frame navigation. The canvasIsReady state is used elsewhere to ensure the canvas is ready for operations, but its absence in onForward is not linked to any critical dependencies that would cause issues.

  • The canvasIsReady variable is derived from the Redux state and is used in other conditions to ensure readiness for playing frames.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `canvasIsReady` in conjunction with frame navigation methods across the codebase.

# Test: Search for conditions involving `canvasIsReady` and frame navigation. Expect: Ensure proper handling when canvas is not ready.
rg --type js --type ts 'canvasIsReady.*frame'

Length of output: 164


Script:

#!/bin/bash
# Description: Find where `canvasIsReady` is set or modified in the codebase to understand its role.

# Test: Search for assignments or modifications to `canvasIsReady`.
rg --type js --type ts 'canvasIsReady\s*='

Length of output: 772

cvat-ui/src/reducers/annotation-reducer.ts (3)

592-596: Efficient check for object existence in ACTIVATE_OBJECT.

The addition of the requiredObjectExists check before proceeding with state updates is a good optimization, preventing unnecessary operations.


1013-1021: Simplified state update in DELETE_FRAME_SUCCESS.

Directly assigning data to frame.data streamlines the state update process, reducing complexity and improving clarity.


1013-1021: Simplified state update in RESTORE_FRAME_SUCCESS.

Directly assigning data to frame.data streamlines the state update process, reducing complexity and improving clarity.

cvat-canvas/src/typescript/canvasModel.ts (2)

552-556: Conditional notification for OBJECTS_UPDATED.

Adding a check to ensure OBJECTS_UPDATED is only triggered if an image exists improves performance by avoiding unnecessary updates.


561-564: Improved state management for imageIsDeleted.

Setting imageIsDeleted immediately and resetting angle if the image is deleted ensures accurate internal state representation.

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

929-931: Good addition of activatedState check.

The added check for activatedState before calling focus improves robustness by preventing potential errors when activatedState is null or undefined.


962-963: Flexible argument handling in frameData proxy.

Modifying the get method to accept variable arguments (...args: any[]) increases flexibility in handling different data retrieval scenarios, aligning with the PR's objective of improving responsiveness.

cvat-canvas/src/typescript/canvasView.ts (4)

65-65: Good addition: isImageLoading property.

The introduction of the isImageLoading property is a well-structured approach to manage the image loading state and control user interactions accordingly.


1442-1442: Appropriate initialization of isImageLoading.

Initializing isImageLoading to true in the constructor is appropriate, as it reflects the initial loading state of the canvas.


1649-1663: Improvement in mousemove event handling.

The check for isImageLoading before dispatching the mousemove event is a smart optimization to prevent unnecessary processing during image loading.


Line range hint 1795-1829: Correct handling of isImageLoading in notify method.

The logic for updating isImageLoading in response to IMAGE_CHANGED events is correctly implemented, ensuring that the canvas accurately reflects the loading state.

@codecov-commenter
Copy link

codecov-commenter commented Aug 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.37%. Comparing base (79ec6a1) to head (d2408de).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8284   +/-   ##
========================================
  Coverage    83.37%   83.37%           
========================================
  Files          390      390           
  Lines        41549    41551    +2     
  Branches      3861     3861           
========================================
+ Hits         34642    34644    +2     
  Misses        6907     6907           
Components Coverage Δ
cvat-ui 79.67% <100.00%> (+<0.01%) ⬆️
cvat-server 86.66% <ø> (ø)

Copy link

sonarcloud bot commented Aug 9, 2024

@bsekachev bsekachev merged commit 26f1f78 into develop Aug 9, 2024
33 checks passed
@bsekachev bsekachev deleted the bs/do_not_block_canvas branch August 9, 2024 11:49
@cvat-bot cvat-bot bot mentioned this pull request Aug 13, 2024
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.

2 participants