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

View file

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

View file

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