main
Dmitry Kalinin 6 years ago
parent 56c6f11569
commit c11cc642df

@ -341,11 +341,10 @@ export default class CanvasWrapperComponent extends React.PureComponent<Props> {
const { const {
activatedStateID, activatedStateID,
onUpdateContextMenu, onUpdateContextMenu,
contextVisible,
contextType, contextType,
} = this.props; } = this.props;
if (!contextVisible && contextType !== ContextMenuType.CANVAS_SHAPE_POINT) { if (contextType !== ContextMenuType.CANVAS_SHAPE_POINT) {
onUpdateContextMenu(activatedStateID !== null, e.clientX, e.clientY, onUpdateContextMenu(activatedStateID !== null, e.clientX, e.clientY,
ContextMenuType.CANVAS_SHAPE); ContextMenuType.CANVAS_SHAPE);
} }

@ -13,7 +13,7 @@ import CanvasPointContextMenuComponent from 'components/annotation-page/standard
interface StateToProps { interface StateToProps {
activatedStateID: number | null; activatedStateID: number | null;
activetedPointID: number | null | undefined; activatedPointID: number | null | undefined;
states: any[]; states: any[];
visible: boolean; visible: boolean;
top: number; top: number;
@ -34,7 +34,7 @@ function mapStateToProps(state: CombinedState): StateToProps {
top, top,
left, left,
type, type,
pointID: activetedPointID, pointID: activatedPointID,
}, },
}, },
}, },
@ -42,7 +42,7 @@ function mapStateToProps(state: CombinedState): StateToProps {
return { return {
activatedStateID, activatedStateID,
activetedPointID, activatedPointID,
states, states,
visible, visible,
left, left,
@ -70,6 +70,8 @@ function mapDispatchToProps(dispatch: any): DispatchToProps {
type Props = StateToProps & DispatchToProps; type Props = StateToProps & DispatchToProps;
interface State { interface State {
activatedStateID: number | null | undefined;
activatedPointID: number | null | undefined;
latestLeft: number; latestLeft: number;
latestTop: number; latestTop: number;
left: number; left: number;
@ -81,6 +83,8 @@ class CanvasContextMenuContainer extends React.PureComponent<Props, State> {
super(props); super(props);
this.state = { this.state = {
activatedStateID: null,
activatedPointID: null,
latestLeft: 0, latestLeft: 0,
latestTop: 0, latestTop: 0,
left: 0, left: 0,
@ -88,19 +92,25 @@ class CanvasContextMenuContainer extends React.PureComponent<Props, State> {
}; };
} }
static getDerivedStateFromProps(props: Props, state: State): State | null { static getDerivedStateFromProps(props: Props, state: State): State {
if (props.left === state.latestLeft const newState: State = { ...state };
&& props.top === state.latestTop) {
return null; if (props.left !== state.latestLeft
|| props.top !== state.latestTop) {
newState.latestLeft = props.left;
newState.latestTop = props.top;
newState.top = props.top;
newState.left = props.left;
} }
return { if (typeof state.activatedStateID !== typeof props.activatedStateID
...state, || typeof state.activatedPointID !== typeof props.activatedPointID) {
latestLeft: props.left, newState.activatedStateID = props.activatedStateID;
latestTop: props.top, newState.activatedPointID = props.activatedPointID;
top: props.top, }
left: props.left,
};
return newState;
} }
public componentDidUpdate(): void { public componentDidUpdate(): void {
@ -130,17 +140,20 @@ class CanvasContextMenuContainer extends React.PureComponent<Props, State> {
private deletePoint(): void { private deletePoint(): void {
const { const {
activetedPointID,
activatedStateID,
states, states,
onUpdateAnnotations, onUpdateAnnotations,
onCloseContextMenu, onCloseContextMenu,
} = this.props; } = this.props;
const {
activatedStateID,
activatedPointID,
} = this.state;
const [objectState] = states.filter((e) => (e.clientID === activatedStateID)); const [objectState] = states.filter((e) => (e.clientID === activatedStateID));
if (activetedPointID) { if (typeof activatedPointID === 'number') {
objectState.points = objectState.points.slice(0, activetedPointID * 2) objectState.points = objectState.points.slice(0, activatedPointID * 2)
.concat(objectState.points.slice(activetedPointID * 2 + 2)); .concat(objectState.points.slice(activatedPointID * 2 + 2));
onUpdateAnnotations([objectState]); onUpdateAnnotations([objectState]);
onCloseContextMenu(); onCloseContextMenu();
} }

Loading…
Cancel
Save