diff --git a/sites/shared/components/workbench/edit.js b/sites/shared/components/workbench/edit.js
index 48f904a9a7a..444f97ab845 100644
--- a/sites/shared/components/workbench/edit.js
+++ b/sites/shared/components/workbench/edit.js
@@ -3,6 +3,8 @@ import hljs from 'highlight.js/lib/common'
import defaultSettings from './default-settings'
import validateGist from './gist-validator'
import { useEffect, useState, useRef } from 'react'
+import Json from 'shared/components/json-highlight.js'
+import Popout from 'shared/components/popout.js'
const countLines = (txt) => txt.split('\n').length
const Edit = (props) => {
@@ -11,6 +13,7 @@ const Edit = (props) => {
const inputRef = useRef(null)
const [gistAsYaml, setGistAsYaml] = useState(null)
const [numLines, setNumLines] = useState(0)
+ const [error, setError] = useState(null)
useEffect(() => {
setGistAsYaml(yaml.dump(gist))
@@ -19,10 +22,16 @@ const Edit = (props) => {
if (gistAsYaml) setNumLines(countLines(gistAsYaml))
}, [gistAsYaml])
- const onChange = (e) => {
+ const onSave = () => {
+ setError(null)
const editedAsJson = yaml.load(inputRef.current.value)
- if (validateGist(editedAsJson, design).valid) {
+ const validation = validateGist(editedAsJson, design)
+ if (validation.valid) {
setGist({ ...defaultSettings, ...editedAsJson, design: gist.design })
+ } else {
+ const newError = JSON.stringify(validation.errors, null, 2)
+ const newErrorHighlight = hljs.highlight(newError, { language: 'json' })
+ setError(newError)
}
}
@@ -32,7 +41,18 @@ const Edit = (props) => {
return (
-
Edit Pattern Configuration
+
Edit Pattern Configuration
+
+ {error ? (
+
+ Issues with input
+ Your input wasn't saved due to the following errors:
+
+
+ ) : null}
{
/>
-