main
Dmitry Kalinin 6 years ago
parent 56c6f11569
commit c11cc642df

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

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

Loading…
Cancel
Save