Skip to content

Commit 2dd4f08

Browse files
committed
feat: replace singleselectfield with newsingleselectfield across multiple components
1 parent 1fb4436 commit 2dd4f08

File tree

14 files changed

+136
-112
lines changed

14 files changed

+136
-112
lines changed

i18n/en.pot

Lines changed: 6 additions & 3 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: 2025-10-23T11:41:11.943Z\n"
9-
"PO-Revision-Date: 2025-10-23T11:41:11.943Z\n"
8+
"POT-Creation-Date: 2025-12-15T16:34:38.508Z\n"
9+
"PO-Revision-Date: 2025-12-15T16:34:38.508Z\n"
1010

1111
msgid "Choose one or more dates..."
1212
msgstr "Choose one or more dates..."
@@ -1128,6 +1128,9 @@ msgstr "Create new event"
11281128
msgid "Search for a {{trackedEntityName}} in {{programName}}"
11291129
msgstr "Search for a {{trackedEntityName}} in {{programName}}"
11301130

1131+
msgid "Select tracked entity type"
1132+
msgstr "Select tracked entity type"
1133+
11311134
msgid "No tracked entity types available"
11321135
msgstr "No tracked entity types available"
11331136

@@ -2138,7 +2141,7 @@ msgid ""
21382141
"The following attribute type is not supported for searching and has been "
21392142
"hidden"
21402143
msgid_plural ""
2141-
"The following attribute types is not supported for searching and has been "
2144+
"The following attribute type is not supported for searching and has been "
21422145
"hidden"
21432146
msgstr[0] ""
21442147
"The following attribute type is not supported for searching and has been "

src/core_modules/capture-core/components/D2Form/field/Components/OptionSetField/OptionSetSelectFieldForCustomForm.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
SingleSelectField,
2+
NewSingleSelectField,
33
withSelectSingleTranslations,
44
withGotoInterface,
55
withHideCompatibility,
@@ -31,7 +31,7 @@ export const OptionSetSelectFieldForCustomForm = withGotoInterface()(
3131
withCustomElementContainer(getContainerClass)(
3232
withOptionsIconElement()(
3333
withRulesOptionVisibilityHandler()(
34-
SingleSelectField,
34+
NewSingleSelectField,
3535
),
3636
),
3737
),

src/core_modules/capture-core/components/D2Form/field/Components/OptionSetField/OptionSetSelectFieldForForm.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
SingleSelectField,
2+
NewSingleSelectField,
33
withSelectSingleTranslations,
44
withGotoInterface,
55
withHideCompatibility,
@@ -41,7 +41,7 @@ export const OptionSetSelectFieldForForm = withGotoInterface()(
4141
withOptionsIconElement()(
4242
withRulesOptionVisibilityHandler()(
4343
withFilterProps(getFilteredProps)(
44-
withSelectSingleTranslations()(SingleSelectField),
44+
withSelectSingleTranslations()(NewSingleSelectField),
4545
),
4646
),
4747
),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
withDefaultFieldContainer,
2525
withDefaultShouldUpdateInterface,
2626
orientations,
27-
SingleSelectField,
27+
NewSingleSelectField,
2828
} from '../../FormFields/New';
2929
import labelTypeClasses from './fieldLabels.module.css';
3030
import {
@@ -289,7 +289,7 @@ const getCategoryOptionsSettingsFn = () => {
289289
})(
290290
withDisplayMessages()(
291291
withInternalChangeHandler()(
292-
withFilterProps(defaultFilterProps)(SingleSelectField),
292+
withFilterProps(defaultFilterProps)(NewSingleSelectField),
293293
),
294294
),
295295
),

src/core_modules/capture-core/components/DataEntries/SingleEventRegistrationEntry/DataEntryWrapper/DataEntry/DataEntry.component.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
withDefaultFieldContainer,
3434
withDefaultShouldUpdateInterface,
3535
orientations,
36-
SingleSelectField,
36+
NewSingleSelectField,
3737
SingleOrgUnitSelectField,
3838
} from '../../../../FormFields/New';
3939
import { Assignee } from './Assignee';
@@ -362,7 +362,7 @@ const buildCategoryOptionsFieldSettingsFn = () => {
362362
})(
363363
withDisplayMessages()(
364364
withInternalChangeHandler()(
365-
withFilterProps(defaultFilterProps)(SingleSelectField),
365+
withFilterProps(defaultFilterProps)(NewSingleSelectField),
366366
),
367367
),
368368
),

src/core_modules/capture-core/components/FormFields/New/Fields/SingleSelectField/SingleSelectField.component.tsx

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect, useRef } from 'react';
22
import { SimpleSingleSelect } from '@dhis2-ui/select';
33
import { withFocusHandler } from './withFocusHandler';
44
import { withSelectSingleTranslations } from './withTranslations';
@@ -23,7 +23,7 @@ type Props = {
2323
dataTest?: string;
2424
};
2525

26-
const SingleSelectFieldComponentPlain = ({
26+
const NewSingleSelectFieldComponentPlain = ({
2727
id,
2828
value,
2929
onChange,
@@ -37,6 +37,7 @@ const SingleSelectFieldComponentPlain = ({
3737
clearable = true,
3838
dataTest,
3939
}: Props) => {
40+
const selectRef = useRef<HTMLDivElement | null>(null);
4041
const fieldName = id ?? 'single-select-field';
4142

4243
const selectedOption = value != null
@@ -65,24 +66,46 @@ const SingleSelectFieldComponentPlain = ({
6566
onBlur?.(null);
6667
};
6768

69+
useEffect(() => {
70+
const element = selectRef.current;
71+
if (!element) {
72+
return undefined;
73+
}
74+
75+
const handleKeyDown = (event: KeyboardEvent) => {
76+
if (event.key === 'Backspace' && value != null) {
77+
onChange?.(null);
78+
onBlur?.(null);
79+
}
80+
};
81+
82+
element.addEventListener('keydown', handleKeyDown);
83+
84+
return () => {
85+
element.removeEventListener('keydown', handleKeyDown);
86+
};
87+
}, [onBlur, onChange, value]);
88+
6889
return (
69-
<SimpleSingleSelect
70-
name={fieldName}
71-
options={options}
72-
// @ts-expect-error - selected is not typed correctly
73-
selected={selectedOption}
74-
placeholder={placeholder}
75-
clearable={clearable}
76-
filterable={filterable}
77-
aria-required={required}
78-
onChange={handleChange}
79-
onBlur={handleBlur}
80-
onFocus={handleFocus}
81-
onClear={handleClear}
82-
dataTest={dataTest}
83-
disabled={disabled}
84-
/>
90+
<div ref={selectRef}>
91+
<SimpleSingleSelect
92+
name={fieldName}
93+
options={options}
94+
// @ts-expect-error - selected is not typed correctly
95+
selected={selectedOption}
96+
placeholder={placeholder}
97+
clearable={clearable}
98+
filterable={filterable}
99+
aria-required={required}
100+
onChange={handleChange}
101+
onBlur={handleBlur}
102+
onFocus={handleFocus}
103+
onClear={handleClear}
104+
dataTest={dataTest}
105+
disabled={disabled}
106+
/>
107+
</div>
85108
);
86109
};
87110

88-
export const SingleSelectField = withFocusHandler()(withSelectSingleTranslations()(SingleSelectFieldComponentPlain));
111+
export const NewSingleSelectField = withFocusHandler()(withSelectSingleTranslations()(NewSingleSelectFieldComponentPlain));

src/core_modules/capture-core/components/FormFields/New/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export { TextField } from './Fields/TextField/TextField.component';
33
export { BooleanField } from './Fields/BooleanField/BooleanField.component';
44
export { AgeField } from './Fields/AgeField/AgeField.component';
55
export { TrueOnlyField } from './Fields/TrueOnlyField/TrueOnlyField.component';
6-
export { SingleSelectField } from './Fields/SingleSelectField/SingleSelectField.component';
6+
export { NewSingleSelectField } from './Fields/SingleSelectField/SingleSelectField.component';
77
export { MultiSelectField } from './Fields/MultiSelectField/MultiSelectField.component';
88
export { withSelectSingleTranslations } from './Fields/SingleSelectField/withTranslations';
99
export { withSelectMultiTranslations } from './Fields/MultiSelectField/withTranslations';

src/core_modules/capture-core/components/Pages/NewRelationship/RegisterTei/RegistrationSection/ProgramSelector/ComposedProgramSelector.component.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ProgramFilterer } from '../../../../../ProgramFilterer';
66
import type { Program } from '../../../../../../metaData';
77
import { TrackerProgram } from '../../../../../../metaData';
88
import {
9-
SingleSelectField,
9+
NewSingleSelectField,
1010
withSelectSingleTranslations,
1111
withFocusSaver,
1212
withDefaultFieldContainer,
@@ -118,7 +118,7 @@ class ProgramSelector extends React.Component<Props> {
118118
{
119119
(programs: Program[], isFiltered: boolean) => (
120120
<div>
121-
<SingleSelectField
121+
<NewSingleSelectField
122122
options={this.getOptionsFromPrograms(programs)}
123123
required={false}
124124
onBlur={onUpdateSelectedProgram}

src/core_modules/capture-core/components/Pages/common/TEIRelationshipsWidget/RegisterTei/RegistrationSection/ProgramSelector/ComposedProgramSelector.component.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { LinkButton } from '../../../../../../Buttons/LinkButton.component';
55
import { ProgramFilterer } from '../../../../../../ProgramFilterer';
66
import { TrackerProgram } from '../../../../../../../metaData';
77
import {
8-
SingleSelectField,
8+
NewSingleSelectField,
99
withSelectSingleTranslations,
1010
withFocusSaver,
1111
withDefaultFieldContainer,
@@ -108,7 +108,7 @@ class ProgramSelector extends React.Component<Props> {
108108
{
109109
(programs: Program[], isFiltered: boolean) => (
110110
<div>
111-
<SingleSelectField
111+
<NewSingleSelectField
112112
options={this.getOptionsFromPrograms(programs)}
113113
required={false}
114114
onBlur={onUpdateSelectedProgram}
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as React from 'react';
22
import i18n from '@dhis2/d2-i18n';
3-
import { SingleSelectField, SingleSelectOption } from '@dhis2/ui';
4-
import { withDefaultFieldContainer, withLabel } from '../../FormFields/New';
3+
import { NewSingleSelectField, withDefaultFieldContainer, withLabel } from '../../FormFields/New';
54
import type { SearchProgramSelectorProps } from './SearchProgramSelector.types';
65

7-
const SearchProgramField = withDefaultFieldContainer()(withLabel()(SingleSelectField));
6+
const SearchProgramField = withDefaultFieldContainer()(withLabel()(NewSingleSelectField));
87

98
const programFieldStyles = {
109
labelContainerStyle: {
@@ -25,20 +24,13 @@ export class SearchProgramSelectorComponent extends React.Component<SearchProgra
2524
return (
2625
<SearchProgramField
2726
styles={programFieldStyles}
28-
selected={selectedProgramId}
29-
onChange={this.onSelectProgram}
27+
value={selectedProgramId}
28+
onChange={value => this.onSelectProgram({ selected: value || '' })}
3029
label={i18n.t('Selected program')}
3130
clearable
3231
filterable
33-
>
34-
{programOptions.map(option => (
35-
<SingleSelectOption
36-
key={option.value}
37-
label={option.label}
38-
value={option.value}
39-
/>
40-
))}
41-
</SearchProgramField>
32+
options={programOptions}
33+
/>
4234
);
4335
}
4436
}

0 commit comments

Comments
 (0)