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

Hide mask during editing #8554

Merged
merged 34 commits into from
Oct 31, 2024
Merged

Hide mask during editing #8554

merged 34 commits into from
Oct 31, 2024

Conversation

klakhov
Copy link
Contributor

@klakhov klakhov commented Oct 17, 2024

Motivation and context

Added ability to hide a mask during editing
hide-mask

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

Release Notes

  • New Features

    • Added the ability to hide edited objects in the canvas configuration.
    • Enhanced drawing functionality with visibility controls for shapes.
    • Introduced new methods for managing the state of edited annotations.
  • Bug Fixes

    • Improved handling of drawing actions based on visibility states.
  • Documentation

    • Updated interfaces and action types to reflect new features and state management capabilities.
  • Chores

    • Refined component logic to support new visibility state management.

@klakhov klakhov added the ui/ux label Oct 17, 2024
@klakhov klakhov marked this pull request as ready for review October 18, 2024 11:20
Copy link
Contributor

coderabbitai bot commented Oct 18, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduced in this pull request enhance the configuration and visibility management of edited objects in the canvas model. A new optional property hideEditedObject is added to the Configuration interface, affecting various components such as DrawHandlerImpl, MasksHandlerImpl, and UI elements. The editedState is integrated into the state management system, allowing for better control over the visibility of edited shapes. New methods and properties are introduced across multiple files to support these functionalities, ensuring a cohesive experience when managing annotations and their visibility.

Changes

File Path Change Summary
cvat-canvas/src/typescript/canvasModel.ts Added hideEditedObject?: boolean to Configuration. Updated constructor and configure method.
cvat-canvas/src/typescript/drawHandler.ts Added private isHidden: boolean. Introduced updateDrawInstance, updateInnerCircles, and modified drawPolyshape.
cvat-canvas/src/typescript/masksHandler.ts Added private isHidden: boolean, updateHidden, and updated configurate method. Changed latestMousePos type to Position.
cvat-canvas/src/typescript/svg.patch.ts Updated SVG.Element.prototype.draw methods. Added undo function and new methods for transforming shapes.
cvat-ui/src/actions/annotation-actions.ts Added updateEditedStateAsync, resetEditedStateAsync, resetEditedState, changeHideEditedStateAsync. Updated AnnotationActionTypes enum.
cvat-ui/src/components/annotation-page/canvas/views/canvas2d/brush-tools.tsx Added editedState variable and integrated changeHideEditedStateAsync. Updated rendering logic.
cvat-ui/src/components/annotation-page/canvas/views/canvas2d/canvas-wrapper.tsx Added onUpdateEditedObject and onResetEditedObject methods to DispatchToProps.
cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/object-buttons.tsx Updated import statements. Added changeHideEditedState method and updated StateToProps interface.
cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/objects-list.tsx Integrated changeHideEditedStateAsync. Updated StateToProps and DispatchToProps interfaces.
cvat-ui/src/reducers/annotation-reducer.ts Added editedState to defaultState. Introduced new action types: RESET_EDITED_STATE, UPDATE_EDITED_STATE, HIDE_EDITED_STATE.
cvat-ui/src/reducers/index.ts Added EditedState interface and updated AnnotationState to include editedState.

Poem

In the canvas where shapes play,
A toggle hides them, come what may.
With a flick, they vanish from sight,
Edited states dance in the light.
A brush, a click, a hidden trace,
In our world, they find their place! 🐇✨


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

🧹 Outside diff range and nitpick comments (7)
cvat-canvas/src/typescript/canvasModel.ts (1)

986-989: Implementation of hideEditedObject configuration

The configure method has been updated to handle the new hideEditedObject option. This allows users to dynamically change the visibility of edited objects during runtime.

However, consider adding a comment explaining the purpose and impact of this new configuration option for better maintainability.

 if (typeof configuration.hideEditedObject === 'boolean') {
+    // Controls whether the object being edited should be hidden during the editing process
     this.data.configuration.hideEditedObject = configuration.hideEditedObject;
 }
cvat-ui/src/reducers/annotation-reducer.ts (1)

644-657: LGTM: UPDATE_EDITED_STATE case implementation with a minor suggestion

The UPDATE_EDITED_STATE case correctly updates the shapeType and editedStateInstance properties of the editedState object. The use of the nullish coalescing operator (??) ensures that null values are set when the payload properties are undefined.

For consistency with the RESET_EDITED_STATE case, consider explicitly preserving the editedStateHidden property:

 editedState: {
     ...state.annotations.editedState,
     shapeType: (shapeType ?? null),
     editedStateInstance: (editedStateInstance ?? null),
+    editedStateHidden: state.annotations.editedState.editedStateHidden,
 },

This change isn't strictly necessary due to the spread operator, but it makes the code more explicit and consistent with the other cases.

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

373-383: Simplify className construction for improved readability

The className property is currently constructed using array concatenation and join, which can be simplified for better readability. Consider using template literals or the classnames utility for cleaner code.

For example, you can rewrite it as:

className={`cvat-brush-tools-hide ${editedState.editedStateHidden ? 'cvat-brush-tools-active-tool' : ''}`}

373-383: Add unit tests for the new hide/show edited mask functionality

To ensure the new feature works correctly and to prevent future regressions, please consider adding unit tests that cover the hide/show functionality of the edited mask.

Would you like assistance in creating these tests or opening a GitHub issue to track this task?

cvat-canvas/src/typescript/svg.patch.ts (1)

Line range hint 99-100: Simplify array destructuring for this.p.x and this.p.y

Currently, this.p.x and this.p.y are assigned separately from array[i]. You can simplify the code by destructuring both values in a single statement.

Apply this diff:

-        [this.p.x] = array[i];
-        [, this.p.y] = array[i];
+        [this.p.x, this.p.y] = array[i];
cvat-canvas/src/typescript/drawHandler.ts (2)

1309-1317: Avoid using 'any'; define proper typings for 'paintHandler'.

The use of as any when casting paintHandler can obscure type checking and potentially introduce errors. Consider defining an interface or type for paintHandler to enhance type safety and maintainability.

Suggested improvement:

Define a type for paintHandler if possible, for example:

interface PaintHandler {
    set: {
        members: SVG.Element[];
    };
}

Then, you can use:

const paintHandler = this.drawInstance.remember('_paintHandler') as PaintHandler;

Line range hint 1319-1343: Fix typo in variable name 'isFilalblePolygon'.

The variable isFilalblePolygon appears to be misspelled. It should be isFillablePolygon to maintain consistency and readability.

Apply this diff to correct the typo:

- const isFilalblePolygon = this.drawData && this.drawData.shapeType === 'polygon';
+ const isFillablePolygon = this.drawData && this.drawData.shapeType === 'polygon';

Also, update all usages of isFilalblePolygon to isFillablePolygon within the method:

- if (this.drawInstance && (isFilalblePolygon)) {
+ if (this.drawInstance && (isFillablePolygon)) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5be5d59 and 60005d0.

📒 Files selected for processing (11)
  • cvat-canvas/src/typescript/canvasModel.ts (3 hunks)
  • cvat-canvas/src/typescript/drawHandler.ts (6 hunks)
  • cvat-canvas/src/typescript/masksHandler.ts (8 hunks)
  • cvat-canvas/src/typescript/svg.patch.ts (1 hunks)
  • cvat-ui/src/actions/annotation-actions.ts (2 hunks)
  • cvat-ui/src/components/annotation-page/canvas/views/canvas2d/brush-tools.tsx (5 hunks)
  • cvat-ui/src/components/annotation-page/canvas/views/canvas2d/canvas-wrapper.tsx (9 hunks)
  • cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/object-buttons.tsx (5 hunks)
  • cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/objects-list.tsx (8 hunks)
  • cvat-ui/src/reducers/annotation-reducer.ts (2 hunks)
  • cvat-ui/src/reducers/index.ts (3 hunks)
🧰 Additional context used
🔇 Additional comments (48)
cvat-ui/src/reducers/index.ts (4)

12-12: New import added for ObjectState

The ObjectState import has been added from 'cvat-core-wrapper'. This is likely to support the new EditedState interface.


696-700: New EditedState interface looks good

The new EditedState interface is well-structured and provides a clear representation of an edited state in the application. It includes:

  • shapeType: Allows for a ShapeType or null, providing flexibility.
  • editedStateInstance: Can be an ObjectState or null, which is good for handling various scenarios.
  • editedStateHidden: A boolean flag for visibility control.

This interface will help in managing and tracking edited states in the application.


780-780: AnnotationState interface updated with editedState property

The AnnotationState interface has been updated to include an editedState property of type EditedState. This addition is consistent with the newly created EditedState interface and will allow for tracking the currently edited state within the annotation process.


12-12: Summary of changes: Enhanced state management for edited states

The changes introduced in this file improve the state management capabilities for edited states in the annotation process. Here's a summary of the modifications:

  1. Added import for ObjectState from 'cvat-core-wrapper'.
  2. Introduced a new EditedState interface to represent the state of edited objects.
  3. Updated the AnnotationState interface to include an editedState property of type EditedState.

These changes provide a more structured way to handle and track edited states during the annotation process, which should improve the overall functionality and maintainability of the application.

Also applies to: 696-700, 780-780

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

99-99: New configuration option added: hideEditedObject

A new optional boolean property hideEditedObject has been added to the Configuration interface. This addition allows for more flexible control over the visibility of edited objects in the canvas.


420-420: Default value set for new configuration option

The hideEditedObject property is initialized with a default value of false in the CanvasModelImpl constructor. This ensures backward compatibility with existing implementations.


99-99: Summary of changes: New configuration option for hiding edited objects

The changes introduce a new configuration option hideEditedObject to the CanvasModel. This boolean option allows for controlling the visibility of objects being edited. The implementation includes:

  1. Adding the option to the Configuration interface
  2. Setting a default value in the CanvasModelImpl constructor
  3. Handling the option in the configure method

These changes provide more flexibility in how edited objects are displayed, which could be useful for various use cases such as reducing visual clutter or focusing on specific parts of an annotation.

To fully utilize this new feature, make sure to update any relevant UI components or documentation to reflect this new configuration option.

Also applies to: 420-420, 986-989

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

101-105: New editedState property added to annotations

The editedState property has been added to the annotations object in the defaultState. This new property includes shapeType, editedStateInstance, and editedStateHidden, which are all initialized with null or false values. This addition allows for tracking the current editing state of annotations.


630-643: LGTM: RESET_EDITED_STATE case implementation

The RESET_EDITED_STATE case correctly resets all properties of the editedState object to their initial values. This implementation ensures that the editing state can be cleared when necessary.


658-670: LGTM: HIDE_EDITED_STATE case implementation

The HIDE_EDITED_STATE case correctly updates the editedStateHidden property of the editedState object. The implementation preserves the other properties of editedState while updating the visibility state.

cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/object-buttons.tsx (6)

12-13: Import Statements Updated Correctly

The addition of changeHideEditedStateAsync and EditedState to the import statements is appropriate and follows the project's import conventions.


32-32: Added editedState to StateToProps Interface

Including editedState: EditedState in the StateToProps interface ensures that the component has access to the edited state from the Redux store.


38-38: Added changeHideEditedState to DispatchToProps Interface

Defining changeHideEditedState(value: boolean): void in the DispatchToProps interface allows the component to dispatch actions to change the hide state of the edited object.


44-44: Destructured editedState from Redux State

In mapStateToProps, extracting editedState from annotation.annotations ensures that the component receives the current edited state.


66-66: Passed editedState to Component Props

Including editedState in the returned object of mapStateToProps makes it available to the component, enabling conditional logic based on the edited state.


82-84: Implemented changeHideEditedState in mapDispatchToProps

The changeHideEditedState function correctly dispatches the changeHideEditedStateAsync action, aligning with Redux Thunk practices.

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

107-109: Well-structured use of useCallback for hideMask function

The hideMask function is properly memoized using useCallback, which helps prevent unnecessary re-renders by maintaining a stable function reference.

cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/objects-list.tsx (7)

22-22: ****


29-29: ****


60-60: ****


72-72: ****


186-186: ****


240-240: ****


271-273: ****

cvat-canvas/src/typescript/masksHandler.ts (9)

9-9: Import Position type for consistency

Adding Position to the import statement ensures type consistency across the codebase.


64-64: Use Position type for latestMousePos

Changing the type of latestMousePos to Position enhances type safety and clarity.


68-68: Add isHidden property to manage visibility state

Introducing the isHidden property allows the handler to manage the visibility of edited objects effectively.


221-224: Correct parameters in getImageData call

The parameters in the getImageData method correctly define the area from which to extract image data.


371-371: Initialize isHidden to false in constructor

Setting isHidden to false ensures the canvas is visible by default upon initialization.


474-474: Prevent drawing when canvas is hidden

Adding !this.isHidden to the condition correctly prevents drawing operations when the canvas is hidden.


589-592: Consistent parameter usage in imageDataToDataURL

Matching parameter adjustments in imageDataToDataURL calls ensures consistency in image processing functions.


683-686: Update parameters for imageDataToDataURL in edit flow

Adjusting the parameters when editing masks maintains consistency and correctness in the mask editing process.


552-555: Synchronize isHidden state with configuration

Updating the isHidden state based on configuration.hideEditedObject ensures that the visibility setting is applied correctly.

Ensure that the hideEditedObject property exists in the Configuration interface and is properly typed.

Run the following script to verify its presence:

If the property is not found, please update the Configuration interface accordingly.

✅ Verification successful

hideEditedObject property is correctly defined in the Configuration interface

The hideEditedObject property exists in the Configuration interface and is properly typed as an optional boolean.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that 'hideEditedObject' is defined in the 'Configuration' interface.

# Test: Search for the 'hideEditedObject' property definition in 'canvasModel.ts'.
# Expect: At least one match indicating the property is defined.

ast-grep --lang typescript --pattern 'interface Configuration { $$$; hideEditedObject?: boolean; $$$ }' ./src/typescript/canvasModel.ts

Length of output: 216


Script:

#!/bin/bash
# Description: Locate the 'Configuration' interface definition in the codebase.

# Search for the 'Configuration' interface definition across all TypeScript files.
# Expect: At least one match indicating where the interface is defined.

ast-grep --lang typescript --pattern 'interface Configuration { $$$ }' .

Length of output: 1714

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

48-49: Importing new action creators

The action creators updateEditedStateAsync and resetEditedStateAsync are correctly imported, enabling dispatching these actions within the component.


151-152: Adding methods to DispatchToProps interface

The methods onUpdateEditedObject and onResetEditedObject are appropriately added to the DispatchToProps interface, ensuring they are available as props.


354-359: Defining dispatch methods for edited object actions

The dispatch methods onUpdateEditedObject and onResetEditedObject are properly defined in mapDispatchToProps, allowing the component to dispatch edited object state updates.


683-683: Resetting edited object state after shape is drawn

Calling onResetEditedObject() after a shape is drawn ensures that the edited object state is cleared, preventing unintended behavior.


911-913: Resetting edited object state upon canvas cancel

Including onResetEditedObject() in the onCanvasCancel method ensures the edited object state is reset when canvas interactions are canceled, maintaining the correct application state.


844-847: Updating edited object state on canvas draw start

The onCanvasDrawStart method correctly updates the edited object state by calling onUpdateEditedObject with the shape type, which is appropriate.


849-852: Updating active control and edited object state on edit start

In the onCanvasEditStart method, updating the active control to ActiveControl.EDIT and calling onUpdateEditedObject with the shape type and state ensures proper state management during editing.


Line range hint 856-871: Resetting edited object state after editing is done

Calling onResetEditedObject() at the end of onCanvasEditDone ensures that the edited object state is properly reset after editing is completed.

cvat-canvas/src/typescript/svg.patch.ts (1)

Line range hint 97-99: Verify loop boundary condition in drawCircles

The loop uses i < array.length - 1, which may skip processing the last element of array. Please verify if this is intentional. If all elements should be processed, consider changing the condition to i < array.length.

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

129-131: Action types added to AnnotationActionTypes

The new action types UPDATE_EDITED_STATE, HIDE_EDITED_STATE, and RESET_EDITED_STATE are appropriately added to the AnnotationActionTypes enum.


1615-1644: Implementation of updateEditedStateAsync is appropriate

The function updateEditedStateAsync correctly updates the canvas configuration and dispatches the necessary actions to manage the edited state.


1670-1693: Function changeHideEditedStateAsync correctly updates hide state

The function changeHideEditedStateAsync properly updates the canvas configuration, dispatches the HIDE_EDITED_STATE action, and updates the hidden property of editedStateInstance.

cvat-canvas/src/typescript/drawHandler.ts (3)

8-8: Import of 'CIRCLE_STROKE' looks correct.

The import statement for 'CIRCLE_STROKE' from './svg.patch' is appropriate and ensures the constant is available for use in the class.


107-107: Initialization of 'isHidden' property is appropriate.

The declaration and initialization of the isHidden property correctly manage the visibility state of the drawn shapes.

Also applies to: 1283-1283


1345-1350: 'updateHidden' method logic is sound.

The updateHidden method correctly updates the hidden state and adjusts the draw instance's opacity accordingly.

@codecov-commenter
Copy link

codecov-commenter commented Oct 21, 2024

Codecov Report

Attention: Patch coverage is 52.17391% with 33 lines in your changes missing coverage. Please review.

Project coverage is 74.26%. Comparing base (23e1e0a) to head (c00529c).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8554      +/-   ##
===========================================
- Coverage    74.32%   74.26%   -0.07%     
===========================================
  Files          401      401              
  Lines        43319    43379      +60     
  Branches      3925     3945      +20     
===========================================
+ Hits         32198    32216      +18     
- Misses       11121    11163      +42     
Components Coverage Δ
cvat-ui 78.60% <52.17%> (-0.15%) ⬇️
cvat-server 70.55% <ø> (ø)

Copy link
Member

@bsekachev bsekachev left a comment

Choose a reason for hiding this comment

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

I think we should remove shapeType and editedStateHidden from editing in global store, because the implementation only was requested for masks and it works only for masks.

You already have shapeType in drawing state (when we speak about initial creating of the mask), do not need to duplicate it. You may use existing value.

Also, small bug was found:

  1. In brush tools switch to polygon drawing
  2. Draw part of polygon
  3. Press hide, press show
  4. Drawn part of polygon lost

cvat-core/src/annotations-collection.ts Outdated Show resolved Hide resolved
@@ -1026,6 +1026,7 @@ export default class Collection {
label_id: state.label.id,
outside: state.outside || false,
occluded: state.occluded || false,
hidden: state.hidden || false,
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure that creating a new object already hidden makes sense as it confuses the user
They press N and expect a new object to be appear, I think.
If the object is hidden, they may think that something is going wrong and start drawing it again (especially when there are a lot of objects in the sidebar, newly added is not visible in the list)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, maybe it is for new objects.
But what about edited ones? Should this hide feature affect state.hidden at all then?

cvat-ui/src/actions/annotation-actions.ts Outdated Show resolved Hide resolved
Comment on lines 1620 to 1635
if (editedStateInstance) {
const state = getState();
const { instance: canvas } = state.annotation.canvas;
if (canvas) {
(canvas as Canvas).configure({
hideEditedObject: editedStateInstance.hidden,
});
}

dispatch({
type: AnnotationActionTypes.HIDE_EDITED_STATE,
payload: {
hide: editedStateInstance.hidden,
},
});
}
Copy link
Member

Choose a reason for hiding this comment

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

I think we have three actions changeHideEditedStateAsync, updateEditedStateAsync, resetEditedStateAsync doing the same thing (updating the same key in store).

Probably we may combine them to reduce the code duplication. Let it accept shapeType, objectState and isHidden. And use these arguments to update store and objectState properly

Copy link
Member

Choose a reason for hiding this comment

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

Considering my general review comment it should only accept objectState: ObjectState | null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now we have two actions: updateEditedStateAsync for manipulation of edited state object, another - changeHideActiveObjectAsync to change the hide flag. I put the hide flag in canvas part of the store.

@@ -649,6 +664,7 @@ class CanvasWrapperComponent extends React.PureComponent<Props> {
state.rotation = state.rotation || 0;
state.occluded = state.occluded || false;
state.outside = state.outside || false;
state.hidden = state.hidden || (editedStateHidden && workspace !== Workspace.SINGLE_SHAPE);
Copy link
Member

Choose a reason for hiding this comment

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

see my comment in cvat-core

@@ -29,11 +29,13 @@ interface StateToProps {
outsideDisabled: boolean;
hiddenDisabled: boolean;
keyframeDisabled: boolean;
editedState: EditingState,
Copy link
Member

Choose a reason for hiding this comment

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

As it comes from global store and we anyway use mapStateToProps here, I do not see the reason to pass as own props

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We dont pass new value as own prop, Im not sure what you mean here

@klakhov
Copy link
Contributor Author

klakhov commented Oct 25, 2024

I think we should remove shapeType and editedStateHidden from editing in global store, because the implementation only was requested for masks and it works only for masks.

You already have shapeType in drawing state (when we speak about initial creating of the mask), do not need to duplicate it. You may use existing value.

I dont think we can really remove shapeType and editedStateHidden. There are cases when we need them:

  1. shapeType - the problem with shapeType in drawing is that it is not reset after finishing drawing something. I suppose this value is used for re-draw feature. In shortcut handler we want to know if we need to dispatch changeHideEditedObject by this value. We can try to rely on editedState but we dont have it in case if new mask is drawn.
  2. editedStateHidden - when we have a mask we can use objectState.hidden to keep the state of current object, but when we draw a new mask we dont have a objectState, so we dont know state of hidden variable.

It seems we can create dummy ObjectState to keep the state when mask is not yet drawn, but I think it feels less convinient. Also when we are updating the hidden state of edited mask, we want to dispatch updateAnnotationsAsync to update the original objectState. In case of dummy object we dont need that so we need to know the difference somehow

@bsekachev
Copy link
Member

bsekachev commented Oct 25, 2024

shapeType - the problem with shapeType in drawing is that it is not reset after finishing drawing something

The store also have information about whether drawing is on or off currently, is not it?
Just putting any information related to drawing to editing state looks not exactly logically correct, because drawing and editing are different actions. Additionally, as I mentioned, it is just duplication as we have shapeType in both places now.

editedStateHidden - when we have a mask we can use objectState.hidden to keep the state of current object, but when we draw a new mask we dont have a objectState, so we dont know state of hidden variable.

Partially I agree with that, but if we are talking about editing, we always have ObjectState (something what we edit). Additionally when we are talking about drawing, as mentioned before, we should not keep related information about drawing process in editing store. So, we probably need this flag somewhere, but not in editing store.

Copy link
Member

@bsekachev bsekachev left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

sonarcloud bot commented Oct 31, 2024

@klakhov klakhov merged commit 7f5bc4b into develop Oct 31, 2024
34 checks passed
klakhov added a commit that referenced this pull request Nov 6, 2024
<!-- Raise an issue to propose your change
(https://github.com/cvat-ai/cvat/issues).
It helps to avoid duplication of efforts from multiple independent
contributors.
Discuss your ideas with maintainers to be sure that changes will be
approved and merged.
Read the [Contribution guide](https://docs.cvat.ai/docs/contributing/).
-->

<!-- Provide a general summary of your changes in the Title above -->

### Motivation and context
<!-- Why is this change required? What problem does it solve? If it
fixes an open
issue, please link to the issue here. Describe your changes in detail,
add
screenshots. -->
Test and docs for #8554

### How has this been tested?
<!-- Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc. -->

### Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply.
If an item isn't applicable for some reason, then ~~explicitly
strikethrough~~ the whole
line. If you don't do that, GitHub will show incorrect progress for the
pull request.
If you're unsure about any of these, don't hesitate to ask. We're here
to help! -->
- [x] I submit my changes into the `develop` branch
- ~~[ ] I have created a changelog fragment <!-- see top comment in
CHANGELOG.md -->~~
- ~~[ ] I have updated the documentation accordingly~~
- [x] I have added tests to cover my changes
- [x] I have linked related issues (see [GitHub docs](

https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword))
- [x] I have increased versions of npm packages if it is necessary

([cvat-canvas](https://github.com/cvat-ai/cvat/tree/develop/cvat-canvas#versioning),

[cvat-core](https://github.com/cvat-ai/cvat/tree/develop/cvat-core#versioning),

[cvat-data](https://github.com/cvat-ai/cvat/tree/develop/cvat-data#versioning)
and

[cvat-ui](https://github.com/cvat-ai/cvat/tree/develop/cvat-ui#versioning))

### License

- [x] I submit _my code changes_ under the same [MIT License](
https://github.com/cvat-ai/cvat/blob/develop/LICENSE) that covers the
project.
  Feel free to contact the maintainers if that's a concern.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Tests**
- Introduced a new test case to verify the functionality of hiding and
showing masks through both button clicks and keyboard shortcuts.
- Enhanced the test suite with comprehensive checks for the hide mask
feature, ensuring expected behavior during UI interactions and editing.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Boris Sekachev <[email protected]>
@bsekachev bsekachev deleted the kl/hide-mask branch November 8, 2024 13:40
@cvat-bot cvat-bot bot mentioned this pull request Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants