Removed code duplications, added checks to CI (#5253)
parent
aadfd8814e
commit
e5d01359aa
@ -1,61 +0,0 @@
|
|||||||
// Copyright (C) 2022 CVAT.ai Corporation
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
import React from 'react';
|
|
||||||
import { Row, Col } from 'antd/lib/grid';
|
|
||||||
import Button from 'antd/lib/button';
|
|
||||||
import Text from 'antd/lib/typography/Text';
|
|
||||||
|
|
||||||
import LabelSelector from 'components/label-selector/label-selector';
|
|
||||||
import CVATTooltip from 'components/common/cvat-tooltip';
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
labels: any[];
|
|
||||||
selectedLabelID: number;
|
|
||||||
repeatShapeShortcut: string;
|
|
||||||
onChangeLabel(value: string): void;
|
|
||||||
onDraw(labelID: number): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
function DrawMaskPopover(props: Props): JSX.Element {
|
|
||||||
const {
|
|
||||||
labels, selectedLabelID, repeatShapeShortcut, onChangeLabel, onDraw,
|
|
||||||
} = props;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='cvat-draw-shape-popover-content'>
|
|
||||||
<Row justify='start'>
|
|
||||||
<Col>
|
|
||||||
<Text className='cvat-text-color' strong>
|
|
||||||
Draw new mask
|
|
||||||
</Text>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
<Row justify='start'>
|
|
||||||
<Col>
|
|
||||||
<Text className='cvat-text-color'>Label</Text>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
<Row justify='center'>
|
|
||||||
<Col span={24}>
|
|
||||||
<LabelSelector
|
|
||||||
style={{ width: '100%' }}
|
|
||||||
labels={labels}
|
|
||||||
value={selectedLabelID}
|
|
||||||
onChange={onChangeLabel}
|
|
||||||
/>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
<Row justify='space-around'>
|
|
||||||
<Col span={24}>
|
|
||||||
<CVATTooltip title={`Press ${repeatShapeShortcut} to draw a mask again`}>
|
|
||||||
<Button onClick={() => onDraw(selectedLabelID)}>Draw a mask</Button>
|
|
||||||
</CVATTooltip>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default React.memo(DrawMaskPopover);
|
|
||||||
@ -1,108 +0,0 @@
|
|||||||
// Copyright (C) 2022 CVAT.ai Corporation
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
import React from 'react';
|
|
||||||
import { connect } from 'react-redux';
|
|
||||||
|
|
||||||
import DrawMaskPopoverComponent from 'components/annotation-page/standard-workspace/controls-side-bar/draw-mask-popover';
|
|
||||||
import { rememberObject } from 'actions/annotation-actions';
|
|
||||||
import { CombinedState, ShapeType, ObjectType } from 'reducers';
|
|
||||||
import { Canvas } from 'cvat-canvas-wrapper';
|
|
||||||
|
|
||||||
interface DispatchToProps {
|
|
||||||
onDrawStart(
|
|
||||||
shapeType: ShapeType,
|
|
||||||
labelID: number,
|
|
||||||
objectType: ObjectType,
|
|
||||||
): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface StateToProps {
|
|
||||||
normalizedKeyMap: Record<string, string>;
|
|
||||||
canvasInstance: Canvas;
|
|
||||||
labels: any[];
|
|
||||||
}
|
|
||||||
|
|
||||||
function mapDispatchToProps(dispatch: any): DispatchToProps {
|
|
||||||
return {
|
|
||||||
onDrawStart(
|
|
||||||
shapeType: ShapeType,
|
|
||||||
labelID: number,
|
|
||||||
objectType: ObjectType,
|
|
||||||
): void {
|
|
||||||
dispatch(
|
|
||||||
rememberObject({
|
|
||||||
activeObjectType: objectType,
|
|
||||||
activeShapeType: shapeType,
|
|
||||||
activeLabelID: labelID,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function mapStateToProps(state: CombinedState): StateToProps {
|
|
||||||
const {
|
|
||||||
annotation: {
|
|
||||||
canvas: { instance: canvasInstance },
|
|
||||||
job: { labels },
|
|
||||||
},
|
|
||||||
shortcuts: { normalizedKeyMap },
|
|
||||||
} = state;
|
|
||||||
|
|
||||||
return {
|
|
||||||
canvasInstance: canvasInstance as Canvas,
|
|
||||||
normalizedKeyMap,
|
|
||||||
labels,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
type Props = StateToProps & DispatchToProps;
|
|
||||||
|
|
||||||
interface State {
|
|
||||||
selectedLabelID: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
class DrawShapePopoverContainer extends React.PureComponent<Props, State> {
|
|
||||||
constructor(props: Props) {
|
|
||||||
super(props);
|
|
||||||
const defaultLabelID = props.labels.length ? props.labels[0].id : null;
|
|
||||||
this.state = { selectedLabelID: defaultLabelID };
|
|
||||||
}
|
|
||||||
|
|
||||||
private onDraw = (): void => {
|
|
||||||
const { canvasInstance, onDrawStart } = this.props;
|
|
||||||
const { selectedLabelID } = this.state;
|
|
||||||
|
|
||||||
canvasInstance.cancel();
|
|
||||||
canvasInstance.draw({
|
|
||||||
enabled: true,
|
|
||||||
shapeType: ShapeType.MASK,
|
|
||||||
crosshair: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
onDrawStart(ShapeType.MASK, selectedLabelID, ObjectType.SHAPE);
|
|
||||||
};
|
|
||||||
|
|
||||||
private onChangeLabel = (value: any): void => {
|
|
||||||
this.setState({ selectedLabelID: value.id });
|
|
||||||
};
|
|
||||||
|
|
||||||
public render(): JSX.Element {
|
|
||||||
const { selectedLabelID } = this.state;
|
|
||||||
const { normalizedKeyMap, labels } = this.props;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<DrawMaskPopoverComponent
|
|
||||||
labels={labels}
|
|
||||||
selectedLabelID={selectedLabelID}
|
|
||||||
repeatShapeShortcut={normalizedKeyMap.SWITCH_DRAW_MODE}
|
|
||||||
onChangeLabel={this.onChangeLabel}
|
|
||||||
onDraw={this.onDraw}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(DrawShapePopoverContainer);
|
|
||||||
Loading…
Reference in New Issue