ohif-viewer/platform/ui/src/components/HotkeysPreferences/utils.js
Igor Octaviano 3e944780dc
OHIF-332: Users should be able to see all available hotkeys and language settings in one place (#1895)
* OHIF-330: Update Modal Styles

* feat/ohif-332: finish raw ui

* feat/ohif-332: update mode configuration strategy

* feat/ohif-332: fix hotkey errors

* feat/ohif-332: update hotkey logic with recent merged changes

* feat/ohif-322: wrap

* feat/ohif-322: add disable state

* ohif-332: cr updates

* ohif-332: disable

* ohif-332: cr updates

* ohif-332: extract header component

* ohif-332: cr update to fix merge conflicts and design issue

Co-authored-by: Rodrigo Antinarelli <rodrigoantinarelli@gmail.com>
2020-08-19 15:02:59 -04:00

53 lines
1.3 KiB
JavaScript

import { hotkeysValidators } from './hotkeysValidators';
/**
* Split hotkeys definitions and create hotkey related tuples
*
* @param {array} hotkeyDefinitions
* @returns {array} array of tuples consisted of command name and hotkey definition
*/
const splitHotkeyDefinitionsAndCreateTuples = hotkeyDefinitions => {
const splitedHotkeys = [];
const arrayHotkeys = Object.entries(hotkeyDefinitions);
if (arrayHotkeys.length) {
const halfwayThrough = Math.ceil(arrayHotkeys.length / 2);
splitedHotkeys.push(arrayHotkeys.slice(0, halfwayThrough));
splitedHotkeys.push(
arrayHotkeys.slice(halfwayThrough, arrayHotkeys.length)
);
}
return splitedHotkeys;
};
/**
* Validate a hotkey change
*
* @param {Object} arguments
* @param {string} arguments.commandName command name or id
* @param {array} arguments.pressedKeys new keys
* @param {array} arguments.hotkeys current hotkeys
* @returns {Object} {error} validation error
*/
const validate = ({ commandName, pressedKeys, hotkeys }) => {
for (const validator of hotkeysValidators) {
const validation = validator({
commandName,
pressedKeys,
hotkeys,
});
if (validation && validation.error) {
return validation;
}
}
return { error: undefined };
};
export {
validate,
splitHotkeyDefinitionsAndCreateTuples
};