blob: 2d001302dcd6d1b8e8bff6702abd931ac70069a6 (
plain)
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
|
import PropTypes from 'prop-types'
import React from 'react'
import Modal from '../Modal'
import { AVAILABLE_METRICS } from '../../../util/available-metrics'
class NewPortfolioModalComponent extends React.Component {
static propTypes = {
show: PropTypes.bool.isRequired,
callback: PropTypes.func.isRequired,
}
constructor(props) {
super(props)
this.metricCheckboxes = {}
}
componentDidMount() {
this.reset()
}
reset() {
this.textInput.value = ''
AVAILABLE_METRICS.forEach((metric) => {
this.metricCheckboxes[metric].checked = true
})
this.repeatsInput.value = 1
}
onSubmit() {
this.props.callback(this.textInput.value, {
enabledMetrics: AVAILABLE_METRICS.filter((metric) => this.metricCheckboxes[metric].checked),
repeatsPerScenario: parseInt(this.repeatsInput.value),
})
this.reset()
}
onCancel() {
this.props.callback(undefined)
this.reset()
}
render() {
return (
<Modal
title="New Portfolio"
show={this.props.show}
onSubmit={this.onSubmit.bind(this)}
onCancel={this.onCancel.bind(this)}
>
<form
onSubmit={(e) => {
e.preventDefault()
this.onSubmit()
}}
>
<div className="form-group">
<label className="form-control-label">Name</label>
<input
type="text"
className="form-control"
required
ref={(textInput) => (this.textInput = textInput)}
/>
</div>
<h4>Targets</h4>
<h5>Metrics</h5>
<div className="form-group">
{AVAILABLE_METRICS.map((metric) => (
<div className="form-check" key={metric}>
<label className="form-check-label">
<input
type="checkbox"
className="form-check-input"
ref={(checkbox) => (this.metricCheckboxes[metric] = checkbox)}
/>
<code>{metric}</code>
</label>
</div>
))}
</div>
<div className="form-group">
<label className="form-control-label">Repeats per scenario</label>
<input
type="number"
className="form-control"
required
ref={(repeatsInput) => (this.repeatsInput = repeatsInput)}
/>
</div>
</form>
</Modal>
)
}
}
export default NewPortfolioModalComponent
|