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

feat: [DHIS2-18746] Show org. unit in edit event form in Tracker program #3949

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const TopBar = ({
onResetOrgUnitId={() => resetOrgUnitId()}
isUserInteractionInProgress={isUserInteractionInProgress}
onStartAgain={() => reset()}
isReadOnly={mode === dataEntryKeys.EDIT}
>
<SingleLockedSelect
displayOnly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
withDefaultFieldContainer,
withDefaultShouldUpdateInterface,
VirtualizedSelectField,
SingleOrgUnitSelectField,
} from '../../FormFields/New';
import { statusTypes, translatedStatusTypes } from '../../../events/statusTypes';
import labelTypeClasses from '../DataEntry/dataEntryFieldLabels.module.css';
Expand All @@ -48,6 +49,7 @@ import {
withDataEntryFields,
} from '../../DataEntryDhis2Helpers/';
import type { UserFormField } from '../../FormFields/UserField';
import { getOrgUnitValidatorContainers } from '../DataEntry/fieldValidators';

const tabMode = Object.freeze({
REPORT: 'REPORT',
Expand Down Expand Up @@ -197,6 +199,46 @@ const buildScheduleDateSettingsFn = () => {
return scheduleDateSettings;
};

const buildOrgUnitSettingsFn = () => {
const orgUnitComponent =
withCalculateMessages(overrideMessagePropNames)(
withFocusSaver()(
withDefaultFieldContainer()(
withDefaultShouldUpdateInterface()(
withLabel({
onGetUseVerticalOrientation: (props: Object) => props.formHorizontal,
onGetCustomFieldLabeClass: (props: Object) => `${props.fieldOptions.fieldLabelMediaBasedClass} ${labelTypeClasses.orgUnitLabel}`,
})(
withDisplayMessages()(
withInternalChangeHandler()(
withFilterProps(defaultFilterProps)(SingleOrgUnitSelectField),
),
),
),
),
),
),
);

const orgUnitSettings = {
getComponent: () => orgUnitComponent,
getComponentProps: (props: Object) => createComponentProps(props, {
width: props && props.formHorizontal ? 150 : 350,
label: i18n.t('Organisation unit'),
required: true,
}),
getPropName: () => 'orgUnit',
getValidatorContainers: () => getOrgUnitValidatorContainers(),
getMeta: () => ({
placement: placements.TOP,
section: dataEntrySectionNames.BASICINFO,
}),
};

return orgUnitSettings;
};


const pointComponent = withCalculateMessages(overrideMessagePropNames)(
withFocusSaver()(
withDefaultFieldContainer()(
Expand Down Expand Up @@ -359,7 +401,8 @@ const saveHandlerConfig = {
const AOCFieldBuilderHOC = withAOCFieldBuilder({})(withDataEntryFields(getCategoryOptionsSettingsFn())(DataEntry));
const CleanUpHOC = withCleanUp()(AOCFieldBuilderHOC);
const GeometryField = withDataEntryFieldIfApplicable(buildGeometrySettingsFn())(CleanUpHOC);
const ScheduleDateField = withDataEntryField(buildScheduleDateSettingsFn())(GeometryField);
const OrgUnitField = withDataEntryField(buildOrgUnitSettingsFn())(GeometryField);
const ScheduleDateField = withDataEntryField(buildScheduleDateSettingsFn())(OrgUnitField);
const ReportDateField = withDataEntryField(buildReportDateSettingsFn())(ScheduleDateField);
const SaveableDataEntry = withSaveHandler(saveHandlerConfig)(withMainButton()(ReportDateField));
const CancelableDataEntry = withCancelButton(getCancelOptions)(SaveableDataEntry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React, { type ComponentType, useEffect } from 'react';
import { spacersNum } from '@dhis2/ui';
import withStyles from '@material-ui/core/styles/withStyles';
import { DividerHorizontal as Divider } from 'capture-ui';
import i18n from '@dhis2/d2-i18n';
import { isValidOrgUnit } from 'capture-core-utils/validators/form';
import { DataSection } from '../DataSection';
Expand All @@ -15,11 +16,17 @@ import { CategoryOptions } from './CategoryOptions/CategoryOptions.component';
import { Assignee } from './Assignee';
import { ScheduleOrgUnit } from './ScheduleOrgUnit/ScheduleOrgUnit.component';

const styles = () => ({
const styles = theme => ({
wrapper: {
paddingLeft: spacersNum.dp16,
minWidth: '300px',
},
evenNumbersRecords: {
backgroundColor: theme.palette.grey.lightest,
},
divider: {
backgroundColor: theme.palette.dividerForm,
},
});

const WidgetEventSchedulePlain = ({
Expand Down Expand Up @@ -76,12 +83,6 @@ const WidgetEventSchedulePlain = ({
dataTest="schedule-section"
sectionName={i18n.t('Schedule info')}
>
<ScheduleOrgUnit
orgUnit={orgUnit}
onSelectOrgUnit={onSelectOrgUnit}
onDeselectOrgUnit={onDeselectOrgUnit}
{...passOnProps}
/>
<ScheduleDate
programId={programId}
stageId={stageId}
Expand All @@ -91,6 +92,15 @@ const WidgetEventSchedulePlain = ({
serverSuggestedScheduleDate={serverSuggestedScheduleDate}
{...passOnProps}
/>
<Divider className={classes.divider} />
<div className={classes.evenNumbersRecords}>
<ScheduleOrgUnit
orgUnit={orgUnit}
onSelectOrgUnit={onSelectOrgUnit}
onDeselectOrgUnit={onDeselectOrgUnit}
{...passOnProps}
/>
</div>
</DataSection>
{programCategory && <DataSection
dataTest="category-options-section"
Expand Down
Loading