-
Notifications
You must be signed in to change notification settings - Fork 794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2698 plugin selector core #2841
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
387eeea
UI: Pass in plugins to plugin selector template
VakarisZ ec79c6c
UI: Implementing plugin selector
VakarisZ d1bbbe1
UI: Fix PluginSelector master select button
ilija-lazoroski 62cb39d
UI: Add unsafe icons to plugins in PluginSelector
ilija-lazoroski f55c585
UI: Fix plugin selector to actually mutate the plugin config
VakarisZ e2c13df
UI: Remove seemingly unused methods in ConfigurePage.js
VakarisZ 3447c1e
UI: Refactor deprecated "classNames" property in UiSchema.js
VakarisZ fed2e4f
UI: Fix bugs and improve plugin selection in configuration
VakarisZ ab2a39f
UI: Change filterUnselectedPlugins to return whole config
ilija-lazoroski 0eb4649
UI: Add a comment clarifying what EXPLOITERS_SCHEMA_PATH consts mean
VakarisZ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
109 changes: 75 additions & 34 deletions
109
...ey/monkey_island/cc/ui/src/components/configuration-components/PluginSelectorTemplate.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,89 @@ | ||
import {ObjectFieldTemplateProps} from '@rjsf/utils'; | ||
import {getDefaultFormState, ObjectFieldTemplateProps} from '@rjsf/utils'; | ||
import React, {useState} from 'react'; | ||
import {Dropdown} from 'react-bootstrap'; | ||
|
||
const PluginSelector = (props) => { | ||
let selectOptions = []; | ||
for (const [name, plugin] of Object.entries(props.plugins)) { | ||
selectOptions.push( | ||
<Dropdown.Item onClick={() => props.onClick(name)} | ||
eventKey={`plugin['title']`}> | ||
{plugin['title']}</Dropdown.Item> | ||
)} | ||
|
||
return ( | ||
<Dropdown> | ||
<Dropdown.Toggle variant="success" id="dropdown-basic"> | ||
Select a plugin | ||
</Dropdown.Toggle> | ||
<Dropdown.Menu> | ||
{selectOptions} | ||
</Dropdown.Menu> | ||
</Dropdown> | ||
) | ||
} | ||
import ChildCheckboxContainer from '../ui-components/ChildCheckbox'; | ||
import {AdvancedMultiSelectHeader} from '../ui-components/AdvancedMultiSelect'; | ||
import {MasterCheckboxState} from '../ui-components/MasterCheckbox'; | ||
|
||
|
||
export default function PluginSelectorTemplate(props: ObjectFieldTemplateProps) { | ||
|
||
function getPluginDisplay(plugin, allPlugins){ | ||
let [selectedPlugin, setSelectedPlugin] = useState(null); | ||
|
||
function getPluginDisplay(plugin, allPlugins) { | ||
let selectedPlugin = allPlugins.filter((pluginInArray) => pluginInArray.name == plugin) | ||
if(selectedPlugin.length === 1){ | ||
if (selectedPlugin.length === 1) { | ||
return <div className="property-wrapper">{selectedPlugin[0].content}</div> | ||
} | ||
} | ||
|
||
let [element, setElement] = useState(null); | ||
function getOptions() { | ||
let selectorOptions = []; | ||
for (let [name, schema] of Object.entries(props.schema.properties)) { | ||
selectorOptions.push({label: schema.title, value: name}); | ||
} | ||
return selectorOptions; | ||
} | ||
|
||
function togglePluggin(pluginName) { | ||
let plugins = new Set(props.formContext.selectedExploiters); | ||
if (props.formContext.selectedExploiters.has(pluginName)) { | ||
plugins.delete(pluginName); | ||
} else { | ||
plugins.add(pluginName); | ||
} | ||
props.formContext.setSelectedExploiters(plugins) | ||
} | ||
|
||
function getMasterCheckboxState(selectValues) { | ||
if (Object.keys(selectValues).length === 0) { | ||
return MasterCheckboxState.NONE; | ||
} | ||
|
||
if (Object.keys(selectValues).length !== getOptions().length) { | ||
return MasterCheckboxState.MIXED; | ||
} | ||
|
||
return MasterCheckboxState.ALL; | ||
} | ||
|
||
function generateDefaultConfig() { | ||
return getDefaultFormState(props.registry.schemaUtils.validator, | ||
props.schema, {}, props.registry.rootSchema, true); | ||
} | ||
|
||
function onMasterPluginCheckboxClick() { | ||
let checkboxState = getMasterCheckboxState(props.formContext.selectedExploiters); | ||
if (checkboxState == MasterCheckboxState.ALL) { | ||
props.formContext.setSelectedExploiters({}); | ||
} else { | ||
props.formContext.setSelectedExploiters(generateDefaultConfig()); | ||
} | ||
} | ||
|
||
function isPluginSafe(itemKey) { | ||
let itemSchema = Object.entries(props.schema.properties).filter(e => e[0] == itemKey)[0][1]; | ||
return itemSchema['safe']; | ||
} | ||
|
||
return ( | ||
<div> | ||
{props.title} | ||
{props.description} | ||
<PluginSelector plugins={{"TODO": {"title": "pass in actual schema"}}} | ||
onClick={(pluginName) => { | ||
setElement(pluginName) | ||
}}/> | ||
{getPluginDisplay(element, props.properties)} | ||
<div className={'advanced-multi-select'}> | ||
<AdvancedMultiSelectHeader title={props.schema.title} | ||
onCheckboxClick={onMasterPluginCheckboxClick} | ||
checkboxState={ | ||
getMasterCheckboxState( | ||
[...props.formContext.selectedExploiters])} | ||
hideReset={false} | ||
onResetClick={() => { | ||
}}/> | ||
|
||
<ChildCheckboxContainer id={'abc'} multiple={true} required={false} | ||
autoFocus={false} | ||
selectedValues={[...props.formContext.selectedExploiters]} | ||
onCheckboxClick={togglePluggin} | ||
isSafe={isPluginSafe} | ||
onPaneClick={setSelectedPlugin} | ||
enumOptions={getOptions()}/> | ||
{getPluginDisplay(selectedPlugin, props.properties)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could've been a separate PR, but for the sake of speed left it here