From 22694e76b1555fd88df679363fc90c1e730e8692 Mon Sep 17 00:00:00 2001 From: jasquat Date: Mon, 31 Oct 2022 17:19:07 -0400 Subject: [PATCH] Squashed 'spiffworkflow-frontend/' changes from c6a47df1b..dcc280118 dcc280118 cleaned up some frontend code and put back logic for script unit tests w/ burnettk danfunk d8ee4dfc5 using new bpmn-js-spiffworkflow for python scripts w/ burnettk danfunk git-subtree-dir: spiffworkflow-frontend git-subtree-split: dcc280118614314a8f3c25775d0910ec11345998 --- src/components/ReactDiagramEditor.tsx | 15 ++++++++----- src/routes/ProcessModelEditDiagram.tsx | 30 ++++++++++++++++++++------ src/routes/TaskShow.tsx | 2 +- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/components/ReactDiagramEditor.tsx b/src/components/ReactDiagramEditor.tsx index c8b079f39..9728e7d50 100644 --- a/src/components/ReactDiagramEditor.tsx +++ b/src/components/ReactDiagramEditor.tsx @@ -177,11 +177,16 @@ export default function ReactDiagramEditor({ }); } - function handleLaunchScriptEditor(element: any) { + function handleLaunchScriptEditor( + element: any, + script: string, + scriptType: string, + eventBus: any + ) { if (onLaunchScriptEditor) { setPerformingXmlUpdates(true); const modeling = diagramModeler.get('modeling'); - onLaunchScriptEditor(element, modeling); + onLaunchScriptEditor(element, script, scriptType, eventBus, modeling); } } @@ -199,12 +204,12 @@ export default function ReactDiagramEditor({ setDiagramModelerState(diagramModeler); - diagramModeler.on('launch.script.editor', (event: any) => { - const { error, element } = event; + diagramModeler.on('script.editor.launch', (event: any) => { + const { error, element, scriptType, script, eventBus } = event; if (error) { console.log(error); } - handleLaunchScriptEditor(element); + handleLaunchScriptEditor(element, script, scriptType, eventBus); }); // 'element.hover', diff --git a/src/routes/ProcessModelEditDiagram.tsx b/src/routes/ProcessModelEditDiagram.tsx index 2382fce72..aa1643d84 100644 --- a/src/routes/ProcessModelEditDiagram.tsx +++ b/src/routes/ProcessModelEditDiagram.tsx @@ -18,7 +18,9 @@ export default function ProcessModelEditDiagram() { const [showFileNameEditor, setShowFileNameEditor] = useState(false); const handleShowFileNameEditor = () => setShowFileNameEditor(true); - const [scriptText, setScriptText] = useState(''); + const [scriptText, setScriptText] = useState(''); + const [scriptType, setScriptType] = useState(''); + const [scriptEventBus, setScriptEventBus] = useState(null); const [scriptModeling, setScriptModeling] = useState(null); const [scriptElement, setScriptElement] = useState(null); const [showScriptEditor, setShowScriptEditor] = useState(false); @@ -275,25 +277,39 @@ export default function ProcessModelEditDiagram() { } }; - const onLaunchScriptEditor = (element: any, modeling: any) => { - setScriptText(element.businessObject.script || ''); + const onLaunchScriptEditor = ( + element: any, + script: string, + scriptTypeString: string, + eventBus: any, + modeling: any + ) => { + // TODO: modeling is only needed for script unit tests. + // we should update this to act like updating scripts + // where we pass an event to bpmn-js setScriptModeling(modeling); + + setScriptText(script || ''); + setScriptType(scriptTypeString); + setScriptEventBus(eventBus); setScriptElement(element); setScriptUnitTestElementWithIndex(0, element); handleShowScriptEditor(); }; const handleScriptEditorClose = () => { + scriptEventBus.fire('script.editor.update', { + scriptType, + script: scriptText, + element: scriptElement, + }); + resetUnitTextResult(); setShowScriptEditor(false); }; const handleEditorScriptChange = (value: any) => { setScriptText(value); - (scriptModeling as any).updateProperties(scriptElement, { - scriptFormat: 'python', - script: value, - }); }; const handleEditorScriptTestUnitInputChange = (value: any) => { diff --git a/src/routes/TaskShow.tsx b/src/routes/TaskShow.tsx index 28fc8582a..c1c1cfe2d 100644 --- a/src/routes/TaskShow.tsx +++ b/src/routes/TaskShow.tsx @@ -144,7 +144,7 @@ export default function TaskShow() { const instructionsElement = (taskToUse: any) => { let instructions = ''; - if (taskToUse.type === 'Manual Task') { + if (taskToUse.properties.instructionsForEndUser) { instructions = taskToUse.properties.instructionsForEndUser; } return (