summaryrefslogtreecommitdiff
path: root/frontend/src
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2020-11-11 00:51:23 +0100
committerGitHub <noreply@github.com>2020-11-11 00:51:23 +0100
commite1716ee419c218f879c046917eaeb1e566230b0e (patch)
tree399969e871ef89f427707c927ff5e65d4c14eba8 /frontend/src
parentf3f8d1d494a08a032940c6587c7865cd0ac0dd7a (diff)
parente6c36a309c7372bb0de3ae4a3277e91c1ee4913b (diff)
Merge pull request #62 from atlarge-research/bug/tutorial
Implement various fixes in preparation for tutorial
Diffstat (limited to 'frontend/src')
-rw-r--r--frontend/src/components/modals/Modal.js10
-rw-r--r--frontend/src/components/modals/custom-components/NewPortfolioModalComponent.js19
-rw-r--r--frontend/src/components/modals/custom-components/NewScenarioModalComponent.js6
-rw-r--r--frontend/src/components/modals/custom-components/NewTopologyModalComponent.js8
-rw-r--r--frontend/src/index.js12
5 files changed, 45 insertions, 10 deletions
diff --git a/frontend/src/components/modals/Modal.js b/frontend/src/components/modals/Modal.js
index b494d970..21b7f119 100644
--- a/frontend/src/components/modals/Modal.js
+++ b/frontend/src/components/modals/Modal.js
@@ -9,12 +9,14 @@ function Modal({ children, title, show, onSubmit, onCancel, submitButtonType, su
const toggle = () => setModal(!modal)
const cancel = () => {
- toggle()
- onCancel()
+ if (onCancel() !== false) {
+ toggle()
+ }
}
const submit = () => {
- toggle()
- onSubmit()
+ if (onSubmit() !== false) {
+ toggle()
+ }
}
return (
diff --git a/frontend/src/components/modals/custom-components/NewPortfolioModalComponent.js b/frontend/src/components/modals/custom-components/NewPortfolioModalComponent.js
index 67646e2c..3c6b8724 100644
--- a/frontend/src/components/modals/custom-components/NewPortfolioModalComponent.js
+++ b/frontend/src/components/modals/custom-components/NewPortfolioModalComponent.js
@@ -5,15 +5,23 @@ import Modal from '../Modal'
import { AVAILABLE_METRICS, METRIC_NAMES } from '../../../util/available-metrics'
const NewPortfolioModalComponent = ({ show, callback }) => {
+ const form = useRef(null)
const textInput = useRef(null)
const repeatsInput = useRef(null)
const metricCheckboxes = useRef({})
- const onSubmit = () =>
- callback(textInput.current.value, {
- enabledMetrics: AVAILABLE_METRICS.filter((metric) => metricCheckboxes.current[metric].checked),
- repeatsPerScenario: parseInt(repeatsInput.current.value),
- })
+ const onSubmit = () => {
+ if (form.current.reportValidity()) {
+ callback(textInput.current.value, {
+ enabledMetrics: AVAILABLE_METRICS.filter((metric) => metricCheckboxes.current[metric].checked),
+ repeatsPerScenario: parseInt(repeatsInput.current.value),
+ })
+
+ return true
+ } else {
+ return false
+ }
+ }
const onCancel = () => callback(undefined)
return (
@@ -23,6 +31,7 @@ const NewPortfolioModalComponent = ({ show, callback }) => {
e.preventDefault()
this.onSubmit()
}}
+ innerRef={form}
>
<FormGroup>
<Label for="name">Name</Label>
diff --git a/frontend/src/components/modals/custom-components/NewScenarioModalComponent.js b/frontend/src/components/modals/custom-components/NewScenarioModalComponent.js
index 631082a2..01a5719c 100644
--- a/frontend/src/components/modals/custom-components/NewScenarioModalComponent.js
+++ b/frontend/src/components/modals/custom-components/NewScenarioModalComponent.js
@@ -13,6 +13,7 @@ const NewScenarioModalComponent = ({
topologies,
schedulers,
}) => {
+ const form = useRef(null)
const textInput = useRef(null)
const traceSelect = useRef(null)
const traceLoadInput = useRef(null)
@@ -22,6 +23,9 @@ const NewScenarioModalComponent = ({
const schedulerSelect = useRef(null)
const onSubmit = () => {
+ if (!form.current.reportValidity()) {
+ return false
+ }
callback(
textInput.current.value,
currentPortfolioId,
@@ -38,6 +42,7 @@ const NewScenarioModalComponent = ({
schedulerName: schedulerSelect.current.value,
}
)
+ return true
}
const onCancel = () => {
callback(undefined)
@@ -50,6 +55,7 @@ const NewScenarioModalComponent = ({
e.preventDefault()
onSubmit()
}}
+ innerRef={form}
>
<FormGroup>
<Label for="name">Name</Label>
diff --git a/frontend/src/components/modals/custom-components/NewTopologyModalComponent.js b/frontend/src/components/modals/custom-components/NewTopologyModalComponent.js
index b20ec13b..9fee8831 100644
--- a/frontend/src/components/modals/custom-components/NewTopologyModalComponent.js
+++ b/frontend/src/components/modals/custom-components/NewTopologyModalComponent.js
@@ -5,6 +5,7 @@ import Shapes from '../../../shapes'
import Modal from '../Modal'
const NewTopologyModalComponent = ({ show, onCreateTopology, onDuplicateTopology, onCancel, topologies }) => {
+ const form = useRef(null)
const textInput = useRef(null)
const originTopology = useRef(null)
@@ -17,11 +18,15 @@ const NewTopologyModalComponent = ({ show, onCreateTopology, onDuplicateTopology
}
const onSubmit = () => {
- if (originTopology.current.selectedIndex === 0) {
+ if (!form.current.reportValidity()) {
+ return false
+ } else if (originTopology.current.selectedIndex === 0) {
onCreate()
} else {
onDuplicate()
}
+
+ return true
}
return (
@@ -31,6 +36,7 @@ const NewTopologyModalComponent = ({ show, onCreateTopology, onDuplicateTopology
e.preventDefault()
onSubmit()
}}
+ innerRef={form}
>
<FormGroup>
<Label for="name">Name</Label>
diff --git a/frontend/src/index.js b/frontend/src/index.js
index 0971b1e6..fe119dfb 100644
--- a/frontend/src/index.js
+++ b/frontend/src/index.js
@@ -1,5 +1,7 @@
import React from 'react'
import ReactDOM from 'react-dom'
+import * as Sentry from '@sentry/react'
+import { Integrations } from '@sentry/tracing'
import { Provider } from 'react-redux'
import { setupSocketConnection } from './api/socket'
import './index.sass'
@@ -9,6 +11,16 @@ import configureStore from './store/configure-store'
setupSocketConnection(() => {
const store = configureStore()
+ // Initialize Sentry if the user has configured a DSN
+ if (process.env.REACT_APP_SENTRY_DSN) {
+ Sentry.init({
+ environment: process.env.NODE_ENV,
+ dsn: process.env.REACT_APP_SENTRY_DSN,
+ integrations: [new Integrations.BrowserTracing()],
+ tracesSampleRate: 0.5,
+ })
+ }
+
ReactDOM.render(
<Provider store={store}>
<Routes />