diff --git a/cvat-ui/src/components/annotation-page/standard-workspace/objects-side-bar/object-item.tsx b/cvat-ui/src/components/annotation-page/standard-workspace/objects-side-bar/object-item.tsx index a75fd7368779..ced24f3c053b 100644 --- a/cvat-ui/src/components/annotation-page/standard-workspace/objects-side-bar/object-item.tsx +++ b/cvat-ui/src/components/annotation-page/standard-workspace/objects-side-bar/object-item.tsx @@ -10,7 +10,6 @@ import Collapse from 'antd/lib/collapse'; import ObjectButtonsContainer from 'containers/annotation-page/standard-workspace/objects-side-bar/object-buttons'; import ItemDetailsContainer from 'containers/annotation-page/standard-workspace/objects-side-bar/object-item-details'; import { ObjectType, ShapeType, ColorBy } from 'reducers'; -import { ObjectState } from 'cvat-core-wrapper'; import ObjectItemElementComponent from './object-item-element'; import ItemBasics from './object-item-basics'; @@ -25,7 +24,7 @@ interface Props { labelID: number; isGroundTruth: boolean; locked: boolean; - elements: any[]; + elements: number[]; color: string; colorBy: ColorBy; labels: any[]; @@ -141,29 +140,27 @@ function ObjectItemComponent(props: Props): JSX.Element { /> )} {!!elements.length && ( - <> - - - PARTS -
- - )} - key='elements' - > - {elements.map((element: ObjectState) => ( - - ))} -
-
- + + + PARTS +
+ + )} + key='elements' + > + {elements.map((element: number) => ( + + ))} +
+
)} diff --git a/cvat-ui/src/containers/annotation-page/canvas/canvas-context-menu.tsx b/cvat-ui/src/containers/annotation-page/canvas/canvas-context-menu.tsx index 2344c1025cf2..74ac036c6270 100644 --- a/cvat-ui/src/containers/annotation-page/canvas/canvas-context-menu.tsx +++ b/cvat-ui/src/containers/annotation-page/canvas/canvas-context-menu.tsx @@ -26,7 +26,7 @@ interface StateToProps { contextMenuParentID: number | null; contextMenuClientID: number | null; canvasInstance: Canvas | null; - objectStates: any[]; + objectStates: ObjectState[]; frameConflicts: QualityConflict[]; visible: boolean; top: number; @@ -155,7 +155,7 @@ class CanvasContextMenuContainer extends React.PureComponent { }; } - static getDerivedStateFromProps(props: Props, state: State): State | null { + static getDerivedStateFromProps(props: Readonly, state: State): State | null { if (props.left === state.latestLeft && props.top === state.latestTop) { return null; } diff --git a/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/label-item.tsx b/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/label-item.tsx index ac2cba8493be..56bdff93be13 100644 --- a/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/label-item.tsx +++ b/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/label-item.tsx @@ -81,7 +81,7 @@ class LabelItemContainer extends React.PureComponent { }; } - static getDerivedStateFromProps(props: Props, state: State): State | null { + static getDerivedStateFromProps(props: Readonly, state: State): State | null { if (props.objectStates === state.objectStates) { return null; } diff --git a/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/object-item.tsx b/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/object-item.tsx index ad9d3491e966..be9817ee6b68 100644 --- a/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/object-item.tsx +++ b/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/object-item.tsx @@ -23,6 +23,7 @@ import { import ObjectStateItemComponent from 'components/annotation-page/standard-workspace/objects-side-bar/object-item'; import { getColor } from 'components/annotation-page/standard-workspace/objects-side-bar/shared'; import { shift } from 'utils/math'; +import { Label, ObjectState } from 'cvat-core-wrapper'; import { Canvas, CanvasMode } from 'cvat-canvas-wrapper'; import { Canvas3d } from 'cvat-canvas3d-wrapper'; import { filterApplicableLabels } from 'utils/filter-applicable-labels'; @@ -128,7 +129,34 @@ function mapDispatchToProps(dispatch: any): DispatchToProps { } type Props = StateToProps & DispatchToProps & OwnProps; -class ObjectItemContainer extends React.PureComponent { +interface State { + labels: Label[]; + elements: number[]; +} + +class ObjectItemContainer extends React.PureComponent { + public constructor(props: Props) { + super(props); + this.state = { + labels: props.labels, + elements: props.objectState.elements.map((el: ObjectState) => el.clientID), + }; + } + + public static getDerivedStateFromProps(props: Readonly, state: Readonly): State | null { + const { objectState, labels } = props; + const applicableLabels = filterApplicableLabels(objectState, labels); + if (state.labels.length !== applicableLabels.length || + state.labels.some((label, idx) => label.id !== applicableLabels[idx].id)) { + return { + ...state, + labels: applicableLabels, + }; + } + + return null; + } + private copy = (): void => { const { objectState, readonly, copyShape } = this.props; if (!readonly) { @@ -312,9 +340,9 @@ class ObjectItemContainer extends React.PureComponent { } public render(): JSX.Element { + const { labels, elements } = this.state; const { objectState, - labels, attributes, activated, colorBy, @@ -323,8 +351,6 @@ class ObjectItemContainer extends React.PureComponent { jobInstance, } = this.props; - const applicableLabels = filterApplicableLabels(objectState, labels); - return ( { isGroundTruth={objectState.isGroundTruth} color={getColor(objectState, colorBy)} attributes={attributes} - elements={objectState.elements} + elements={elements} normalizedKeyMap={normalizedKeyMap} - labels={applicableLabels} + labels={labels} colorBy={colorBy} activate={this.activate} remove={this.remove} @@ -354,7 +380,7 @@ class ObjectItemContainer extends React.PureComponent { changeColor={this.changeColor} changeLabel={this.changeLabel} edit={this.edit} - resetCuboidPerspective={() => this.resetCuboidPerspective()} + resetCuboidPerspective={this.resetCuboidPerspective} /> ); }