From d28efa876643ff249d51d950c7d814f05936f6c8 Mon Sep 17 00:00:00 2001 From: Hunter Achieng Date: Mon, 13 May 2024 12:06:02 +0300 Subject: [PATCH 1/3] fix: handle bulk data in state Signed-off-by: Hunter Achieng --- form-sharing/1-getNewKoboForms.js | 3 +++ form-sharing/2-getSheetsList.js | 3 ++- form-sharing/4-upsertAsanaTask.js | 1 - form-sharing/workflow.json | 6 +++--- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/form-sharing/1-getNewKoboForms.js b/form-sharing/1-getNewKoboForms.js index df181a9..7f5b4e3 100644 --- a/form-sharing/1-getNewKoboForms.js +++ b/form-sharing/1-getNewKoboForms.js @@ -6,5 +6,8 @@ getForms({}, state => { }; state.koboForms = state.data.results.filter(form => checkForKeyWords(form.name)); + state.data={}; + state.references = []; return state; }); + diff --git a/form-sharing/2-getSheetsList.js b/form-sharing/2-getSheetsList.js index f9f569c..7cabc02 100644 --- a/form-sharing/2-getSheetsList.js +++ b/form-sharing/2-getSheetsList.js @@ -10,7 +10,8 @@ getValues( state.filteredKoboFormsData = koboForms.filter( form => !sheetsUids.includes(form.uid) ); - + state.data = {}; + state.references = []; return state; } ); diff --git a/form-sharing/4-upsertAsanaTask.js b/form-sharing/4-upsertAsanaTask.js index ad164b0..3dba4dc 100644 --- a/form-sharing/4-upsertAsanaTask.js +++ b/form-sharing/4-upsertAsanaTask.js @@ -14,7 +14,6 @@ fn(state => { notes: `New form added to OpenFn: ${form.name}. Please review the Google Sheet and add the manual values missing: https://docs.google.com/spreadsheets/d/1s7K3kxzm5AlpwiALattyc7D9_aIyqWmo2ubcQIUlqlY/edit#gid=0`, }; }); - return state; }); each( diff --git a/form-sharing/workflow.json b/form-sharing/workflow.json index 43218cb..2b4bebd 100644 --- a/form-sharing/workflow.json +++ b/form-sharing/workflow.json @@ -10,7 +10,7 @@ "adaptor": "kobotoolbox", "expression": "1-getNewKoboForms.js", "next": { - "getSheetsList": "!state.error && state.data.length !== 0" + "getSheetsList": "!state.errors" } }, { @@ -19,7 +19,7 @@ "expression": "2-getSheetsList.js", "adaptor": "googlesheets", "next": { - "updateSheetsList": "!state.error && state.data.length !== 0" + "updateSheetsList": "!state.errors" } }, { @@ -28,7 +28,7 @@ "expression": "3-updateSheetsList.js", "adaptor": "googlesheets", "next": { - "upsertAsanaTask": "!state.error && state.sheetsData.length !== 0" + "upsertAsanaTask": "!state.errors" } }, { From 94be915a6098577fd28f6ce5f16074326cc0bd0b Mon Sep 17 00:00:00 2001 From: Hunter Achieng Date: Tue, 14 May 2024 10:01:03 +0300 Subject: [PATCH 2/3] fix: add filter for forms with active deployment status Signed-off-by: Hunter Achieng --- form-sharing/1-getNewKoboForms.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/form-sharing/1-getNewKoboForms.js b/form-sharing/1-getNewKoboForms.js index 164e062..9177def 100644 --- a/form-sharing/1-getNewKoboForms.js +++ b/form-sharing/1-getNewKoboForms.js @@ -10,7 +10,7 @@ getForms({}, state => { return keywords.some(keyword => name.toLowerCase().includes(keyword)); }; - state.koboForms = state.data.results.filter(form => checkForKeyWords(form.name)); + state.koboForms = state.data.results.filter(form => checkForKeyWords(form.name)).filter(form => form.deployment__active); state.data={}; state.references = []; return state; From 8235b1a9a3517ff8483dc88f0c493c51fb629a8c Mon Sep 17 00:00:00 2001 From: Hunter Achieng Date: Tue, 14 May 2024 11:26:27 +0300 Subject: [PATCH 3/3] fix: format state.data Signed-off-by: Hunter Achieng --- form-sharing/1-getNewKoboForms.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/form-sharing/1-getNewKoboForms.js b/form-sharing/1-getNewKoboForms.js index 9177def..0bd6253 100644 --- a/form-sharing/1-getNewKoboForms.js +++ b/form-sharing/1-getNewKoboForms.js @@ -1,8 +1,8 @@ //Check Kobo account for forms with these matching keywords getForms({}, state => { - //ALL KEYWORDS: + //ALL KEYWORDS: //const keywords = ['price', 'prix', 'bns', 'nrgt', 'grm', 'feedback']; - + //BNS KEYWORDS ONLY const keywords = ['price', 'prix', 'bns', 'nrgt']; @@ -10,9 +10,10 @@ getForms({}, state => { return keywords.some(keyword => name.toLowerCase().includes(keyword)); }; - state.koboForms = state.data.results.filter(form => checkForKeyWords(form.name)).filter(form => form.deployment__active); - state.data={}; + state.koboForms = state.data.results + .filter(form => checkForKeyWords(form.name)) + .filter(form => form.deployment__active); + state.data = {}; state.references = []; return state; }); -