Skip to content

Commit

Permalink
feat: 🎸 Correctly handle and remove cancelled new measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesAPetts authored Jul 3, 2020
1 parent b037c89 commit 6693743
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
29 changes: 18 additions & 11 deletions src/eventDispatchers/mouseEventHandlers/addNewMeasurement.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import EVENTS from '../../events.js';
import external from '../../externalModules.js';
import { addToolState } from '../../stateManagement/toolState.js';
import {
addToolState,
removeToolState,
} from '../../stateManagement/toolState.js';
import { moveHandle, moveNewHandle } from '../../manipulators/index.js';
import { getLogger } from '../../util/logger.js';
import triggerEvent from '../../util/triggerEvent.js';
Expand Down Expand Up @@ -36,20 +39,24 @@ export default function(evt, tool) {
measurementData.handles.end,
tool.options,
'mouse',
() => {
success => {
if (measurementData.cancelled) {
return;
}

const eventType = EVENTS.MEASUREMENT_COMPLETED;
const eventData = {
toolName: tool.name,
toolType: tool.name, // Deprecation notice: toolType will be replaced by toolName
element,
measurementData,
};

triggerEvent(element, eventType, eventData);
if (success) {
const eventType = EVENTS.MEASUREMENT_COMPLETED;
const eventData = {
toolName: tool.name,
toolType: tool.name, // Deprecation notice: toolType will be replaced by toolName
element,
measurementData,
};

triggerEvent(element, eventType, eventData);
} else {
removeToolState(element, tool.name, measurementData);
}
}
);
}
7 changes: 6 additions & 1 deletion src/tools/annotation/bidirectionalTool/addNewMeasurement.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ export default function(evt, interactionType) {
end,
{},
interactionType,
() => {
success => {
if (!success) {
removeToolState(element, this.name, measurementData);

return;
}
const { handles, longestDiameter, shortestDiameter } = measurementData;
const hasHandlesOutside = anyHandlesOutsideImage(eventData, handles);
const longestDiameterSize = parseFloat(longestDiameter) || 0;
Expand Down

0 comments on commit 6693743

Please sign in to comment.