Skip to content

Commit

Permalink
fix: set proper default values for checkbox inputs
Browse files Browse the repository at this point in the history
fixes inconsistency issues with job recreation
  • Loading branch information
awgaan committed Sep 23, 2020
1 parent c7fd0a2 commit 1a40055
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 28 deletions.
4 changes: 3 additions & 1 deletion src/components/Inputs/FirstRowIsHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { FormField } from '../index'

const { Field } = ReactFinalForm

const defaultFirstRowIsHeaderOption = false

const NAME = 'firstRowIsHeader'
const DATATEST = 'input-first-row-is-header'
const SHORT_LABEL = i18n.t('Is the first row a header row?')
Expand All @@ -30,4 +32,4 @@ FirstRowIsHeader.propTypes = {
show: PropTypes.bool.isRequired,
}

export { FirstRowIsHeader }
export { FirstRowIsHeader, defaultFirstRowIsHeaderOption }
4 changes: 3 additions & 1 deletion src/components/Inputs/IsAsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { FormField } from '../index'

const { Field } = ReactFinalForm

const defaultIsAsyncOption = true

const NAME = 'isAsync'
const DATATEST = 'input-is-async'
const SHORT_LABEL = i18n.t('Async')
Expand All @@ -24,4 +26,4 @@ const IsAsync = () => (
</FormField>
)

export { IsAsync }
export { IsAsync, defaultIsAsyncOption }
4 changes: 3 additions & 1 deletion src/components/Inputs/PreheatCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { FormField } from '../index'

const { Field } = ReactFinalForm

const defaultPreheatCacheOption = false

const NAME = 'preheatCache'
const DATATEST = 'input-preheat-cache'
const SHORT_LABEL = i18n.t('Preheat cache')
Expand All @@ -26,4 +28,4 @@ const PreheatCache = () => (
</FormField>
)

export { PreheatCache }
export { PreheatCache, defaultPreheatCacheOption }
4 changes: 3 additions & 1 deletion src/components/Inputs/SkipAudit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { FormField } from '../index'

const { Field } = ReactFinalForm

const defaultSkipAuditOption = false

const NAME = 'skipAudit'
const DATATEST = 'input-has-authority-to-skip-audit'
const SHORT_LABEL = i18n.t('Skip audit')
Expand All @@ -26,4 +28,4 @@ const SkipAudit = () => (
</FormField>
)

export { SkipAudit }
export { SkipAudit, defaultSkipAuditOption }
4 changes: 3 additions & 1 deletion src/components/Inputs/SkipExistingCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { FormField } from '../index'

const { Field } = ReactFinalForm

const defaultSkipExistingCheckOption = false

const NAME = 'skipExistingCheck'
const DATATEST = 'input-skip-exisiting-check'
const SHORT_LABEL = i18n.t('Skip exisiting check')
Expand All @@ -26,4 +28,4 @@ const SkipExistingCheck = () => (
</FormField>
)

export { SkipExistingCheck }
export { SkipExistingCheck, defaultSkipExistingCheckOption }
4 changes: 3 additions & 1 deletion src/components/Inputs/SkipSharing.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { FormField } from '../index'

const { Field } = ReactFinalForm

const defaultSkipSharingOption = false

const NAME = 'skipSharing'
const DATATEST = 'input-skip-sharing'
const SHORT_LABEL = i18n.t('Skip sharing')
Expand All @@ -26,4 +28,4 @@ const SkipSharing = () => (
</FormField>
)

export { SkipSharing }
export { SkipSharing, defaultSkipSharingOption }
3 changes: 2 additions & 1 deletion src/components/Inputs/SkipValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ReactFinalForm, CheckboxFieldFF } from '@dhis2/ui'
import { FormField } from '../index'

const { Field } = ReactFinalForm
const defaultSkipValidationOption = false

const NAME = 'skipValidation'
const DATATEST = 'input-skip-validation'
Expand All @@ -22,4 +23,4 @@ const SkipValidation = () => (
</FormField>
)

export { SkipValidation }
export { SkipValidation, defaultSkipValidationOption }
20 changes: 13 additions & 7 deletions src/components/Inputs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ export {
formatJsonpOptions,
defaultFormatOption,
} from './Format'
export { FirstRowIsHeader } from './FirstRowIsHeader'
export {
FirstRowIsHeader,
defaultFirstRowIsHeaderOption,
} from './FirstRowIsHeader'
export { ClassKey } from './ClassKey'
export { Strategy, defaultStrategyOption } from './Strategy'
export { PreheatCache } from './PreheatCache'
export { SkipAudit } from './SkipAudit'
export { SkipExistingCheck } from './SkipExistingCheck'
export { PreheatCache, defaultPreheatCacheOption } from './PreheatCache'
export { SkipAudit, defaultSkipAuditOption } from './SkipAudit'
export {
SkipExistingCheck,
defaultSkipExistingCheckOption,
} from './SkipExistingCheck'
export { Identifier, defaultIdentifierOption } from './Identifier'
export {
ImportReportMode,
Expand All @@ -30,9 +36,9 @@ export {
InclusionStrategy,
defaultInclusionStrategyOption,
} from './InclusionStrategy'
export { SkipSharing } from './SkipSharing'
export { SkipValidation } from './SkipValidation'
export { IsAsync } from './IsAsync'
export { SkipSharing, defaultSkipSharingOption } from './SkipSharing'
export { SkipValidation, defaultSkipValidationOption } from './SkipValidation'
export { IsAsync, defaultIsAsyncOption } from './IsAsync'
export { OrgUnitTree } from './OrgUnitTree'
export { DataSetPicker } from './DataSetPicker'
export { ProgramPicker } from './ProgramPicker'
Expand Down
26 changes: 21 additions & 5 deletions src/pages/DataImport/DataImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ import { useConfig } from '@dhis2/app-runtime'
import { ReactFinalForm } from '@dhis2/ui'
import i18n from '@dhis2/d2-i18n'

import { getPrevJobDetails } from '../../utils/helper'
import { getPrevJobDetails, getInitialBoolValue } from '../../utils/helper'
import {
FileUpload,
Format,
formatAdxPdfOptions,
defaultFormatOption,
FirstRowIsHeader,
defaultFirstRowIsHeaderOption,
Strategy,
defaultStrategyOption,
PreheatCache,
defaultPreheatCacheOption,
SkipAudit,
defaultSkipAuditOption,
SkipExistingCheck,
defaultSkipExistingCheckOption,
DataElementIdScheme,
defaultDataElementIdSchemeOption,
IdScheme,
Expand Down Expand Up @@ -50,15 +54,27 @@ const createInitialValues = prevJobDetails => ({
files: prevJobDetails.files,
format: prevJobDetails.format || defaultFormatOption,
strategy: prevJobDetails.strategy || defaultStrategyOption,
firstRowIsHeader: !!prevJobDetails.firstRowIsHeader,
preheatCache: !!prevJobDetails.preheatCache,
skipAudit: !!prevJobDetails.skipAudit,
firstRowIsHeader: getInitialBoolValue(
prevJobDetails.firstRowIsHeader,
defaultFirstRowIsHeaderOption
),
preheatCache: getInitialBoolValue(
prevJobDetails.preheatCache,
defaultPreheatCacheOption
),
skipAudit: getInitialBoolValue(
prevJobDetails.skipAudit,
defaultSkipAuditOption
),
dataElementIdScheme:
prevJobDetails.dataElementIdScheme || defaultDataElementIdSchemeOption,
orgUnitIdScheme:
prevJobDetails.orgUnitIdScheme || defaultOrgUnitIdSchemeOption,
idScheme: prevJobDetails.idScheme || defaultIdSchemeOption,
skipExistingCheck: !!prevJobDetails.skipExistingCheck,
skipExistingCheck: getInitialBoolValue(
prevJobDetails.skipExistingCheck,
defaultSkipExistingCheckOption
),
})

const DataImport = () => {
Expand Down
23 changes: 18 additions & 5 deletions src/pages/MetadataImport/MetadataImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { useConfig } from '@dhis2/app-runtime'
import { ReactFinalForm } from '@dhis2/ui'
import i18n from '@dhis2/d2-i18n'

import { getPrevJobDetails } from '../../utils/helper'
import { getPrevJobDetails, getInitialBoolValue } from '../../utils/helper'
import {
FileUpload,
Format,
formatOptions,
defaultFormatOption,
FirstRowIsHeader,
defaultFirstRowIsHeaderOption,
ClassKey,
Identifier,
defaultIdentifierOption,
Expand All @@ -27,8 +28,11 @@ import {
FlushMode,
defaultFlushModeOption,
SkipSharing,
defaultSkipSharingOption,
SkipValidation,
defaultSkipValidationOption,
IsAsync,
defaultIsAsyncOption,
InclusionStrategy,
defaultInclusionStrategyOption,
ImportButtonStrip,
Expand Down Expand Up @@ -61,15 +65,24 @@ const createInitialValues = prevJobDetails => ({
preheatMode: prevJobDetails.preheatMode || defaultPreheatModeOption,
importStrategy:
prevJobDetails.importStrategy || defaultImportStrategyOption,
firstRowIsHeader: !!prevJobDetails.firstRowIsHeader,
firstRowIsHeader: getInitialBoolValue(
prevJobDetails.firstRowIsHeader,
defaultFirstRowIsHeaderOption
),
atomicMode: prevJobDetails.atomicMode || defaultAtomicModeOption,
mergeMode: prevJobDetails.mergeMode || defaultMergeModeOption,
flushMode: prevJobDetails.flushMode || defaultFlushModeOption,
inclusionStrategy:
prevJobDetails.inclusionStrategy || defaultInclusionStrategyOption,
skipSharing: !!prevJobDetails.skipSharing,
skipValidation: !!prevJobDetails.skipValidation,
isAsync: !prevJobDetails.isAsync,
skipSharing: getInitialBoolValue(
prevJobDetails.skipSharing,
defaultSkipSharingOption
),
skipValidation: getInitialBoolValue(
prevJobDetails.skipValidation,
defaultSkipValidationOption
),
isAsync: getInitialBoolValue(prevJobDetails.isAsync, defaultIsAsyncOption),
})

const MetadataImport = () => {
Expand Down
17 changes: 13 additions & 4 deletions src/pages/TEIImport/TEIImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useConfig } from '@dhis2/app-runtime'
import { ReactFinalForm } from '@dhis2/ui'
import i18n from '@dhis2/d2-i18n'

import { getPrevJobDetails } from '../../utils/helper'
import { getPrevJobDetails, getInitialBoolValue } from '../../utils/helper'
import {
FileUpload,
Format,
Expand All @@ -25,8 +25,11 @@ import {
FlushMode,
defaultFlushModeOption,
SkipSharing,
defaultSkipSharingOption,
SkipValidation,
defaultSkipValidationOption,
IsAsync,
defaultIsAsyncOption,
InclusionStrategy,
defaultInclusionStrategyOption,
ImportButtonStrip,
Expand Down Expand Up @@ -73,9 +76,15 @@ const createInitialValues = prevJobDetails => ({
flushMode: prevJobDetails.flushMode || defaultFlushModeOption,
inclusionStrategy:
prevJobDetails.inclusionStrategy || defaultInclusionStrategyOption,
skipSharing: !!prevJobDetails.skipSharing,
skipValidation: !!prevJobDetails.skipValidation,
isAsync: !prevJobDetails.isAsync,
skipSharing: getInitialBoolValue(
prevJobDetails.skipSharing,
defaultSkipSharingOption
),
skipValidation: getInitialBoolValue(
prevJobDetails.skipValidation,
defaultSkipValidationOption
),
isAsync: getInitialBoolValue(prevJobDetails.isAsync, defaultIsAsyncOption),
dataElementIdScheme:
prevJobDetails.dataElementIdScheme || defaultDataElementIdSchemeOption,
orgUnitIdScheme:
Expand Down
8 changes: 8 additions & 0 deletions src/utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,19 @@ const getPrevJobDetails = (query, tasks) => {
return job.jobDetails
}

const getInitialBoolValue = (prevValue, defaultValue) => {
if (prevValue === null || prevValue === undefined) {
return defaultValue
}
return prevValue
}

export {
createBlob,
downloadBlob,
fetchAttributes,
getPrevJobDetails,
getInitialBoolValue,
locationAssign,
jsDateToISO8601,
jsDateToString,
Expand Down

0 comments on commit 1a40055

Please sign in to comment.