Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent enrollment date setting with no program in TrackedEntity layer #3477

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions src/components/edit/trackedEntity/PeriodTypeSelect.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import i18n from '@dhis2/d2-i18n'
import PropTypes from 'prop-types'
import React from 'react'
import { connect } from 'react-redux'
import { setPeriodType } from '../../../actions/layerEdit.js'
import { LAST_UPDATED_DATES } from '../../../constants/periods.js'
import { Radio, RadioGroup } from '../../core/index.js'
import styles from './styles/PeriodTypeSelect.module.css'

const PeriodTypeSelect = ({
program,
periodType = 'lastUpdated',
setPeriodType,
periodType = LAST_UPDATED_DATES,
onChange,
}) => {
const label = i18n.t(
'Select period when tracked entities were last updated'
Expand All @@ -19,7 +18,7 @@ const PeriodTypeSelect = ({
<RadioGroup
name="type"
value={periodType}
onChange={(type) => setPeriodType({ value: type })}
onChange={(type) => onChange({ value: type })}
>
<Radio value="lastUpdated" label={label} />
<Radio
Expand All @@ -35,15 +34,9 @@ const PeriodTypeSelect = ({
}

PeriodTypeSelect.propTypes = {
setPeriodType: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired,
periodType: PropTypes.string,
program: PropTypes.object,
}

export default connect(
({ layerEdit }) => ({
program: layerEdit.program,
periodType: layerEdit.periodType,
}),
{ setPeriodType }
)(PeriodTypeSelect)
export default PeriodTypeSelect
27 changes: 24 additions & 3 deletions src/components/edit/trackedEntity/TrackedEntityDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
setFollowUpStatus,
setTrackedEntityRelationshipType,
setTrackedEntityRelationshipOutsideProgram,
setPeriodType,
setStartDate,
setEndDate,
setOrgUnits,
Expand All @@ -31,6 +32,7 @@ import {
MIN_RADIUS,
MAX_RADIUS,
} from '../../../constants/layers.js'
import { LAST_UPDATED_DATES } from '../../../constants/periods.js'
import { getOrgUnitsFromRows } from '../../../util/analytics.js'
import { getDefaultDatesInCalendar } from '../../../util/date.js'
import { getStartEndDateError } from '../../../util/time.js'
Expand Down Expand Up @@ -58,6 +60,7 @@ class TrackedEntityDialog extends Component {
setEventPointRadius: PropTypes.func.isRequired,
setFollowUpStatus: PropTypes.func.isRequired,
setOrgUnits: PropTypes.func.isRequired,
setPeriodType: PropTypes.func.isRequired,
setProgram: PropTypes.func.isRequired,
setProgramStatus: PropTypes.func.isRequired,
setRelatedPointColor: PropTypes.func.isRequired,
Expand All @@ -73,6 +76,7 @@ class TrackedEntityDialog extends Component {
eventPointRadius: PropTypes.number,
followUp: PropTypes.bool,
orgUnits: PropTypes.object,
periodType: PropTypes.string,
periodsSettings: PropTypes.object,
program: PropTypes.object,
programStatus: PropTypes.string,
Expand Down Expand Up @@ -130,8 +134,14 @@ class TrackedEntityDialog extends Component {
}

componentDidUpdate(prev) {
const { validateLayer, onLayerValidation, startDate, endDate } =
this.props
const {
validateLayer,
onLayerValidation,
startDate,
endDate,
program,
setPeriodType,
} = this.props
const { periodError } = this.state

if (validateLayer && validateLayer !== prev.validateLayer) {
Expand All @@ -144,13 +154,18 @@ class TrackedEntityDialog extends Component {
) {
this.setErrorState('periodError', null, 'period')
}

if (!program && prev.program !== program) {
setPeriodType(LAST_UPDATED_DATES)
}
}

render() {
const {
eventPointColor,
eventPointRadius,
followUp,
periodType,
program,
programStatus,
trackedEntityType,
Expand All @@ -163,6 +178,7 @@ class TrackedEntityDialog extends Component {

const {
setTrackedEntityType,
setPeriodType,
setProgram,
setProgramStatus,
setFollowUpStatus,
Expand Down Expand Up @@ -284,7 +300,11 @@ class TrackedEntityDialog extends Component {
))}
{tab === 'period' && (
<div className={styles.flexRowFlow}>
<PeriodTypeSelect />
<PeriodTypeSelect
program={program}
periodType={periodType}
onChange={setPeriodType}
/>
<StartEndDate
onSelectStartDate={setStartDate}
onSelectEndDate={setEndDate}
Expand Down Expand Up @@ -436,6 +456,7 @@ export default connect(
setFollowUpStatus,
setTrackedEntityRelationshipType,
setTrackedEntityRelationshipOutsideProgram,
setPeriodType,
setStartDate,
setEndDate,
setOrgUnits,
Expand Down
1 change: 1 addition & 0 deletions src/constants/periods.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const PREDEFINED_PERIODS = 'PREDEFINED_PERIODS'
export const RELATIVE_PERIODS = 'RELATIVE_PERIODS'
export const FIXED_PERIODS = 'FIXED_PERIODS'
export const START_END_DATES = 'START_END_DATES'
export const LAST_UPDATED_DATES = 'lastUpdated'

export const periodTypes = (includeRelativePeriods) => [
...(includeRelativePeriods
Expand Down
Loading