Skip to content

Commit 44daf16

Browse files
committed
feat: clean up hoc use
1 parent c609900 commit 44daf16

6 files changed

Lines changed: 68 additions & 43 deletions

File tree

i18n/en.pot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ msgstr ""
55
"Content-Type: text/plain; charset=utf-8\n"
66
"Content-Transfer-Encoding: 8bit\n"
77
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
8-
"POT-Creation-Date: 2026-09-09T08:08:19.569Z\n"
9-
"PO-Revision-Date: 2026-09-09T08:08:19.569Z\n"
8+
"POT-Creation-Date: 2026-09-09T08:53:03.161Z\n"
9+
"PO-Revision-Date: 2026-09-09T08:53:03.161Z\n"
1010

1111
msgid "The application could not be loaded."
1212
msgstr "The application could not be loaded."

src/core_modules/capture-core/components/DataEntries/Enrollment/EnrollmentDataEntry.component.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ import {
3939
ProgramStage,
4040
RenderFoundation,
4141
getProgramThrowIfNotFound,
42-
getTermLabel,
4342
LabelKeys,
4443
} from '../../../metaData';
44+
import { withCustomLabels } from '../../../HOC/withCustomLabels';
4545
import { EnrollmentWithFirstStageDataEntry } from './EnrollmentWithFirstStageDataEntry';
4646
import {
4747
getCategoryOptionsValidatorContainers,
@@ -363,6 +363,7 @@ type FinalTeiDataEntryProps = {
363363
};
364364
};
365365
formFoundation: RenderFoundation;
366+
enrollmentLabel: string;
366367
};
367368
// final step before the generic dataEntry is inserted
368369
class FinalEnrollmentDataEntry extends React.Component<FinalTeiDataEntryProps> {
@@ -371,9 +372,11 @@ class FinalEnrollmentDataEntry extends React.Component<FinalTeiDataEntryProps> {
371372
}
372373

373374
render() {
374-
const { enrollmentMetadata, firstStageMetaData, relatedStageActionsOptions, programId, ...passOnProps } = this.props;
375+
const {
376+
enrollmentMetadata, firstStageMetaData, relatedStageActionsOptions, programId,
377+
enrollmentLabel, ...passOnProps
378+
} = this.props;
375379

376-
const { enrollmentLabel } = getTermLabel([LabelKeys.enrollmentSingular], { programId });
377380
const dataEntrySections = {
378381
[sectionKeysForEnrollmentDataEntry.ENROLLMENT]: {
379382
placement: placements.TOP,
@@ -402,10 +405,14 @@ class FinalEnrollmentDataEntry extends React.Component<FinalTeiDataEntryProps> {
402405
}
403406
}
404407

408+
const FinalEnrollmentDataEntryWithLabels = withCustomLabels(
409+
[LabelKeys.enrollmentSingular] as const,
410+
)(FinalEnrollmentDataEntry);
411+
405412
const AOCFieldBuilderHOC = withAOCFieldBuilder(getAOCSettingsFn())(
406413
withDataEntryFields(
407414
getCategoryOptionsSettingsFn(),
408-
)(FinalEnrollmentDataEntry));
415+
)(FinalEnrollmentDataEntryWithLabels));
409416
const LocationHOC = withDataEntryFieldIfApplicable(getGeometrySettings())(AOCFieldBuilderHOC);
410417
const IncidentDateFieldHOC = withDataEntryFieldIfApplicable(getIncidentDateSettings())(LocationHOC);
411418
const EnrollmentDateFieldHOC = withDataEntryField(getEnrollmentDateSettings())(IncidentDateFieldHOC);

src/core_modules/capture-core/components/DataEntries/Enrollment/EnrollmentWithFirstStageDataEntry/EnrollmentWithFirstStageDataEntry.component.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import i18n from '@dhis2/d2-i18n';
22
import { isLangRtl } from '../../../../utils/rtl';
3-
import { getTermLabel, LabelKeys } from '../../../../metaData';
3+
import { LabelKeys } from '../../../../metaData';
4+
import { withCustomLabels } from '../../../../HOC/withCustomLabels';
45
import { DataEntry } from '../../../DataEntry';
56
import { Assignee } from '../../SingleEventRegistrationEntry/DataEntryWrapper/DataEntry/Assignee';
67
import {
@@ -177,15 +178,12 @@ const getCompleteFieldSettingsFn = () => {
177178
const completeSettings = {
178179
isApplicable: (props: any) => props.firstStageMetaData && props.firstStageMetaData.stage?.stageForm,
179180
getComponent: () => completeComponent,
180-
getComponentProps: (props: any) => {
181-
const { eventLabel } = getTermLabel([LabelKeys.eventSingular], { programId: props.programId });
182-
return createComponentProps(props, {
183-
label: i18n.t('Complete {{eventLabel}}', {
184-
eventLabel,
185-
}),
186-
id: 'complete',
187-
});
188-
},
181+
getComponentProps: (props: any) => createComponentProps(props, {
182+
label: i18n.t('Complete {{eventLabel}}', {
183+
eventLabel: props.eventLabel,
184+
}),
185+
id: 'complete',
186+
}),
189187
getPropName: () => stageMainDataIds.COMPLETE,
190188
getValidatorContainers: () => [],
191189
getMeta: () => ({
@@ -272,4 +270,7 @@ const getAssigneeSettingsFn = () => {
272270
const StageLocationHOC = withDataEntryFieldIfApplicable(getStageGeometrySettings())(withCleanUp()(DataEntry));
273271
const CompleteHOC = withDataEntryFieldIfApplicable(getCompleteFieldSettingsFn())(StageLocationHOC);
274272
const AssigneeHOC = withDataEntryFieldIfApplicable(getAssigneeSettingsFn())(CompleteHOC);
275-
export const FirstStageDataEntry = withDataEntryFieldIfApplicable(getReportDateSettingsFn())(AssigneeHOC);
273+
const ReportDateHOC = withDataEntryFieldIfApplicable(getReportDateSettingsFn())(AssigneeHOC);
274+
export const FirstStageDataEntry = withCustomLabels(
275+
[LabelKeys.eventSingular] as const,
276+
)(ReportDateHOC);

src/core_modules/capture-core/components/Pages/ViewEvent/RightColumn/NotesSection/NotesSection.component.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import { ViewEventSection } from '../../Section/ViewEventSection.component';
99
import { ViewEventSectionHeader } from '../../Section/ViewEventSectionHeader.component';
1010
import { Notes } from '../../../../Notes/Notes.component';
1111
import { withLoadingIndicator } from '../../../../../HOC/withLoadingIndicator';
12+
import { withCustomLabels } from '../../../../../HOC/withCustomLabels';
1213
import type { PlainProps } from './NotesSection.types';
13-
import { getTermLabel, LabelKeys } from '../../../../../metaData';
14+
import { LabelKeys } from '../../../../../metaData';
1415

1516
const LoadingNotes = withLoadingIndicator(null, props => ({ style: props.loadingIndicatorStyle }))(Notes);
1617

@@ -32,14 +33,19 @@ const getStyles = (theme: any) => ({
3233
},
3334
});
3435

35-
type Props = PlainProps & WithStyles<typeof getStyles>;
36+
type LabelProps = {
37+
eventLabel: string;
38+
noteLabel: string;
39+
notesLabel: string;
40+
};
41+
42+
type Props = PlainProps & LabelProps & WithStyles<typeof getStyles>;
3643

3744
class NotesSectionPlain extends React.Component<Props> {
3845
renderHeader = () => {
39-
const { classes, notes, ready, programId } = this.props;
46+
const { classes, notes, ready, notesLabel } = this.props;
4047
const count = notes ? notes.length : 0;
4148
const badgeCount = ready ? count : undefined;
42-
const { notesLabel } = getTermLabel([LabelKeys.notePlural], { programId });
4349
return (
4450
<ViewEventSectionHeader
4551
icon={IconMessages24}
@@ -51,12 +57,11 @@ class NotesSectionPlain extends React.Component<Props> {
5157
}
5258

5359
render() {
54-
const { classes, notes, fieldValue, onAddNote, ready, readOnly, programId } = this.props;
60+
const {
61+
classes, notes, fieldValue, onAddNote, ready, readOnly, programId,
62+
eventLabel, notesLabel, noteLabel,
63+
} = this.props;
5564
const isEmpty = ready && (!notes || notes.length === 0);
56-
const { eventLabel, notesLabel, noteLabel } = getTermLabel(
57-
[LabelKeys.eventSingular, LabelKeys.notePlural, LabelKeys.noteSingular],
58-
{ programId },
59-
);
6065
return (
6166
<ViewEventSection
6267
collapsable
@@ -88,4 +93,6 @@ class NotesSectionPlain extends React.Component<Props> {
8893
}
8994
}
9095

91-
export const NotesSectionComponent = withStyles(getStyles)(NotesSectionPlain) as ComponentType<PlainProps>;
96+
export const NotesSectionComponent = withCustomLabels(
97+
[LabelKeys.eventSingular, LabelKeys.notePlural, LabelKeys.noteSingular] as const,
98+
)(withStyles(getStyles)(NotesSectionPlain)) as ComponentType<PlainProps>;

src/core_modules/capture-core/components/Pages/ViewEvent/RightColumn/RelationshipsSection/RelationshipsSection.component.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import { ViewEventSection } from '../../Section/ViewEventSection.component';
99
import { ViewEventSectionHeader } from '../../Section/ViewEventSectionHeader.component';
1010
import { Relationships } from '../../../../Relationships/Relationships.component';
1111
import { withLoadingIndicator } from '../../../../../HOC/withLoadingIndicator';
12+
import { withCustomLabels } from '../../../../../HOC/withCustomLabels';
1213
import { ConnectedEntity } from './ConnectedEntity';
1314
import type { Entity } from '../../../../Relationships/relationships.types';
1415
import type { PlainProps } from './RelationshipsSection.types';
15-
import { getTermLabel, LabelKeys } from '../../../../../metaData';
16+
import { LabelKeys } from '../../../../../metaData';
1617

1718
const LoadingRelationships =
1819
withLoadingIndicator(null, props => ({ style: props.loadingIndicatorStyle }))(Relationships);
@@ -35,7 +36,12 @@ const getStyles = (theme: any) => ({
3536
},
3637
});
3738

38-
type Props = PlainProps & WithStyles<typeof getStyles>;
39+
type LabelProps = {
40+
eventLabel: string;
41+
relationshipsLabel: string;
42+
};
43+
44+
type Props = PlainProps & LabelProps & WithStyles<typeof getStyles>;
3945

4046
class RelationshipsSectionPlain extends React.Component<Props> {
4147
handleOpenAddRelationship = () => {
@@ -47,10 +53,9 @@ class RelationshipsSectionPlain extends React.Component<Props> {
4753
}
4854

4955
renderHeader = () => {
50-
const { classes, relationships, ready, programId } = this.props;
56+
const { classes, relationships, ready, relationshipsLabel } = this.props;
5157
const count = relationships ? relationships.length : 0;
5258
const badgeCount = ready ? count : undefined;
53-
const { relationshipsLabel } = getTermLabel([LabelKeys.relationshipPlural], { programId });
5459
return (
5560
<ViewEventSectionHeader
5661
icon={IconLink24}
@@ -79,18 +84,17 @@ class RelationshipsSectionPlain extends React.Component<Props> {
7984
}
8085

8186
render() {
82-
const { classes, programStage, programId, eventId, relationships, ready, readOnly } = this.props;
87+
const {
88+
classes, programStage, programId, eventId, relationships, ready, readOnly,
89+
eventLabel, relationshipsLabel,
90+
} = this.props;
8391
const relationshipTypes = programStage.relationshipTypes || [];
8492
const hasRelationshipTypes = relationshipTypes.length > 0;
8593

8694
const writableRelationshipTypes =
8795
programStage.relationshipTypesWhereStageIsFrom.filter(rt => rt.access.data.write);
8896

8997
const isEmpty = ready && (!relationships || relationships.length === 0);
90-
const { eventLabel, relationshipsLabel } = getTermLabel(
91-
[LabelKeys.eventSingular, LabelKeys.relationshipPlural],
92-
{ programId },
93-
);
9498

9599
return hasRelationshipTypes && (
96100
<ViewEventSection
@@ -125,4 +129,6 @@ class RelationshipsSectionPlain extends React.Component<Props> {
125129
}
126130
}
127131

128-
export const RelationshipsSectionComponent = withStyles(getStyles)(RelationshipsSectionPlain) as ComponentType<PlainProps>;
132+
export const RelationshipsSectionComponent = withCustomLabels(
133+
[LabelKeys.eventSingular, LabelKeys.relationshipPlural] as const,
134+
)(withStyles(getStyles)(RelationshipsSectionPlain)) as ComponentType<PlainProps>;

src/core_modules/capture-core/components/WidgetEventEdit/DataEntry/withDeleteButton.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ import * as React from 'react';
22
import i18n from '@dhis2/d2-i18n';
33
import { Modal, ModalTitle, ModalContent, ModalActions, ButtonStrip, Button } from '@dhis2/ui';
44
import type { Props, State } from './withDeleteButton.types';
5-
import { getTermLabel, LabelKeys } from '../../../metaData';
5+
import { LabelKeys } from '../../../metaData';
6+
import { withCustomLabels } from '../../../HOC/withCustomLabels';
7+
8+
type InternalProps = Props & { eventLabel: string };
69

710
const getDeleteButton = (InnerComponent: React.ComponentType<any>) =>
8-
class DeleteButtonHOC extends React.Component<Props, State> {
11+
class DeleteButtonHOC extends React.Component<InternalProps, State> {
912
innerInstance: any;
10-
constructor(props: Props) {
13+
constructor(props: InternalProps) {
1114
super(props);
1215
this.state = {
1316
isOpen: false,
@@ -19,7 +22,7 @@ const getDeleteButton = (InnerComponent: React.ComponentType<any>) =>
1922
}
2023

2124
renderDeleteButton = (hasDeleteButton?: boolean) => {
22-
const { eventLabel } = getTermLabel([LabelKeys.eventSingular], { programId: this.props.programId });
25+
const { eventLabel } = this.props;
2326
return (
2427
hasDeleteButton ? (<div>
2528
<Button
@@ -72,7 +75,7 @@ const getDeleteButton = (InnerComponent: React.ComponentType<any>) =>
7275
};
7376

7477
render() {
75-
const { onDelete, hasDeleteButton, ...passOnProps } = this.props;
78+
const { onDelete, hasDeleteButton, eventLabel, ...passOnProps } = this.props;
7679

7780
return (
7881
<InnerComponent
@@ -85,4 +88,5 @@ const getDeleteButton = (InnerComponent: React.ComponentType<any>) =>
8588
};
8689

8790

88-
export const withDeleteButton = () => (InnerComponent: React.ComponentType<any>) => getDeleteButton(InnerComponent);
91+
export const withDeleteButton = () => (InnerComponent: React.ComponentType<any>) =>
92+
withCustomLabels([LabelKeys.eventSingular] as const)(getDeleteButton(InnerComponent));

0 commit comments

Comments
 (0)