From e42c4a0fa27ed8f348eda32ac7d5b204199f2edc Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Tue, 25 Aug 2020 11:30:12 +0300 Subject: [PATCH] More work and styling of monkey run page components --- .../pages/RunMonkeyPage/CommandDisplay.js | 39 ++++++++++++------- .../RunMonkeyPage/LocalManualRunOptions.js | 8 ++-- .../pages/RunMonkeyPage/ManualRunOptions.js | 28 ++++++++----- .../pages/RunMonkeyPage/RunOptions.js | 0 .../ui-components/DropdownSelect.js | 5 ++- .../inline-selection/BackButton.js | 15 +++++-- .../inline-selection/InlineSelection.js | 5 ++- .../inline-selection/NextSelectionButton.js | 24 +++++++++--- .../monkey_island/cc/ui/src/styles/Main.scss | 4 +- .../styles/components/InlineSelection.scss | 8 ---- .../inline-selection/BackButton.scss | 20 ++++++++++ .../inline-selection/InlineSelection.scss | 12 ++++++ .../inline-selection/NextSelectionButton.scss | 34 ++++++++++++++++ 13 files changed, 153 insertions(+), 49 deletions(-) delete mode 100644 monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOptions.js delete mode 100644 monkey/monkey_island/cc/ui/src/styles/components/InlineSelection.scss create mode 100644 monkey/monkey_island/cc/ui/src/styles/components/inline-selection/BackButton.scss create mode 100644 monkey/monkey_island/cc/ui/src/styles/components/inline-selection/InlineSelection.scss create mode 100644 monkey/monkey_island/cc/ui/src/styles/components/inline-selection/NextSelectionButton.scss diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/CommandDisplay.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/CommandDisplay.js index bf0852c59..b237e25d2 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/CommandDisplay.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/CommandDisplay.js @@ -2,42 +2,53 @@ import {Button, Card, Nav} from 'react-bootstrap'; import CopyToClipboard from 'react-copy-to-clipboard'; import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; import {faClipboard} from '@fortawesome/free-solid-svg-icons/faClipboard'; -import React, {useState} from 'react'; +import React, {useEffect, useState} from 'react'; import PropTypes from 'prop-types'; export default function commandDisplay(props) { - const [selectedVariant, setSelectedVariant] = useState(props.commands[0].name); + const [selectedCommand, setSelectedCommand] = useState(props.commands[0]); + + function setSelectedCommandByName(type){ + setSelectedCommand(getCommandByName(props.commands, type)); + } + + function getCommandByName(commands, type){ + return commands.find((command) => {return command.type === type}); + } + + useEffect(() => { + let sameTypeCommand = getCommandByName(props.commands, selectedCommand.type); + if( sameTypeCommand !== undefined){ + setSelectedCommand(sameTypeCommand); + } else { + setSelectedCommand(props.commands[0]); + } + }, [props.commands]); function renderNav() { return ( -