renamed to SelectControlOption

This commit is contained in:
Erik Jan de Wit 2023-07-06 09:33:28 +02:00 committed by Pedro Igor
parent ac135dbfdc
commit a230a4588a
3 changed files with 9 additions and 8 deletions

View file

@ -1,6 +1,6 @@
import { useState } from "react"; import { useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import type { SelectOption } from "ui-shared"; import type { SelectControlOption } from "ui-shared";
import { SelectControl } from "ui-shared"; import { SelectControl } from "ui-shared";
import { getSupportedLocales } from "../api/methods"; import { getSupportedLocales } from "../api/methods";
import { usePromise } from "../utils/usePromise"; import { usePromise } from "../utils/usePromise";
@ -15,13 +15,13 @@ const localeToDisplayName = (locale: string) => {
export const LocaleSelector = () => { export const LocaleSelector = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const [locales, setLocales] = useState<SelectOption[]>([]); const [locales, setLocales] = useState<SelectControlOption[]>([]);
usePromise( usePromise(
(signal) => getSupportedLocales({ signal }), (signal) => getSupportedLocales({ signal }),
(locales) => (locales) =>
setLocales( setLocales(
locales.map<Option>((locale) => ({ locales.map<SelectControlOption>((locale) => ({
key: locale, key: locale,
value: localeToDisplayName(locale) || "", value: localeToDisplayName(locale) || "",
})) }))

View file

@ -15,7 +15,7 @@ import {
} from "@patternfly/react-core"; } from "@patternfly/react-core";
import { FormLabel } from "./FormLabel"; import { FormLabel } from "./FormLabel";
export type SelectOption = { export type SelectControlOption = {
key: string; key: string;
value: string; value: string;
}; };
@ -30,7 +30,7 @@ export type SelectControlProps<
UseControllerProps<T, P> & { UseControllerProps<T, P> & {
name: string; name: string;
label?: string; label?: string;
options: string[] | Option[]; options: string[] | SelectControlOption[];
controller: Omit<ControllerProps, "name" | "render">; controller: Omit<ControllerProps, "name" | "render">;
}; };
@ -68,8 +68,9 @@ export const SelectControl = <
onToggle={(isOpen) => setOpen(isOpen)} onToggle={(isOpen) => setOpen(isOpen)}
selections={ selections={
typeof options[0] !== "string" typeof options[0] !== "string"
? (options as Option[]).find((o) => o.key === value[0]) ? (options as SelectControlOption[]).find(
?.value || value (o) => o.key === value[0]
)?.value || value
: value : value
} }
onSelect={(_, v) => { onSelect={(_, v) => {

View file

@ -1,6 +1,6 @@
export { ContinueCancelModal } from "./continue-cancel/ContinueCancelModal"; export { ContinueCancelModal } from "./continue-cancel/ContinueCancelModal";
export { SelectControl } from "./controls/SelectControl"; export { SelectControl } from "./controls/SelectControl";
export type { Option } from "./controls/SelectControl"; export type { SelectControlOption } from "./controls/SelectControl";
export { SwitchControl } from "./controls/SwitchControl"; export { SwitchControl } from "./controls/SwitchControl";
export { TextControl } from "./controls/TextControl"; export { TextControl } from "./controls/TextControl";
export { TextAreaControl } from "./controls/TextAreaControl"; export { TextAreaControl } from "./controls/TextAreaControl";