1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
import PropTypes from 'prop-types'
import React, { useRef } from 'react'
import { Form, FormGroup, Input, Label } from 'reactstrap'
import { Scheduler, Topology, Trace } from '../../../shapes'
import Modal from '../Modal'
const NewScenarioModalComponent = ({
show,
callback,
currentPortfolioId,
currentPortfolioScenarioIds,
traces,
topologies,
schedulers,
}) => {
const form = useRef(null)
const textInput = useRef(null)
const traceSelect = useRef(null)
const traceLoadInput = useRef(null)
const topologySelect = useRef(null)
const failuresCheckbox = useRef(null)
const performanceInterferenceCheckbox = useRef(null)
const schedulerSelect = useRef(null)
const onSubmit = () => {
if (!form.current.reportValidity()) {
return false
}
callback(
textInput.current.value,
currentPortfolioId,
{
traceId: traceSelect.current.value,
loadSamplingFraction: parseFloat(traceLoadInput.current.value),
},
{
topologyId: topologySelect.current.value,
},
{
failuresEnabled: failuresCheckbox.current.checked,
performanceInterferenceEnabled: performanceInterferenceCheckbox.current.checked,
schedulerName: schedulerSelect.current.value,
}
)
return true
}
const onCancel = () => {
callback(undefined)
}
return (
<Modal title="New Scenario" show={show} onSubmit={onSubmit} onCancel={onCancel}>
<Form
onSubmit={(e) => {
e.preventDefault()
onSubmit()
}}
innerRef={form}
>
<FormGroup>
<Label for="name">Name</Label>
<Input
name="name"
type="text"
required
disabled={currentPortfolioScenarioIds.length === 0}
defaultValue={currentPortfolioScenarioIds.length === 0 ? 'Base scenario' : ''}
innerRef={textInput}
/>
</FormGroup>
<h4>Trace</h4>
<FormGroup>
<Label for="trace">Trace</Label>
<Input name="trace" type="select" innerRef={traceSelect}>
{traces.map((trace) => (
<option value={trace._id} key={trace._id}>
{trace.name}
</option>
))}
</Input>
</FormGroup>
<FormGroup>
<Label for="trace-load">Load sampling fraction</Label>
<Input
name="trace-load"
type="number"
innerRef={traceLoadInput}
required
defaultValue="1"
min="0"
max="1"
step="0.1"
/>
</FormGroup>
<h4>Topology</h4>
<div className="form-group">
<Label for="topology">Topology</Label>
<Input name="topology" type="select" innerRef={topologySelect}>
{topologies.map((topology) => (
<option value={topology._id} key={topology._id}>
{topology.name}
</option>
))}
</Input>
</div>
<h4>Operational Phenomena</h4>
<FormGroup check>
<Label check for="failures">
<Input type="checkbox" name="failures" innerRef={failuresCheckbox} />{' '}
<span className="ml-2">Enable failures</span>
</Label>
</FormGroup>
<FormGroup check>
<Label check for="perf-interference">
<Input type="checkbox" name="perf-interference" innerRef={performanceInterferenceCheckbox} />{' '}
<span className="ml-2">Enable performance interference</span>
</Label>
</FormGroup>
<FormGroup>
<Label for="scheduler">Scheduler</Label>
<Input name="scheduler" type="select" innerRef={schedulerSelect}>
{schedulers.map((scheduler) => (
<option value={scheduler.name} key={scheduler.name}>
{scheduler.name}
</option>
))}
</Input>
</FormGroup>
</Form>
</Modal>
)
}
NewScenarioModalComponent.propTypes = {
show: PropTypes.bool.isRequired,
currentPortfolioId: PropTypes.string.isRequired,
currentPortfolioScenarioIds: PropTypes.arrayOf(PropTypes.string),
traces: PropTypes.arrayOf(Trace),
topologies: PropTypes.arrayOf(Topology),
schedulers: PropTypes.arrayOf(Scheduler),
callback: PropTypes.func.isRequired,
}
export default NewScenarioModalComponent
|