Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(state manager): Make viewport-related data optional for annotation event #950

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AnnotationState,
GroupSpecificAnnotations,
} from '../../types/AnnotationTypes';
import { triggerAnnotationAddedForFOR } from './helpers/state';

import { AnnotationGroupSelector, IAnnotationManager } from '../../types';

Expand Down Expand Up @@ -233,6 +234,8 @@ class FrameOfReferenceSpecificAnnotationManager implements IAnnotationManager {
toolSpecificAnnotations.push(annotation);
checkAndDefineIsLockedProperty(annotation);
checkAndDefineIsVisibleProperty(annotation);

triggerAnnotationAddedForFOR(annotation);
};

/**
Expand Down
16 changes: 6 additions & 10 deletions packages/tools/src/stateManagement/annotation/helpers/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@ function triggerAnnotationAddedForFOR(annotation: Annotation) {
const { toolName } = annotation.metadata;

const toolGroups = getToolGroupsWithToolName(toolName);

if (!toolGroups.length) {
return;
}

// Find the viewports in the toolGroups who has the same FrameOfReferenceUID
const viewportsToRender = [];

toolGroups.forEach((toolGroup) => {
toolGroup.viewportsInfo.forEach((viewportInfo) => {
const { renderingEngineId, viewportId } = viewportInfo;
Expand All @@ -63,19 +61,17 @@ function triggerAnnotationAddedForFOR(annotation: Annotation) {
});
});

const eventType = Events.ANNOTATION_ADDED;
const eventDetail: AnnotationAddedEventDetail = { annotation };

if (!viewportsToRender.length) {
triggerEvent(eventTarget, eventType, eventDetail);
return;
}

const eventType = Events.ANNOTATION_ADDED;

viewportsToRender.forEach(({ renderingEngineId, viewportId }) => {
const eventDetail: AnnotationAddedEventDetail = {
annotation,
viewportId,
renderingEngineId,
};

eventDetail.viewportId = viewportId;
eventDetail.renderingEngineId = renderingEngineId;
triggerEvent(eventTarget, eventType, eventDetail);
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/tools/src/types/EventTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ type ToolActivatedEventDetail = {
*/
type AnnotationAddedEventDetail = {
/** unique id of the viewport */
viewportId: string;
viewportId?: string;
/** unique id of the rendering engine */
renderingEngineId: string;
renderingEngineId?: string;
/** The annotation that is being added to the annotations manager. */
annotation: Annotation;
};
Expand Down