Skip to content

Commit bd6655f

Browse files
committed
chore: select values should be arrays Ref: LINK-1759
1 parent 4bc10f5 commit bd6655f

15 files changed

Lines changed: 74 additions & 70 deletions

File tree

src/common/components/eventSelector/EventSelector.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import { Language, OptionType } from '../../../types';
1717
import getPathBuilder from '../../../utils/getPathBuilder';
1818
import getValue from '../../../utils/getValue';
1919
import parseIdFromAtId from '../../../utils/parseIdFromAtId';
20-
import Select, { SingleSelectPropsWithValue } from '../select/Select';
20+
import Select, { SelectPropsWithValue } from '../select/Select';
2121

2222
export type EventSelectorProps = {
2323
getOption: (event: EventFieldsFragment, locale: Language) => OptionType;
2424
variables: EventsQueryVariables;
25-
} & SingleSelectPropsWithValue<string | null>;
25+
} & SelectPropsWithValue<string | null>;
2626

2727
const EventSelector: React.FC<EventSelectorProps> = ({
2828
getOption,
@@ -119,7 +119,7 @@ const EventSelector: React.FC<EventSelectorProps> = ({
119119
);
120120

121121
const selectedEvent = React.useMemo(
122-
() => (eventData?.event ? getOption(eventData.event, locale) : null),
122+
() => (eventData?.event ? [getOption(eventData.event, locale)] : []),
123123
[eventData?.event, getOption, locale]
124124
);
125125

@@ -136,7 +136,7 @@ const EventSelector: React.FC<EventSelectorProps> = ({
136136
clearButtonAriaLabel_one: t('common.combobox.clearEvents'),
137137
}}
138138
options={options}
139-
value={selectedEvent?.value}
139+
value={selectedEvent}
140140
/>
141141
);
142142
};

src/common/components/formFields/placeSelectorField/PlaceSelectorField.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { FieldProps } from 'formik';
22
import React from 'react';
33

44
import PlaceSelector from '../../placeSelector/PlaceSelector';
5-
import { SingleSelectPropsWithValue } from '../../select/Select';
5+
import { SelectPropsWithValue } from '../../select/Select';
66
import useSingleSelectFieldProps from '../hooks/useSingleSelectFieldProps';
77

8-
type Props = SingleSelectPropsWithValue<string | null> & FieldProps;
8+
type Props = SelectPropsWithValue<string | null> & FieldProps;
99

1010
const PlaceSelectorField: React.FC<Props> = ({
1111
field: { name, onBlur, onChange, value, ...field },

src/common/components/formFields/publisherSelectorField/PublisherSelectorField.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { FieldProps } from 'formik';
22
import React from 'react';
33

44
import PublisherSelector from '../../publisherSelector/PublisherSelector';
5-
import { SingleSelectPropsWithValue } from '../../select/Select';
5+
import { SelectPropsWithValue } from '../../select/Select';
66
import useSingleSelectFieldProps from '../hooks/useSingleSelectFieldProps';
77

8-
type Props = SingleSelectPropsWithValue<string | null> & FieldProps<string>;
8+
type Props = SelectPropsWithValue<string | null> & FieldProps<string>;
99

1010
const PublisherSelectorField: React.FC<Props> = ({
1111
field: { name, onBlur, onChange, value, ...field },

src/common/components/formFields/registrationEventSelectorField/RegistrationEventSelectorField.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import {
1616
import { Language, OptionType } from '../../../../types';
1717
import skipFalsyType from '../../../../utils/skipFalsyType';
1818
import EventSelector from '../../eventSelector/EventSelector';
19-
import { SingleSelectPropsWithValue } from '../../select/Select';
19+
import { SelectPropsWithValue } from '../../select/Select';
2020
import useSingleSelectFieldProps from '../hooks/useSingleSelectFieldProps';
2121

2222
type Props = {
2323
onChangeCb?: (val: string | null) => void;
2424
variables: EventsQueryVariables;
25-
} & SingleSelectPropsWithValue<string | null> &
25+
} & SelectPropsWithValue<string | null> &
2626
FieldProps<string>;
2727

2828
const RegistrationEventSelectorField: React.FC<Props> = ({

src/common/components/formFields/singleKeywordSelectorField/SingleKeywordSelectorField.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { FieldProps } from 'formik';
22
import React from 'react';
33

4-
import { SingleSelectPropsWithValue } from '../../select/Select';
4+
import { SelectPropsWithValue } from '../../select/Select';
55
import SingleKeywordSelector from '../../singleKeywordSelector/SingleKeywordSelector';
66
import useSingleSelectFieldProps from '../hooks/useSingleSelectFieldProps';
77

8-
type Props = SingleSelectPropsWithValue<string> & FieldProps<string>;
8+
type Props = SelectPropsWithValue<string> & FieldProps<string>;
99

1010
const SingleKeywordSelectorField: React.FC<Props> = ({
1111
field: { name, onBlur, onChange, value, ...field },

src/common/components/formFields/singleOrganizationClassSelectorField/SingleOrganizationClassSelectorField.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { FieldProps } from 'formik';
22
import React from 'react';
33

4-
import { SingleSelectPropsWithValue } from '../../select/Select';
4+
import { SelectPropsWithValue } from '../../select/Select';
55
import SingleOrganizationClassSelector from '../../singleOrganizationClassSelector/SingleOrganizationClassSelector';
66
import useSingleSelectFieldProps from '../hooks/useSingleSelectFieldProps';
77

8-
type Props = SingleSelectPropsWithValue<string | null> & FieldProps<string>;
8+
type Props = SelectPropsWithValue<string | null> & FieldProps<string>;
99

1010
const SingleOrganizationClassSelectorField: React.FC<Props> = ({
1111
field: { name, onBlur, onChange, value, ...field },

src/common/components/formFields/singleOrganizationSelectorField/SingleOrganizationSelectorField.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { FieldProps } from 'formik';
22
import React from 'react';
33

4-
import { SingleSelectPropsWithValue } from '../../select/Select';
4+
import { SelectPropsWithValue } from '../../select/Select';
55
import SingleOrganizationSelector from '../../singleOrganizationSelector/SingleOrganizationSelector';
66
import useSingleSelectFieldProps from '../hooks/useSingleSelectFieldProps';
77

8-
type Props = SingleSelectPropsWithValue<string | null> & FieldProps;
8+
type Props = SelectPropsWithValue<string | null> & FieldProps;
99

1010
const SingleOrganizationSelectorField: React.FC<Props> = ({
1111
field: { name, onBlur, onChange, value, ...field },

src/common/components/formFields/singleSelectField/SingleSelectField.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FieldProps } from 'formik';
2-
import React from 'react';
2+
import React, { useMemo } from 'react';
33
import { useTranslation } from 'react-i18next';
44

55
import { OptionType } from '../../../../types';
@@ -28,10 +28,14 @@ const SingleSelectField: React.FC<Props> = ({
2828
value,
2929
});
3030

31-
const selected = options?.find(
32-
(option): option is OptionType =>
33-
typeof option !== 'string' && option.value === value
34-
);
31+
const selected = useMemo(() => {
32+
const option = options?.find(
33+
(option): option is OptionType =>
34+
typeof option !== 'string' && option.value === value
35+
);
36+
37+
return option ? [option] : [];
38+
}, [options, value]);
3539

3640
return (
3741
<SingleSelect
@@ -42,7 +46,7 @@ const SingleSelectField: React.FC<Props> = ({
4246
onBlur={handleBlur}
4347
onChange={handleChange}
4448
options={options}
45-
value={selected?.value}
49+
value={selected}
4650
texts={{
4751
...texts,
4852
error: errorText,

src/common/components/formFields/umbrellaEventSelectorField/UmbrellaEventSelectorField.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { EVENT_SORT_OPTIONS } from '../../../../domain/events/constants';
66
import { EventFieldsFragment } from '../../../../generated/graphql';
77
import { Language, OptionType } from '../../../../types';
88
import EventSelector from '../../eventSelector/EventSelector';
9-
import { SingleSelectPropsWithValue } from '../../select/Select';
9+
import { SelectPropsWithValue } from '../../select/Select';
1010
import useSingleSelectFieldProps from '../hooks/useSingleSelectFieldProps';
1111

12-
type Props = SingleSelectPropsWithValue<string | null> & FieldProps<string>;
12+
type Props = SelectPropsWithValue<string | null> & FieldProps<string>;
1313

1414
const getEventOption = (
1515
event: EventFieldsFragment,

src/common/components/placeSelector/PlaceSelector.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import getPathBuilder from '../../../utils/getPathBuilder';
2121
import getValue from '../../../utils/getValue';
2222
import parseIdFromAtId from '../../../utils/parseIdFromAtId';
2323
import skipFalsyType from '../../../utils/skipFalsyType';
24-
import Select, { SingleSelectPropsWithValue } from '../select/Select';
24+
import Select, { SelectPropsWithValue } from '../select/Select';
2525
import styles from './placeSelector.module.scss';
2626

2727
export type GetOptionArgs = {
@@ -57,7 +57,7 @@ export const getOption = ({
5757
};
5858
};
5959

60-
export type PlaceSelectorProps = SingleSelectPropsWithValue<string | null>;
60+
export type PlaceSelectorProps = SelectPropsWithValue<string | null>;
6161

6262
const PlaceSelector: React.FC<PlaceSelectorProps> = ({
6363
texts,
@@ -154,13 +154,15 @@ const PlaceSelector: React.FC<PlaceSelectorProps> = ({
154154
const selectedPlace = React.useMemo(
155155
() =>
156156
placeData?.place
157-
? getOption({
158-
locale,
159-
place: placeData.place,
160-
showEventAmount: false,
161-
t,
162-
})
163-
: null,
157+
? [
158+
getOption({
159+
locale,
160+
place: placeData.place,
161+
showEventAmount: false,
162+
t,
163+
}),
164+
]
165+
: [],
164166
[locale, placeData, t]
165167
);
166168

@@ -179,7 +181,7 @@ const PlaceSelector: React.FC<PlaceSelectorProps> = ({
179181
...texts,
180182
clearButtonAriaLabel_one: t('common.combobox.clearPlaces'),
181183
}}
182-
value={selectedPlace?.label}
184+
value={selectedPlace}
183185
/>
184186
);
185187
};

0 commit comments

Comments
 (0)