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

cvat-core api fixes & refactoring #8016

Merged
merged 16 commits into from
Jun 20, 2024
Merged

cvat-core api fixes & refactoring #8016

merged 16 commits into from
Jun 20, 2024

Conversation

bsekachev
Copy link
Member

@bsekachev bsekachev commented Jun 12, 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

  • Refactor

    • Enhanced parameter handling and method definitions for improved code organization and maintainability.
    • Updated various methods to accept a single flags object parameter for better clarity and flexibility.
  • Tests

    • Adjusted test cases to align with the new parameter handling in method calls.
  • Chores

    • Renamed parameters in functions for consistency and clarity.

@bsekachev bsekachev requested a review from azhavoro as a code owner June 12, 2024 06:46
Copy link
Contributor

coderabbitai bot commented Jun 12, 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 across several files in the CVAT codebase focus on refactoring methods to enhance clarity, flexibility, and maintainability. Key modifications include updating methods to accept object parameters instead of individual parameters, improving parameter handling, and refining error handling. These updates streamline the code, making it more readable and easier to manage.

Changes

Files Change Summary
cvat-core/src/annotations-collection.ts Refactored import method to return void, updated clear method to accept a flags object, and adjusted logic for new parameter structure.
cvat-core/src/annotations.ts Refactored clearAnnotations function to accept a flags object parameter instead of individual parameters.
cvat-core/src/session-implementation.ts Refactored various methods in the Job class, improving parameter handling, error handling, and overall code organization.
cvat-core/src/session.ts Added imports, updated method signatures, and adjusted return types for various methods in the annotations, actions, and frames sections.
cvat-core/tests/api/annotations.cjs, frames.cjs Updated clear method calls to pass an object { reload: true } instead of a boolean true.
cvat-ui/src/actions/annotation-actions.ts Updated removeAnnotationsAsync and getJobAsync to call jobInstance.annotations.clear with an object parameter.
cvat-ui/src/actions/import-actions.ts Modified clear method call in importDatasetAsync to pass an object { reload: true } instead of a boolean true.
cvat-ui/src/containers/annotation-page/top-bar/... Renamed parameters in removeAnnotations function within mapDispatchToProps from startnumber and endnumber to startFrame and endFrame.
tests/cypress/support/commands.js Modified clear method call in headlessCreateObject command to pass an object { reload: true } instead of a boolean true.

Poem

In the code where changes bloom,
Methods now with flags consume,
Refactored paths, clear and bright,
Enhancing flow, a coder's delight.
With objects passed, the code refined,
A smoother journey, intertwined.
🐇✨


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: 2

Outside diff range and nitpick comments (1)
cvat-core/src/annotations-collection.ts (1)

[!TIP]
Codebase Verification

The verification process reveals that not all calls to the clear method in cvat-core/src/annotations.ts, cvat-core/src/annotations-history.ts, and cvat-core/src/session-implementation.ts pass the appropriate flags object. Specifically:

  • In cvat-core/src/annotations.ts, the call to clear does pass the flags object.
  • In cvat-core/src/annotations-history.ts, the call to clear does not pass any flags.
  • In cvat-core/src/session-implementation.ts, the calls to clear do not pass any flags.

These findings indicate that the refactoring to accept a flags object has not been consistently applied across the codebase.

  • cvat-core/src/annotations-history.ts: The constructor calls this.clear() without any flags.
  • cvat-core/src/session-implementation.ts: The clear method is called without any flags in the clearActionsImplementation and Task.prototype.actions.clear.implementation functions.

Action Required:

  • Update the calls to clear in cvat-core/src/annotations-history.ts and cvat-core/src/session-implementation.ts to pass the appropriate flags object.

Locations to Update:

  • cvat-core/src/annotations-history.ts: Line 6
  • cvat-core/src/session-implementation.ts: Lines 5 and 14
Analysis chain

Line range hint 769-803: Refactoring the clear method to accept a flags object enhances flexibility and clarity. Ensure all calls to this method have been updated to pass the appropriate flags object.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all calls to `clear` method pass the appropriate flags object.

# Test: Search for the function usage. Expect: Only calls with the new flags object.
rg --type typescript $'\\.clear\\('

Length of output: 69



Script:

#!/bin/bash
# Description: Verify all calls to `clear` method pass the appropriate flags object.

# Test: Search for the function usage. Expect: Only calls with the new flags object.
rg --type ts '\.clear\('

Length of output: 1576



Script:

#!/bin/bash
# Description: Extract context around calls to `clear` method in relevant files to verify if they pass the appropriate flags object.

# Extract context around calls in cvat-core/src/annotations.ts
rg --context 5 --type ts '\.clear\(' cvat-core/src/annotations.ts

# Extract context around calls in cvat-core/src/annotations-history.ts
rg --context 5 --type ts '\.clear\(' cvat-core/src/annotations-history.ts

# Extract context around calls in cvat-core/src/session-implementation.ts
rg --context 5 --type ts '\.clear\(' cvat-core/src/session-implementation.ts

Length of output: 1824

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 14b65ac and a11801d.

Files selected for processing (10)
  • cvat-core/src/annotations-collection.ts (5 hunks)
  • cvat-core/src/annotations.ts (2 hunks)
  • cvat-core/src/session-implementation.ts (2 hunks)
  • cvat-core/src/session.ts (6 hunks)
  • cvat-core/tests/api/annotations.cjs (14 hunks)
  • cvat-core/tests/api/frames.cjs (4 hunks)
  • cvat-ui/src/actions/annotation-actions.ts (2 hunks)
  • cvat-ui/src/actions/import-actions.ts (1 hunks)
  • cvat-ui/src/containers/annotation-page/top-bar/annotation-menu.tsx (1 hunks)
  • tests/cypress/support/commands.js (1 hunks)
Additional context used
GitHub Check: Linter
cvat-core/src/session.ts

[failure] 29-29:
'Camelized' is defined but never used

Additional comments not posted (32)
cvat-ui/src/containers/annotation-page/top-bar/annotation-menu.tsx (1)

53-54: Parameter names in removeAnnotations have been updated for clarity.

Please ensure that any related documentation is updated to reflect these changes.

cvat-core/tests/api/frames.cjs (1)

50-50: Updated clear method calls to use object parameters.

Please verify that all tests pass with the new method signature.

Also applies to: 60-60, 70-70, 80-80

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

115-115: Updated clear method call to use an object parameter in importDatasetAsync.

Please ensure that the function behaves as expected with the new parameter format.

cvat-core/src/annotations.ts (1)

116-130: Refactored clearAnnotations to use a flags object parameter, enhancing flexibility and clarity.

Consider adding unit tests to cover the new functionality and ensure that existing tests are updated to reflect these changes.

cvat-core/src/session-implementation.ts (2)

57-572: Refactored Job class implementations are well-structured and maintain consistency.

The use of Object.defineProperty for method implementations ensures encapsulation and control over property behaviors, which is a good practice in complex systems. However, ensure thorough testing, especially for asynchronous operations and error handling paths.


Line range hint 579-937: Refactored Task class implementations follow a consistent pattern and improve maintainability.

Similar to the Job class, the Task class uses Object.defineProperty effectively. It's crucial to verify that all new implementations interact correctly with existing functionalities and that side effects are handled appropriately.

cvat-core/tests/api/annotations.cjs (18)

250-250: Refactor to use object parameter for clear method aligns with API changes.


263-263: Refactor to use object parameter for clear method aligns with API changes.


280-280: Refactor to use object parameter for clear method aligns with API changes.


310-310: Refactor to use object parameter for clear method aligns with API changes.


331-331: Refactor to use object parameter for clear method aligns with API changes.


346-346: Refactor to use object parameter for clear method aligns with API changes.


366-366: Refactor to use object parameter for clear method aligns with API changes.


381-381: Refactor to use object parameter for clear method aligns with API changes.


412-412: Refactor to use object parameter for clear method aligns with API changes.


772-772: Refactor to use object parameter for clear method aligns with API changes.


820-820: Refactor to use object parameter for clear method aligns with API changes.


833-833: Refactor to use object parameter for clear method aligns with API changes.


841-841: Refactor to use object parameter for clear method aligns with API changes.


849-849: Refactor to use object parameter for clear method aligns with API changes.


857-857: Refactor to use object parameter for clear method aligns with API changes.


865-865: Refactor to use object parameter for clear method aligns with API changes.


879-879: Refactor to use object parameter for clear method aligns with API changes.


958-958: Refactor to use object parameter for clear method aligns with API changes.

cvat-core/src/session.ts (6)

8-8: Import of ChunkQuality from cvat-data added.

This import is necessary for the updated method signatures that use ChunkQuality as a parameter type.


28-28: Import of Issue added.

This import is used in the updated method signatures and implementations related to issue handling in the Job class.


30-30: Import of ObjectState added.

This import is crucial for the type annotations in methods that deal with object states, enhancing type safety and clarity.


60-62: Refactored clear method to accept a flags object.

This change aligns with the PR's objective to enhance parameter handling and maintainability by using object parameters instead of multiple individual parameters.


314-365: Updated method signatures in the Session class to include specific parameter and return types.

These changes improve type safety and clarity, making the API more robust and easier to use correctly.


Line range hint 662-682: Enhanced error handling and specific return types in the Job class methods.

These updates are part of the extensive refactoring effort to improve the reliability and maintainability of the code.

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

378-383: Refactored removeAnnotationsAsync to use object parameters for clarity and maintainability.

tests/cypress/support/commands.js (1)

272-272: The update to pass an object { reload: true } instead of a boolean true aligns with the overall refactoring strategy to improve parameter handling across the codebase.

cvat-core/src/session.ts Outdated Show resolved Hide resolved
cvat-core/src/annotations-collection.ts Outdated Show resolved Hide resolved
@bsekachev bsekachev changed the title cvat-core api refactoring cvat-core api fixes & refactoring Jun 12, 2024
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 77.48227% with 127 lines in your changes missing coverage. Please review.

Project coverage is 83.48%. Comparing base (14b65ac) to head (ebac4d1).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8016      +/-   ##
===========================================
- Coverage    83.55%   83.48%   -0.08%     
===========================================
  Files          384      384              
  Lines        40350    40415      +65     
  Branches      3771     3772       +1     
===========================================
+ Hits         33716    33740      +24     
- Misses        6634     6675      +41     
Components Coverage Δ
cvat-ui 79.25% <77.48%> (-0.15%) ⬇️
cvat-server 87.35% <ø> (ø)

Copy link

sonarcloud bot commented Jun 19, 2024

@bsekachev bsekachev merged commit deb9681 into develop Jun 20, 2024
33 checks passed
@bsekachev bsekachev deleted the bs/refactoring branch June 20, 2024 13:37
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.

3 participants