From 9e605f436d6d03d53545172f7e9e4735961c6e3a Mon Sep 17 00:00:00 2001 From: Boris Sekachev Date: Fri, 15 Mar 2024 08:55:34 +0200 Subject: [PATCH] Fixed using single shape annotation mode with multiple labels (#7606) --- .../20240314_105752_boris_fixed_ssa.md | 4 ++ .../single-shape-sidebar.tsx | 11 ++++- .../e2e/features/single_object_annotation.js | 40 +++++++++++++++++-- 3 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 changelog.d/20240314_105752_boris_fixed_ssa.md diff --git a/changelog.d/20240314_105752_boris_fixed_ssa.md b/changelog.d/20240314_105752_boris_fixed_ssa.md new file mode 100644 index 000000000000..1756e3924c99 --- /dev/null +++ b/changelog.d/20240314_105752_boris_fixed_ssa.md @@ -0,0 +1,4 @@ +### Fixed + +- Using single shape annotation mode with multiple labels + () diff --git a/cvat-ui/src/components/annotation-page/single-shape-workspace/single-shape-sidebar/single-shape-sidebar.tsx b/cvat-ui/src/components/annotation-page/single-shape-workspace/single-shape-sidebar/single-shape-sidebar.tsx index 1775493993b3..10d336620f70 100644 --- a/cvat-ui/src/components/annotation-page/single-shape-workspace/single-shape-sidebar/single-shape-sidebar.tsx +++ b/cvat-ui/src/components/annotation-page/single-shape-workspace/single-shape-sidebar/single-shape-sidebar.tsx @@ -18,13 +18,15 @@ import Alert from 'antd/lib/alert'; import Modal from 'antd/lib/modal'; import Button from 'antd/lib/button'; -import { CombinedState, NavigationType } from 'reducers'; +import { CombinedState, NavigationType, ObjectType } from 'reducers'; import { Canvas, CanvasMode } from 'cvat-canvas-wrapper'; import { Job, JobState, Label, LabelType, } from 'cvat-core-wrapper'; import { ActionUnion, createAction } from 'utils/redux'; -import { changeFrameAsync, saveAnnotationsAsync, setNavigationType } from 'actions/annotation-actions'; +import { + rememberObject, changeFrameAsync, saveAnnotationsAsync, setNavigationType, +} from 'actions/annotation-actions'; import LabelSelector from 'components/label-selector/label-selector'; import GlobalHotKeys from 'utils/mousetrap-react'; @@ -219,6 +221,11 @@ function SingleShapeSidebar(): JSX.Element { canvasInitializerRef.current = (): void => { const canvas = store.getState().annotation.canvas.instance as Canvas; if (isCanvasReady && canvas.mode() !== CanvasMode.DRAW && state.label && state.labelType !== LabelType.ANY) { + appDispatch(rememberObject({ + activeLabelID: state.label.id, + activeObjectType: ObjectType.SHAPE, + })); + canvas.draw({ enabled: true, shapeType: state.labelType, diff --git a/tests/cypress/e2e/features/single_object_annotation.js b/tests/cypress/e2e/features/single_object_annotation.js index d53a27529a7f..f56db41f499c 100644 --- a/tests/cypress/e2e/features/single_object_annotation.js +++ b/tests/cypress/e2e/features/single_object_annotation.js @@ -100,6 +100,18 @@ context('Single object annotation mode', { scrollBehavior: false }, () => { submitJob(); } + function changeLabel(labelName) { + cy.get('.cvat-single-shape-annotation-sidebar-label-select').click(); + cy.get('.ant-select-dropdown').not('.ant-select-dropdown-hidden').within(() => { + cy.get('.ant-select-item-option-content').contains(labelName).click(); + }); + } + + function resetAfterTestCase() { + cy.removeAnnotations(); + cy.saveJob('PUT'); + } + before(() => { cy.visit('auth/login'); cy.login(); @@ -147,10 +159,7 @@ context('Single object annotation mode', { scrollBehavior: false }, () => { }); describe('Tests basic features of single shape annotation mode', () => { - afterEach(() => { - cy.removeAnnotations(); - cy.saveJob('PUT'); - }); + afterEach(resetAfterTestCase); it('Check basic single shape annotation pipeline for polygon', () => { openJob({ defaultLabel: 'polygon_label', defaultPointsCount: 4 }); @@ -190,6 +199,8 @@ context('Single object annotation mode', { scrollBehavior: false }, () => { }); describe('Tests advanced features of single shape annotation mode', () => { + afterEach(resetAfterTestCase); + it('Check single shape annotation mode controls', () => { openJob({ defaultLabel: 'polygon_label', defaultPointsCount: 4 }); checkSingleShapeModeOpened(); @@ -231,4 +242,25 @@ context('Single object annotation mode', { scrollBehavior: false }, () => { cy.saveJob(); }); }); + + describe('Regression tests', () => { + afterEach(resetAfterTestCase); + + it('Changing labels in single shape annotation mode', () => { + openJob({ defaultLabel: 'polygon_label', defaultPointsCount: 4 }); + checkSingleShapeModeOpened(); + + const anotherLabelName = 'points_label'; + changeLabel(anotherLabelName); + clickPoints(pointsShape); + + cy.changeWorkspace('Standard'); + cy.goCheckFrameNumber(0); + cy.get('#cvat-objects-sidebar-state-item-1').within(() => { + cy.get('.cvat-objects-sidebar-state-item-label-selector').should('have.text', anotherLabelName); + }); + + cy.saveJob(); + }); + }); });