Skip to content

Commit 2da29e4

Browse files
author
Boris Sekachev
authored
Do not call HOC component each render (#2780)
* Fixed issue #2753 * Updated version & changelog * Wire opencv popover via HOC
1 parent 0c0c609 commit 2da29e4

12 files changed

+42
-48
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3939
- A couple of css-related issues (top bar disappear, wrong arrow position on collapse elements) (<https://github.com/openvinotoolkit/cvat/pull/2736>)
4040
- Issue with point region doesn't work in Firefox (<https://github.com/openvinotoolkit/cvat/pull/2727>)
4141
- Fixed cuboid perpective change (<https://github.com/openvinotoolkit/cvat/pull/2733>)
42+
- Annotation page popups (ai tools, drawing) reset state after detecting, tracking, drawing (<https://github.com/openvinotoolkit/cvat/pull/2780>)
4243

4344
### Security
4445

cvat-ui/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cvat-ui/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cvat-ui",
3-
"version": "1.14.0",
3+
"version": "1.14.1",
44
"description": "CVAT single-page application",
55
"main": "src/index.tsx",
66
"scripts": {

cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/draw-cuboid-control.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Intel Corporation
1+
// Copyright (C) 2020-2021 Intel Corporation
22
//
33
// SPDX-License-Identifier: MIT
44

@@ -19,10 +19,9 @@ interface Props {
1919
isDrawing: boolean;
2020
}
2121

22+
const CustomPopover = withVisibilityHandling(Popover, 'draw-cuboid');
2223
function DrawPolygonControl(props: Props): JSX.Element {
2324
const { canvasInstance, isDrawing } = props;
24-
const CustomPopover = withVisibilityHandling(Popover, 'draw-cuboid');
25-
2625
const dynamcPopoverPros = isDrawing ?
2726
{
2827
overlayStyle: {

cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/draw-points-control.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Intel Corporation
1+
// Copyright (C) 2020-2021 Intel Corporation
22
//
33
// SPDX-License-Identifier: MIT
44

@@ -18,10 +18,9 @@ interface Props {
1818
isDrawing: boolean;
1919
}
2020

21+
const CustomPopover = withVisibilityHandling(Popover, 'draw-points');
2122
function DrawPointsControl(props: Props): JSX.Element {
2223
const { canvasInstance, isDrawing } = props;
23-
const CustomPopover = withVisibilityHandling(Popover, 'draw-points');
24-
2524
const dynamcPopoverPros = isDrawing ?
2625
{
2726
overlayStyle: {

cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/draw-polygon-control.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Intel Corporation
1+
// Copyright (C) 2020-2021 Intel Corporation
22
//
33
// SPDX-License-Identifier: MIT
44

@@ -18,10 +18,9 @@ interface Props {
1818
isDrawing: boolean;
1919
}
2020

21+
const CustomPopover = withVisibilityHandling(Popover, 'draw-polygon');
2122
function DrawPolygonControl(props: Props): JSX.Element {
2223
const { canvasInstance, isDrawing } = props;
23-
const CustomPopover = withVisibilityHandling(Popover, 'draw-polygon');
24-
2524
const dynamcPopoverPros = isDrawing ?
2625
{
2726
overlayStyle: {

cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/draw-polyline-control.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Intel Corporation
1+
// Copyright (C) 2020-2021 Intel Corporation
22
//
33
// SPDX-License-Identifier: MIT
44

@@ -18,10 +18,9 @@ interface Props {
1818
isDrawing: boolean;
1919
}
2020

21+
const CustomPopover = withVisibilityHandling(Popover, 'draw-polyline');
2122
function DrawPolylineControl(props: Props): JSX.Element {
2223
const { canvasInstance, isDrawing } = props;
23-
const CustomPopover = withVisibilityHandling(Popover, 'draw-polyline');
24-
2524
const dynamcPopoverPros = isDrawing ?
2625
{
2726
overlayStyle: {

cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/draw-rectangle-control.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Intel Corporation
1+
// Copyright (C) 2020-2021 Intel Corporation
22
//
33
// SPDX-License-Identifier: MIT
44

@@ -18,10 +18,9 @@ interface Props {
1818
isDrawing: boolean;
1919
}
2020

21+
const CustomPopover = withVisibilityHandling(Popover, 'draw-rectangle');
2122
function DrawRectangleControl(props: Props): JSX.Element {
2223
const { canvasInstance, isDrawing } = props;
23-
const CustomPopover = withVisibilityHandling(Popover, 'draw-rectangle');
24-
2524
const dynamcPopoverPros = isDrawing ?
2625
{
2726
overlayStyle: {

cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/opencv-control.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
createAnnotationsAsync,
3030
} from 'actions/annotation-actions';
3131
import LabelSelector from 'components/label-selector/label-selector';
32+
import withVisibilityHandling from './handle-popover-visibility';
3233

3334
interface Props {
3435
labels: any[];
@@ -55,6 +56,7 @@ interface State {
5556
}
5657

5758
const core = getCore();
59+
const CustomPopover = withVisibilityHandling(Popover, 'opencv-control');
5860

5961
function mapStateToProps(state: CombinedState): Props {
6062
const {
@@ -73,7 +75,7 @@ function mapStateToProps(state: CombinedState): Props {
7375

7476
return {
7577
isActivated: activeControl === ActiveControl.OPENCV_TOOLS,
76-
canvasInstance,
78+
canvasInstance: canvasInstance as Canvas,
7779
jobInstance,
7880
curZOrder,
7981
labels,
@@ -402,14 +404,14 @@ class OpenCVControlComponent extends React.PureComponent<Props & DispatchToProps
402404
};
403405

404406
return (
405-
<Popover
407+
<CustomPopover
406408
{...dynamcPopoverPros}
407409
placement='right'
408410
overlayClassName='cvat-opencv-control-popover'
409411
content={this.renderContent()}
410412
>
411413
<Icon {...dynamicIconProps} component={OpenCVIcon} />
412-
</Popover>
414+
</CustomPopover>
413415
);
414416
}
415417
}

cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/rotate-control.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Intel Corporation
1+
// Copyright (C) 2020-2021 Intel Corporation
22
//
33
// SPDX-License-Identifier: MIT
44

@@ -18,9 +18,9 @@ interface Props {
1818
rotateFrame(rotation: Rotation): void;
1919
}
2020

21+
const CustomPopover = withVisibilityHandling(Popover, 'rotate-canvas');
2122
function RotateControl(props: Props): JSX.Element {
2223
const { anticlockwiseShortcut, clockwiseShortcut, rotateFrame } = props;
23-
const CustomPopover = withVisibilityHandling(Popover, 'rotate-canvas');
2424

2525
return (
2626
<CustomPopover

cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/setup-tag-control.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Intel Corporation
1+
// Copyright (C) 2020-2021 Intel Corporation
22
//
33
// SPDX-License-Identifier: MIT
44

@@ -17,10 +17,9 @@ interface Props {
1717
isDrawing: boolean;
1818
}
1919

20+
const CustomPopover = withVisibilityHandling(Popover, 'setup-tag');
2021
function SetupTagControl(props: Props): JSX.Element {
2122
const { isDrawing } = props;
22-
const CustomPopover = withVisibilityHandling(Popover, 'setup-tag');
23-
2423
const dynamcPopoverPros = isDrawing ?
2524
{
2625
overlayStyle: {

cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/tools-control.tsx

+20-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020 Intel Corporation
1+
// Copyright (C) 2020-2021 Intel Corporation
22
//
33
// SPDX-License-Identifier: MIT
44

@@ -56,6 +56,7 @@ interface DispatchToProps {
5656
}
5757

5858
const core = getCore();
59+
const CustomPopover = withVisibilityHandling(Popover, 'tools-control');
5960

6061
function mapStateToProps(state: CombinedState): StateToProps {
6162
const { annotation } = state;
@@ -73,7 +74,7 @@ function mapStateToProps(state: CombinedState): StateToProps {
7374
activeLabelID: annotation.drawing.activeLabelID,
7475
labels: annotation.job.labels,
7576
states: annotation.annotations.states,
76-
canvasInstance,
77+
canvasInstance: canvasInstance as Canvas,
7778
jobInstance,
7879
frame,
7980
curZOrder: annotation.annotations.zLayer.cur,
@@ -303,11 +304,7 @@ export class ToolsControlComponent extends React.PureComponent<Props, State> {
303304

304305
private onTracking = async (e: Event): Promise<void> => {
305306
const {
306-
isActivated,
307-
jobInstance,
308-
frame,
309-
curZOrder,
310-
fetchAnnotations,
307+
isActivated, jobInstance, frame, curZOrder, fetchAnnotations,
311308
} = this.props;
312309

313310
if (!isActivated) {
@@ -520,8 +517,8 @@ export class ToolsControlComponent extends React.PureComponent<Props, State> {
520517
min={1}
521518
precision={0}
522519
max={jobInstance.stopFrame - frame}
523-
onChange={(value: number | undefined | string): void => {
524-
if (typeof value !== 'undefined') {
520+
onChange={(value: number | undefined | string | null): void => {
521+
if (typeof value !== 'undefined' && value !== null) {
525522
this.setState({
526523
trackingFrames: +value,
527524
});
@@ -659,19 +656,20 @@ export class ToolsControlComponent extends React.PureComponent<Props, State> {
659656
try {
660657
this.setState({ mode: 'detection', fetching: true });
661658
const result = await core.lambda.call(task, model, { ...body, frame });
662-
const states = result.map((data: any): any => (
663-
new core.classes.ObjectState({
664-
shapeType: data.type,
665-
label: task.labels.filter((label: any): boolean => label.name === data.label)[0],
666-
points: data.points,
667-
objectType: ObjectType.SHAPE,
668-
frame,
669-
occluded: false,
670-
source: 'auto',
671-
attributes: {},
672-
zOrder: curZOrder,
673-
})
674-
));
659+
const states = result.map(
660+
(data: any): any =>
661+
new core.classes.ObjectState({
662+
shapeType: data.type,
663+
label: task.labels.filter((label: any): boolean => label.name === data.label)[0],
664+
points: data.points,
665+
objectType: ObjectType.SHAPE,
666+
frame,
667+
occluded: false,
668+
source: 'auto',
669+
attributes: {},
670+
zOrder: curZOrder,
671+
}),
672+
);
675673

676674
await jobInstance.annotations.put(states);
677675
fetchAnnotations();
@@ -722,7 +720,6 @@ export class ToolsControlComponent extends React.PureComponent<Props, State> {
722720
const { fetching, trackingProgress } = this.state;
723721

724722
if (![...interactors, ...detectors, ...trackers].length) return null;
725-
const CustomPopover = withVisibilityHandling(Popover, 'tools-control');
726723

727724
const dynamcPopoverPros = isActivated ?
728725
{

0 commit comments

Comments
 (0)