From 02fd242bb7bb390392b441d6a65c40bc11e60251 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Fri, 5 Aug 2022 20:09:23 +0200 Subject: [PATCH] feat: _value, _index => iter.value, iter.index --- backend/src/worker_flow.rs | 25 +++++++++++++++------- frontend/src/lib/components/flows/utils.ts | 14 ++++++------ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/backend/src/worker_flow.rs b/backend/src/worker_flow.rs index 795f97b0a7..78a9cdf9b6 100644 --- a/backend/src/worker_flow.rs +++ b/backend/src/worker_flow.rs @@ -472,12 +472,16 @@ async fn push_next_flow_job( } }; let mut args = Map::new(); - args.insert("_iterator".to_string(), last_result.clone()); - args.insert( - "_index".to_string(), + let mut iteration_map = Map::new(); + iteration_map.insert( + "index".to_string(), serde_json::Value::Number(serde_json::Number::from(0)), ); - args.insert("_value".to_string(), itered[0].clone()); + iteration_map.insert("value".to_string(), itered[0].clone()); + args.insert( + "iteration".to_string(), + serde_json::Value::Object(iteration_map), + ); match itered { serde_json::Value::Array(arr) => (Some(args), Some((0 as u8, arr, vec![]))), a @ _ => Err(Error::BadRequest(format!( @@ -493,14 +497,19 @@ async fn push_next_flow_job( } if index.to_owned() + 1 < itered.len() as u8 => { let mut args = args.clone(); let nindex = index.to_owned() + 1; - args.insert( - "_index".to_string(), + let mut iteration_map = Map::new(); + iteration_map.insert( + "index".to_string(), serde_json::Value::Number(serde_json::Number::from(nindex.to_owned())), ); - args.insert( - "_value".to_string(), + iteration_map.insert( + "value".to_string(), itered[nindex.to_owned() as usize].clone(), ); + args.insert( + "iteration".to_string(), + serde_json::Value::Object(iteration_map), + ); ( Some(args), Some((nindex, itered.clone(), forloop_jobs.clone())), diff --git a/frontend/src/lib/components/flows/utils.ts b/frontend/src/lib/components/flows/utils.ts index c3c4d06b21..7f317f7462 100644 --- a/frontend/src/lib/components/flows/utils.ts +++ b/frontend/src/lib/components/flows/utils.ts @@ -233,13 +233,15 @@ export async function runFlowPreview(args: Record, flow: Flow) { function computeFlowInputPull(previewResult: any | undefined, flowInputAsObject: any) { const iteratorValues = (previewResult && Array.isArray(previewResult)) ? { - _iterator: previewResult, - _value: previewResult[0], - _index: `The current index of the iteration as a number (here from 0 to ${previewResult.length - 1})` + iter: { + value: previewResult[0], + index: `The current index of the iteration as a number (here from 0 to ${previewResult.length - 1})` + } } : { - _iterator: 'All the values returned by the previous step', - _value: 'The current value of the iteration as an object', - _index: 'The current index of the iteration as a number' + iter: { + value: 'The current value of the iteration as an object', + index: 'The current index of the iteration as a number' + } } return Object.assign(Object.assign(flowInputAsObject, previewResult), iteratorValues)