-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
feat(toolbar): enable extensions to change toolbar button sections #4367
feat(toolbar): enable extensions to change toolbar button sections #4367
Conversation
✅ Deploy Preview for ohif-platform-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for ohif-dev ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR makes sense to me, unless i'm missing something. It's a nice fix. I also tried locally and for example, if in your extensions 'onModeEnter' you define something like:
toolbarService.createButtonSection('primary', ['CornerstoneButton']);
toolbarService.addButtons([
{
id: 'CornerstoneButton',
uiType: 'ohif.radioGroup',
props: {
icon: 'tool-zoom',
label: 'Zoom',
commands: [
{
commandName: 'setToolActiveToolbar',
commandOptions: {
toolGroupIds: ['default', 'mpr', 'SRToolGroup', 'volume3d'],
},
},
],
evaluate: 'evaluate.cornerstoneTool',
},
},
]);
It seems that later on when mode.OnModeEnter()
is called, that also calls the toolbarServices.createButtonSection()
, which does set the buttons but also overrides the existing section at the same time
createButtonSection(key, buttons) {
this.state.buttonSections[key] = buttons;
this._broadcastEvent(this.EVENTS.TOOL_BAR_MODIFIED, { ...this.state });
}
I thought we could try using a different buttonSectionId
for our section like cornerstoneSection
, but the top toolbar uses primary
by default so it won't appear up there but will be in the state,
however, do you think this is a cleaner fix? I think this way no one needs to modify their modes or add anything extra.
createButtonSection(key, buttons) {
if (this.state.buttonSections[key]) {
this.state.buttonSections[key].push(...buttons);
} else {
this.state.buttonSections[key] = buttons;
}
this._broadcastEvent(this.EVENTS.TOOL_BAR_MODIFIED, { ...this.state });
}
This appends to the existing section if it exists, so if a mode finds that primary exists, it will add on top of it, and it should work fine since the toolbar is always reset when you enter a brand new mode, so the appending shouldn't cause any collisions or state management issues.
that's a good idea @IbrahimCSAE, the only thing I'd do differently is that I'd create a new method with a different name, since now we're not creating a button section anymore, we're sort of "upserting". The current name could be misleading and changing it's behavior right now could affect other people's customizations. |
Context
Currently, it's not possible to modify the primary toolbar button section with an extension. There are a few scenarios in which one could want to do that. For example:
The reason it's not possible to do that today is the following:
The mode's toolbar operations override the extensions', because the
onModeEnter
method of the mode runs after the extensions' one:Since OHIF's pre-existing modes, such as longitudinal, tmtv, etc, create button sections from scratch, instead of adding buttons to a button section, it's not possible to add anything to the primary button section from the extension, since it gets overwritten later on.
Changes & Results
With these changes, one can now add buttons to every mode by using the extensions
onModeEnter
to alter the button section. See an example:Before (extension has no bearing in the toolbar):
After (extension can add buttons to the toolbar):
Testing
Checklist
PR
semantic-release format and guidelines.
Code
etc.)
Public Documentation Updates
additions or removals.
Tested Environment