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 all commits
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
4 changes: 2 additions & 2 deletions common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ export { annotation }

// @public (undocumented)
type AnnotationAddedEventDetail = {
viewportId: string;
renderingEngineId: string;
viewportId?: string;
renderingEngineId?: string;
annotation: Annotation;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,18 @@ function addAnnotation(
}

const manager = getAnnotationManager();
const groupKey = manager.getGroupKey(annotationGroupSelector);

manager.addAnnotation(annotation, groupKey);

// if the annotation manager selector is an element, trigger the
// annotation added event for that element.
if (annotationGroupSelector instanceof HTMLDivElement) {
const groupKey = manager.getGroupKey(annotationGroupSelector);
manager.addAnnotation(annotation, groupKey);
triggerAnnotationAddedForElement(annotation, annotationGroupSelector);
} else {
// if no element is provided, render all viewports that have the
// same frame of reference.
// Todo: we should do something else here for other types of annotation managers.
manager.addAnnotation(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