@@ -26,7 +26,7 @@ import { ColorOptions, colorOptions } from './instance-coloring';
2626import { RemoveReadOnly , truthyFilter } from '@/lib/typescript-utils' ;
2727import type { ElementLike } from 'diagram-js/lib/core/Types' ;
2828import { wrapServerCall } from '@/lib/wrap-server-call' ;
29- import { getLatestDeployment , getVersionInstances , getYoungestInstance } from './instance-helpers' ;
29+ import { getLatestVersion , getVersionInstances , getYoungestInstance } from './instance-helpers' ;
3030
3131import useColors from './use-colors' ;
3232import useTokens from './use-tokens' ;
@@ -53,8 +53,8 @@ import { useQuery } from '@tanstack/react-query';
5353import { getProcessDeployments } from '@/lib/data/deployment' ;
5454import { isSuccessResponse , isUserErrorResponse , userError } from '@/lib/user-error' ;
5555import { getInstance } from '@/lib/data/instance' ;
56- import { asyncMap , pick } from '@/lib/helpers/javascriptHelpers' ;
57- import { getProcessBPMN } from '@/lib/data/processes' ;
56+ import { asyncFilter , asyncMap , pick } from '@/lib/helpers/javascriptHelpers' ;
57+ import { getVersions } from '@/lib/data/processes' ;
5858import { enableInstanceCSVExport } from 'FeatureFlags' ;
5959import jsonToCsvExport from 'json-to-csv-export' ;
6060
@@ -80,10 +80,40 @@ export default function ProcessDeploymentView({ processId }: { processId: string
8080 const canvasRef = useRef < BPMNCanvasRef > ( null ) ;
8181 const [ infoPanelOpen , setInfoPanelOpen ] = useState ( false ) ;
8282
83+ const isExecutableVersionMap = useRef < Record < string , boolean > > ( { } ) ;
84+
85+ const { data : versions } = useQuery ( {
86+ queryFn : async ( ) => {
87+ let versions = await getVersions ( spaceId , processId ) ;
88+ if ( isUserErrorResponse ( versions ) ) return [ ] ;
89+
90+ // filter out all versions that are not executable
91+ versions = await asyncFilter ( versions , async ( version ) => {
92+ if ( version . id in isExecutableVersionMap . current ) {
93+ return isExecutableVersionMap . current [ version . id ] ;
94+ }
95+
96+ const bpmnObj = await toBpmnObject ( version . bpmn ) ;
97+ const processes = getElementsByTagName ( bpmnObj , 'bpmn:Process' ) ;
98+ if ( ! processes . length ) return false ;
99+ isExecutableVersionMap . current [ version . id ] = processes [ 0 ] . isExecutable ;
100+ return processes [ 0 ] . isExecutable ;
101+ } ) ;
102+
103+ versions . sort ( ( a , b ) => {
104+ return b . createdOn . getTime ( ) - a . createdOn . getTime ( ) ;
105+ } ) ;
106+
107+ return versions ;
108+ } ,
109+ queryKey : [ 'processVersions' , spaceId , processId ] ,
110+ refetchInterval : 1000 ,
111+ } ) ;
112+
83113 // get information where the process is deployed and which instances exist
84114 const { data : deployments , refetch : refetchDeployments } = useQuery ( {
85115 queryFn : async ( ) => {
86- const deployments = await getProcessDeployments ( spaceId , processId ) ;
116+ const deployments = await getProcessDeployments ( spaceId , processId , undefined , true , true ) ;
87117 if ( isUserErrorResponse ( deployments ) ) return null ;
88118 return deployments ;
89119 } ,
@@ -130,8 +160,8 @@ export default function ProcessDeploymentView({ processId }: { processId: string
130160 const { selectedVersion, versionInstances, currentVersion } = useMemo ( ( ) => {
131161 let selectedVersion , versionInstances , currentVersion ;
132162
133- if ( deployments ?. length ) {
134- selectedVersion = deployments . find ( ( d ) => d . versionId === selectedVersionId ) ?. version ;
163+ if ( versions ?. length ) {
164+ selectedVersion = versions . find ( ( v ) => v . id === selectedVersionId ) ;
135165
136166 // sort instances newest first
137167 const rawInstances = getVersionInstances ( knownInstances , selectedVersionId ) ;
@@ -143,21 +173,21 @@ export default function ProcessDeploymentView({ processId }: { processId: string
143173 ? versionInstances . find ( ( i ) => i . processInstanceId === selectedInstanceId )
144174 : undefined ;
145175
146- let currentVersionId = getLatestDeployment ( deployments ) ! . versionId ;
176+ let currentVersionId = getLatestVersion ( versions ) ! . id ;
147177 if ( selectedInstance ) {
148178 currentVersionId = selectedInstance . processVersion ;
149179 } else if ( selectedVersionId ) {
150180 currentVersionId = selectedVersionId ;
151181 }
152- currentVersion = deployments . find ( ( d ) => d . versionId === currentVersionId ) ! . version ;
182+ currentVersion = versions . find ( ( v ) => v . id === currentVersionId ) ;
153183 }
154184
155185 return {
156186 selectedVersion,
157187 versionInstances,
158188 currentVersion,
159189 } ;
160- } , [ deployments , knownInstances , selectedVersionId , selectedInstanceId ] ) ;
190+ } , [ versions , knownInstances , selectedVersionId , selectedInstanceId ] ) ;
161191
162192 const { data : currentInstance , refetch : refetchCurrentInstance } = useQuery ( {
163193 queryKey : [ 'processDeployments' , spaceId , processId , 'instance' , selectedInstanceId ] ,
@@ -179,9 +209,7 @@ export default function ProcessDeploymentView({ processId }: { processId: string
179209
180210 const { data : selectedBpmn } = useQuery ( {
181211 queryFn : async ( ) => {
182- const bpmn = await getProcessBPMN ( processId , spaceId , currentVersion ?. id ) ;
183- if ( isUserErrorResponse ( bpmn ) ) return undefined ;
184- return { bpmn } ;
212+ return { bpmn : currentVersion ?. bpmn || '' } ;
185213 } ,
186214 queryKey : [ 'space' , spaceId , 'process' , processId , 'version' , currentVersion ?. id || '' , 'bpmn' ] ,
187215 } ) ;
@@ -320,11 +348,11 @@ export default function ProcessDeploymentView({ processId }: { processId: string
320348 } ,
321349 ]
322350 : [ ] ) ,
323- ...deployments . map ( ( { version } ) => ( {
324- label : version . name ,
325- key : ` ${ version . id } ` ,
351+ ...( versions ? .map ( ( v ) => ( {
352+ key : v . id ,
353+ label : v . name ,
326354 disabled : false ,
327- } ) ) ,
355+ } ) ) || [ ] ) ,
328356 ] ,
329357 selectable : true ,
330358 onSelect : ( { key } ) => {
@@ -375,14 +403,7 @@ export default function ProcessDeploymentView({ processId }: { processId: string
375403 setStartingInstance ( true ) ;
376404 await wrapServerCall ( {
377405 fn : async ( ) => {
378- const latestDeployment = getLatestDeployment ( deployments ) ;
379- if ( ! latestDeployment ) {
380- return userError (
381- 'The current process does not seem to be deployed anymore.' ,
382- ) ;
383- }
384-
385- const { versionId } = latestDeployment ;
406+ const { id : versionId } = currentVersion ! ;
386407
387408 let startForm = await getProcessStartForm ( spaceId , processId , versionId ) ;
388409
@@ -454,7 +475,7 @@ export default function ProcessDeploymentView({ processId }: { processId: string
454475 onClick = { async ( ) => {
455476 setTogglingActivation ( true ) ;
456477 const nextState = ! isProcessActivated ;
457- const versionId = getLatestDeployment ( deployments ) ! . versionId ;
478+ const versionId = currentVersion ! . id ;
458479 await wrapServerCall ( {
459480 fn : ( ) =>
460481 changeDeploymentActivation ( processId , spaceId , versionId , nextState ) ,
@@ -644,10 +665,10 @@ export default function ProcessDeploymentView({ processId }: { processId: string
644665 // start the instance with the initial variable values from the start form
645666 await wrapServerCall ( {
646667 fn : async ( ) => {
647- const deployment = getLatestDeployment ( deployments ) ;
648-
649- if ( ! deployment ) {
650- return userError ( 'The current process does not seem to be deployed.' ) ;
668+ if ( ! currentVersion ) {
669+ return userError (
670+ 'The current process does not seem to have versions to execute.' ,
671+ ) ;
651672 }
652673
653674 const mappedVariables : Record < string , { value : any } > = { } ;
@@ -659,8 +680,8 @@ export default function ProcessDeploymentView({ processId }: { processId: string
659680
660681 return startInstance (
661682 spaceId ,
662- deployment . processId ,
663- deployment . version . id ,
683+ currentVersion . processId ,
684+ currentVersion . id ,
664685 mappedVariables ,
665686 true ,
666687 ) ;
0 commit comments