3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*/
5
5
6
- import { WORKFLOW_STATE , Workflow } from '../../common' ;
6
+ import { WORKFLOW_STATE , Workflow , WorkflowDict } from '../../common' ;
7
7
8
8
// OSD does not provide an interface for this response, but this is following the suggested
9
9
// implementations. To prevent typescript complaining, leaving as loosely-typed 'any'
@@ -19,18 +19,47 @@ export function generateCustomError(res: any, err: any) {
19
19
} ) ;
20
20
}
21
21
22
- export function toWorkflowObj ( workflowHit : any ) : Workflow {
22
+ function toWorkflowObj ( workflowHit : any ) : Workflow {
23
23
// TODO: update schema parsing after hit schema has been updated.
24
24
// https://github.com/opensearch-project/flow-framework/issues/546
25
25
const hitSource = workflowHit . fields . filter [ 0 ] ;
26
- // const hitSource = workflowHit._source;
27
26
return {
28
27
id : workflowHit . _id ,
29
28
name : hitSource . name ,
29
+ useCase : hitSource . use_case ,
30
30
description : hitSource . description || '' ,
31
31
// TODO: update below values after frontend Workflow interface is finalized
32
32
template : { } ,
33
+ // TODO: this needs to be persisted by backend. Tracking issue:
34
+ // https://github.com/opensearch-project/flow-framework/issues/548
33
35
lastUpdated : 1234 ,
34
- state : WORKFLOW_STATE . SUCCEEDED ,
35
36
} as Workflow ;
36
37
}
38
+
39
+ // TODO: can remove or simplify if we can fetch all data from a single API call. Tracking issue:
40
+ // https://github.com/opensearch-project/flow-framework/issues/171
41
+ // Current implementation combines 2 search responses to create a single set of workflows with
42
+ // static information + state information
43
+ export function getWorkflowsFromResponses (
44
+ workflowHits : any [ ] ,
45
+ workflowStateHits : any [ ]
46
+ ) : WorkflowDict {
47
+ const workflowDict = { } as WorkflowDict ;
48
+ workflowHits . forEach ( ( workflowHit : any ) => {
49
+ workflowDict [ workflowHit . _id ] = toWorkflowObj ( workflowHit ) ;
50
+ const workflowStateHit = workflowStateHits . find (
51
+ ( workflowStateHit ) => workflowStateHit . _id === workflowHit . _id
52
+ ) ;
53
+ const workflowState = workflowStateHit . _source
54
+ . state as typeof WORKFLOW_STATE ;
55
+ workflowDict [ workflowHit . _id ] = {
56
+ ...workflowDict [ workflowHit . _id ] ,
57
+ // @ts -ignore
58
+ state : WORKFLOW_STATE [ workflowState ] ,
59
+ // TODO: this needs to be persisted by backend. Tracking issue:
60
+ // https://github.com/opensearch-project/flow-framework/issues/548
61
+ lastLaunched : 1234 ,
62
+ } ;
63
+ } ) ;
64
+ return workflowDict ;
65
+ }
0 commit comments