From eb55bfc763ee6177e8a348bcef12769fab4f0320 Mon Sep 17 00:00:00 2001 From: jbirddog <100367399+jbirddog@users.noreply.github.com> Date: Thu, 15 Dec 2022 11:56:54 -0500 Subject: [PATCH] Allow viewing/editing xml of bpmn and dmn files (#76) --- .../src/components/ReactDiagramEditor.tsx | 22 +++++++++++++++ .../src/routes/ReactFormEditor.tsx | 28 ++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx b/spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx index a1be5efac..3584a6d27 100644 --- a/spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx +++ b/spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx @@ -52,6 +52,8 @@ import TouchModule from 'diagram-js/lib/navigation/touch'; // @ts-expect-error TS(7016) FIXME import ZoomScrollModule from 'diagram-js/lib/navigation/zoomscroll'; +import { useNavigate } from 'react-router-dom'; + import { Can } from '@casl/react'; import HttpService from '../services/HttpService'; @@ -119,6 +121,7 @@ export default function ReactDiagramEditor({ [targetUris.processModelFileShowPath]: ['POST', 'GET', 'PUT', 'DELETE'], }; const { ability } = usePermissionFetcher(permissionRequestData); + const navigate = useNavigate(); useEffect(() => { if (diagramModelerState) { @@ -542,6 +545,8 @@ export default function ReactDiagramEditor({ }); }; + const canViewXml = fileName !== undefined; + const userActionOptions = () => { if (diagramType !== 'readonly') { return ( @@ -580,6 +585,23 @@ export default function ReactDiagramEditor({ > + + {canViewXml && ( + + )} + ); } diff --git a/spiffworkflow-frontend/src/routes/ReactFormEditor.tsx b/spiffworkflow-frontend/src/routes/ReactFormEditor.tsx index 5a4da3878..5d1f55279 100644 --- a/spiffworkflow-frontend/src/routes/ReactFormEditor.tsx +++ b/spiffworkflow-frontend/src/routes/ReactFormEditor.tsx @@ -36,7 +36,20 @@ export default function ReactFormEditor() { return searchParams.get('file_ext') ?? 'json'; })(); - const editorDefaultLanguage = fileExtension === 'md' ? 'markdown' : 'json'; + const hasDiagram = fileExtension === 'bpmn' || fileExtension === 'dmn'; + + const editorDefaultLanguage = (() => { + if (fileExtension === 'json') { + return 'json'; + } + if (hasDiagram) { + return 'xml'; + } + if (fileExtension === 'md') { + return 'markdown'; + } + return 'text'; + })(); const modifiedProcessModelId = modifyProcessIdentifierForPathParam( `${params.process_model_id}` @@ -193,6 +206,19 @@ export default function ReactFormEditor() { buttonLabel="Delete" /> ) : null} + {hasDiagram ? ( + + ) : null}