fix: backward compatibility with toolbar service (#5052)

This commit is contained in:
Alireza authored and GitHub committed 2025-05-16 13:42:35 -04:00
1 parent c6b28654b5
commit 9b1b501d83
27 files changed
+198 -144

No files matched your search

@@ -37,20 +37,10 @@ export const TOOLBAR_SECTIONS = {
rightMiddle: 'viewportActionMenu.rightMiddle',
},
/**
* Measurement tools section
*/
measurementSection: 'measurementSection',
/**
* More tools section
*/
moreToolsSection: 'moreToolsSection',
/**
* Advanced rendering controls section
*/
advancedRenderingControlsSection: 'advancedRenderingControlsSection',
// mode specific
segmentationToolbox: 'segmentationToolbox',
dynamicToolbox: 'dynamic-toolbox',
roiThresholdToolbox: 'ROIThresholdToolbox',
};
export enum ButtonLocation {
@@ -199,6 +189,11 @@ export default class ToolbarService extends PubSubService {
button.props = {} as ButtonProps;
}
// if button section is true as boolean, we assign the id of the button to the buttonSection
if (button.props.buttonSection === true) {
button.props.buttonSection = button.id;
}
this.state.buttons[button.id] = button;
}
});
@@ -410,6 +405,19 @@ export default class ToolbarService extends PubSubService {
return this.state.buttons[id];
}
/**
* @deprecated Use register() instead. This method will be removed in a future version.
* Adds buttons to the toolbar.
* @param buttons - The buttons to be added.
* @param replace - Flag indicating if any existing button with the same id as one being added should be replaced
*/
public addButtons(buttons: Button[], replace: boolean = false): void {
console.warn(
'ToolbarService.addButtons() is deprecated. Use ToolbarService.register() instead.'
);
this.register(buttons, replace);
}
/**
* Retrieves the buttons from the toolbar service.
* @returns An array of buttons.
@@ -470,6 +478,19 @@ export default class ToolbarService extends PubSubService {
this._broadcastEvent(this.EVENTS.TOOL_BAR_MODIFIED, { ...this.state });
}
/**
* @deprecated Use updateSection() instead. This method will be removed in a future version.
* Creates a button section with the specified key and buttons.
* @param {string} key - The key of the button section.
* @param {Array} buttons - The buttons to be added to the section.
*/
createButtonSection(key, buttons) {
console.warn(
'ToolbarService.createButtonSection() is deprecated. Use ToolbarService.updateSection() instead.'
);
this.updateSection(key, buttons);
}
/**
* Retrieves the button section with the specified sectionId.
*
@@ -13,8 +13,6 @@ export type ToolbarSections = {
bottomLeft: string;
bottomRight: string;
};
measurementSection: string;
moreToolsSection: string;
};
export type EvaluatePublic =
@@ -59,7 +57,7 @@ export type ButtonProps = {
evaluate?: EvaluatePublic;
listeners?: Record<string, RunCommand>;
options?: ButtonOptions[];
buttonSection?: string;
buttonSection?: string | boolean;
};
export type Button = {
@@ -27,7 +27,7 @@ export const EVENTS = {
sections: [
{
key: 'primary',
buttons: [ 'measurementSection', 'Zoom', ... ],
buttons: [ 'MeasurementTools', 'Zoom', ... ],
},
],
},