@@ -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 } ) ;
@@ -315,11 +343,11 @@ export default function ProcessDeploymentView({ processId }: { processId: string
315343 } ,
316344 ]
317345 : [ ] ) ,
318- ...deployments . map ( ( { version } ) => ( {
319- label : version . name ,
320- key : ` ${ version . id } ` ,
346+ ...( versions ? .map ( ( v ) => ( {
347+ key : v . id ,
348+ label : v . name ,
321349 disabled : false ,
322- } ) ) ,
350+ } ) ) || [ ] ) ,
323351 ] ,
324352 selectable : true ,
325353 onSelect : ( { key } ) => {
@@ -370,14 +398,7 @@ export default function ProcessDeploymentView({ processId }: { processId: string
370398 setStartingInstance ( true ) ;
371399 await wrapServerCall ( {
372400 fn : async ( ) => {
373- const latestDeployment = getLatestDeployment ( deployments ) ;
374- if ( ! latestDeployment ) {
375- return userError (
376- 'The current process does not seem to be deployed anymore.' ,
377- ) ;
378- }
379-
380- const { versionId } = latestDeployment ;
401+ const { id : versionId } = currentVersion ! ;
381402
382403 let startForm = await getProcessStartForm ( spaceId , processId , versionId ) ;
383404
@@ -451,7 +472,7 @@ export default function ProcessDeploymentView({ processId }: { processId: string
451472 onClick = { async ( ) => {
452473 setTogglingActivation ( true ) ;
453474 const nextState = ! isProcessActivated ;
454- const versionId = getLatestDeployment ( deployments ) ! . versionId ;
475+ const versionId = currentVersion ! . id ;
455476 await wrapServerCall ( {
456477 fn : ( ) =>
457478 changeDeploymentActivation ( processId , spaceId , versionId , nextState ) ,
@@ -641,10 +662,10 @@ export default function ProcessDeploymentView({ processId }: { processId: string
641662 // start the instance with the initial variable values from the start form
642663 await wrapServerCall ( {
643664 fn : async ( ) => {
644- const deployment = getLatestDeployment ( deployments ) ;
645-
646- if ( ! deployment ) {
647- return userError ( 'The current process does not seem to be deployed.' ) ;
665+ if ( ! currentVersion ) {
666+ return userError (
667+ 'The current process does not seem to have versions to execute.' ,
668+ ) ;
648669 }
649670
650671 const mappedVariables : Record < string , { value : any } > = { } ;
@@ -656,8 +677,8 @@ export default function ProcessDeploymentView({ processId }: { processId: string
656677
657678 return startInstance (
658679 spaceId ,
659- deployment . processId ,
660- deployment . version . id ,
680+ currentVersion . processId ,
681+ currentVersion . id ,
661682 mappedVariables ,
662683 ) ;
663684 } ,
0 commit comments