diff --git a/components/Codemirror/index.js b/components/Codemirror/index.js
index 54ffbbf..4bed7b7 100644
--- a/components/Codemirror/index.js
+++ b/components/Codemirror/index.js
@@ -17,7 +17,7 @@ import 'codemirror/addon/display/fullscreen.css';
import 'codemirror/addon/fold/foldgutter.css';
function CodeMirror({
- formKey, isEditView, readOnly, values, data,
+ formKey, isEditView, readOnly, values, data, id,
}) {
const codeRef = useRef(null);
const [mounted, setMounted] = useState(false);
@@ -111,7 +111,7 @@ function CodeMirror({
}, []);
return (
-
+
{mounted
? (
{
api.patch('/events/abort', {
- bridge_id: id,
+ bridge_id: bridgeId,
})
.then((res) => {
if (res.status === 200) {
@@ -51,8 +51,8 @@ function ActionsDialog({
};
const handleActivate = async () => {
- await api.patch(`/bridges/${id}/${active ? 'deactivate' : 'activate'}`).then(() => {
- router.push(`/bridge/${id}`);
+ await api.patch(`/bridges/${bridgeId}/${active ? 'deactivate' : 'activate'}`).then(() => {
+ router.push(`/bridge/${bridgeId}`);
setSuccessOpen(true);
setTimeout(() => {
setSuccessOpen(false);
@@ -66,7 +66,7 @@ function ActionsDialog({
};
const handleDelete = () => {
- api.delete(`/bridges/${id}`).then(() => {
+ api.delete(`/bridges/${bridgeId}`).then(() => {
router.push('/dashboard');
}).catch(() => {
setErrorOpen(true);
@@ -82,6 +82,7 @@ function ActionsDialog({
anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
open={successOpen}
autoHideDuration={3000}
+ id="actions-success-message"
>
Success! Your bridge has been updated.
@@ -91,14 +92,16 @@ function ActionsDialog({
anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
open={errorOpen}
autoHideDuration={3000}
+ id="actions-error-message"
>
Some error occurred. Please try again.
+
Bridge Actions
-
+
@@ -106,7 +109,8 @@ function ActionsDialog({
-
+
+
@@ -114,7 +118,8 @@ function ActionsDialog({
-
+
+
@@ -131,7 +136,7 @@ ActionsDialog.propTypes = {
active: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired,
open: PropTypes.bool.isRequired,
- id: PropTypes.number.isRequired,
+ bridgeId: PropTypes.number.isRequired,
};
export default ActionsDialog;
diff --git a/components/Editor/BridgeTestCard/index.js b/components/Editor/BridgeTestCard/index.js
index 19b098d..0912ffe 100644
--- a/components/Editor/BridgeTestCard/index.js
+++ b/components/Editor/BridgeTestCard/index.js
@@ -67,6 +67,7 @@ function BridgeTestCard({ isEditView, values }) {
formKey="testPayloadCode"
isEditView={isEditView}
values={values}
+ id="test-payload"
/>
diff --git a/components/Editor/EnvironmentVariablesCard/index.js b/components/Editor/EnvironmentVariablesCard/index.js
index fc81038..081e590 100644
--- a/components/Editor/EnvironmentVariablesCard/index.js
+++ b/components/Editor/EnvironmentVariablesCard/index.js
@@ -89,6 +89,7 @@ function EnvironmentVariablesCard({ environmentVariables }) {
name={`environmentVariables[${idx}].value`}
value={envVar.value || ''}
placeholder="Value"
+ id={`envVar-${idx}-value`}
fullWidth
validate={validateEnvVars}
/>
@@ -97,6 +98,7 @@ function EnvironmentVariablesCard({ environmentVariables }) {
@@ -109,6 +111,7 @@ function EnvironmentVariablesCard({ environmentVariables }) {
variant="outlined"
className={classes.plusButton}
onClick={() => arrayHelpers.push({ key: '', value: '' })}
+ id="envPlusBtn"
>
+
diff --git a/components/Editor/HeadersCard/DelayDropdown.js b/components/Editor/HeadersCard/DelayDropdown.js
index e0a864d..8a4a658 100644
--- a/components/Editor/HeadersCard/DelayDropdown.js
+++ b/components/Editor/HeadersCard/DelayDropdown.js
@@ -47,6 +47,7 @@ function MethodDropdown() {
select
validate={validateDelay}
className={classes.dropDown}
+ id="delay"
>
diff --git a/components/Editor/HeadersCard/HeaderTextFields.js b/components/Editor/HeadersCard/HeaderTextFields.js
index f09f711..b2848e9 100644
--- a/components/Editor/HeadersCard/HeaderTextFields.js
+++ b/components/Editor/HeadersCard/HeaderTextFields.js
@@ -90,6 +90,7 @@ function HeaderTextFields({ headers }) {
name={`headers[${idx}].value`}
value={header.value || ''}
placeholder="Value"
+ id={`headers-${idx}-value`}
validate={validateHeaders}
fullWidth
/>
@@ -98,6 +99,7 @@ function HeaderTextFields({ headers }) {
@@ -110,6 +112,7 @@ function HeaderTextFields({ headers }) {
variant="outlined"
className={classes.plusButton}
onClick={() => arrayHelpers.push({ key: '', value: '' })}
+ id="headerPlusBtn"
>
+
diff --git a/components/Editor/HeadersCard/MethodDropdown.js b/components/Editor/HeadersCard/MethodDropdown.js
index cd905ad..34e08d2 100644
--- a/components/Editor/HeadersCard/MethodDropdown.js
+++ b/components/Editor/HeadersCard/MethodDropdown.js
@@ -42,11 +42,12 @@ function MethodDropdown() {
{methods.map((method) => (
diff --git a/components/Editor/HeadersCard/RetryDropdown.js b/components/Editor/HeadersCard/RetryDropdown.js
index 6830861..ffdbc85 100644
--- a/components/Editor/HeadersCard/RetryDropdown.js
+++ b/components/Editor/HeadersCard/RetryDropdown.js
@@ -46,9 +46,10 @@ function MethodDropdown() {
select
validate={validateRetries}
className={classes.dropDown}
+ id="retries"
>
{retries.map((retry) => (
-
+
))}
diff --git a/components/Editor/HeadersCard/index.js b/components/Editor/HeadersCard/index.js
index 3386bf8..aa1263f 100644
--- a/components/Editor/HeadersCard/index.js
+++ b/components/Editor/HeadersCard/index.js
@@ -46,7 +46,7 @@ function HeaderCard({ headers, outboundUrl, title }) {
let error;
if (!bridgeTitle) {
error = 'Required';
- } else if (bridgeTitle.size < 3) {
+ } else if (bridgeTitle.length < 3) {
error = 'Title must be at least 3 characters long';
}
return error;
diff --git a/components/Editor/PayloadCard/index.js b/components/Editor/PayloadCard/index.js
index 5af8318..5fe238c 100644
--- a/components/Editor/PayloadCard/index.js
+++ b/components/Editor/PayloadCard/index.js
@@ -71,7 +71,7 @@ function PayloadCard({ isEditView, values }) {
Edit outbound payload
-
+
diff --git a/components/Editor/index.js b/components/Editor/index.js
index fe5a874..69719f4 100644
--- a/components/Editor/index.js
+++ b/components/Editor/index.js
@@ -42,6 +42,8 @@ function Editor({ bridge, isEditView }) {
const [open, setOpen] = useState(false);
const [actionsDialogOpen, setActionsDialogOpen] = useState(false);
const [errorOpen, setErrorOpen] = useState(false);
+ const [errorMessage, setErrorMessage] = useState('Some error has occurred. Please try again.');
+
// TODO: Custom error messages
// const [errMsg, setErrMsg] = useState('');
@@ -49,7 +51,7 @@ function Editor({ bridge, isEditView }) {
active,
id,
outboundUrl,
- method,
+ httpMethod,
headers,
environmentVariables,
data,
@@ -62,7 +64,7 @@ function Editor({ bridge, isEditView }) {
active,
title,
outboundUrl,
- method,
+ httpMethod,
retries,
delay,
headers,
@@ -98,7 +100,7 @@ function Editor({ bridge, isEditView }) {
const generatePayload = (values) => ({
active: values.active,
title: values.title,
- http_method: values.method,
+ http_method: values.httpMethod,
outbound_url: values.outboundUrl,
retries: values.retries,
delay: values.delay,
@@ -110,20 +112,54 @@ function Editor({ bridge, isEditView }) {
},
});
+ const validatePayloads = (payloadCode, testPayloadCode) => {
+ const erraneousPayloads = [];
+ const validatePayload = (payload, type) => {
+ try { JSON.parse(payload); } catch { erraneousPayloads.push(type); }
+ };
+ const createErrorMessage = () => {
+ if (erraneousPayloads.length === 1) {
+ setErrorMessage(`Invalid JSON for ${erraneousPayloads[0]} editor`);
+ } else {
+ setErrorMessage('Invalid JSON for Payload and Test Payload editors');
+ }
+ };
+
+ validatePayload(payloadCode, 'Payload');
+ validatePayload(testPayloadCode, 'Test Payload');
+
+ if (erraneousPayloads.length !== 0) {
+ createErrorMessage();
+ setErrorOpen(true);
+ return false;
+ }
+
+ return true;
+ };
+
const handleSubmit = async (values, setSubmitting) => {
- if (id) {
+ if (validatePayloads(values.payloadCode, values.testPayloadCode)) {
// POST if new bridge, otherwise PATCH
- await api
- .patch(`/bridges/${id}`, generatePayload(values))
- .catch(() => setErrorOpen(true));
- } else {
- await api
- .post('/bridges', generatePayload(values))
- .then((res) => router.push(`/bridge/${res.data.id}`))
- .catch(() => setErrorOpen(true));
+ if (id) {
+ await api
+ .patch(`/bridges/${id}`, generatePayload(values))
+ .then(() => setOpen(true))
+ .catch(() => setErrorOpen(true));
+ } else {
+ await api
+ .post('/bridges', generatePayload(values))
+ .then((res) => {
+ setOpen(true);
+ // TODO: Should timeout so user gets a chance to read the snack
+ // but is 200ms the time we want?
+ setTimeout(() => {
+ router.push(`/bridge/${res.data.id}`);
+ }, 200);
+ })
+ .catch(() => setErrorOpen(true));
+ }
}
- setOpen(true);
setSubmitting(false);
};
@@ -149,6 +185,7 @@ function Editor({ bridge, isEditView }) {
validateOnChange={false}
validateOnBlur={false}
className={classes.root}
+ id="form"
>
{({ values, submitForm }) => (