Skip to content

Commit

Permalink
PR review comments - removed run command
Browse files Browse the repository at this point in the history
  • Loading branch information
wayfarer3130 committed Nov 22, 2024
1 parent 34d9756 commit 04cbc18
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 69 deletions.
7 changes: 3 additions & 4 deletions extensions/cornerstone/src/panels/PanelMeasurement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ export default function PanelMeasurementTable({
}
}, [displayMeasurements.length]);

const bindCommand = (name: string, options?) => {
const bindCommand = (name: string | string[], options?) => {
return (uid: string) => {
commandsManager.runCommand(name, { ...options, uid });
commandsManager.run(name, { ...options, uid });
};
};

const jumpToImage = bindCommand('jumpToMeasurement', { displayMeasurements });
const removeMeasurement = bindCommand('removeMeasurement');
const renameMeasurement = bindCommand('run', {
commands: ['jumpToMeasurement', 'renameMeasurement'],
const renameMeasurement = bindCommand(['jumpToMeasurement', 'renameMeasurement'], {
displayMeasurements,
});
const toggleLockMeasurement = bindCommand('toggleLockMeasurement');
Expand Down
74 changes: 10 additions & 64 deletions extensions/default/src/commandsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,39 +47,6 @@ const commandsModule = ({
const contextMenuController = new ContextMenuController(servicesManager, commandsManager);

const actions = {
/**
* Runs commands specified in the options.
* This allows running multiple commands when only one is specified. It
* also allows an async instantiation of a command so that the return is
* immediate without waiting for the command to complete.
*
* @param options.options - shared options for the child command
* @param options.commands - a list of commands to run. This is an array, and can
* be either a full command, or just a name.
* @param options.async - set to true to run async
* @param options.parallel - set to false, WITH async true to run non-parallel
*/
run: options => {
const { options: sharedOptions, commands = [], parallel = true, async = false } = options;
const childOptions = {
...options,
options: undefined,
commands: undefined,
parallel: undefined,
async: undefined,
...sharedOptions,
};
if (async) {
if (parallel) {
return Promise.all(
commands.map(async command => commandsManager.run(command, childOptions))
);
}
return (async () => await commandsManager.run(commands, childOptions))();
}
return commandsManager.run(commands, childOptions);
},

/**
* Show the context menu.
* @param options.menuId defines the menu name to lookup, from customizationService
Expand Down Expand Up @@ -587,26 +554,13 @@ const commandsModule = ({
};

const definitions = {
run: actions.run,
showContextMenu: actions.showContextMenu,
closeContextMenu: {
commandFn: actions.closeContextMenu,
},
clearMeasurements: {
commandFn: actions.clearMeasurements,
},
displayNotification: {
commandFn: actions.displayNotification,
},
setHangingProtocol: {
commandFn: actions.setHangingProtocol,
},
toggleHangingProtocol: {
commandFn: actions.toggleHangingProtocol,
},
navigateHistory: {
commandFn: actions.navigateHistory,
},
closeContextMenu: actions.closeContextMenu,
clearMeasurements: actions.clearMeasurements,
displayNotification: actions.displayNotification,
setHangingProtocol: actions.setHangingProtocol,
toggleHangingProtocol: actions.toggleHangingProtocol,
navigateHistory: actions.navigateHistory,
nextStage: {
commandFn: actions.deltaStage,
options: { direction: 1 },
Expand All @@ -615,18 +569,10 @@ const commandsModule = ({
commandFn: actions.deltaStage,
options: { direction: -1 },
},
setViewportGridLayout: {
commandFn: actions.setViewportGridLayout,
},
toggleOneUp: {
commandFn: actions.toggleOneUp,
},
openDICOMTagViewer: {
commandFn: actions.openDICOMTagViewer,
},
updateViewportDisplaySet: {
commandFn: actions.updateViewportDisplaySet,
},
setViewportGridLayout: actions.setViewportGridLayout,
toggleOneUp: actions.toggleOneUp,
openDICOMTagViewer: actions.openDICOMTagViewer,
updateViewportDisplaySet: actions.updateViewportDisplaySet,
};

return {
Expand Down
2 changes: 1 addition & 1 deletion platform/core/src/classes/CommandsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class CommandsManager {
* the commandOptions specified in the base.
*/
public run(
toRun: Command | Commands | Command[] | string | undefined,
toRun: Command | Commands | (Command | string)[] | string | undefined,
options?: Record<string, unknown>
): unknown {
if (!toRun) {
Expand Down

0 comments on commit 04cbc18

Please sign in to comment.