summaryrefslogtreecommitdiff
path: root/frontend/src/components/modals/custom-components/NewPortfolioModalComponent.js
diff options
context:
space:
mode:
authorjc0b <j@jc0b.computer>2020-07-10 15:18:49 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:48:02 +0200
commitd8479e7e3744b8d1d31ac4d9f972e560eacd2cf8 (patch)
tree79b7dfccec6e3cc1fce189b4605a37b354d676a2 /frontend/src/components/modals/custom-components/NewPortfolioModalComponent.js
parent4befa57993831274ad7e6ca62f96aa582f81cc5d (diff)
parent3b4e27320c479bd6ef48998f448ed070e8bd7511 (diff)
Merge branch 'master' of github.com:atlarge-research/opendc-dev
Diffstat (limited to 'frontend/src/components/modals/custom-components/NewPortfolioModalComponent.js')
-rw-r--r--frontend/src/components/modals/custom-components/NewPortfolioModalComponent.js99
1 files changed, 99 insertions, 0 deletions
diff --git a/frontend/src/components/modals/custom-components/NewPortfolioModalComponent.js b/frontend/src/components/modals/custom-components/NewPortfolioModalComponent.js
new file mode 100644
index 00000000..ace2d751
--- /dev/null
+++ b/frontend/src/components/modals/custom-components/NewPortfolioModalComponent.js
@@ -0,0 +1,99 @@
+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