diff --git a/src/admin/components/elements/ReactSelect/types.ts b/src/admin/components/elements/ReactSelect/types.ts index 76718fc190..7b7c318e57 100644 --- a/src/admin/components/elements/ReactSelect/types.ts +++ b/src/admin/components/elements/ReactSelect/types.ts @@ -11,7 +11,7 @@ export type Value = { export type Props = { className?: string value?: Value | Value[], - onChange?: (value: Value) => void, + onChange?: (value: any) => void, // eslint-disable-line @typescript-eslint/no-explicit-any disabled?: boolean, showError?: boolean, options: Options diff --git a/src/admin/components/forms/field-types/Select/Input.tsx b/src/admin/components/forms/field-types/Select/Input.tsx index 4ebddb5420..62f1309ca6 100644 --- a/src/admin/components/forms/field-types/Select/Input.tsx +++ b/src/admin/components/forms/field-types/Select/Input.tsx @@ -2,15 +2,15 @@ import React from 'react'; import Label from '../../Label'; import Error from '../../Error'; import FieldDescription from '../../FieldDescription'; -import { SelectField } from '../../../../../fields/config/types'; +import { OptionObject, SelectField } from '../../../../../fields/config/types'; import { Description } from '../../FieldDescription/types'; import ReactSelect from '../../../elements/ReactSelect'; -import { Value as ReactSelectValue, Options as ReactSelectOptions } from '../../../elements/ReactSelect/types'; +import { Value as ReactSelectValue } from '../../../elements/ReactSelect/types'; // import { FieldType } from '../../useField/types'; import './index.scss'; -export type SelectInputProps = Omit & { +export type SelectInputProps = Omit & { showError: boolean errorMessage?: string readOnly?: boolean @@ -22,7 +22,7 @@ export type SelectInputProps = Omit & { style?: React.CSSProperties width?: string hasMany?: boolean - options?: ReactSelectOptions + options?: OptionObject[] } const SelectInput: React.FC = (props) => { @@ -70,7 +70,7 @@ const SelectInput: React.FC = (props) => { /> options.map((option) => { +const formatOptions = (options: Option[]): OptionObject[] => options.map((option) => { if (typeof option === 'object' && option.value) { return option; } return { - label: option as string, + label: option, value: option, - }; + } as OptionObject; }); const Select: React.FC = (props) => { diff --git a/src/admin/components/views/collections/List/Cell/field-types/Select/index.tsx b/src/admin/components/views/collections/List/Cell/field-types/Select/index.tsx index 5c7be34e3d..985d89c839 100644 --- a/src/admin/components/views/collections/List/Cell/field-types/Select/index.tsx +++ b/src/admin/components/views/collections/List/Cell/field-types/Select/index.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { OptionObject, optionsAreObjects, SelectField } from '../../../../../../../../fields/config/types'; -const SelectCell = ({ data, field }: {data: any, field: SelectField}) => { +const SelectCell = ({ data, field }: { data: any, field: SelectField }) => { const findLabel = (items: string[]) => items.map((i) => { const found = (field.options as OptionObject[]) .filter((f: OptionObject) => f.value === i)?.[0]?.label; diff --git a/src/fields/config/types.ts b/src/fields/config/types.ts index 6aeec910eb..ad05aeee5f 100644 --- a/src/fields/config/types.ts +++ b/src/fields/config/types.ts @@ -48,10 +48,13 @@ export type Labels = { export type Validate = (value?: T, options?: any) => string | true | Promise; -export type Option = { +export type OptionObject = { label: string value: string } + +export type Option = OptionObject | string + export interface FieldBase { name: string; label?: string | false;