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(events): ANNOTATION_REMOVED event listener on removing ALL annotations. #1236

Merged
merged 9 commits into from
Jun 5, 2024

Conversation

ChandlerClevenger
Copy link
Contributor

@ChandlerClevenger ChandlerClevenger commented May 3, 2024

Context

Fixes #1056

Changes & Results

Moved code from FrameOfReferenceSpecificAnnotationManager into annotationState and re-used the same annotation removal code.

Testing

I used the annotationVisibility example and added another button to remove selected annotation OR if none are selected it would remove them all. I tested this way and it worked.

Checklist

PR

  • My Pull Request title is descriptive, accurate and follows the
    semantic-release format and guidelines.

Code

  • My code has been well-documented (function documentation, inline comments,
    etc.)

  • I have run the yarn build:update-api to update the API documentation, and have
    committed the changes to this PR. (Read more here https://www.cornerstonejs.org/docs/contribute/update-api)
    N/A really

Public Documentation Updates

  • The documentation page has been updated as necessary for any public API
    additions or removals.

Tested Environment

  • "OS: Windows 11
  • "Node version: Node v20.12.2
  • "Browser: Chrome Version 124.0.6367.119 (Official Build) (64-bit)

Copy link

netlify bot commented May 3, 2024

Deploy Preview for cornerstone-3d-docs ready!

Name Link
🔨 Latest commit 773543a
🔍 Latest deploy log https://app.netlify.com/sites/cornerstone-3d-docs/deploys/6660a58fd50d250008d7d096
😎 Deploy Preview https://deploy-preview-1236--cornerstone-3d-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@sedghi sedghi self-requested a review May 6, 2024 13:24
@sedghi sedghi self-assigned this May 6, 2024
Comment on lines 279 to 284
if (annotationToRemove !== null) {
triggerEvent(eventTarget, csToolEvents.ANNOTATION_REMOVED, {
annotation: annotationToRemove,
annotationManagerUID: this.uid,
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you examine other sections in this file, we don't publish events here but rather in the annotationState. Could you perhaps follow the same pattern?

@@ -223,16 +217,6 @@ function removeAnnotation(annotationUID: string): void {
);

manager.removeAnnotation(annotationUID);

// trigger annotation removed
const eventType = Events.ANNOTATION_REMOVED;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think make a copy here

Copy link
Member

@sedghi sedghi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my comments please

Comment on lines 257 to 262
*/
function removeAnnotations(groupKey: string, toolName?: string): void {
const manager = getAnnotationManager();
const removedAnnotations = manager.removeAnnotations(groupKey, toolName);

for (const annotation of removedAnnotations) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't expect this, why groupKey is part of the params? can you follow how other state functions behave please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is meant to be AnnotationGroupSelector instead of string? I will make this change as that is how other functions in this file handle this.

@ChandlerClevenger
Copy link
Contributor Author

I made that function parameter more in-line with the other functions in that file. Thank you for these reviews.

Copy link
Member

@sedghi sedghi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I just re-orderd the params to be consistent with other annotation state APIs

@sedghi sedghi changed the title Fix ANNOTATION_REMOVED event listener on removing ALL annotations. fix(events): ANNOTATION_REMOVED event listener on removing ALL annotations. Jun 5, 2024
@sedghi sedghi merged commit 5bddf05 into cornerstonejs:main Jun 5, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cornerstone.annotation.state.removeAllAnnotations() should dispatchEvent for ANNOATION_REMOVED
2 participants