summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/components/modals
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-web/opendc-web-ui/src/components/modals')
-rw-r--r--opendc-web/opendc-web-ui/src/components/modals/ConfirmationModal.js27
-rw-r--r--opendc-web/opendc-web-ui/src/components/modals/Modal.js38
-rw-r--r--opendc-web/opendc-web-ui/src/components/modals/TextInputModal.js70
-rw-r--r--opendc-web/opendc-web-ui/src/components/modals/custom-components/NewPortfolioModal.js139
-rw-r--r--opendc-web/opendc-web-ui/src/components/modals/custom-components/NewScenarioModal.js159
-rw-r--r--opendc-web/opendc-web-ui/src/components/modals/custom-components/NewTopologyModal.js81
6 files changed, 0 insertions, 514 deletions
diff --git a/opendc-web/opendc-web-ui/src/components/modals/ConfirmationModal.js b/opendc-web/opendc-web-ui/src/components/modals/ConfirmationModal.js
deleted file mode 100644
index f6e1c98b..00000000
--- a/opendc-web/opendc-web-ui/src/components/modals/ConfirmationModal.js
+++ /dev/null
@@ -1,27 +0,0 @@
-import PropTypes from 'prop-types'
-import React from 'react'
-import Modal from './Modal'
-
-function ConfirmationModal({ title, message, isOpen, callback }) {
- return (
- <Modal
- title={title}
- isOpen={isOpen}
- onSubmit={() => callback(true)}
- onCancel={() => callback(false)}
- submitButtonType="danger"
- submitButtonText="Confirm"
- >
- {message}
- </Modal>
- )
-}
-
-ConfirmationModal.propTypes = {
- title: PropTypes.string.isRequired,
- message: PropTypes.string.isRequired,
- isOpen: PropTypes.bool.isRequired,
- callback: PropTypes.func.isRequired,
-}
-
-export default ConfirmationModal
diff --git a/opendc-web/opendc-web-ui/src/components/modals/Modal.js b/opendc-web/opendc-web-ui/src/components/modals/Modal.js
deleted file mode 100644
index d4577062..00000000
--- a/opendc-web/opendc-web-ui/src/components/modals/Modal.js
+++ /dev/null
@@ -1,38 +0,0 @@
-import React from 'react'
-import PropTypes from 'prop-types'
-import { Button, Modal as PModal, ModalVariant } from '@patternfly/react-core'
-
-function Modal({ children, title, isOpen, onSubmit, onCancel, submitButtonType, submitButtonText }) {
- const actions = [
- <Button variant={submitButtonType} onClick={onSubmit} key="confirm">
- {submitButtonText}
- </Button>,
- <Button variant="link" onClick={onCancel} key="cancel">
- Cancel
- </Button>,
- ]
-
- return (
- <PModal variant={ModalVariant.small} isOpen={isOpen} onClose={onCancel} title={title} actions={actions}>
- {children}
- </PModal>
- )
-}
-
-Modal.propTypes = {
- title: PropTypes.string.isRequired,
- isOpen: PropTypes.bool,
- onSubmit: PropTypes.func.isRequired,
- onCancel: PropTypes.func.isRequired,
- submitButtonType: PropTypes.string,
- submitButtonText: PropTypes.string,
- children: PropTypes.node,
-}
-
-Modal.defaultProps = {
- submitButtonType: 'primary',
- submitButtonText: 'Save',
- isOpen: false,
-}
-
-export default Modal
diff --git a/opendc-web/opendc-web-ui/src/components/modals/TextInputModal.js b/opendc-web/opendc-web-ui/src/components/modals/TextInputModal.js
deleted file mode 100644
index 392a729e..00000000
--- a/opendc-web/opendc-web-ui/src/components/modals/TextInputModal.js
+++ /dev/null
@@ -1,70 +0,0 @@
-import PropTypes from 'prop-types'
-import React, { useRef, useState } from 'react'
-import Modal from './Modal'
-import { Form, FormGroup, TextInput } from '@patternfly/react-core'
-
-function TextInputModal({ title, label, isOpen, callback, initialValue }) {
- const textInput = useRef(null)
- const [isSubmitted, setSubmitted] = useState(false)
- const [isValid, setValid] = useState(true)
-
- const resetState = () => {
- textInput.current.value = ''
- setSubmitted(false)
- setValid(false)
- }
- const onSubmit = (event) => {
- const value = textInput.current.value
- setSubmitted(true)
-
- if (event) {
- event.preventDefault()
- }
-
- if (!value) {
- setValid(false)
- return false
- }
-
- callback(value)
- resetState()
- return true
- }
- const onCancel = () => {
- callback(undefined)
- resetState()
- }
-
- return (
- <Modal title={title} isOpen={isOpen} onSubmit={onSubmit} onCancel={onCancel}>
- <Form onSubmit={onSubmit}>
- <FormGroup
- label={label}
- fieldId="text-input"
- isRequired
- validated={isSubmitted && !isValid ? 'error' : 'default'}
- helperTextInvalid="This field cannot be empty"
- >
- <TextInput
- id="text-input"
- name="text-input"
- isRequired
- type="text"
- ref={textInput}
- defaultValue={initialValue}
- />
- </FormGroup>
- </Form>
- </Modal>
- )
-}
-
-TextInputModal.propTypes = {
- title: PropTypes.string.isRequired,
- label: PropTypes.string.isRequired,
- isOpen: PropTypes.bool.isRequired,
- callback: PropTypes.func.isRequired,
- initialValue: PropTypes.string,
-}
-
-export default TextInputModal
diff --git a/opendc-web/opendc-web-ui/src/components/modals/custom-components/NewPortfolioModal.js b/opendc-web/opendc-web-ui/src/components/modals/custom-components/NewPortfolioModal.js
deleted file mode 100644
index afe07597..00000000
--- a/opendc-web/opendc-web-ui/src/components/modals/custom-components/NewPortfolioModal.js
+++ /dev/null
@@ -1,139 +0,0 @@
-import PropTypes from 'prop-types'
-import React, { useRef, useState } from 'react'
-import Modal from '../Modal'
-import {
- Form,
- FormGroup,
- FormSection,
- NumberInput,
- Select,
- SelectGroup,
- SelectOption,
- SelectVariant,
- TextInput,
-} from '@patternfly/react-core'
-import { METRIC_GROUPS, METRIC_NAMES } from '../../../util/available-metrics'
-
-const NewPortfolioModal = ({ isOpen, onSubmit: onSubmitUpstream, onCancel: onUpstreamCancel }) => {
- const nameInput = useRef(null)
- const [repeats, setRepeats] = useState(1)
- const [isSelectOpen, setSelectOpen] = useState(false)
- const [selectedMetrics, setSelectedMetrics] = useState([])
-
- const [isSubmitted, setSubmitted] = useState(false)
- const [errors, setErrors] = useState({})
-
- const clearState = () => {
- setSubmitted(false)
- setErrors({})
- nameInput.current.value = ''
- setRepeats(1)
- setSelectOpen(false)
- setSelectedMetrics([])
- }
-
- const onSubmit = (event) => {
- setSubmitted(true)
-
- if (event) {
- event.preventDefault()
- }
-
- const name = nameInput.current.value
-
- if (!name) {
- setErrors({ name: true })
- return false
- } else {
- onSubmitUpstream(name, { enabledMetrics: selectedMetrics, repeatsPerScenario: repeats })
- }
-
- clearState()
- return false
- }
- const onCancel = () => {
- onUpstreamCancel()
- clearState()
- }
-
- const onSelect = (event, selection) => {
- if (selectedMetrics.includes(selection)) {
- setSelectedMetrics((metrics) => metrics.filter((item) => item !== selection))
- } else {
- setSelectedMetrics((metrics) => [...metrics, selection])
- }
- }
-
- return (
- <Modal title="New Portfolio" isOpen={isOpen} onSubmit={onSubmit} onCancel={onCancel}>
- <Form onSubmit={onSubmit}>
- <FormSection>
- <FormGroup
- label="Name"
- fieldId="name"
- isRequired
- validated={isSubmitted && errors.name ? 'error' : 'default'}
- helperTextInvalid="This field cannot be empty"
- >
- <TextInput
- name="name"
- id="name"
- type="text"
- isRequired
- ref={nameInput}
- placeholder="My Portfolio"
- />
- </FormGroup>
- </FormSection>
- <FormSection title="Targets" titleElement="h4">
- <FormGroup label="Metrics" fieldId="metrics">
- <Select
- variant={SelectVariant.typeaheadMulti}
- typeAheadAriaLabel="Select a metric"
- onToggle={() => setSelectOpen(!isSelectOpen)}
- onSelect={onSelect}
- onClear={() => setSelectedMetrics([])}
- selections={selectedMetrics}
- isOpen={isSelectOpen}
- placeholderText="Select a metric"
- menuAppendTo="parent"
- maxHeight="300px"
- chipGroupProps={{ numChips: 1 }}
- isGrouped
- >
- {Object.entries(METRIC_GROUPS).map(([group, metrics]) => (
- <SelectGroup label={group} key={group}>
- {metrics.map((metric) => (
- <SelectOption key={metric} value={metric}>
- {METRIC_NAMES[metric]}
- </SelectOption>
- ))}
- </SelectGroup>
- ))}
- </Select>
- </FormGroup>
- <FormGroup label="Repeats per Scenario" fieldId="repeats">
- <NumberInput
- id="repeats"
- inputName="repeats"
- type="number"
- value={repeats}
- onChange={(e) => setRepeats(Number(e.target.value))}
- onPlus={() => setRepeats((r) => r + 1)}
- onMinus={() => setRepeats((r) => r - 1)}
- min={1}
- />
- </FormGroup>
- </FormSection>
- </Form>
- </Modal>
- )
-}
-
-NewPortfolioModal.propTypes = {
- isOpen: PropTypes.bool.isRequired,
- onSubmit: PropTypes.func.isRequired,
- onCancel: PropTypes.func.isRequired,
-}
-
-export default NewPortfolioModal
diff --git a/opendc-web/opendc-web-ui/src/components/modals/custom-components/NewScenarioModal.js b/opendc-web/opendc-web-ui/src/components/modals/custom-components/NewScenarioModal.js
deleted file mode 100644
index 94d0d424..00000000
--- a/opendc-web/opendc-web-ui/src/components/modals/custom-components/NewScenarioModal.js
+++ /dev/null
@@ -1,159 +0,0 @@
-import PropTypes from 'prop-types'
-import React, { useRef, useState } from 'react'
-import { Portfolio } from '../../../shapes'
-import Modal from '../Modal'
-import {
- Checkbox,
- Form,
- FormGroup,
- FormSection,
- FormSelect,
- FormSelectOption,
- NumberInput,
- TextInput,
-} from '@patternfly/react-core'
-import { useSchedulers, useTraces } from '../../../data/experiments'
-import { useProjectTopologies } from '../../../data/topology'
-import { usePortfolio } from '../../../data/project'
-
-const NewScenarioModal = ({ portfolioId, isOpen, onSubmit: onSubmitUpstream, onCancel: onCancelUpstream }) => {
- const { data: portfolio } = usePortfolio(portfolioId)
- const { data: topologies = [] } = useProjectTopologies(portfolio?.projectId)
- const { data: traces = [] } = useTraces()
- const { data: schedulers = [] } = useSchedulers()
-
- const [isSubmitted, setSubmitted] = useState(false)
- const [traceLoad, setTraceLoad] = useState(100)
- const [trace, setTrace] = useState(undefined)
- const [topology, setTopology] = useState(undefined)
- const [scheduler, setScheduler] = useState(undefined)
- const [failuresEnabled, setFailuresEnabled] = useState(false)
- const [opPhenEnabled, setOpPhenEnabled] = useState(false)
- const nameInput = useRef(null)
-
- const resetState = () => {
- setSubmitted(false)
- setTraceLoad(100)
- setTrace(undefined)
- setTopology(undefined)
- setScheduler(undefined)
- setFailuresEnabled(false)
- setOpPhenEnabled(false)
- nameInput.current.value = ''
- }
-
- const onSubmit = (event) => {
- setSubmitted(true)
-
- if (event) {
- event.preventDefault()
- }
-
- const name = nameInput.current.value
-
- onSubmitUpstream(
- name,
- portfolio._id,
- {
- traceId: trace || traces[0]._id,
- loadSamplingFraction: traceLoad / 100,
- },
- {
- topologyId: topology || topologies[0]._id,
- },
- {
- failuresEnabled,
- performanceInterferenceEnabled: opPhenEnabled,
- schedulerName: scheduler || schedulers[0].name,
- }
- )
-
- resetState()
- return true
- }
- const onCancel = () => {
- onCancelUpstream()
- resetState()
- }
-
- return (
- <Modal title="New Scenario" isOpen={isOpen} onSubmit={onSubmit} onCancel={onCancel}>
- <Form onSubmit={onSubmit}>
- <FormGroup label="Name" fieldId="name" isRequired>
- <TextInput
- id="name"
- name="name"
- type="text"
- isDisabled={portfolio?.scenarioIds?.length === 0}
- defaultValue={portfolio?.scenarioIds?.length === 0 ? 'Base scenario' : ''}
- ref={nameInput}
- />
- </FormGroup>
- <FormSection title="Workload">
- <FormGroup label="Trace" fieldId="trace" isRequired>
- <FormSelect id="trace" name="trace" value={trace} onChange={setTrace}>
- {traces.map((trace) => (
- <FormSelectOption value={trace._id} key={trace._id} label={trace.name} />
- ))}
- </FormSelect>
- </FormGroup>
- <FormGroup label="Load Sampling Fraction" fieldId="trace-load" isRequired>
- <NumberInput
- name="trace-load"
- type="number"
- min={0}
- max={100}
- value={traceLoad}
- onMinus={() => setTraceLoad((load) => load - 1)}
- onPlus={() => setTraceLoad((load) => load + 1)}
- onChange={(e) => setTraceLoad(Number(e.target.value))}
- unit="%"
- />
- </FormGroup>
- </FormSection>
- <FormSection title="Topology">
- <FormGroup label="Topology" fieldId="topology" isRequired>
- <FormSelect id="topology" name="topology" value={topology} onChange={setTopology}>
- {topologies.map((topology) => (
- <FormSelectOption value={topology._id} key={topology._id} label={topology.name} />
- ))}
- </FormSelect>
- </FormGroup>
-
- <FormGroup label="Scheduler" fieldId="scheduler" isRequired>
- <FormSelect id="scheduler" name="scheduler" value={scheduler} onChange={setScheduler}>
- {schedulers.map((scheduler) => (
- <FormSelectOption value={scheduler.name} key={scheduler.name} label={scheduler.name} />
- ))}
- </FormSelect>
- </FormGroup>
- </FormSection>
- <FormSection title="Operational Phenomena">
- <Checkbox
- label="Failures"
- id="failures"
- name="failures"
- isChecked={failuresEnabled}
- onChange={() => setFailuresEnabled((e) => !e)}
- />
- <Checkbox
- label="Performance Interference"
- id="perf-interference"
- name="perf-interference"
- isChecked={opPhenEnabled}
- onChange={() => setOpPhenEnabled((e) => !e)}
- />
- </FormSection>
- </Form>
- </Modal>
- )
-}
-
-NewScenarioModal.propTypes = {
- portfolioId: PropTypes.string,
- isOpen: PropTypes.bool.isRequired,
- onSubmit: PropTypes.func.isRequired,
- onCancel: PropTypes.func.isRequired,
-}
-
-export default NewScenarioModal
diff --git a/opendc-web/opendc-web-ui/src/components/modals/custom-components/NewTopologyModal.js b/opendc-web/opendc-web-ui/src/components/modals/custom-components/NewTopologyModal.js
deleted file mode 100644
index 49952aec..00000000
--- a/opendc-web/opendc-web-ui/src/components/modals/custom-components/NewTopologyModal.js
+++ /dev/null
@@ -1,81 +0,0 @@
-import PropTypes from 'prop-types'
-import React, { useRef, useState } from 'react'
-import Modal from '../Modal'
-import { Form, FormGroup, FormSelect, FormSelectOption, TextInput } from '@patternfly/react-core'
-import { useProjectTopologies } from '../../../data/topology'
-
-const NewTopologyModal = ({ projectId, isOpen, onSubmit: onSubmitUpstream, onCancel: onCancelUpstream }) => {
- const nameInput = useRef(null)
- const [isSubmitted, setSubmitted] = useState(false)
- const [originTopology, setOriginTopology] = useState(-1)
- const [errors, setErrors] = useState({})
-
- const { data: topologies = [] } = useProjectTopologies(projectId)
-
- const clearState = () => {
- nameInput.current.value = ''
- setSubmitted(false)
- setOriginTopology(-1)
- setErrors({})
- }
-
- const onSubmit = (event) => {
- setSubmitted(true)
-
- if (event) {
- event.preventDefault()
- }
-
- const name = nameInput.current.value
-
- if (!name) {
- setErrors({ name: true })
- return false
- } else if (originTopology === -1) {
- onSubmitUpstream(name)
- } else {
- onSubmitUpstream(name, originTopology)
- }
-
- clearState()
- return true
- }
-
- const onCancel = () => {
- onCancelUpstream()
- clearState()
- }
-
- return (
- <Modal title="New Topology" isOpen={isOpen} onSubmit={onSubmit} onCancel={onCancel}>
- <Form onSubmit={onSubmit}>
- <FormGroup
- label="Name"
- fieldId="name"
- isRequired
- validated={isSubmitted && errors.name ? 'error' : 'default'}
- helperTextInvalid="This field cannot be empty"
- >
- <TextInput id="name" name="name" type="text" isRequired ref={nameInput} />
- </FormGroup>
- <FormGroup label="Topology to duplicate" fieldId="origin" isRequired>
- <FormSelect id="origin" name="origin" value={originTopology} onChange={setOriginTopology}>
- <FormSelectOption value={-1} key={-1} label="None - start from scratch" />
- {topologies.map((topology) => (
- <FormSelectOption value={topology._id} key={topology._id} label={topology.name} />
- ))}
- </FormSelect>
- </FormGroup>
- </Form>
- </Modal>
- )
-}
-
-NewTopologyModal.propTypes = {
- projectId: PropTypes.string,
- isOpen: PropTypes.bool.isRequired,
- onSubmit: PropTypes.func.isRequired,
- onCancel: PropTypes.func.isRequired,
-}
-
-export default NewTopologyModal