fix(toolbar): prevent duplicate command execution on repeated interactions (#5456)
This commit is contained in:
1 parent
9e79e76bab
commit
4d04dd5651
6 files changed
+238
-42
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import { ButtonProps, RunCommand } from '../types';
|
||||
|
||||
const toArray = <T>(value?: T | T[]): T[] =>
|
||||
Array.isArray(value) ? value : value != null ? [value] : [];
|
||||
|
||||
export const buildButtonCommands = (
|
||||
buttonProps: ButtonProps,
|
||||
baseArgs: Record<string, unknown>,
|
||||
{ servicesManager, commandsManager }: AppTypes.Managers
|
||||
): Array<() => unknown> => {
|
||||
const allCommands: Array<() => unknown> = [];
|
||||
|
||||
// 1) normalize item-level commands
|
||||
for (const command of toArray(buttonProps.commands as RunCommand)) {
|
||||
allCommands.push(() => commandsManager.run(command, baseArgs));
|
||||
}
|
||||
|
||||
// 2) normalize option-level commands
|
||||
for (const option of toArray(buttonProps.options)) {
|
||||
const shouldSkip = !option?.commands || option.explicitRunOnly;
|
||||
if (shouldSkip) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const valueToUse = option.value;
|
||||
for (const command of toArray(option.commands)) {
|
||||
const commandOptions = {
|
||||
...option,
|
||||
value: valueToUse,
|
||||
options: buttonProps.options,
|
||||
servicesManager,
|
||||
commandsManager,
|
||||
};
|
||||
|
||||
allCommands.push(() => commandsManager.run(command, commandOptions));
|
||||
}
|
||||
}
|
||||
|
||||
return allCommands;
|
||||
};
|
||||
@@ -46,6 +46,8 @@ import getClosestOrientationFromIOP from './getClosestOrientationFromIOP';
|
||||
import calculateScanAxisNormal from './calculateScanAxisNormal';
|
||||
import areAllImageOrientationsEqual from './areAllImageOrientationsEqual';
|
||||
import { structuredCloneWithFunctions } from './structuredCloneWithFunctions';
|
||||
import { buildButtonCommands } from './buildButtonCommands';
|
||||
|
||||
// Commented out unused functionality.
|
||||
// Need to implement new mechanism for derived displaySets using the displaySetManager.
|
||||
|
||||
@@ -134,6 +136,7 @@ export {
|
||||
createStudyBrowserTabs,
|
||||
MeasurementFilters,
|
||||
getClosestOrientationFromIOP,
|
||||
buildButtonCommands,
|
||||
};
|
||||
|
||||
export default utils;
|
||||
Reference in new issue
Block a user