Skip to content

Commit 692c3c8

Browse files
committed
fix: update SingleSelectField and TrackedEntityTypeSelector for improved type safety
1 parent 9eaa98a commit 692c3c8

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const NewSingleSelectFieldComponentPlain = ({
4242

4343
const selectedOption = value != null
4444
? options.find(option => option.value === value) ?? { value, label: String(value) }
45-
: null;
45+
: undefined;
4646

4747
const handleChange = (nextValue: string | { value: string }) => {
4848
const resolvedValue = typeof nextValue === 'string' ? nextValue : nextValue?.value;
@@ -91,7 +91,6 @@ const NewSingleSelectFieldComponentPlain = ({
9191
<SimpleSingleSelect
9292
name={fieldName}
9393
options={options}
94-
// @ts-expect-error - selected is not typed correctly
9594
selected={selectedOption}
9695
placeholder={placeholder}
9796
clearable={clearable}

src/core_modules/capture-core/components/TrackedEntityTypeSelector/TrackedEntityTypeSelector.component.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { withStyles, type WithStyles } from 'capture-core-utils/styles';
44
import { spacers } from '@dhis2/ui';
55
// @ts-expect-error - SimpleSingleSelectField exists but types may not be available
66
import { SimpleSingleSelectField } from '@dhis2-ui/select';
7-
import type { Props } from './TrackedEntityTypeSelector.types';
7+
import type { Props, SelectOption } from './TrackedEntityTypeSelector.types';
88
import { scopeTypes } from '../../metaData';
99
import { useTrackedEntityTypesWithCorrelatedPrograms, useCurrentTrackedEntityTypeId } from '../../hooks';
1010

@@ -23,7 +23,7 @@ export const TrackedEntityTypeSelectorPlain =
2323
const trackedEntityTypesWithCorrelatedPrograms = useTrackedEntityTypesWithCorrelatedPrograms();
2424
const selectedSearchScopeId = useCurrentTrackedEntityTypeId();
2525

26-
const options = useMemo(() =>
26+
const options: SelectOption[] = useMemo(() =>
2727
Object.values(trackedEntityTypesWithCorrelatedPrograms)
2828
.filter(({ trackedEntityTypeAccess }: any) => {
2929
if (accessNeeded === 'write') {
@@ -48,7 +48,7 @@ export const TrackedEntityTypeSelectorPlain =
4848
return options.find(opt => opt.value === selectedSearchScopeId);
4949
}, [selectedSearchScopeId, options]);
5050

51-
const handleSelectionChange = (option: { value: string; label: string }) => {
51+
const handleSelectionChange = (option: SelectOption) => {
5252
onSelect(option.value, scopeTypes.TRACKED_ENTITY_TYPE as keyof typeof scopeTypes);
5353
onSetTrackedEntityTypeIdOnUrl({ trackedEntityTypeId: option.value });
5454
};

src/core_modules/capture-core/components/TrackedEntityTypeSelector/TrackedEntityTypeSelector.types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type { scopeTypes } from '../../metaData';
22

3+
export type SelectOption = {
4+
label: string;
5+
value: string;
6+
};
7+
38
export type OwnProps = {
49
accessNeeded?: 'write' | 'read';
510
onSelect: (searchScopeId: string, searchScopeType: keyof typeof scopeTypes) => void;

0 commit comments

Comments
 (0)