Skip to content

Commit

Permalink
Accelerated React rendering of objects list for tracks (#6544)
Browse files Browse the repository at this point in the history
<!-- Raise an issue to propose your change
(https://github.com/opencv/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://opencv.github.io/cvat/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. -->

### 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 added a description of my changes into the
[CHANGELOG](https://github.com/opencv/cvat/blob/develop/CHANGELOG.md)
file
- [ ] I have updated the documentation accordingly
- [ ] I have added tests to cover my changes
- [ ] 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))
- [ ] I have increased versions of npm packages if it is necessary

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

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

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

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

### License

- [x] I submit _my code changes_ under the same [MIT License](
https://github.com/opencv/cvat/blob/develop/LICENSE) that covers the
project.
  Feel free to contact the maintainers if that's a concern.
  • Loading branch information
bsekachev authored Jul 24, 2023
1 parent 1bc7767 commit 2896bec
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -25,7 +24,7 @@ interface Props {
labelID: number;
isGroundTruth: boolean;
locked: boolean;
elements: any[];
elements: number[];
color: string;
colorBy: ColorBy;
labels: any[];
Expand Down Expand Up @@ -141,29 +140,27 @@ function ObjectItemComponent(props: Props): JSX.Element {
/>
)}
{!!elements.length && (
<>
<Collapse className='cvat-objects-sidebar-state-item-elements-collapse'>
<Collapse.Panel
header={(
<>
<Text style={{ fontSize: 10 }} type='secondary'>PARTS</Text>
<br />
</>
)}
key='elements'
>
{elements.map((element: ObjectState) => (
<ObjectItemElementComponent
key={element.clientID as number}
readonly={readonly}
parentID={clientID}
clientID={element.clientID as number}
onMouseLeave={activateState}
/>
))}
</Collapse.Panel>
</Collapse>
</>
<Collapse className='cvat-objects-sidebar-state-item-elements-collapse'>
<Collapse.Panel
header={(
<>
<Text style={{ fontSize: 10 }} type='secondary'>PARTS</Text>
<br />
</>
)}
key='elements'
>
{elements.map((element: number) => (
<ObjectItemElementComponent
key={element}
readonly={readonly}
parentID={clientID}
clientID={element}
onMouseLeave={activateState}
/>
))}
</Collapse.Panel>
</Collapse>
)}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -155,7 +155,7 @@ class CanvasContextMenuContainer extends React.PureComponent<Props, State> {
};
}

static getDerivedStateFromProps(props: Props, state: State): State | null {
static getDerivedStateFromProps(props: Readonly<Props>, state: State): State | null {
if (props.left === state.latestLeft && props.top === state.latestTop) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class LabelItemContainer extends React.PureComponent<Props, State> {
};
}

static getDerivedStateFromProps(props: Props, state: State): State | null {
static getDerivedStateFromProps(props: Readonly<Props>, state: State): State | null {
if (props.objectStates === state.objectStates) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -128,7 +129,34 @@ function mapDispatchToProps(dispatch: any): DispatchToProps {
}

type Props = StateToProps & DispatchToProps & OwnProps;
class ObjectItemContainer extends React.PureComponent<Props> {
interface State {
labels: Label[];
elements: number[];
}

class ObjectItemContainer extends React.PureComponent<Props, State> {
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<Props>, state: Readonly<State>): 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) {
Expand Down Expand Up @@ -312,9 +340,9 @@ class ObjectItemContainer extends React.PureComponent<Props> {
}

public render(): JSX.Element {
const { labels, elements } = this.state;
const {
objectState,
labels,
attributes,
activated,
colorBy,
Expand All @@ -323,8 +351,6 @@ class ObjectItemContainer extends React.PureComponent<Props> {
jobInstance,
} = this.props;

const applicableLabels = filterApplicableLabels(objectState, labels);

return (
<ObjectStateItemComponent
jobInstance={jobInstance}
Expand All @@ -339,9 +365,9 @@ class ObjectItemContainer extends React.PureComponent<Props> {
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}
Expand All @@ -354,7 +380,7 @@ class ObjectItemContainer extends React.PureComponent<Props> {
changeColor={this.changeColor}
changeLabel={this.changeLabel}
edit={this.edit}
resetCuboidPerspective={() => this.resetCuboidPerspective()}
resetCuboidPerspective={this.resetCuboidPerspective}
/>
);
}
Expand Down

0 comments on commit 2896bec

Please sign in to comment.