Skip to content

Commit

Permalink
feat: move TEI import to new tracker endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
kabaros committed Feb 23, 2024
1 parent 32c401b commit 01d94e7
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/components/Inputs/AtomicMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion src/components/Inputs/TEITypeFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') },
]
Expand Down
2 changes: 1 addition & 1 deletion src/components/JobSummary/SingleSummary/SingleSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const SingleSummary = ({
</Table>
</>
</FormField>
{validationReport?.errorReports && (
{!!validationReport?.errorReports?.length && (
<FormField
label={`${i18n.t('Reports')}`}
dataTest="tracker-summary-reports"
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const defaultRefetchPeriod = 2000
const createFetchEvents =
(engine, setTasks, fetchSummary) => (type, id, task) => {
const fetchEvents = async () => {
console.debug('[fetch event]', type, id, task)
if (task.completed) {
return
}
Expand Down
1 change: 1 addition & 0 deletions src/pages/EventExport/EventExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const initialValues = {
orgUnitIdScheme: defaultOrgUnitIdSchemeOption,
idScheme: defaultIdSchemeOption,
inclusion: defaultInclusionOption,
skipPaging: true
}

const EventExport = () => {
Expand Down
3 changes: 1 addition & 2 deletions src/pages/EventImport/form-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ const onImport =

// send xhr
const apiBaseUrl = `${baseUrl}/api/tracker`
const endpoint = ''
const params = [
`async=${isAsync}`,
`importMode=${dryRun ? 'validate' : 'commit'}`,
`dataElementIdScheme=${dataElementIdScheme}`,
`orgUnitIdScheme=${orgUnitIdScheme}`,
`idScheme=${idScheme}`,
].join('&')
const url = `${apiBaseUrl}${endpoint}?${params}`
const url = `${apiBaseUrl}?${params}`

try {
await uploadFile({
Expand Down
1 change: 1 addition & 0 deletions src/pages/TEIExport/form-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const valuesToParams = (
orgUnitIdScheme: orgUnitIdScheme,
idScheme: idScheme,
attachment: filename,
skipPaging: true
}

// include selected org.units only when manual selection is selected
Expand Down
4 changes: 1 addition & 3 deletions src/pages/TEIImport/TEIImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 8 additions & 7 deletions src/pages/TEIImport/form-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 01d94e7

Please sign in to comment.