diff --git a/src/mocks/Editor/Editor.js b/src/mocks/Editor/Editor.js index 5aea6b00a68a620da76ddca5344fc74fad70715d..05f71016bfc57bd16b652f17bc7f0650c604bc6f 100644 --- a/src/mocks/Editor/Editor.js +++ b/src/mocks/Editor/Editor.js @@ -1,7 +1,7 @@ /** * Mock data and variants for Editor and JSONEditor testing */ -const startup = `# +const startup = `# MOCK CONFIG FOR TESTING # Require module: essioc # require essioc diff --git a/src/stories/code/Editor.stories.js b/src/stories/code/Editor.stories.js index 2612d3eb2f103c358b126bc3ded9e8c953fd5f53..bc2365d1ca7df075eb10fc2bafa4d9f6d015fbef 100644 --- a/src/stories/code/Editor.stories.js +++ b/src/stories/code/Editor.stories.js @@ -4,7 +4,7 @@ import { editorModes, editorThemes } from "../../components/code/Editor"; -import { files } from "./data"; +import { files } from "../../mocks/Editor/Editor"; export default { title: "Code/Editor" diff --git a/src/stories/code/JSONEditor.stories.js b/src/stories/code/JSONEditor.stories.js index 254ea3ddeed00830fd8873c5c35686e1471dd4e0..56801cd174b2f8caf8e067b7921fcaa89c572ac9 100644 --- a/src/stories/code/JSONEditor.stories.js +++ b/src/stories/code/JSONEditor.stories.js @@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react"; import { JSONEditor } from "../../components/code/JSONEditor"; import { editorModes, editorThemes } from "../../components/code/Editor"; import { sbDisabledArg } from "../utils/common-args"; -import { schema, invalid } from "./data"; +import { schemaTwo, invalid } from "../../mocks/Editor/Editor"; export default { title: "Code/JSONEditor" @@ -28,7 +28,7 @@ Validate.args = { showAlerts: true, maxAlerts: 3, readOnly: false, - schema: schema, + schema: schemaTwo, theme: "monokai", value: JSON.stringify(invalid, null, 2) }; diff --git a/src/stories/code/data.js b/src/stories/code/data.js deleted file mode 100644 index de92441d501bac12a27954ce9565a95b584f6180..0000000000000000000000000000000000000000 --- a/src/stories/code/data.js +++ /dev/null @@ -1,236 +0,0 @@ -const startup = `# -# Require module: essioc -# -require essioc - -# -# Require module: vac_ctrl_mks946_937b -# -require vac_ctrl_mks946_937b - -# -# Setting STREAM_PROTOCOL_PATH -# -epicsEnvSet(STREAM_PROTOCOL_PATH, "\${vac_ctrl_mks946_937b_DB}") - -# -# Module: essioc -# -iocshLoad("\${essioc_DIR}/common_config.iocsh") - -# -# Device: {{ essName }} -# Module: vac_ctrl_mks946_937b -# -iocshLoad("\${vac_ctrl_mks946_937b_DIR}/vac_ctrl_mks946_937b_moxa.iocsh", "DEVICENAME = {{ essName }}, BOARD_A_SERIAL_NUMBER = {{ boardASerialNumber }}, BOARD_B_SERIAL_NUMBER = {{ boardBSerialNumber}}, IPADDR = {{ moxaFQDN }}, PORT = {{ moxaPort }}") - -{{#gauges}} -# -# Device: {{ essName }} -# Module: vac_ctrl_mks946_937b -# -iocshLoad("\${vac_ctrl_mks946_937b_DIR}/{{ type }}.iocsh", "DEVICENAME = {{ essName }}, CHANNEL = {{ channel }}, CONTROLLERNAME = {{ ../essName }}") - -{{/gauges}}`; - -const schemaJSON = JSON.stringify( - { - $defs: { - ESSName: { type: "string", title: "ESS Name", maxLength: 34 }, - CSEntryHost: { type: "string" }, - Gauge: { - type: "object", - required: ["essName", "channel", "type"], - properties: { - essName: { $ref: "#/$defs/ESSName", title: "ESS Name of Gauge" }, - channel: { type: "string", title: "Channel" }, - type: { - type: "string", - title: "Type of Gauge", - enum: [ - "vac_gauge_mks_vgc", - "vac_gauge_mks_vgd", - "vac_gauge_mks_vgp", - "vac_mfc_mks_gv50a" - ] - } - } - }, - BoardSerialNumber: { - type: "string", - minLength: 10, - maxLength: 10 - } - }, - title: "Configure Vacuum Gauge Controller ", - type: "object", - required: [ - "essName", - "moxaFQDN", - "moxaPort", - "boardASerialNumber", - "boardBSerialNumber", - "guages" - ], - properties: { - essName: { $ref: "#/$defs/ESSName", title: "ESS Name of Controller" }, - moxaFQDN: { $ref: "#/$defs/CSEntryHost", title: "Moxa FQDN" }, - moxaPort: { type: "number", title: "Moxa Port" }, - boardASerialNumber: { - $ref: "#/$defs/BoardSerialNumber", - title: "Board A Serial Number" - }, - boardBSerialNumber: { - $ref: "#/$defs/BoardSerialNumber", - title: "Board B Serial Number" - }, - gauges: { - title: "Gauges to Control", - type: "array", - minItems: 1, - uniqueItems: true, - items: { $ref: "#/$defs/Gauge" } - } - } - }, - null, - 2 -); - -const editorjs = `import React, { useEffect, useRef, useState } from "react"; -import AceEditor from "react-ace"; - -// allows Ace to resolve location of modes, themes, etc -import 'ace-builds/webpack-resolver' - -// enables autocomplete -import "ace-builds/src-noconflict/ext-language_tools.js"; - -// some meta info about modes and themes -import modeList from 'ace-builds/src-noconflict/ext-modelist' -import themeList from 'ace-builds/src-noconflict/ext-themelist'; - -export const editorModes = Object.keys(modeList.modesByName) -export const editorThemes = Object.keys(themeList.themesByName) - -function getMode(modeName, fileName) { - return modeName ?? modeList.getModeForPath(fileName ?? "").name -} - -export function Editor({ uniqueName, value = "null", mode, filename, theme, width = "100%", height = "100%", readOnly }) { - const [aceMode, setAceMode] = useState(getMode(mode, filename)); - - useEffect(() => { - setAceMode(getMode(mode, filename)) - }, [filename, mode]) - - return ( - <AceEditor - readOnly={readOnly} - mode={aceMode} - theme={theme} - name={uniqueName} - width={width} - height={height} - showPrintMargin={false} - value={value} - editorProps={{ $blockScrolling: true }} - wrapEnabled={true} - fontSize={16} - setOptions={{ - useWorker: false, - displayIndentGuides: false, - enableBasicAutocompletion: true, - enableLiveAutocompletion: true, - enableSnippets: false, - showLineNumbers: true, - tabSize: 2 - }} - /> - ); -}`; - -export const files = { - "startup.sh": startup, - "startup.mustache": startup, - "schema.json": schemaJSON, - "Editor.js": editorjs -}; - -export const schema = { - $defs: { - ESSName: { type: "string", title: "ESS Name", maxLength: 34 }, - CSEntryHost: { type: "string", format: "hostname" }, - Gauge: { - type: "object", - required: ["essName", "channel", "type"], - additionalProperties: false, - properties: { - essName: { $ref: "#/$defs/ESSName", title: "ESS Name of Gauge" }, - channel: { type: "string", title: "Channel" }, - type: { - type: "string", - title: "Type of Gauge", - enum: [ - "vac_gauge_mks_vgc", - "vac_gauge_mks_vgd", - "vac_gauge_mks_vgp", - "vac_mfc_mks_gv50a" - ] - } - } - }, - BoardSerialNumber: { - type: "string", - minLength: 10, - maxLength: 10 - } - }, - title: "Configure Vacuum Gauge Controller ", - type: "object", - required: [ - "essName", - "moxaFQDN", - "moxaPort", - "boardASerialNumber", - "boardBSerialNumber", - "gauges" - ], - additionalProperties: false, - properties: { - essName: { $ref: "#/$defs/ESSName", title: "ESS Name of Controller" }, - moxaFQDN: { $ref: "#/$defs/CSEntryHost", title: "Moxa FQDN" }, - moxaPort: { type: "number", title: "Moxa Port" }, - boardASerialNumber: { - $ref: "#/$defs/BoardSerialNumber", - title: "Board A Serial Number" - }, - boardBSerialNumber: { - $ref: "#/$defs/BoardSerialNumber", - title: "Board B Serial Number" - }, - gauges: { - title: "Gauges to Control", - type: "array", - minItems: 1, - uniqueItems: true, - items: { $ref: "#/$defs/Gauge" } - } - } -}; - -export const invalid = { - gauges: [ - { - essName: "LEBT-010:Vac-VGP-00021", - channel: "A1", - type: "vac_gauge_mks_xyz", - d: "test" - } - ], - essName: "LEBT-010:Vac-VEG-00011", - moxaFQDN: "apple.tn.esss.lu.se", - moxaPort: "4005", - boardASerialNumber: "150923104", - c: "1609141318" -};