diff --git a/src/components/JobSummary/SingleSummary/SingleSummary.js b/src/components/JobSummary/SingleSummary/SingleSummary.js index f54ae56cd..a8e1f211d 100644 --- a/src/components/JobSummary/SingleSummary/SingleSummary.js +++ b/src/components/JobSummary/SingleSummary/SingleSummary.js @@ -20,6 +20,7 @@ const SingleSummary = ({ status, description, conflicts, + validationReport, id, }) => (
@@ -29,7 +30,7 @@ const SingleSummary = ({ name="summary" > <> - {status && ( + {status && description && ( - {importCount.imported} - {importCount.deleted} - {importCount.ignored} - {importCount.updated} - {importCount.total} + + {importCount?.imported ?? '0'} + + {importCount?.deleted} + {importCount?.ignored} + {importCount?.updated} + {importCount?.total} + {validationReport?.errorReports && ( + + + + + {i18n.t('UID')} + + {i18n.t('Error Code')} + + {i18n.t('Message')} + + {i18n.t('Tracker Type')} + + {/* {i18n.t('')} */} + + + + {validationReport.errorReports.map((c, i) => ( + + {c.uid} + + + {c.warningCode ?? c.errorCode} + + + {c.message} + {c.trackerType} + + ))} + +
+
+ )} {conflicts && ( { importCount={importCount} status={summary.status} description={summary.description} + validationReport={summary.validationReport} conflicts={ summary.conflicts && (summary.conflicts.length || null) && diff --git a/src/hooks/useTasks.js b/src/hooks/useTasks.js index 7dfcc606c..7b52c2794 100644 --- a/src/hooks/useTasks.js +++ b/src/hooks/useTasks.js @@ -16,6 +16,20 @@ const jobSummaryQuery = { }, } +const trackerEventQuery = { + events: { + resource: 'tracker/jobs/', + id: ({ taskId }) => `${taskId}`, + }, +} + +const trackerSummaryQuery = { + summary: { + resource: 'tracker/jobs/', + id: ({ taskId }) => `${taskId}/report`, + }, +} + const defaultTasks = { data: {}, event: {}, @@ -39,13 +53,20 @@ const createFetchEvents = } const newTask = { ...task } - const { events, error } = await engine.query(jobEventQuery, { + const query = + task.importType === 'TRACKER_IMPORT_JOB' + ? trackerEventQuery + : jobEventQuery + + const response = await engine.query(query, { variables: { type: task.importType, taskId: task.id, }, }) + const { events, error } = response + if (error) { console.error('fetchEvents error: ', error) return @@ -90,13 +111,24 @@ const createFetchEvents = const createFetchSummary = (engine, setTasks) => async (type, id, task) => { const newTask = { ...task } - const { summary, error } = await engine.query(jobSummaryQuery, { + // we could still keep one query here (the jobs query), but tracker provides a facade to these + // and even though this branches the logic unnecessarily, we should stick to + // trackers' endpoint for tracker imports and they could abstract some job-related details + // more details here: https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-master/tracker.html#webapi_nti_import_summary + const query = + task.importType === 'TRACKER_IMPORT_JOB' + ? trackerSummaryQuery + : jobSummaryQuery + + const response = await engine.query(query, { variables: { type: task.importType, taskId: task.id, }, }) + const { summary, error } = response + if (error) { console.error('fetchSummary error: ', error) return diff --git a/src/pages/EventImport/EventImport.js b/src/pages/EventImport/EventImport.js index 4f9e867f9..d078443aa 100644 --- a/src/pages/EventImport/EventImport.js +++ b/src/pages/EventImport/EventImport.js @@ -14,7 +14,6 @@ import { import { FileUpload, Format, - formatOptions, defaultFormatOption, DataElementIdScheme, defaultDataElementIdSchemeOption, @@ -26,6 +25,7 @@ import { defaultOrgUnitIdSchemeOption, ImportButtonStrip, FormAlerts, + formatNoXmlOptions, } from '../../components/Inputs/index.js' import { TaskContext, getNewestTask } from '../../contexts/index.js' import { getPrevJobDetails } from '../../utils/helper.js' @@ -102,7 +102,7 @@ const EventImport = () => { )} /> diff --git a/src/pages/EventImport/form-helper.js b/src/pages/EventImport/form-helper.js index af0ce5664..8fcb3001a 100644 --- a/src/pages/EventImport/form-helper.js +++ b/src/pages/EventImport/form-helper.js @@ -12,22 +12,18 @@ const onImport = format, dataElementIdScheme, orgUnitIdScheme, - eventIdScheme, idScheme, } = values // send xhr - const apiBaseUrl = `${baseUrl}/api/` - const endpoint = 'events.json' + const apiBaseUrl = `${baseUrl}/api/tracker` + const endpoint = '' const params = [ - 'skipFirst=true', `async=${isAsync}`, - `dryRun=${dryRun}`, + `importMode=${dryRun ? 'validate' : 'commit'}`, `dataElementIdScheme=${dataElementIdScheme}`, `orgUnitIdScheme=${orgUnitIdScheme}`, - `eventIdScheme=${eventIdScheme}`, `idScheme=${idScheme}`, - `payloadFormat=${format}`, ].join('&') const url = `${apiBaseUrl}${endpoint}?${params}` @@ -36,11 +32,10 @@ const onImport = url, file: files[0], format: format, - type: 'EVENT_IMPORT', - isAsync: isAsync, + type: 'TRACKER_IMPORT_JOB', + isAsync, setProgress, - addEntry: (id, entry) => - addTask('event', id, { ...entry, jobDetails: values }), + addEntry: (id, entry) => addTask('event', id, { ...entry, jobDetails: values }) }) return jobStartedMessage } catch (e) { diff --git a/src/utils/helper.js b/src/utils/helper.js index 5db84c3f2..0b1590697 100644 --- a/src/utils/helper.js +++ b/src/utils/helper.js @@ -101,7 +101,8 @@ const uploadFile = ({ url, upload: file, type, - onResponse: ({ error, id, msg, typeReports }) => { + onResponse: (response) => { + const { error, id, msg, typeReports } = response let entry if (!isAsync) { // we are done @@ -149,12 +150,14 @@ const uploadFile = ({ created: new Date(), lastUpdated: new Date(), completed: false, - events: [msg], + events: [{ ...msg, date: new Date() }], // this is a workaround for the initial message date coming as invalid + summary: undefined, error: false, importType: type, } } + addEntry(entry.id, entry) if (error) { @@ -169,7 +172,7 @@ const uploadFile = ({ const response = JSON.parse(ev.target.response) message = response.message } catch (e2) { - message = genericErrorMessage + message = ev } console.error('sendFile error', message) reject(errF(message))