From 01d94e7d558b97176235957e13cd00f1ae2198a4 Mon Sep 17 00:00:00 2001 From: Mozafar Haider Date: Fri, 23 Feb 2024 14:22:36 +0000 Subject: [PATCH] feat: move TEI import to new tracker endpoints --- src/components/Inputs/AtomicMode.js | 2 +- src/components/Inputs/TEITypeFilter.js | 1 - .../JobSummary/SingleSummary/SingleSummary.js | 2 +- src/hooks/useTasks.js | 1 + src/pages/EventExport/EventExport.js | 1 + src/pages/EventImport/form-helper.js | 3 +-- src/pages/TEIExport/form-helper.js | 1 + src/pages/TEIImport/TEIImport.js | 4 +--- src/pages/TEIImport/form-helper.js | 15 ++++++++------- src/utils/helper.js | 1 + 10 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/components/Inputs/AtomicMode.js b/src/components/Inputs/AtomicMode.js index e0165a2f2..468061c8b 100644 --- a/src/components/Inputs/AtomicMode.js +++ b/src/components/Inputs/AtomicMode.js @@ -4,7 +4,7 @@ import { RadioGroupField } from '../index.js' const atomicModeOptions = [ { value: 'ALL', label: i18n.t('Do not import') }, - { value: 'NONE', label: i18n.t('Import') }, + { value: 'OBJECT', label: i18n.t('Import') }, ] const defaultAtomicModeOption = atomicModeOptions[0].value diff --git a/src/components/Inputs/TEITypeFilter.js b/src/components/Inputs/TEITypeFilter.js index f440f0478..822e9956f 100644 --- a/src/components/Inputs/TEITypeFilter.js +++ b/src/components/Inputs/TEITypeFilter.js @@ -3,7 +3,6 @@ import React from 'react' import { RadioGroupField } from '../index.js' const teiTypeFilterOptions = [ - { value: 'NONE', label: i18n.t('None') }, { value: 'PROGRAM', label: i18n.t('Program') }, { value: 'TE', label: i18n.t('Tracked entity type') }, ] diff --git a/src/components/JobSummary/SingleSummary/SingleSummary.js b/src/components/JobSummary/SingleSummary/SingleSummary.js index a8e1f211d..001bf54d1 100644 --- a/src/components/JobSummary/SingleSummary/SingleSummary.js +++ b/src/components/JobSummary/SingleSummary/SingleSummary.js @@ -60,7 +60,7 @@ const SingleSummary = ({ - {validationReport?.errorReports && ( + {!!validationReport?.errorReports?.length && ( (type, id, task) => { const fetchEvents = async () => { + console.debug('[fetch event]', type, id, task) if (task.completed) { return } diff --git a/src/pages/EventExport/EventExport.js b/src/pages/EventExport/EventExport.js index 8deb3c229..4565c7ee3 100644 --- a/src/pages/EventExport/EventExport.js +++ b/src/pages/EventExport/EventExport.js @@ -65,6 +65,7 @@ const initialValues = { orgUnitIdScheme: defaultOrgUnitIdSchemeOption, idScheme: defaultIdSchemeOption, inclusion: defaultInclusionOption, + skipPaging: true } const EventExport = () => { diff --git a/src/pages/EventImport/form-helper.js b/src/pages/EventImport/form-helper.js index 8fcb3001a..81f335c75 100644 --- a/src/pages/EventImport/form-helper.js +++ b/src/pages/EventImport/form-helper.js @@ -17,7 +17,6 @@ const onImport = // send xhr const apiBaseUrl = `${baseUrl}/api/tracker` - const endpoint = '' const params = [ `async=${isAsync}`, `importMode=${dryRun ? 'validate' : 'commit'}`, @@ -25,7 +24,7 @@ const onImport = `orgUnitIdScheme=${orgUnitIdScheme}`, `idScheme=${idScheme}`, ].join('&') - const url = `${apiBaseUrl}${endpoint}?${params}` + const url = `${apiBaseUrl}?${params}` try { await uploadFile({ diff --git a/src/pages/TEIExport/form-helper.js b/src/pages/TEIExport/form-helper.js index a3390a605..aff47c216 100644 --- a/src/pages/TEIExport/form-helper.js +++ b/src/pages/TEIExport/form-helper.js @@ -44,6 +44,7 @@ const valuesToParams = ( orgUnitIdScheme: orgUnitIdScheme, idScheme: idScheme, attachment: filename, + skipPaging: true } // include selected org.units only when manual selection is selected diff --git a/src/pages/TEIImport/TEIImport.js b/src/pages/TEIImport/TEIImport.js index 3daed9cf9..518e38242 100644 --- a/src/pages/TEIImport/TEIImport.js +++ b/src/pages/TEIImport/TEIImport.js @@ -81,9 +81,7 @@ const createInitialValues = (prevJobDetails) => ({ prevJobDetails.skipValidation, defaultSkipValidationOption ), - // disable async until it is fully implemented for this resource - // (expected 2.36) - isAsync: false, + isAsync: true, dataElementIdScheme: prevJobDetails.dataElementIdScheme || defaultDataElementIdSchemeOption, orgUnitIdScheme: diff --git a/src/pages/TEIImport/form-helper.js b/src/pages/TEIImport/form-helper.js index d7386cbb0..dc089691a 100644 --- a/src/pages/TEIImport/form-helper.js +++ b/src/pages/TEIImport/form-helper.js @@ -26,8 +26,7 @@ const onImport = } = values // send xhr - const apiBaseUrl = `${baseUrl}/api/` - const endpoint = 'trackedEntityInstances.json' + const apiBaseUrl = `${baseUrl}/api/tracker/` const params = [ `importMode=${dryRun ? 'VALIDATE' : 'COMMIT'}`, `identifier=${identifier}`, @@ -49,18 +48,20 @@ const onImport = ] .filter((s) => s != '') .join('&') - const url = `${apiBaseUrl}${endpoint}?${params}` - + const url = `${apiBaseUrl}?${params}` + console.debug('[TEI import url]', url) try { await uploadFile({ url, file: files[0], format: format, - type: 'TEI_IMPORT', + type: 'TRACKER_IMPORT_JOB', isAsync: isAsync, setProgress, - addEntry: (id, entry) => - addTask('tei', id, { ...entry, jobDetails: values }), + addEntry: (id, entry) => { + addTask('tei', id, { ...entry, jobDetails: values }); + } + }) return jobStartedMessage } catch (e) { diff --git a/src/utils/helper.js b/src/utils/helper.js index 853274c24..a37774538 100644 --- a/src/utils/helper.js +++ b/src/utils/helper.js @@ -104,6 +104,7 @@ const uploadFile = ({ onResponse: (response) => { const { error, id, msg, typeReports } = response let entry + console.debug('response from uploading file', response) if (!isAsync) { // we are done entry = {