Skip to content

Commit

Permalink
feat: show form without selected org unit
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikmv committed Dec 6, 2024
1 parent 587a441 commit 5056f96
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 57 deletions.
19 changes: 5 additions & 14 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-11-11T07:41:42.396Z\n"
"PO-Revision-Date: 2024-11-11T07:41:42.396Z\n"
"POT-Creation-Date: 2024-12-06T11:29:57.874Z\n"
"PO-Revision-Date: 2024-12-06T11:29:57.874Z\n"

msgid "Choose one or more dates..."
msgstr "Choose one or more dates..."
Expand Down Expand Up @@ -745,9 +745,6 @@ msgstr "There was an error opening the Page"
msgid "There was an error loading the page"
msgstr "There was an error loading the page"

msgid "Choose an organisation unit to start reporting"
msgstr "Choose an organisation unit to start reporting"

msgid "Program stage is invalid"
msgstr "Program stage is invalid"

Expand Down Expand Up @@ -804,6 +801,9 @@ msgstr ""
"You don't have access to create a {{trackedEntityName}} in the current "
"selections"

msgid "Choose an organisation unit to start reporting"
msgstr "Choose an organisation unit to start reporting"

msgid "Choose the {{missingCategories}} to start reporting"
msgstr "Choose the {{missingCategories}} to start reporting"

Expand Down Expand Up @@ -1671,15 +1671,6 @@ msgstr "Follow up"
msgid "Choose a program stage to filter by {{label}}"
msgstr "Choose a program stage to filter by {{label}}"

msgid "Active enrollments"
msgstr "Active enrollments"

msgid "Completed enrollments"
msgstr "Completed enrollments"

msgid "Cancelled enrollments"
msgstr "Cancelled enrollments"

msgid ""
"Some enrollments were completed successfully, but there was an error while "
"completing the rest. Please see the details below."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const convertToClientCoordinates = ({ coordinates, type }: { coordinates: any[],

const getCenterPoint = (InnerComponent: ComponentType<any>) => (props: Object) => {
const { orgUnit, ...passOnProps } = props;
const [orgUnitKey, setOrgUnitKey] = useState(orgUnit.id);
const [orgUnitKey, setOrgUnitKey] = useState(orgUnit?.id);
const [shouldFetch, setShouldFetch] = useState(false);
const queryKey = ['organisationUnit', 'geometry', orgUnitKey];
const queryFn = {
Expand All @@ -28,8 +28,8 @@ const getCenterPoint = (InnerComponent: ComponentType<any>) => (props: Object) =
},
};
const queryOptions = useMemo(
() => ({ enabled: Boolean(orgUnit.id) && shouldFetch }),
[shouldFetch, orgUnit.id],
() => ({ enabled: Boolean(orgUnit?.id) && shouldFetch }),
[shouldFetch, orgUnit?.id],
);
const { data } = useApiMetadataQuery<any>(queryKey, queryFn, queryOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import i18n from '@dhis2/d2-i18n';
import { spacersNum } from '@dhis2/ui';
import withStyles from '@material-ui/core/styles/withStyles';
import type { Props } from './EnrollmentAddEventPageDefault.types';
import { IncompleteSelectionsMessage } from '../../../IncompleteSelectionsMessage';
import { EnrollmentPageLayout } from '../../common/EnrollmentOverviewDomain/EnrollmentPageLayout';
import {
EnrollmentPageKeys,
Expand Down Expand Up @@ -65,14 +64,6 @@ const EnrollmentAddEventPagePain = ({
);
}

if (!orgUnitId) {
return (
<IncompleteSelectionsMessage>
{i18n.t('Choose an organisation unit to start reporting')}
</IncompleteSelectionsMessage>
);
}

if (!ready) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { RulesExecutionDependenciesClientFormatted } from '../common.types'
export type ContainerProps = {|
stage: ProgramStage,
formFoundation: RenderFoundation,
orgUnit: OrgUnit,
orgUnit?: OrgUnit,
id: string,
itemId: string,
formRef: (formInstance: any) => void,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ const dataEntryPropsToInclude: DataEntryPropsToInclude = [

export const getOpenDataEntryActions =
(dataEntryId: string, itemId: string, programCategory?: ProgramCategory, orgUnit: Object) => {
const { id, name, path } = orgUnit;
const defaultDataEntryValues = {
orgUnit: { id, name, path },
};
const { id, name, path } = orgUnit || {};
const defaultDataEntryValues = { id, name, path };
if (programCategory && programCategory.categories) {
dataEntryPropsToInclude.push(...programCategory.categories.map(category => ({
id: `attributeCategoryOptions-${category.id}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@ export const OrgUnitFetcher = ({
);
}

if (orgUnit) {
return (
<Validated
{...passOnProps}
orgUnit={orgUnit}
/>
);
}

return null;
return (
<Validated
{...passOnProps}
orgUnit={orgUnit}
/>
);
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

export type Props = {|
orgUnitName: string,
orgUnitName?: string,
stageName: string,
programName: string,
|};
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const ValidatedPlain = ({
cancelButtonIsDisabled={eventSaveInProgress}
id={id}
/>
<SavingText programName={programName} stageName={stage.name} orgUnitName={orgUnit.name} />
<SavingText programName={programName} stageName={stage.name} orgUnitName={orgUnit?.name} />
</div>
)}
</Widget>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ export const Validated = ({
dataEntryId,
itemId,
programId: program.id,
orgUnitId: orgUnit.id,
orgUnitName: orgUnit.name,
teiId,
enrollmentId,
formFoundation,
Expand Down Expand Up @@ -137,15 +135,15 @@ export const Validated = ({
dispatch(startCreateNewAfterCompleting({
enrollmentId,
isCreateNew,
orgUnitId: orgUnit.id,
orgUnitId: orgUnit?.id,
programId: program.id,
teiId,
availableProgramStages,
}));
} catch (error) {
// Related stages has displayed an error message. No need to do anything here.
}
}, [handleSave, formFoundation, dispatch, enrollmentId, orgUnit.id, program.id, teiId, availableProgramStages]);
}, [handleSave, formFoundation, dispatch, enrollmentId, orgUnit?.id, program.id, teiId, availableProgramStages]);


const handleSaveAndCompleteEnrollment = useCallback(
Expand Down Expand Up @@ -177,7 +175,7 @@ export const Validated = ({
stage={stage}
allowGenerateNextVisit={stage.allowGenerateNextVisit}
askCompleteEnrollmentOnEventComplete={stage.askCompleteEnrollmentOnEventComplete}
selectedOrgUnitId={orgUnit.id}
selectedOrgUnitId={orgUnit?.id}
availableProgramStages={availableProgramStages}
eventSaveInProgress={eventSaveInProgress}
ready={ready}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import type { LinkedRequestEvent, RelatedStageRefPayload, RequestEvent } from '.
type Props = {
dataEntryId: string,
itemId: string,
orgUnitId: string,
programId: string,
formFoundation: RenderFoundation,
enrollmentId: string,
orgUnitName: string,
teiId: string,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const useLifecycle = ({
program: TrackerProgram,
stage: ProgramStage,
formFoundation: RenderFoundation,
orgUnit: OrgUnit,
orgUnit?: OrgUnit,
dataEntryId: string,
itemId: string,
rulesExecutionDependenciesClientFormatted: RulesExecutionDependenciesClientFormatted,
Expand All @@ -39,12 +39,12 @@ export const useLifecycle = ({
useEffect(() => {
if (!isLoading) {
dispatch(batchActions([
...getOpenDataEntryActions(dataEntryId, itemId, programCategory, orgUnit),
...getOpenDataEntryActions(dataEntryId, itemId, programCategory),
]));
dataEntryReadyRef.current = true;
delayRulesExecutionRef.current = true;
}
}, [dispatch, dataEntryId, itemId, program, formFoundation, isLoading, programCategory, orgUnit]);
}, [dispatch, dataEntryId, itemId, program, formFoundation, isLoading, programCategory]);

const eventsRef = useRef();
const attributesRef = useRef();
Expand All @@ -55,7 +55,7 @@ export const useLifecycle = ({
// Refactor the helper methods (getCurrentClientValues, getCurrentClientMainData in rules/actionsCreator) to be more explicit with the arguments.
const state = useSelector(stateArg => stateArg);
useEffect(() => {
if (isLoading) { return; }
if (isLoading || !orgUnit) { return; }
if (delayRulesExecutionRef.current) {
// getRulesActions depends on settings in the redux store that are being managed through getOpenDataEntryActions.
// The purpose of the following lines of code is to make sure the redux store is ready before calling getRulesActions.
Expand Down Expand Up @@ -96,9 +96,12 @@ export const useLifecycle = ({
]);

const rulesReady =
(!orgUnit) ||
(
eventsRef.current === eventsRulesDependency &&
attributesRef.current === attributesValuesRulesDependency &&
enrollmentDataRef.current === enrollmentDataRulesDependency;
enrollmentDataRef.current === enrollmentDataRulesDependency
);

return dataEntryReadyRef.current && rulesReady;
};
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type RelatedStageRefPayload = {|

export type ContainerProps = {|
...CommonValidatedProps,
orgUnit: OrgUnit,
orgUnit?: OrgUnit,
|};

export type Props = {|
Expand All @@ -50,7 +50,7 @@ export type Props = {|
eventSaveInProgress: boolean,
stage: ProgramStage,
formFoundation: RenderFoundation,
orgUnit: OrgUnit,
orgUnit?: OrgUnit,
ready: boolean,
id: string,
itemId: string,
Expand Down

0 comments on commit 5056f96

Please sign in to comment.