11import React , { useEffect , useState , useRef } from "react" ;
22import { useSelector , useDispatch } from "react-redux" ;
3- import { useParams } from "react-router-dom" ;
3+ import { useParams , useLocation } from "react-router-dom" ;
44import { push } from "connected-react-router" ;
55import PropTypes from "prop-types" ;
66import {
@@ -52,9 +52,9 @@ import NavigateBlocker from "../../../components/CustomComponents/NavigateBlocke
5252const EXPORT = "EXPORT" ;
5353const IMPORT = "IMPORT" ;
5454const CategoryType = { FORM : "FORM" , WORKFLOW : "WORKFLOW" } ;
55-
5655const ProcessCreateEdit = ( { type } ) => {
5756 const { processKey, step } = useParams ( ) ;
57+ const location = useLocation ( ) ;
5858 const isCreate = step === "create" ;
5959 const isBPMN = type === "BPMN" ;
6060 const Process = {
@@ -80,7 +80,12 @@ const ProcessCreateEdit = ({ type }) => {
8080 const dmnRef = useRef ( ) ;
8181 const { t } = useTranslation ( ) ;
8282 const tenantKey = useSelector ( ( state ) => state . tenants ?. tenantId ) ;
83- const redirectUrl = MULTITENANCY_ENABLED ? `/tenant/${ tenantKey } /` : "/" ;
83+
84+ // Helper function to get redirect URL
85+ const getRedirectUrl = ( ) => {
86+ return MULTITENANCY_ENABLED ? `/tenant/${ tenantKey } /` : "/" ;
87+ } ;
88+ const redirectUrl = getRedirectUrl ( ) ;
8489 const processData = useSelector ( ( state ) => state . process ?. processData ) ;
8590 const [ selectedAction , setSelectedAction ] = useState ( null ) ;
8691 const [ newActionModal , setNewActionModal ] = useState ( false ) ;
@@ -178,7 +183,12 @@ const ProcessCreateEdit = ({ type }) => {
178183 } , [ processData ] ) ;
179184
180185
181- const publishText = isPublished ? t ( "Unpublish" ) : t ( "Publish" ) ;
186+ // Helper function to get publish text
187+ const getPublishText = ( ) => {
188+ return isPublished ? t ( "Unpublish" ) : t ( "Publish" ) ;
189+ } ;
190+ const publishText = getPublishText ( ) ;
191+
182192 const processName = processData . name ;
183193 const fileName = ( processName + Process . extension ) . replaceAll ( " " , "" ) ;
184194
@@ -225,7 +235,11 @@ const ProcessCreateEdit = ({ type }) => {
225235 } ,
226236 } ) ;
227237
228- const processDataXML = isReverted ? historyData ?. processData : processData ?. processData ;
238+ // Helper function to get process data XML
239+ const getProcessDataXML = ( ) => {
240+ return isReverted ? historyData ?. processData : processData ?. processData ;
241+ } ;
242+ const processDataXML = getProcessDataXML ( ) ;
229243 // handle history modal
230244 // const handleToggleHistoryModal = () => setHistoryModalShow(!historyModalShow);
231245
@@ -528,8 +542,17 @@ const ProcessCreateEdit = ({ type }) => {
528542 } ;
529543 const handleCloseErrorModal = ( ) => setShowErrorModal ( false ) ;
530544
531- if ( isProcessDetailsLoading ) {
532- return < Loading /> ;
545+ // Helper function to render loading state
546+ const renderLoadingState = ( ) => {
547+ if ( isProcessDetailsLoading ) {
548+ return < Loading /> ;
549+ }
550+ return null ;
551+ } ;
552+
553+ const loadingComponent = renderLoadingState ( ) ;
554+ if ( loadingComponent ) {
555+ return loadingComponent ;
533556 }
534557
535558 const getModalContent = ( ) => {
@@ -600,13 +623,40 @@ const ProcessCreateEdit = ({ type }) => {
600623 } ;
601624
602625 const modalContent = getModalContent ( ) ;
626+
627+ // Helper function to get editor reference
628+ const getEditorRef = ( ) => {
629+ return isBPMN ? bpmnRef : dmnRef ;
630+ } ;
631+
603632 const handleImportData = ( xml ) => {
604- const ref = isBPMN ? bpmnRef : dmnRef ;
633+ const ref = getEditorRef ( ) ;
605634 if ( ref . current ) {
606635 ref . current ?. handleImport ( xml ) ;
607636 }
608637 } ;
609638
639+ // Helper function to render editor component
640+ const renderEditor = ( ) => {
641+ if ( isBPMN ) {
642+ return (
643+ < BpmnEditor
644+ onChange = { enableWorkflowChange }
645+ ref = { bpmnRef }
646+ bpmnXml = { isCreate ? defaultProcessXmlData : processDataXML }
647+ setLintErrors = { setLintErrors }
648+ />
649+ ) ;
650+ }
651+ return (
652+ < DmnEditor
653+ onChange = { enableWorkflowChange }
654+ ref = { dmnRef }
655+ dmnXml = { isCreate ? defaultDmnXmlData : processDataXML }
656+ />
657+ ) ;
658+ } ;
659+
610660 return (
611661 < div >
612662 < NavigateBlocker isBlock = { isWorkflowChanged } message = { "You have made changes that are not saved yet" } />
@@ -734,20 +784,7 @@ const ProcessCreateEdit = ({ type }) => {
734784 spinner
735785 text = { t ( "Loading..." ) }
736786 >
737- { isBPMN ? (
738- < BpmnEditor
739- onChange = { enableWorkflowChange }
740- ref = { bpmnRef }
741- bpmnXml = { isCreate ? defaultProcessXmlData : processDataXML }
742- setLintErrors = { setLintErrors }
743- />
744- ) : (
745- < DmnEditor
746- onChange = { enableWorkflowChange }
747- ref = { dmnRef }
748- dmnXml = { isCreate ? defaultDmnXmlData : processDataXML }
749- />
750- ) }
787+ { renderEditor ( ) }
751788 </ LoadingOverlay >
752789 )
753790 ) }
0 commit comments