@@ -18,16 +18,30 @@ interface EditorState {
1818 workflow : RpaWorkflowSchema ;
1919}
2020
21- interface StoredWorkflowStep {
22- id ?: string ;
23- type ?: string ;
24- name ?: string ;
25- enabled ?: boolean ;
26- next ?: string | null ;
27- branches ?: Record < string , string > ;
28- config ?: Record < string , unknown > ;
29- ui ?: {
30- source_type ?: string ;
21+ interface StoredWorkflowStep {
22+ id ?: string ;
23+ type ?: string ;
24+ name ?: string ;
25+ enabled ?: boolean ;
26+ next ?: string | null ;
27+ branches ?: Record < string , string > ;
28+ click_type ?: string ;
29+ wait_for_element ?: boolean ;
30+ clear_first ?: boolean ;
31+ type_slowly ?: boolean ;
32+ duration_ms ?: number ;
33+ timeout_ms ?: number ;
34+ output ?: string ;
35+ script ?: string ;
36+ url ?: string ;
37+ value ?: string ;
38+ target ?: {
39+ by ?: string ;
40+ value ?: string ;
41+ } ;
42+ config ?: Record < string , unknown > ;
43+ ui ?: {
44+ source_type ?: string ;
3145 position ?: {
3246 x ?: number ;
3347 y ?: number ;
@@ -330,18 +344,69 @@ function mapStoredGlobalVariables(
330344 . filter ( ( variable ) => variable . name . trim ( ) ) ;
331345}
332346
333- function buildFlowStepFromStoredStep ( step : StoredWorkflowStep ) : FlowStep {
334- const uiType = typeof step . ui ?. source_type === 'string' ? step . ui . source_type : step . type ;
335- const position = step . ui ?. position ;
336- const parentLoopId = typeof step . ui ?. parent_id === 'string' ? step . ui . parent_id : null ;
337- const config =
338- step . config && typeof step . config === 'object'
339- ? { ...( step . config as Record < string , unknown > ) }
340- : { } ;
341-
342- if ( step . branches && typeof step . branches === 'object' ) {
343- config . branches = step . branches ;
344- }
347+ function buildFlowStepFromStoredStep ( step : StoredWorkflowStep ) : FlowStep {
348+ const uiType = typeof step . ui ?. source_type === 'string' ? step . ui . source_type : step . type ;
349+ const position = step . ui ?. position ;
350+ const parentLoopId = typeof step . ui ?. parent_id === 'string' ? step . ui . parent_id : null ;
351+ const config =
352+ step . config && typeof step . config === 'object'
353+ ? { ...( step . config as Record < string , unknown > ) }
354+ : { } ;
355+ const selector = typeof step . target ?. value === 'string' ? step . target . value : '' ;
356+
357+ if ( ! config . selector && selector ) {
358+ config . selector = selector ;
359+ }
360+
361+ if ( ! config . url && typeof step . url === 'string' ) {
362+ config . url = step . url ;
363+ }
364+
365+ if ( step . type === 'click' ) {
366+ if ( ! config . clickType && typeof step . click_type === 'string' ) {
367+ config . clickType = step . click_type ;
368+ }
369+ if ( ! Object . prototype . hasOwnProperty . call ( config , 'waitForElement' ) ) {
370+ config . waitForElement = step . wait_for_element !== false ;
371+ }
372+ }
373+
374+ if ( step . type === 'fill' ) {
375+ if ( ! config . text && typeof step . value === 'string' ) {
376+ config . text = step . value ;
377+ }
378+ if ( ! Object . prototype . hasOwnProperty . call ( config , 'clearFirst' ) ) {
379+ config . clearFirst = step . clear_first !== false ;
380+ }
381+ if ( ! Object . prototype . hasOwnProperty . call ( config , 'typeSlowly' ) ) {
382+ config . typeSlowly = step . type_slowly === true ;
383+ }
384+ }
385+
386+ if ( step . type === 'delay' ) {
387+ if ( ! config . duration && typeof step . duration_ms === 'number' ) {
388+ config . duration = step . duration_ms ;
389+ }
390+ if ( ! config . waitType ) {
391+ config . waitType = 'time' ;
392+ }
393+ }
394+
395+ if ( step . type === 'wait_for' && ! config . timeout && typeof step . timeout_ms === 'number' ) {
396+ config . timeout = step . timeout_ms ;
397+ }
398+
399+ if ( ! config . outputKey && typeof step . output === 'string' ) {
400+ config . outputKey = step . output ;
401+ }
402+
403+ if ( ! config . script && typeof step . script === 'string' ) {
404+ config . script = step . script ;
405+ }
406+
407+ if ( step . branches && typeof step . branches === 'object' ) {
408+ config . branches = step . branches ;
409+ }
345410
346411 return {
347412 id : String ( step . id ) ,
@@ -548,31 +613,43 @@ export function mapPortableTaskToEditorState(document: PortableRpaTaskDocument):
548613 } ) ?. config ?. workflow_meta as StoredWorkflowMeta | undefined ;
549614 const importedIdMap = new Map < string , string > ( ) ;
550615 sortedSteps . forEach ( ( step ) => {
551- importedIdMap . set ( step . uuid , crypto . randomUUID ( ) ) ;
616+ const nextId = crypto . randomUUID ( ) ;
617+ importedIdMap . set ( step . uuid , nextId ) ;
618+
619+ const storedStep = step . config ?. workflow_step ;
620+ if ( storedStep && typeof storedStep === 'object' && typeof storedStep . id === 'string' ) {
621+ importedIdMap . set ( storedStep . id , nextId ) ;
622+ }
552623 } ) ;
553624 const storedStartStepId =
554625 typeof storedWorkflowMeta ?. start_step_id === 'string'
555626 ? importedIdMap . get ( storedWorkflowMeta . start_step_id ) ?? null
556627 : null ;
557628
558629 const steps = sortedSteps . map ( ( step , index ) => {
559- const legacyStep = buildLegacyFlowStep (
560- {
561- uuid : step . uuid ,
562- step_type : step . step_type ,
563- name : step . name ,
564- config : step . config ,
565- enabled : step . enabled ?? true ,
566- position_x : step . position_x ,
567- position_y : step . position_y ,
568- sort_order : step . sort_order ,
569- next_step_uuid : step . next_step_uuid ,
570- branch_config : step . branch_config ,
571- } ,
572- step . next_step_uuid ?? sortedSteps [ index + 1 ] ?. uuid ?? null
573- ) ;
574-
575- const currentBranches = ( legacyStep . config . branches as Record < string , unknown > | undefined ) ?? { } ;
630+ const storedStep =
631+ step . config ?. workflow_step && typeof step . config . workflow_step === 'object'
632+ ? ( step . config . workflow_step as StoredWorkflowStep )
633+ : null ;
634+ const baseStep = storedStep
635+ ? buildFlowStepFromStoredStep ( storedStep )
636+ : buildLegacyFlowStep (
637+ {
638+ uuid : step . uuid ,
639+ step_type : step . step_type ,
640+ name : step . name ,
641+ config : step . config ,
642+ enabled : step . enabled ?? true ,
643+ position_x : step . position_x ,
644+ position_y : step . position_y ,
645+ sort_order : step . sort_order ,
646+ next_step_uuid : step . next_step_uuid ,
647+ branch_config : step . branch_config ,
648+ } ,
649+ step . next_step_uuid ?? sortedSteps [ index + 1 ] ?. uuid ?? null
650+ ) ;
651+ const sourceId = storedStep ?. id ?? step . uuid ;
652+ const currentBranches = ( baseStep . config . branches as Record < string , unknown > | undefined ) ?? { } ;
576653 const mappedBranches = Object . fromEntries (
577654 Object . entries ( currentBranches ) . map ( ( [ key , value ] ) => [
578655 key ,
@@ -581,17 +658,18 @@ export function mapPortableTaskToEditorState(document: PortableRpaTaskDocument):
581658 ) ;
582659
583660 return {
584- ...legacyStep ,
585- id : importedIdMap . get ( step . uuid ) ?? legacyStep . id ,
586- nextStepId : step . next_step_uuid ? importedIdMap . get ( step . next_step_uuid ) ?? null : null ,
587- isStart : storedStartStepId ? importedIdMap . get ( step . uuid ) === storedStartStepId : index === 0 ,
661+ ...baseStep ,
662+ id : importedIdMap . get ( sourceId ) ?? baseStep . id ,
663+ nextStepId : baseStep . nextStepId ? importedIdMap . get ( baseStep . nextStepId ) ?? null : null ,
664+ parentLoopId : baseStep . parentLoopId ? importedIdMap . get ( baseStep . parentLoopId ) ?? null : null ,
665+ isStart : storedStartStepId ? importedIdMap . get ( sourceId ) === storedStartStepId : index === 0 ,
588666 config :
589667 Object . keys ( mappedBranches ) . length > 0
590668 ? {
591- ...legacyStep . config ,
669+ ...baseStep . config ,
592670 branches : mappedBranches ,
593671 }
594- : legacyStep . config ,
672+ : baseStep . config ,
595673 } ;
596674 } ) ;
597675
0 commit comments