Skip to content

Commit 44e6424

Browse files
authored
refactor: exports components as constants and moves the files around (#1231)
* feat: adds tetselector on the new page * feat: trackedEntityTypeId on url for new and search page * refactor: cleans up the older func * chore: removes debugger * chore: order * fix: one trackedEntityTypeId * chore: one line * feat: adds the enrollment and profile sections * chore: tetype once * chore: better id * chore: reverts * chore: reverts * chore: reverts * chore: linting * chore: styles the forms * chore: rebasing * chore: reverts * chore: reverts ;) * chore: styles the max width * refactor: exports consts and moves the files around * chore: remove line * chore: rebasing * chore: styles * chore: removes dispatch * [part 02] refactors the Enrollment and TEI entries (#1232) * refactor: the registration entries are self initialised and ready to use * chore: rebasing * fix: infinite loading state * chore: lints * chore: reverts * chore: no {} chore: * chore: creates containers * chore: fixes the paths * chore: loading indicator * chore: no need for startDataEntryInitialisationEpic
1 parent 4f01752 commit 44e6424

File tree

57 files changed

+531
-372
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+531
-372
lines changed

i18n/en.pot

+12-12
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ msgstr ""
124124
msgid "A future date is not allowed"
125125
msgstr ""
126126

127+
msgid "Metadata error. see log for details"
128+
msgstr ""
129+
127130
msgid "An error has occurred. See log for details"
128131
msgstr ""
129132

@@ -615,6 +618,15 @@ msgstr ""
615618
msgid "You dont have access to create an event in the current selections"
616619
msgstr ""
617620

621+
msgid "Review duplicates"
622+
msgstr ""
623+
624+
msgid "Create {{trackedEntityTypeName}} and link"
625+
msgstr ""
626+
627+
msgid "Review Duplicates"
628+
msgstr ""
629+
618630
msgid "A duplicate exists (but there were some errors, see log for details"
619631
msgstr ""
620632

@@ -640,15 +652,6 @@ msgstr ""
640652
msgid "Link"
641653
msgstr ""
642654

643-
msgid "Metadata error. see log for details"
644-
msgstr ""
645-
646-
msgid "Review duplicates"
647-
msgstr ""
648-
649-
msgid "Create {{trackedEntityTypeName}} and link"
650-
msgstr ""
651-
652655
msgid "Possible duplicates found"
653656
msgstr ""
654657

@@ -670,9 +673,6 @@ msgstr ""
670673
msgid "Registration"
671674
msgstr ""
672675

673-
msgid "Review Duplicates"
674-
msgstr ""
675-
676676
msgid "Search results"
677677
msgstr ""
678678

src/core_modules/capture-core/components/DataEntries/Enrollment/Enrollment.component.js renamed to src/core_modules/capture-core/components/DataEntries/Enrollment/EnrollmentDataEntry.component.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ class FinalEnrollmentDataEntry extends React.Component<FinalTeiDataEntryProps> {
277277
return (
278278
// $FlowFixMe[cannot-spread-inexact] automated comment
279279
<DataEntry
280-
dataEntrySections={FinalEnrollmentDataEntry.dataEntrySectionDefinitions}
281280
{...passOnProps}
281+
dataEntrySections={FinalEnrollmentDataEntry.dataEntrySectionDefinitions}
282282
formFoundation={enrollmentMetadata.enrollmentForm}
283283
/>
284284
);
@@ -310,7 +310,7 @@ class PreEnrollmentDataEntryPure extends React.PureComponent<Object> {
310310
}
311311
}
312312

313-
class PreEnrollmentDataEntry extends React.Component<PreEnrollmentDataEntryProps> {
313+
export class EnrollmentDataEntryComponent extends React.Component<PreEnrollmentDataEntryProps> {
314314
getValidationContext = () => {
315315
const { orgUnit, onGetUnsavedAttributeValues } = this.props;
316316
return {
@@ -341,7 +341,8 @@ class PreEnrollmentDataEntry extends React.Component<PreEnrollmentDataEntryProps
341341
onUpdateDataEntryField,
342342
onStartAsyncUpdateField,
343343
onGetUnsavedAttributeValues,
344-
...passOnProps } = this.props;
344+
...passOnProps
345+
} = this.props;
345346
return (
346347
// $FlowFixMe[cannot-spread-inexact] automated comment
347348
<PreEnrollmentDataEntryPure
@@ -354,5 +355,3 @@ class PreEnrollmentDataEntry extends React.Component<PreEnrollmentDataEntryProps
354355
);
355356
}
356357
}
357-
358-
export default PreEnrollmentDataEntry;

src/core_modules/capture-core/components/DataEntries/Enrollment/Enrollment.container.js renamed to src/core_modules/capture-core/components/DataEntries/Enrollment/EnrollmentDataEntry.container.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { connect } from 'react-redux';
33
import { updateFieldBatch, asyncUpdateSuccessBatch, updateDataEntryFieldBatch } from './actions/enrollment.actionBatchs';
44
import { startAsyncUpdateFieldForNewEnrollment } from './actions/enrollment.actions';
5-
import Enrollment from './Enrollment.component';
5+
import { EnrollmentDataEntryComponent } from './EnrollmentDataEntry.component';
66

77
const mapStateToProps = () => ({});
88

@@ -46,5 +46,5 @@ const mapDispatchToProps = (dispatch: ReduxDispatch) => ({
4646
});
4747

4848
// $FlowFixMe
49-
export default connect(mapStateToProps, mapDispatchToProps)(Enrollment);
49+
export const EnrollmentDataEntry = connect(mapStateToProps, mapDispatchToProps)(EnrollmentDataEntryComponent);
5050

src/core_modules/capture-core/components/DataEntries/Enrollment/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @flow
2-
export { default as Enrollment } from './Enrollment.container';
2+
export { EnrollmentDataEntry } from './EnrollmentDataEntry.container';
33
export { default as sectionKeys } from './constants/sectionKeys.const';
44
export { actionTypes as openActionTypes } from './actions/open.actions';
55
export {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @flow
2+
import { actionCreator } from '../../../actions/actions.utils';
3+
4+
export const enrollmentRegistrationEntryActionTypes = {
5+
TRACKER_PROGRAM_REGISTRATION_ENTRY_INITIALISATION_START: 'StartInitForEnrollmentRegistrationForm',
6+
};
7+
8+
export const startNewEnrollmentDataEntryInitialisation = ({ selectedOrgUnitId, selectedScopeId, dataEntryId, formFoundation }: Object) =>
9+
actionCreator(enrollmentRegistrationEntryActionTypes.TRACKER_PROGRAM_REGISTRATION_ENTRY_INITIALISATION_START)({ selectedOrgUnitId, selectedScopeId, dataEntryId, formFoundation });
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @flow
2+
import React from 'react';
3+
import { useScopeInfo } from '../../../hooks/useScopeInfo';
4+
import { scopeTypes } from '../../../metaData';
5+
import { EnrollmentDataEntry } from '../Enrollment';
6+
import { useCurrentOrgUnitInfo } from '../../../hooks/useCurrentOrgUnitInfo';
7+
import { useRegistrationFormInfoForSelectedScope } from '../common/useRegistrationFormInfoForSelectedScope';
8+
import type { OwnProps } from './EnrollmentRegistrationEntry.types';
9+
10+
export const EnrollmentRegistrationEntryComponent = ({ selectedScopeId, id, ...rest }: OwnProps) => {
11+
const { scopeType } = useScopeInfo(selectedScopeId);
12+
const { formId, registrationMetaData, formFoundation } = useRegistrationFormInfoForSelectedScope(selectedScopeId);
13+
const orgUnit = useCurrentOrgUnitInfo();
14+
15+
return (
16+
<>
17+
{
18+
scopeType === scopeTypes.TRACKER_PROGRAM && formId &&
19+
<EnrollmentDataEntry
20+
orgUnit={orgUnit}
21+
programId={selectedScopeId}
22+
formFoundation={formFoundation}
23+
enrollmentMetadata={registrationMetaData}
24+
id={id}
25+
{...rest}
26+
/>
27+
}
28+
</>
29+
);
30+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// @flow
2+
import { useDispatch } from 'react-redux';
3+
import React, { useEffect } from 'react';
4+
import type { ComponentType } from 'react';
5+
import { EnrollmentRegistrationEntryComponent } from './EnrollmentRegistrationEntry.component';
6+
import { startNewEnrollmentDataEntryInitialisation } from './EnrollmentRegistrationEntry.actions';
7+
import type { OwnProps } from './EnrollmentRegistrationEntry.types';
8+
import { useScopeInfo } from '../../../hooks/useScopeInfo';
9+
import { useRegistrationFormInfoForSelectedScope } from '../common/useRegistrationFormInfoForSelectedScope';
10+
import { useCurrentOrgUnitInfo } from '../../../hooks/useCurrentOrgUnitInfo';
11+
import { scopeTypes } from '../../../metaData';
12+
13+
const useInitialiseEnrollmentRegistration = (selectedScopeId, dataEntryId) => {
14+
const dispatch = useDispatch();
15+
const { scopeType } = useScopeInfo(selectedScopeId);
16+
const { id: selectedOrgUnitId } = useCurrentOrgUnitInfo();
17+
const { formId, formFoundation } = useRegistrationFormInfoForSelectedScope(selectedScopeId);
18+
const registrationFormReady = !!formId;
19+
useEffect(() => {
20+
if (registrationFormReady && scopeType === scopeTypes.TRACKER_PROGRAM) {
21+
dispatch(
22+
startNewEnrollmentDataEntryInitialisation(
23+
{ selectedOrgUnitId, selectedScopeId, dataEntryId, formFoundation },
24+
),
25+
);
26+
}
27+
}, [
28+
scopeType,
29+
dataEntryId,
30+
selectedScopeId,
31+
selectedOrgUnitId,
32+
registrationFormReady,
33+
formFoundation,
34+
dispatch,
35+
]);
36+
};
37+
38+
39+
export const EnrollmentRegistrationEntry: ComponentType<OwnProps> = ({ selectedScopeId, id, ...rest }) => {
40+
useInitialiseEnrollmentRegistration(selectedScopeId, id);
41+
42+
return (
43+
<EnrollmentRegistrationEntryComponent
44+
selectedScopeId={selectedScopeId}
45+
id={id}
46+
{...rest}
47+
/>);
48+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// @flow
2+
import { ofType } from 'redux-observable';
3+
import { pluck, switchMap } from 'rxjs/operators';
4+
import { empty, from } from 'rxjs';
5+
import { errorCreator } from 'capture-core-utils';
6+
import log from 'loglevel';
7+
import i18n from '@dhis2/d2-i18n';
8+
import { enrollmentRegistrationEntryActionTypes } from './EnrollmentRegistrationEntry.actions';
9+
import { openDataEntryForNewEnrollmentBatchAsync } from '../Enrollment';
10+
import { getTrackerProgramThrowIfNotFound } from '../../../metaData/helpers';
11+
import { openDataEntryFailed } from '../../Pages/NewRelationship/RegisterTei/DataEntry/RegisterTeiDataEntry.actions';
12+
import { type TrackerProgram } from '../../../metaData/Program';
13+
14+
export const startNewEnrollmentDataEntrySelfInitialisationEpic = (action$: InputObservable) =>
15+
action$.pipe(
16+
ofType(enrollmentRegistrationEntryActionTypes.TRACKER_PROGRAM_REGISTRATION_ENTRY_INITIALISATION_START),
17+
pluck('payload'),
18+
switchMap(({ selectedOrgUnitId, selectedScopeId: programId, dataEntryId, formFoundation }) => {
19+
if (selectedOrgUnitId) {
20+
let trackerProgram: ?TrackerProgram;
21+
try {
22+
trackerProgram = getTrackerProgramThrowIfNotFound(programId);
23+
} catch (error) {
24+
log.error(
25+
errorCreator('tracker program for id not found')({ programId, error }),
26+
);
27+
return Promise.resolve(openDataEntryFailed(i18n.t('Metadata error. see log for details')));
28+
}
29+
30+
const openEnrollmentPromise = openDataEntryForNewEnrollmentBatchAsync(
31+
trackerProgram,
32+
formFoundation,
33+
{ id: selectedOrgUnitId },
34+
dataEntryId,
35+
);
36+
37+
return from(openEnrollmentPromise);
38+
}
39+
40+
return empty();
41+
}),
42+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @flow
2+
export type OwnProps = $ReadOnly<{|
3+
selectedScopeId: string,
4+
id: string
5+
|}>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @flow
2+
import { actionCreator } from '../../../actions/actions.utils';
3+
4+
export const teiRegistrationEntryActionTypes = {
5+
TEI_REGISTRATION_ENTRY_INITIALISATION_START: 'StartInitForTrackedEntityTypeRegistrationForm',
6+
};
7+
8+
export const startNewTeiDataEntryInitialisation = ({ selectedOrgUnitId, selectedScopeId, dataEntryId, formFoundation }: Object) =>
9+
actionCreator(teiRegistrationEntryActionTypes.TEI_REGISTRATION_ENTRY_INITIALISATION_START)({ selectedOrgUnitId, selectedScopeId, dataEntryId, formFoundation });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// @flow
2+
import React from 'react';
3+
import { useScopeInfo } from '../../../hooks/useScopeInfo';
4+
import { scopeTypes } from '../../../metaData';
5+
import { TrackedEntityInstanceDataEntry } from '../TrackedEntityInstance';
6+
import { useCurrentOrgUnitInfo } from '../../../hooks/useCurrentOrgUnitInfo';
7+
import type { OwnProps } from './TeiRegistrationEntry.types';
8+
import { useRegistrationFormInfoForSelectedScope } from '../common/useRegistrationFormInfoForSelectedScope';
9+
10+
11+
export const TeiRegistrationEntryComponent = ({ selectedScopeId, id, ...rest }: OwnProps) => {
12+
const { scopeType } = useScopeInfo(selectedScopeId);
13+
const { formId, registrationMetaData, formFoundation } = useRegistrationFormInfoForSelectedScope(selectedScopeId);
14+
const orgUnit = useCurrentOrgUnitInfo();
15+
16+
return (
17+
<>
18+
{
19+
scopeType === scopeTypes.TRACKED_ENTITY_TYPE && formId &&
20+
<TrackedEntityInstanceDataEntry
21+
orgUnit={orgUnit}
22+
formFoundation={formFoundation}
23+
programId={selectedScopeId}
24+
teiRegistrationMetadata={registrationMetaData}
25+
id={id}
26+
{...rest}
27+
/>
28+
}
29+
</>
30+
);
31+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// @flow
2+
import { useDispatch } from 'react-redux';
3+
import React, { useEffect } from 'react';
4+
import type { ComponentType } from 'react';
5+
import { useScopeInfo } from '../../../hooks/useScopeInfo';
6+
import { useRegistrationFormInfoForSelectedScope } from '../common/useRegistrationFormInfoForSelectedScope';
7+
import { useCurrentOrgUnitInfo } from '../../../hooks/useCurrentOrgUnitInfo';
8+
import { scopeTypes } from '../../../metaData';
9+
import { startNewTeiDataEntryInitialisation } from './TeiRegistrationEntry.actions';
10+
import type { OwnProps } from './TeiRegistrationEntry.types';
11+
import { TeiRegistrationEntryComponent } from './TeiRegistrationEntry.component';
12+
13+
const useInitialiseTeiRegistration = (selectedScopeId, dataEntryId) => {
14+
const dispatch = useDispatch();
15+
const { scopeType } = useScopeInfo(selectedScopeId);
16+
const { id: selectedOrgUnitId } = useCurrentOrgUnitInfo();
17+
const { formId, formFoundation } = useRegistrationFormInfoForSelectedScope(selectedScopeId);
18+
const registrationFormReady = !!formId;
19+
useEffect(() => {
20+
if (registrationFormReady && scopeType === scopeTypes.TRACKED_ENTITY_TYPE) {
21+
dispatch(
22+
startNewTeiDataEntryInitialisation(
23+
{ selectedOrgUnitId, selectedScopeId, dataEntryId, formFoundation },
24+
));
25+
}
26+
}, [
27+
scopeType,
28+
dataEntryId,
29+
selectedScopeId,
30+
selectedOrgUnitId,
31+
registrationFormReady,
32+
formFoundation,
33+
dispatch,
34+
]);
35+
};
36+
37+
38+
export const TeiRegistrationEntry: ComponentType<OwnProps> = ({ selectedScopeId, id, ...rest }) => {
39+
useInitialiseTeiRegistration(selectedScopeId, id);
40+
41+
return (
42+
<TeiRegistrationEntryComponent
43+
selectedScopeId={selectedScopeId}
44+
id={id}
45+
{...rest}
46+
/>);
47+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// @flow
2+
import { ofType } from 'redux-observable';
3+
import { pluck, switchMap } from 'rxjs/operators';
4+
import { empty, from } from 'rxjs';
5+
import { errorCreator } from 'capture-core-utils';
6+
import log from 'loglevel';
7+
import i18n from '@dhis2/d2-i18n';
8+
import { teiRegistrationEntryActionTypes } from './TeiRegistrationEntry.actions';
9+
import { openDataEntryForNewTeiBatchAsync } from '../TrackedEntityInstance';
10+
import { getTrackedEntityTypeThrowIfNotFound } from '../../../metaData/helpers';
11+
import { openDataEntryFailed } from '../../Pages/NewRelationship/RegisterTei/DataEntry/RegisterTeiDataEntry.actions';
12+
13+
export const startNewTeiDataEntrySelfInitialisationEpic = (action$: InputObservable) =>
14+
action$.pipe(
15+
ofType(teiRegistrationEntryActionTypes.TEI_REGISTRATION_ENTRY_INITIALISATION_START),
16+
pluck('payload'),
17+
switchMap(({ selectedOrgUnitId, selectedScopeId: TETypeId, dataEntryId, formFoundation }) => {
18+
if (selectedOrgUnitId) {
19+
try {
20+
getTrackedEntityTypeThrowIfNotFound(TETypeId);
21+
} catch (error) {
22+
log.error(errorCreator('TET for id not found')({ TETypeId, error }));
23+
return Promise.resolve(openDataEntryFailed(i18n.t('Metadata error. see log for details')));
24+
}
25+
26+
const openTeiPromise = openDataEntryForNewTeiBatchAsync(
27+
formFoundation,
28+
{ id: selectedOrgUnitId },
29+
dataEntryId,
30+
);
31+
32+
return from(openTeiPromise);
33+
}
34+
35+
return empty();
36+
}),
37+
);
38+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @flow
2+
export type OwnProps = $ReadOnly<{|
3+
selectedScopeId: string,
4+
id: string
5+
|}>

0 commit comments

Comments
 (0)