From 383f21b7a63ba32bf2d17bb5539251e535d4ae7e Mon Sep 17 00:00:00 2001 From: jasquat Date: Mon, 31 Oct 2022 16:51:27 -0400 Subject: [PATCH 1/3] using new bpmn-js-spiffworkflow for python scripts w/ burnettk danfunk --- .../src/components/ReactDiagramEditor.tsx | 17 ++++++---- .../src/routes/ProcessModelEditDiagram.tsx | 33 ++++++++++++++----- .../src/routes/TaskShow.tsx | 2 +- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx b/spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx index c8b079f3..0a604972 100644 --- a/spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx +++ b/spiffworkflow-frontend/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); + // const modeling = diagramModeler.get('modeling'); + onLaunchScriptEditor(element, script, scriptType, eventBus); } } @@ -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/spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx b/spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx index 2382fce7..53f335a2 100644 --- a/spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx +++ b/spiffworkflow-frontend/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,38 @@ export default function ProcessModelEditDiagram() { } }; - const onLaunchScriptEditor = (element: any, modeling: any) => { - setScriptText(element.businessObject.script || ''); - setScriptModeling(modeling); + const onLaunchScriptEditor = ( + element: any, + script: string, + scriptType: string, + eventBus: any + ) => { + setScriptText(script || ''); + setScriptType(scriptType); + setScriptEventBus(eventBus); + // setScriptModeling(modeling); setScriptElement(element); - setScriptUnitTestElementWithIndex(0, 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, - }); + // (scriptModeling as any).updateProperties(scriptElement, { + // scriptFormat: 'python', + // script: value, + // }); }; const handleEditorScriptTestUnitInputChange = (value: any) => { diff --git a/spiffworkflow-frontend/src/routes/TaskShow.tsx b/spiffworkflow-frontend/src/routes/TaskShow.tsx index 28fc8582..c1c1cfe2 100644 --- a/spiffworkflow-frontend/src/routes/TaskShow.tsx +++ b/spiffworkflow-frontend/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 ( From 6bfaf9c5c252e81a4a3c8b74caf48c345ede4449 Mon Sep 17 00:00:00 2001 From: jasquat Date: Mon, 31 Oct 2022 16:52:44 -0400 Subject: [PATCH 2/3] updated backend to send instructions for user tasks through jinja as well w/ burnettk danfunk --- .../routes/process_api_blueprint.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py index 7c7643bf..f2ffec20 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -1069,12 +1069,13 @@ def task_show(process_instance_id: int, task_id: str) -> flask.wrappers.Response ) if ui_form_contents: task.form_ui_schema = ui_form_contents - elif task.type == "Manual Task": - if task.properties and task.data: - if task.properties["instructionsForEndUser"]: - task.properties["instructionsForEndUser"] = render_jinja_template( - task.properties["instructionsForEndUser"], task.data - ) + + if task.properties and task.data and "instructionsForEndUser" in task.properties: + print(f"task.properties['instructionsForEndUser']: {task.properties['instructionsForEndUser']}") + if task.properties["instructionsForEndUser"]: + task.properties["instructionsForEndUser"] = render_jinja_template( + task.properties["instructionsForEndUser"], task.data + ) return make_response(jsonify(task), 200) From 0f683ed24aca79c088287a63152007e011fb5881 Mon Sep 17 00:00:00 2001 From: jasquat Date: Mon, 31 Oct 2022 16:58:10 -0400 Subject: [PATCH 3/3] cleaned up some frontend code and put back logic for script unit tests w/ burnettk danfunk --- .../src/components/ReactDiagramEditor.tsx | 4 ++-- .../src/routes/ProcessModelEditDiagram.tsx | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx b/spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx index 0a604972..9728e7d5 100644 --- a/spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx +++ b/spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx @@ -185,8 +185,8 @@ export default function ReactDiagramEditor({ ) { if (onLaunchScriptEditor) { setPerformingXmlUpdates(true); - // const modeling = diagramModeler.get('modeling'); - onLaunchScriptEditor(element, script, scriptType, eventBus); + const modeling = diagramModeler.get('modeling'); + onLaunchScriptEditor(element, script, scriptType, eventBus, modeling); } } diff --git a/spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx b/spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx index 53f335a2..aa1643d8 100644 --- a/spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx +++ b/spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx @@ -280,15 +280,20 @@ export default function ProcessModelEditDiagram() { const onLaunchScriptEditor = ( element: any, script: string, - scriptType: string, - eventBus: any + 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(scriptType); + setScriptType(scriptTypeString); setScriptEventBus(eventBus); - // setScriptModeling(modeling); setScriptElement(element); - // setScriptUnitTestElementWithIndex(0, element); + setScriptUnitTestElementWithIndex(0, element); handleShowScriptEditor(); }; @@ -305,10 +310,6 @@ export default function ProcessModelEditDiagram() { const handleEditorScriptChange = (value: any) => { setScriptText(value); - // (scriptModeling as any).updateProperties(scriptElement, { - // scriptFormat: 'python', - // script: value, - // }); }; const handleEditorScriptTestUnitInputChange = (value: any) => {