From 16f97f2811472d7a0ca9e6c83276dad13cd73c9a Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Wed, 30 Jun 2021 15:53:40 +0300 Subject: [PATCH] Hide the input fields for directories to be encrypted if "Should encrypt" option is disabled This change will enhance the UX by hiding the irrelevant inputs. This also allows us to add further logic to dynamically hide/show or otherwise modify uiSchema --- .../UISchemaManipulators.tsx | 21 +++++++++++++++++++ .../ui/src/components/pages/ConfigurePage.js | 5 +++++ 2 files changed, 26 insertions(+) create mode 100644 monkey/monkey_island/cc/ui/src/components/configuration-components/UISchemaManipulators.tsx diff --git a/monkey/monkey_island/cc/ui/src/components/configuration-components/UISchemaManipulators.tsx b/monkey/monkey_island/cc/ui/src/components/configuration-components/UISchemaManipulators.tsx new file mode 100644 index 000000000..637a128f3 --- /dev/null +++ b/monkey/monkey_island/cc/ui/src/components/configuration-components/UISchemaManipulators.tsx @@ -0,0 +1,21 @@ + +const manipulatorList = [ransomwareDirManipulator] + +function applyUiSchemaManipulators(selectedSection, + formData, + uiSchema) { + for(let i = 0; i < manipulatorList.length; i++){ + manipulatorList[i](selectedSection, formData, uiSchema); + } +} + +function ransomwareDirManipulator(selectedSection, + formData, + uiSchema) { + if (selectedSection === 'ransomware'){ + uiSchema.encryption.directories = + {'ui:disabled': !formData['encryption']['enabled']}; + } +} + +export default applyUiSchemaManipulators; diff --git a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js index 19dae5fbc..310555408 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js @@ -16,6 +16,7 @@ import UnsafeOptionsWarningModal from '../configuration-components/UnsafeOptions import isUnsafeOptionSelected from '../utils/SafeOptionValidator.js'; import ConfigExportModal from '../configuration-components/ExportConfigModal'; import ConfigImportModal from '../configuration-components/ImportConfigModal'; +import applyUiSchemaManipulators from '../configuration-components/UISchemaManipulators.tsx'; const ATTACK_URL = '/api/attack'; const CONFIG_URL = '/api/configuration/island'; @@ -417,6 +418,10 @@ class ConfigurePageComponent extends AuthComponent { formProperties['className'] = 'config-form'; formProperties['liveValidate'] = true; + applyUiSchemaManipulators(this.state.selectedSection, + formProperties['formData'], + formProperties['uiSchema']); + if (this.state.selectedSection === 'internal') { return () } else {