diff --git a/monkey/monkey_island/cc/ui/src/components/ui-components/AdvancedMultiSelect.js b/monkey/monkey_island/cc/ui/src/components/ui-components/AdvancedMultiSelect.js index e0bc667de..df72ef682 100644 --- a/monkey/monkey_island/cc/ui/src/components/ui-components/AdvancedMultiSelect.js +++ b/monkey/monkey_island/cc/ui/src/components/ui-components/AdvancedMultiSelect.js @@ -6,7 +6,7 @@ import {cloneDeep} from 'lodash'; import {getDefaultPaneParams, InfoPane, WarningType} from './InfoPane'; import {MasterCheckbox, MasterCheckboxState} from './MasterCheckbox'; import ChildCheckboxContainer from './ChildCheckbox'; -import {getFullDefinitionByKey, getObjectFromRegistryByRef} from './JsonSchemaHelpers'; +import {getFullDefinitionByKey} from './JsonSchemaHelpers'; function AdvancedMultiSelectHeader(props) { const { @@ -38,14 +38,12 @@ class AdvancedMultiSelect extends React.Component { this.state = { infoPaneParams: getDefaultPaneParams( - this.props.schema.items.$ref, - this.props.registry, + this.props.schema.items, this.isUnsafeOptionSelected(selectedPluginNames) ), allPluginNames: allPluginNames, masterCheckboxState: this.getMasterCheckboxState(selectedPluginNames), - pluginDefinitions: getObjectFromRegistryByRef(this.props.schema.items.$ref, - this.props.registry).pluginDefs, + pluginDefinitions: this.props.schema.items.pluginDefs, selectedPluginNames: selectedPluginNames }; } @@ -55,23 +53,17 @@ class AdvancedMultiSelect extends React.Component { } onChange = (strValues) => { - let newValues = []; - for (let j = 0; j < strValues.length; j++) { - let found = false; - for (let i = 0; i < this.state.allPluginNames.length; i++) { - if (strValues[j] === this.state.allPluginNames[i]['name']) { - newValues.push(JSON.parse(JSON.stringify(this.props.value[i]))) - found = true; - break; - } - } - if (!found) { - newValues.push(this.state.pluginDefinitions[strValues[j]]); - } + let pluginArray = this.namesToPlugins(strValues, this.state.pluginDefinitions); + this.props.onChange(pluginArray) + this.setState({selectedPluginNames: pluginArray.map(v => v.name)}); + } + + namesToPlugins = (names, allPlugins) => { + let plugins = []; + for (let i = 0; i < names.length; i++){ + plugins.push(_.clone(allPlugins[names[i]])); } - newValues = JSON.parse(JSON.stringify(newValues)); - this.props.onChange(newValues) - this.setState({selectedPluginNames: newValues.map(v => v.name)}); + return plugins } // Sort options alphabetically. "Unsafe" options float to the top so that they @@ -146,14 +138,12 @@ class AdvancedMultiSelect extends React.Component { } isSafe = (itemKey) => { - let fullDef = getFullDefinitionByKey(this.props.schema.items.$ref, - this.props.registry, itemKey); + let fullDef = getFullDefinitionByKey(this.props.schema.items, itemKey); return fullDef.safe; } setPaneInfo = (itemKey) => { - let definitionObj = getFullDefinitionByKey(this.props.schema.items.$ref, - this.props.registry, itemKey); + let definitionObj = getFullDefinitionByKey(this.props.schema.items, itemKey); this.setState( { infoPaneParams: { diff --git a/monkey/monkey_island/cc/ui/src/components/ui-components/JsonSchemaHelpers.js b/monkey/monkey_island/cc/ui/src/components/ui-components/JsonSchemaHelpers.js index 9a3d9c66b..e320e2057 100644 --- a/monkey/monkey_island/cc/ui/src/components/ui-components/JsonSchemaHelpers.js +++ b/monkey/monkey_island/cc/ui/src/components/ui-components/JsonSchemaHelpers.js @@ -1,19 +1,6 @@ -import {resolveObjectPath} from './utils/ObjectPathResolver'; - -function getFullDefinitionByKey(refString, registry, itemKey) { - let fullArray = getFullDefinitionsFromRegistry(refString, registry); +function getFullDefinitionByKey(items, itemKey) { + let fullArray = items.anyOf; return fullArray.filter(e => (e.enum[0] === itemKey))[0]; } -// Definitions passed to components only contains value and label, -// custom fields like "info" or "links" must be pulled from registry object using this function -function getFullDefinitionsFromRegistry(refString, registry) { - return getObjectFromRegistryByRef(refString, registry).anyOf; -} - -function getObjectFromRegistryByRef(refString, registry) { - let refArray = refString.replace('#', '').split('/'); - return resolveObjectPath(refArray, registry); -} - -export {getFullDefinitionByKey, getObjectFromRegistryByRef}; +export {getFullDefinitionByKey}; diff --git a/monkey/monkey_island/cc/ui/src/components/ui-components/utils/ObjectPathResolver.js b/monkey/monkey_island/cc/ui/src/components/ui-components/utils/ObjectPathResolver.js deleted file mode 100644 index 9fef26c7a..000000000 --- a/monkey/monkey_island/cc/ui/src/components/ui-components/utils/ObjectPathResolver.js +++ /dev/null @@ -1,11 +0,0 @@ - -// Resolves object's path if it's specified in a dot notation. -// (e.g. params: "firstLevel.secondLevel.property", myObject) -export function resolveObjectPath(pathArray, obj) { - return pathArray.reduce(function(prev, curr) { - if(curr === '') - return prev; - else - return prev ? prev[curr] : null; - }, obj || self) -}