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

Updated page with allocation report #8558

Merged
merged 3 commits into from
Oct 21, 2024
Merged

Updated page with allocation report #8558

merged 3 commits into from
Oct 21, 2024

Conversation

bsekachev
Copy link
Member

@bsekachev bsekachev commented Oct 17, 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

    • Introduced modular validation layouts for jobs and tasks, enhancing data management.
    • Added new interfaces for serialized job and task validation layouts, improving type specificity.
  • Bug Fixes

    • Resolved inconsistencies by replacing outdated validation layout types across the application.
  • Documentation

    • Updated documentation to reflect changes in validation layout handling and new interface structures.

Copy link
Contributor

coderabbitai bot commented Oct 17, 2024

Walkthrough

The changes involve a significant restructuring of the validation layout system for jobs and tasks within the application. The ValidationLayout class has been replaced by two new classes: JobValidationLayout and TaskValidationLayout. This update includes modifications to import statements, the removal of the old ValidationLayout type, and the introduction of new serialized types. Additionally, the session implementation and various UI components have been updated to reflect these changes, enhancing type safety and clarity in handling job-related data.

Changes

File(s) Change Summary
cvat-core/src/api.ts, cvat-core/src/index.ts, cvat-core/src/session.ts, cvat-ui/src/cvat-core-wrapper.ts, cvat-ui/src/reducers/index.ts Updated import statements to replace ValidationLayout with JobValidationLayout and TaskValidationLayout.
cvat-core/src/api.ts Removed ValidationLayout class; added JobValidationLayout and TaskValidationLayout classes.
cvat-core/src/index.ts Removed ValidationLayout type; added JobValidationLayout and TaskValidationLayout types.
cvat-core/src/server-proxy.ts Updated method signature for validationLayout to return a union type of new serialized types.
cvat-core/src/server-response-types.ts Renamed SerializedValidationLayout to SerializedJobValidationLayout; added SerializedTaskValidationLayout interface with new properties.
cvat-core/src/validation-layout.ts, cvat-core/src/session-implementation.ts Updated constructors and method signatures in JobValidationLayout and TaskValidationLayout to return appropriate types instead of ValidationLayout.
cvat-ui/src/components/quality-control/task-quality/allocation-table.tsx, cvat-ui/src/components/quality-control/task-quality/summary.tsx Updated Props interfaces to include new properties related to validation layouts and modified existing properties for consistency.
cvat-ui/src/reducers/index.ts Added SET_VALIDATION_LAYOUT action type and corresponding action creator for managing state related to task validation layouts.

Poem

In the garden where changes bloom,
New layouts rise, dispelling gloom.
Jobs and tasks, so neat and bright,
Validation's path now feels just right.
Hops of joy, we celebrate,
Structure strong, we elevate! 🐰✨


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

🧹 Outside diff range and nitpick comments (11)
cvat-ui/src/components/quality-control/task-quality/summary.tsx (3)

12-12: LGTM! Consider enhancing type clarity.

The addition of the 'mode' property to the Props interface improves type safety and aligns with the new validation context. Good job!

For improved clarity, consider using a more descriptive type alias:

type ValidationMode = 'ground_truth' | 'honeypot';

This would make the code more self-documenting and easier to understand at a glance.


27-31: LGTM! Consider adding ARIA labels for improved accessibility.

The conditional rendering of the validation mode enhances the UI by providing context-specific information. The implementation is clean and consistent with the existing code style.

To improve accessibility, consider adding ARIA labels to the Text components:

<Text aria-label="Validation mode label">
    Validation mode:
</Text>
{' '}
<Text strong aria-label="Validation mode value">
    {mode === 'gt' ? 'Ground Truth' : 'Honeypots'}
</Text>

This would provide better context for screen readers.


43-49: LGTM! Consider consistent naming for CSS classes.

The addition of the excluded validation frames information enhances the comprehensiveness of the summary. The implementation is consistent with other elements and correctly uses the 'excludedCount' prop.

For consistency with other class names, consider updating the CSS class name:

- <Col span={12} className='cvat-allocation-summary-excluded'>
+ <Col span={12} className='cvat-allocation-summary-excluded-frames'>

This would align with the naming pattern used for other elements (e.g., 'cvat-allocation-summary-active').

cvat-ui/src/cvat-core-wrapper.ts (1)

38-38: Overall assessment: Changes look good and align with PR objectives.

The modifications to this file are minimal and focused on restructuring the validation layout system. The changes are consistent with the PR objectives and the AI-generated summary. The new structure with JobValidationLayout and TaskValidationLayout should provide more flexibility and specificity in handling validations for jobs and tasks.

To ensure a smooth transition:

  1. Verify that all usages of the old ValidationLayout have been updated throughout the codebase.
  2. Consider updating the documentation to reflect these changes in the validation system.
  3. Ensure that any affected tests are updated to use the new layout structures.

Also applies to: 109-110

cvat-core/src/server-response-types.ts (1)

527-530: LGTM. Consider adding documentation.

The SerializedJobValidationLayout interface looks good. It provides a flexible structure for job validation layout with honeypot-related properties.

Consider adding JSDoc comments to explain the purpose of this interface and its properties, especially the concept of honeypot frames in the context of job validation. This will improve code maintainability and help other developers understand the intended use of this interface.

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

29-29: Summary: Validation layout refactoring improves modularity

The changes in this file are part of a larger refactoring effort to separate job and task validation layouts. This separation likely improves the modularity and maintainability of the codebase. The modifications are consistent and well-structured, with no apparent issues in the implementation.

Key points:

  1. Import statement updated to use named imports for specific validation layouts.
  2. New JobValidationLayout and TaskValidationLayout classes added to the classes object.

These changes should provide more flexibility and clarity when working with validation layouts in different contexts (jobs vs. tasks) throughout the CVAT application.

As this refactoring progresses, consider the following:

  1. Ensure all usages of the old ValidationLayout class are updated throughout the codebase.
  2. Update any documentation or API references to reflect these changes.
  3. If not already done, consider adding or updating unit tests to cover the new validation layout classes and their usage.

Also applies to: 430-431

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

689-692: LGTM: Job validation layout return type updated

The validationLayout method now correctly returns a Promise<JobValidationLayout | null> instead of the generic ValidationLayout. This change improves type safety and clarity.

Consider updating the JSDoc comment for this method to reflect the new return type:

/**
 * Retrieves the validation layout for the job.
 * @returns A promise that resolves to a JobValidationLayout or null if not available.
 */
async validationLayout(): Promise<JobValidationLayout | null> {
    // ... existing implementation ...
}

1189-1192: LGTM: Task validation layout return type updated

The validationLayout method now correctly returns a Promise<TaskValidationLayout | null> instead of the generic ValidationLayout. This change improves type safety and clarity, and is consistent with the changes made to the Job class.

Consider updating the JSDoc comment for this method to reflect the new return type:

/**
 * Retrieves the validation layout for the task.
 * @returns A promise that resolves to a TaskValidationLayout or null if not available.
 */
async validationLayout(): Promise<TaskValidationLayout | null> {
    // ... existing implementation ...
}
cvat-core/src/server-proxy.ts (2)

Line range hint 1386-1391: Consider improving type safety in surrounding functions

While reviewing the validationLayout function changes, I noticed that some surrounding functions in this file use the any type. For better type safety and code maintainability, consider replacing any with more specific types where possible.

For example, in the getUsers function:

async function getUsers(filter = { page_size: 'all' }): Promise<SerializedUser[]> {
    // ...
}

You could create a specific type for the filter object:

type UserFilter = {
    page_size: 'all' | number;
    // Add other possible filter properties
};

async function getUsers(filter: UserFilter = { page_size: 'all' }): Promise<SerializedUser[]> {
    // ...
}

This approach would provide better type checking and autocompletion for function arguments.


Line range hint 1-1391: Address TODO comments in the codebase

There are several TODO comments throughout the file that might need attention. For example:

  1. Line 1075: // TODO: rewrite server logic, now it returns 202, 201 codes, but we need RQ statuses and details

These TODO items should be addressed to improve the codebase and remove technical debt. Consider creating issues in your project management system to track and prioritize these tasks.

cvat-ui/src/components/quality-control/quality-control-page.tsx (1)

Line range hint 347-375: Ensure 'Settings' tab is accessible even without a ground truth job

Currently, the 'Settings' tab is added only if gtJobInstance and gtJobMeta are available. This restricts users from accessing the quality settings when no ground truth job exists. If the intention is to allow configuration of quality settings regardless of the ground truth job's presence, consider restructuring the conditions.

Apply this diff to adjust the placement of the 'Settings' tab:

 if (instance && settingsInitialized) {
     // Existing code for backNavigation and title...

     const tabsItems: NonNullable<TabsProps['items']>[0][] = [];

     tabsItems.push({
         key: 'overview',
         label: 'Overview',
         children: (
             <QualityOverviewTab task={instance} targetMetric={targetMetric} />
         ),
     });

+    tabsItems.push({
+        key: 'settings',
+        label: 'Settings',
+        children: (
+            <QualitySettingsTab
+                fetching={qualitySettingsFetching}
+                qualitySettings={qualitySettings}
+                setQualitySettings={onSaveQualitySettings}
+            />
+        ),
+    });

     if (gtJobInstance && gtJobMeta && validationLayout) {
         tabsItems.push({
             key: 'management',
             label: 'Management',
             children: (
                 <QualityManagementTab
                     task={instance}
                     gtJobId={gtJobInstance.id}
                     gtJobMeta={gtJobMeta}
                     validationLayout={validationLayout}
                     onDeleteFrames={onDeleteFrames}
                     onRestoreFrames={onRestoreFrames}
                     fetching={fetching}
                 />
             ),
         });
     }

     tabs = (
         <Tabs
             type='card'
             activeKey={activeTab}
             defaultActiveKey='Overview'
             onChange={onTabKeyChange}
             className='cvat-task-control-tabs'
             items={tabsItems}
         />
     );
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ffe45fe and 32abd1f.

📒 Files selected for processing (13)
  • cvat-core/src/api.ts (2 hunks)
  • cvat-core/src/index.ts (2 hunks)
  • cvat-core/src/server-proxy.ts (2 hunks)
  • cvat-core/src/server-response-types.ts (1 hunks)
  • cvat-core/src/session-implementation.ts (4 hunks)
  • cvat-core/src/session.ts (3 hunks)
  • cvat-core/src/validation-layout.ts (2 hunks)
  • cvat-ui/src/components/quality-control/quality-control-page.tsx (10 hunks)
  • cvat-ui/src/components/quality-control/task-quality/allocation-table.tsx (5 hunks)
  • cvat-ui/src/components/quality-control/task-quality/quality-magement-tab.tsx (3 hunks)
  • cvat-ui/src/components/quality-control/task-quality/summary.tsx (1 hunks)
  • cvat-ui/src/cvat-core-wrapper.ts (2 hunks)
  • cvat-ui/src/reducers/index.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (35)
cvat-ui/src/components/quality-control/task-quality/summary.tsx (4)

19-21: LGTM! Proper implementation of the new 'mode' property.

The destructuring of the 'mode' property from props is correctly implemented and maintains consistency with the existing code style.


36-36: LGTM! Improved clarity in UI text.

The update from "Total count:" to "Total validation frames:" enhances clarity and provides better context for users. This change aligns well with the overall purpose of the component.


52-52: LGTM! Consistent improvement in label clarity.

The update from "Active count:" to "Active validation frames:" is consistent with other label changes in the component. This change enhances clarity and specificity for users.


Line range hint 1-72: Overall, excellent improvements to the SummaryComponent!

The changes in this file significantly enhance the clarity and functionality of the component. The introduction of the 'mode' property and the updated UI text provide better context for users regarding validation frames. The code maintains consistency with the existing style and React best practices.

Key improvements:

  1. Added type safety with the new 'mode' property
  2. Enhanced UI clarity with more descriptive labels
  3. Introduced conditional rendering for different validation modes
  4. Provided more comprehensive information about validation frames

These changes align well with the PR objectives and improve the overall user experience. Great job!

cvat-ui/src/cvat-core-wrapper.ts (1)

109-110: LGTM! Export changes are consistent.

The addition of JobValidationLayout and TaskValidationLayout to the export list is consistent with the import changes and maintains the module's structure. This change makes these new layouts available for use in other parts of the application.

cvat-core/src/index.ts (2)

35-35: LGTM: Import statement updated to reflect new validation layout types.

The change from a single ValidationLayout import to separate JobValidationLayout and TaskValidationLayout imports is a good improvement. This update likely enhances type safety and provides better clarity in distinguishing between job and task validation layouts throughout the codebase.


Line range hint 1-226: Overall assessment: Changes improve type safety and clarity.

The modifications to cvat-core/src/index.ts are well-implemented and align with the PR objectives. The introduction of separate JobValidationLayout and TaskValidationLayout types enhances type safety and provides better clarity in distinguishing between job and task validation layouts. These changes should contribute to improved code maintainability and reduced potential for type-related errors.

cvat-core/src/server-response-types.ts (1)

533-537: LGTM. Please add documentation and clarify the mode property.

The SerializedTaskValidationLayout interface looks good. It extends SerializedJobValidationLayout and adds task-specific properties.

  1. Add JSDoc comments to explain the purpose of this interface and its properties.
  2. Clarify the meaning and implications of the mode property values ('gt', 'gt_pool', null). What do these modes represent in the context of task validation?
  3. Consider using more descriptive names for validation_frames and disabled_frames if possible, or add comments explaining their purpose.

To ensure consistent usage of the new mode property, let's check for its implementation across the codebase:

✅ Verification successful

Verification Successful

The mode property is correctly implemented and used as described in the SerializedTaskValidationLayout interface.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of 'mode' property in the context of task validation
rg --type typescript --type javascript -i "mode.*['\"]gt['\"]|mode.*['\"]gt_pool['\"]|mode\s*:\s*null" -g '!*test*'

Length of output: 160


Script:

#!/bin/bash
# Search for usage of 'mode' property in TypeScript and JavaScript files
rg -g "*.ts" -g "*.js" -i "mode\s*[:=]\s*['\"]gt['\"]|mode\s*[:=]\s*['\"]gt_pool['\"]|mode\s*[:=]\s*null" -A 2 -- '!*test*'

Length of output: 181


Script:

#!/bin/bash
# Search for usage of 'mode' property in TypeScript and JavaScript files, excluding test files
rg -g "*.ts" -g "*.js" -g "!*test*" -i "mode\s*[:=]\s*['\"]gt['\"]|mode\s*[:=]\s*['\"]gt_pool['\"]|mode\s*[:=]\s*null"

Length of output: 262

cvat-core/src/api.ts (2)

430-431: LGTM: New validation layout classes added to the classes object.

The addition of JobValidationLayout and TaskValidationLayout to the classes object aligns with the import changes and makes these new classes available throughout the CVAT application. This is a good step towards more modular and specific validation layouts.

However, we should verify the removal of the old ValidationLayout class:

#!/bin/bash
# Description: Verify the removal of the old ValidationLayout class

# Test 1: Check if ValidationLayout is still present in this file
grep -n "ValidationLayout" cvat-core/src/api.ts

# Test 2: Search for any remaining usage of ValidationLayout in the codebase
rg "ValidationLayout" --type ts

If Test 1 returns any results or if Test 2 finds usages outside of import statements or comments, we may need to address those occurrences to complete the refactoring process.


29-29: LGTM: Import statement updated to reflect modular validation layouts.

The change from a default import to named imports for JobValidationLayout and TaskValidationLayout suggests a good refactoring of the validation-layout module. This separation likely improves modularity and maintainability.

To ensure consistency, let's verify the structure of the validation-layout module:

✅ Verification successful

✅ Verified: Validation-layout module structure confirmed.

The validation-layout.ts file correctly exports JobValidationLayout and TaskValidationLayout classes. All import statements and usages across the codebase are consistent and properly implemented.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the structure of the validation-layout module

# Test: Check if the validation-layout file exists and exports the correct classes
cat cvat-core/src/validation-layout.ts

Length of output: 5851

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

Line range hint 1-1037: Overall assessment: Positive change with minimal impact

The modification in this file is limited to a single type change in the AnnotationState interface. This change from ValidationLayout to JobValidationLayout improves type specificity and is consistent with the reported changes in import statements. The rest of the file, which defines various interfaces and enums for the application state, remains unchanged. This isolated change suggests a focused refactoring effort to improve job-related type handling.

To ensure a smooth transition, please make sure that:

  1. All related components and functions using the AnnotationState interface are updated to work with the new JobValidationLayout type.
  2. Any serialization/deserialization logic handling this data is adjusted if necessary.
  3. Unit tests covering this part of the state are updated to reflect the new type.
cvat-core/src/session.ts (2)

31-31: LGTM: Import statement updated correctly

The import statement has been updated to include JobValidationLayout and TaskValidationLayout instead of the generic ValidationLayout. This change aligns with the modifications in the Job and Task classes, providing more specific validation layout types.


31-31: Summary: Improved type safety for validation layouts

The changes in this file represent a cohesive update to the validation layout system:

  1. The import statement now includes specific JobValidationLayout and TaskValidationLayout types.
  2. The Job class's validationLayout method now returns Promise<JobValidationLayout | null>.
  3. The Task class's validationLayout method now returns Promise<TaskValidationLayout | null>.

These changes improve type safety and make the code more self-documenting. They should help prevent type-related errors and make it easier for developers to understand the expected structure of validation layouts for jobs and tasks.

Also applies to: 689-692, 1189-1192

cvat-core/src/server-proxy.ts (2)

1387-1387: Update function return type to use union type

The return type of the validationLayout function has been updated to use a union type SerializedJobValidationLayout | SerializedTaskValidationLayout. This change improves type safety by specifying that the function can return either a job validation layout or a task validation layout.


Line range hint 1-1391: Summary of review

  1. The changes to the validationLayout function improve type safety by using a union type for the return value.
  2. Some surrounding functions could benefit from improved type safety by replacing any types with more specific types.
  3. There are TODO comments throughout the file that should be addressed to reduce technical debt.

Overall, the changes are good, but there's room for further improvements in the codebase.

cvat-ui/src/components/quality-control/task-quality/quality-magement-tab.tsx (2)

9-9: Import statement updated correctly

The TaskValidationLayout has been properly imported from 'cvat-core-wrapper'.


56-56: Confirm AllocationTable component accepts gtJobId

Ensure that the AllocationTable component has been updated to accept gtJobId instead of gtJob. Verify that all internal references within AllocationTable have been adjusted accordingly to prevent any breaking changes.

Run the following script to check for references to gtJob in AllocationTable:

cvat-core/src/validation-layout.ts (11)

5-5: Import statements are correct

The required serialized types are correctly imported from 'server-response-types'.


13-16: Constructor initializes fields correctly

The constructor properly initializes the private fields, using the nullish coalescing operator to handle undefined values.


19-21: Getter for honeypotCount is implemented correctly

The honeypotCount getter accurately returns the value of #honeypotCount.


23-25: Getter for honeypotFrames is implemented correctly

The honeypotFrames getter returns a copy of the #honeypotFrames array, preventing external mutations.


27-29: Getter for honeypotRealFrames is implemented correctly

The honeypotRealFrames getter returns a copy of the #honeypotRealFrames array, ensuring immutability from outside the class.


Line range hint 37-49: Implementation of getRealFrame is correctly defined

The Object.defineProperties method is used to define the implementation of getRealFrame, which seems consistent with the plugin architecture used in the project.


57-62: Constructor correctly initializes additional fields

The constructor of TaskValidationLayout correctly calls the parent constructor and initializes the new private fields introduced in this subclass.


64-66: Getter for mode is implemented correctly

The mode getter returns the value of #mode, providing access to the task's validation mode.


68-70: Getter for validationFrames is implemented correctly

The validationFrames getter returns a copy of the #validationFrames array, which ensures that the original array remains unmodified.


72-74: Getter for disabledFrames is implemented correctly

The disabledFrames getter returns a copy of the #disabledFrames array, maintaining the integrity of the class's internal state.


32-34: Verify the usage of PluginRegistry.apiWrapper.call

In the getRealFrame method, the PluginRegistry.apiWrapper.call is used with JobValidationLayout.prototype.getRealFrame. Ensure that this usage aligns with the project's plugin architecture and that the method references are correctly set up.

Run the following script to check the implementation and usage:

cvat-ui/src/components/quality-control/task-quality/allocation-table.tsx (5)

17-17: Import statement updated correctly

The addition of TaskValidationLayout to the import statement ensures that the component has access to the necessary type definitions.


23-25: Props interface updated appropriately

The Props interface now includes gtJobId and validationLayout, reflecting the changes in data handling. This modification aligns with the updated structure of the component's requirements.


38-38: Destructuring props includes new properties

Destructuring gtJobId and validationLayout from props is correct and matches the updated Props interface.


70-70: Navigation update uses correct job ID

The history.push call correctly utilizes gtJobId to navigate to the appropriate job frame.


91-91: Navigation handler updated appropriately

The onClick handler now correctly references gtJobId and record.frame to navigate, ensuring consistency with the updated props.

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

30-33: Imports of Serialized Validation Layouts are Correct

The added imports of SerializedJobValidationLayout and SerializedTaskValidationLayout from './server-response-types' are appropriate and necessary for handling the new validation layouts in the code.


43-43: Imports of Validation Layout Classes are Correct

The imports of JobValidationLayout and TaskValidationLayout from './validation-layout' are correctly added and align with their usage in the validationLayoutImplementation methods.

@@ -35,7 +35,7 @@ import Comment from 'cvat-core/src/comment';
import User from 'cvat-core/src/user';
import Organization, { Membership, Invitation } from 'cvat-core/src/organization';
import AnnotationGuide from 'cvat-core/src/guide';
import ValidationLayout from 'cvat-core/src/validation-layout';
import { JobValidationLayout, TaskValidationLayout } from 'cvat-core/src/validation-layout';
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

ValidationLayout is still used in multiple files.

The refactoring to JobValidationLayout and TaskValidationLayout did not completely replace all instances of ValidationLayout. Please update all remaining usages to ensure consistency and prevent potential issues.

  • cvat-ui/src/cvat-core-wrapper.ts
  • cvat-ui/src/reducers/index.ts
  • cvat-ui/src/components/quality-control/quality-control-page.tsx
  • cvat-ui/src/components/quality-control/task-quality/quality-magement-tab.tsx
  • cvat-ui/src/components/quality-control/task-quality/allocation-table.tsx
  • cvat-ui/src/actions/annotation-actions.ts
  • cvat-core/src/validation-layout.ts
  • cvat-core/src/session.ts
  • cvat-core/src/session-implementation.ts
  • cvat-core/src/server-proxy.ts
  • cvat-core/src/index.ts
  • cvat-core/src/api.ts
🔗 Analysis chain

LGTM! Verify usage of new validation layouts.

The import change from a single ValidationLayout to specific JobValidationLayout and TaskValidationLayout aligns with the restructuring mentioned in the PR summary. This change improves granularity and allows for more specific handling of job and task validations.

To ensure consistency across the codebase, please run the following script to verify the usage of these new layouts:


Update: Adjusted the search to target .ts and .tsx files since typescript is not a recognized file type in the current environment. Please run the following updated script to verify the usage of the new validation layouts:

[/run_scripts]

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of JobValidationLayout and TaskValidationLayout

# Test: Search for ValidationLayout usage
echo "Searching for any remaining ValidationLayout usage:"
rg --type typescript "ValidationLayout"

# Test: Search for JobValidationLayout and TaskValidationLayout usage
echo "Searching for JobValidationLayout and TaskValidationLayout usage:"
rg --type typescript "JobValidationLayout|TaskValidationLayout"

Length of output: 429


Script:

#!/bin/bash
# Description: Verify the usage of JobValidationLayout and TaskValidationLayout

# Test: Search for any remaining ValidationLayout usage in .ts and .tsx files
echo "Searching for any remaining ValidationLayout usage:"
rg "ValidationLayout" --glob "*.ts" --glob "*.tsx"

# Test: Search for JobValidationLayout and TaskValidationLayout usage in .ts and .tsx files
echo "Searching for JobValidationLayout and TaskValidationLayout usage:"
rg "JobValidationLayout|TaskValidationLayout" --glob "*.ts" --glob "*.tsx"

Length of output: 11147

Comment on lines +219 to +220
JobValidationLayout: typeof JobValidationLayout;
TaskValidationLayout: typeof TaskValidationLayout;
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

⚠️ Issues Found: Residual ValidationLayout Usages Detected

The verification script identified remaining usages of the old ValidationLayout type in the following files:

  • cvat-ui/src/actions/annotation-actions.ts
  • cvat-core/src/actions/annotation-actions.ts

Please update these instances to use JobValidationLayout and TaskValidationLayout instead of the deprecated ValidationLayout to maintain consistency and ensure type safety throughout the codebase.

🔗 Analysis chain

LGTM: New validation layout types added to classes.

The addition of JobValidationLayout and TaskValidationLayout to the classes section is consistent with the import changes and represents a good improvement in type specificity. This change should enhance type safety and code clarity when working with validation layouts for jobs and tasks.

To ensure this change is consistently applied throughout the codebase, please run the following verification script:


Action Required: Update verification scripts due to errors in initial execution.


Action Required: Correct the verification scripts to address ripgrep errors.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining usage of the old ValidationLayout type and verify the usage of new types.

# Test 1: Check for any remaining usage of ValidationLayout
echo "Checking for any remaining usage of ValidationLayout:"
rg --type typescript "ValidationLayout(?!.*JobValidationLayout.*TaskValidationLayout)" -g '!cvat-core/src/index.ts'

# Test 2: Verify the usage of new JobValidationLayout and TaskValidationLayout types
echo "Verifying usage of new JobValidationLayout and TaskValidationLayout types:"
rg --type typescript "JobValidationLayout|TaskValidationLayout"

# Note: Review the output to ensure that ValidationLayout has been replaced everywhere necessary,
# and that JobValidationLayout and TaskValidationLayout are being used appropriately.

Length of output: 777


Script:

#!/bin/bash
# Description: Check for any remaining usage of the old ValidationLayout type and verify the usage of new types.

# Test 1: Check for any remaining usage of ValidationLayout using PCRE2 to support look-around
echo "Checking for any remaining usage of ValidationLayout:"
rg --pcre2 --type typescript "ValidationLayout(?!.*JobValidationLayout.*TaskValidationLayout)" -g '!cvat-core/src/index.ts'

# Test 2: Verify the usage of new JobValidationLayout and TaskValidationLayout types using file extensions
echo "Verifying usage of new JobValidationLayout and TaskValidationLayout types:"
rg "JobValidationLayout|TaskValidationLayout" -g '*.ts' -g '*.tsx'

# Note: Review the output to ensure that ValidationLayout has been replaced everywhere necessary,
# and that JobValidationLayout and TaskValidationLayout are being used appropriately.

Length of output: 5658


Script:

#!/bin/bash
# Description: Check for any remaining usage of the old ValidationLayout type and verify the usage of new types.

# Test 1: Check for any remaining usage of ValidationLayout using PCRE2 to support look-around
echo "Checking for any remaining usage of ValidationLayout:"
rg --pcre2 "ValidationLayout(?!.*JobValidationLayout.*TaskValidationLayout)" -g '*.ts' -g '*.tsx' -g '!cvat-core/src/index.ts'

# Test 2: Verify the usage of new JobValidationLayout and TaskValidationLayout types using file extensions
echo "Verifying usage of new JobValidationLayout and TaskValidationLayout types:"
rg "JobValidationLayout|TaskValidationLayout" -g '*.ts' -g '*.tsx'

# Note: Review the output to ensure that ValidationLayout has been replaced everywhere necessary,
# and that JobValidationLayout and TaskValidationLayout are being used appropriately.

Length of output: 10973

@@ -730,7 +730,7 @@ export interface AnnotationState {
defaultPointsCount: number | null;
};
groundTruthInfo: {
validationLayout: ValidationLayout | null;
validationLayout: JobValidationLayout | null;
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

ValidationLayout Usage Detected in Multiple Files

Several remaining usages of ValidationLayout were found across the codebase:

  • cvat-ui/src/actions/annotation-actions.ts: validationLayout: ValidationLayout | null;
  • cvat-ui/src/cvat-core-wrapper.ts: Imports and usage of ValidationLayout
  • cvat-ui/src/components/quality-control/quality-control-page.tsx: Multiple instances of ValidationLayout
  • cvat-ui/src/components/quality-control/task-quality/quality-magement-tab.tsx: Import and usage of ValidationLayout
  • cvat-ui/src/components/quality-control/task-quality/allocation-table.tsx: Import and usage of ValidationLayout
  • cvat-core/src/validation-layout.ts: Definitions related to ValidationLayout
  • cvat-core/src/api.ts: Imports of ValidationLayout
  • cvat-core/src/session-implementation.ts: Usage of ValidationLayout
  • cvat-core/src/index.ts: Imports and definitions involving ValidationLayout
  • cvat-core/src/session.ts: Methods returning ValidationLayout

Please review these occurrences to ensure they align with the recent type changes and refactoring efforts.

🔗 Analysis chain

LGTM! Consider verifying usage across the codebase.

The change from ValidationLayout to JobValidationLayout improves type specificity for job-related validation layouts. This is a good improvement for type safety and code clarity.

To ensure this change doesn't introduce any unintended side effects, please run the following script to check for any remaining usage of ValidationLayout in the codebase:

If the script returns any results, please review those occurrences to ensure they are updated accordingly.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining usage of ValidationLayout in the codebase

# Search for ValidationLayout in TypeScript and JavaScript files
echo "Searching for ValidationLayout usage:"
rg --type-add 'script:*.{ts,tsx,js,jsx}' -t script 'ValidationLayout'

# Search for imports of ValidationLayout
echo "\nSearching for ValidationLayout imports:"
rg --type-add 'script:*.{ts,tsx,js,jsx}' -t script 'import.*ValidationLayout'

Length of output: 6947

@@ -41,6 +42,7 @@ function QualityManagementTab(props: Readonly<Props>): JSX.Element {
<Row>
<Col span={24}>
<SummaryComponent
mode={validationLayout.mode}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Pass mode prop safely to SummaryComponent

Ensure that validationLayout.mode is defined before passing it to SummaryComponent to avoid potential undefined property access.

Consider modifying the code as follows:

- mode={validationLayout.mode}
+ mode={validationLayout?.mode || 'default'}

Replace 'default' with an appropriate default mode if necessary.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
mode={validationLayout.mode}
mode={validationLayout?.mode || 'default'}

Comment on lines +29 to +30
const totalCount = validationLayout.validationFrames.length;
const excludedCount = validationLayout.disabledFrames.length;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure safe access to validationLayout properties

To prevent potential runtime errors, consider adding null or undefined checks for validationLayout before accessing its properties validationFrames and disabledFrames. This will ensure the component handles cases where validationLayout might not be provided.

Apply this diff to include safe access:

- const totalCount = validationLayout.validationFrames.length;
- const excludedCount = validationLayout.disabledFrames.length;
+ const totalCount = validationLayout?.validationFrames?.length || 0;
+ const excludedCount = validationLayout?.disabledFrames?.length || 0;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const totalCount = validationLayout.validationFrames.length;
const excludedCount = validationLayout.disabledFrames.length;
const totalCount = validationLayout?.validationFrames?.length || 0;
const excludedCount = validationLayout?.disabledFrames?.length || 0;

Comment on lines +52 to +55
export class TaskValidationLayout extends JobValidationLayout {
#mode: TaskValidationLayout['mode'];
#validationFrames: TaskValidationLayout['validationFrames'];
#disabledFrames: TaskValidationLayout['disabledFrames'];
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid circular type references in TaskValidationLayout's private fields

Similar to JobValidationLayout, the private fields in TaskValidationLayout are defined using types that reference themselves, which can cause circular references.

Consider declaring the types explicitly:

export class TaskValidationLayout extends JobValidationLayout {
-    #mode: TaskValidationLayout['mode'];
-    #validationFrames: TaskValidationLayout['validationFrames'];
-    #disabledFrames: TaskValidationLayout['disabledFrames'];
+    #mode: NonNullable<SerializedTaskValidationLayout['mode']>;
+    #validationFrames: number[];
+    #disabledFrames: number[];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export class TaskValidationLayout extends JobValidationLayout {
#mode: TaskValidationLayout['mode'];
#validationFrames: TaskValidationLayout['validationFrames'];
#disabledFrames: TaskValidationLayout['disabledFrames'];
export class TaskValidationLayout extends JobValidationLayout {
#mode: NonNullable<SerializedTaskValidationLayout['mode']>;
#validationFrames: number[];
#disabledFrames: number[];

Comment on lines +48 to +54
const { disabledFrames } = validationLayout;
const data = validationLayout.validationFrames.map((frame: number, index: number) => ({
key: frame,
frame,
name: gtJobMeta.frames[index]?.name ?? gtJobMeta.frames[0].name,
active: !disabledFrames.includes(frame),
}));
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle potential undefined or mismatched frame data

In the data mapping function, there is a possibility of gtJobMeta.frames[index] being undefined if gtJobMeta.frames doesn't have a frame at the given index. Accessing .name on undefined will result in a runtime error. Similarly, accessing gtJobMeta.frames[0] assumes that there is at least one frame available.

Consider adding a check to ensure that gtJobMeta.frames contains frames at the expected indices. You can provide a default value or handle cases where frames are missing.

Apply this diff to handle potential undefined frames:

 name: gtJobMeta.frames[index]?.name
-    ?? gtJobMeta.frames[0].name,
+    ?? (gtJobMeta.frames[0]?.name ?? 'Unnamed Frame'),

This change adds an extra layer of safety by checking if gtJobMeta.frames[0] exists before accessing .name, and provides a fallback 'Unnamed Frame' if neither is available.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const { disabledFrames } = validationLayout;
const data = validationLayout.validationFrames.map((frame: number, index: number) => ({
key: frame,
frame,
name: gtJobMeta.frames[index]?.name ?? gtJobMeta.frames[0].name,
active: !disabledFrames.includes(frame),
}));
const { disabledFrames } = validationLayout;
const data = validationLayout.validationFrames.map((frame: number, index: number) => ({
key: frame,
frame,
name: gtJobMeta.frames[index]?.name
?? (gtJobMeta.frames[0]?.name ?? 'Unnamed Frame'),
active: !disabledFrames.includes(frame),
}));

Comment on lines +251 to +258
const updateMeta = async (): Promise<void> => {
dispatch(reducerActions.setFetching(true));
try {
const [newMeta] = await (state.gtJobInstance as Job).frames.save();
const validationLayout: TaskValidationLayout | null = await (instance as Task).validationLayout();
dispatch(reducerActions.setGtJobMeta(newMeta));
dispatch(reducerActions.setValidationLayout(validationLayout));
} finally {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null checks to prevent potential null references in 'updateMeta' function

In the updateMeta function, state.gtJobInstance and instance are used without verifying if they are not null. If either is null, this could lead to runtime errors when attempting to access their properties or methods.

Apply this diff to add null checks:

 const updateMeta = async (): Promise<void> => {
     dispatch(reducerActions.setFetching(true));
     try {
+        if (state.gtJobInstance && instance) {
             const [newMeta] = await state.gtJobInstance.frames.save();
             const validationLayout: TaskValidationLayout | null = await instance.validationLayout();
             dispatch(reducerActions.setGtJobMeta(newMeta));
             dispatch(reducerActions.setValidationLayout(validationLayout));
+        } else {
+            notification.error({
+                message: 'Unable to update metadata',
+                description: 'Ground truth job instance or task instance is not available.',
+            });
+        }
     } finally {
         dispatch(reducerActions.setFetching(false));
     }
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const updateMeta = async (): Promise<void> => {
dispatch(reducerActions.setFetching(true));
try {
const [newMeta] = await (state.gtJobInstance as Job).frames.save();
const validationLayout: TaskValidationLayout | null = await (instance as Task).validationLayout();
dispatch(reducerActions.setGtJobMeta(newMeta));
dispatch(reducerActions.setValidationLayout(validationLayout));
} finally {
const updateMeta = async (): Promise<void> => {
dispatch(reducerActions.setFetching(true));
try {
if (state.gtJobInstance && instance) {
const [newMeta] = await state.gtJobInstance.frames.save();
const validationLayout: TaskValidationLayout | null = await instance.validationLayout();
dispatch(reducerActions.setGtJobMeta(newMeta));
dispatch(reducerActions.setValidationLayout(validationLayout));
} else {
notification.error({
message: 'Unable to update metadata',
description: 'Ground truth job instance or task instance is not available.',
});
}
} finally {
dispatch(reducerActions.setFetching(false));
}
};

@@ -171,7 +174,7 @@ export function implementJob(Job: typeof JobClass): typeof JobClass {
): ReturnType<typeof JobClass.prototype.validationLayout> {
const result = await serverProxy.jobs.validationLayout(this.id);
if (Object.keys(result).length) {
return new ValidationLayout(result as Required<SerializedValidationLayout>);
return new JobValidationLayout(result as SerializedJobValidationLayout);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure 'result' is not null or undefined before accessing its properties

In the Job.prototype.validationLayout implementation, there is a check for Object.keys(result).length, but if result is null or undefined, accessing Object.keys(result) can cause a runtime error.

Consider adding a null check for result before accessing its properties:

 async function validationLayoutImplementation(
     this: JobClass,
 ): ReturnType<typeof JobClass.prototype.validationLayout> {
     const result = await serverProxy.jobs.validationLayout(this.id);
-    if (Object.keys(result).length) {
+    if (result && Object.keys(result).length) {
         return new JobValidationLayout(result as SerializedJobValidationLayout);
     }
     return null;
 }

Committable suggestion was skipped due to low confidence.

Comment on lines +647 to +649
const result = await serverProxy.tasks.validationLayout(this.id) as SerializedTaskValidationLayout;
if (result.mode !== null) {
return new TaskValidationLayout(result);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null check for 'result' before accessing 'result.mode'

In the Task.prototype.validationLayout implementation, there is an assumption that result is not null or undefined. If serverProxy.tasks.validationLayout(this.id) returns null or undefined, accessing result.mode will result in a runtime error.

Recommend adding a null check for result:

 const result = await serverProxy.tasks.validationLayout(this.id) as SerializedTaskValidationLayout;
- if (result.mode !== null) {
+ if (result && result.mode !== null) {
     return new TaskValidationLayout(result);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const result = await serverProxy.tasks.validationLayout(this.id) as SerializedTaskValidationLayout;
if (result.mode !== null) {
return new TaskValidationLayout(result);
const result = await serverProxy.tasks.validationLayout(this.id) as SerializedTaskValidationLayout;
if (result && result.mode !== null) {
return new TaskValidationLayout(result);

@codecov-commenter
Copy link

codecov-commenter commented Oct 21, 2024

Codecov Report

Attention: Patch coverage is 75.86207% with 7 lines in your changes missing coverage. Please review.

Project coverage is 74.27%. Comparing base (c557f70) to head (b598ff0).
Report is 6 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8558   +/-   ##
========================================
  Coverage    74.26%   74.27%           
========================================
  Files          400      400           
  Lines        43218    43238   +20     
  Branches      3909     3914    +5     
========================================
+ Hits         32096    32113   +17     
- Misses       11122    11125    +3     
Components Coverage Δ
cvat-ui 78.73% <75.86%> (+<0.01%) ⬆️
cvat-server 70.46% <66.66%> (-0.01%) ⬇️

Copy link

@bsekachev bsekachev merged commit e3e8d99 into develop Oct 21, 2024
34 checks passed
@bsekachev bsekachev deleted the bs/allocation_report branch October 24, 2024 05:15
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