Skip to content

Commit

Permalink
Added some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jjoderis committed Nov 15, 2023
1 parent 19a9984 commit bdd24b3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/management-system-v2/components/xml-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ type XmlEditorProps = {
onSaveXml: (bpmn: string) => Promise<void>;
};

/**
* Checks for syntax errors in the bpmn as well as for moddle warnings
*
* @param bpmn
* @returns found syntax errors or warnings
*/
async function checkBpmn(bpmn: string) {
// check the bpmn (xml) for syntax errors using the domparser
const domParser = new DOMParser();
var dom = domParser.parseFromString(bpmn, 'text/xml');
const parserErrors = dom.getElementsByTagName('parsererror');
Expand All @@ -34,6 +41,7 @@ async function checkBpmn(bpmn: string) {
);

if (match) {
// convert the positional information into a format that can be passed to the monaco editor
let [_, lineString, columnString, message] = match;
const line = parseInt(lineString);
const column = parseInt(columnString);
Expand All @@ -49,8 +57,8 @@ async function checkBpmn(bpmn: string) {
}
}

// check for bpmn related mistakes (nonconformity with the underlying model [e.g. unknown elements or attributes])
const { warnings } = await moddle.fromXML(bpmn);
// TODO: how do we want to show which warnings exist to the user?
return { warnings };
}

Expand All @@ -75,6 +83,7 @@ const XmlEditor: FC<XmlEditorProps> = ({ bpmn, canSave, onClose, onSaveXml }) =>

async function validateProcess() {
if (editorRef.current && monacoRef.current) {
// reset error markings in the editor
monacoRef.current.editor.setModelMarkers(editorRef.current.getModel()!, 'owner', []);
setSaveState('none');
const bpmn = editorRef.current.getValue();
Expand All @@ -83,6 +92,7 @@ const XmlEditor: FC<XmlEditorProps> = ({ bpmn, canSave, onClose, onSaveXml }) =>

if (error) {
setSaveState('error');
// add new error markings
monacoRef.current.editor.setModelMarkers(editorRef.current.getModel()!, 'owner', [
{ ...error, severity: monacoRef.current.MarkerSeverity.Error },
]);
Expand Down

0 comments on commit bdd24b3

Please sign in to comment.