mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-05 22:57:40 +03:00
add optional i18n prefix for select widgets
This commit is contained in:
parent
e7609afb54
commit
5f61c54efd
@ -1,5 +1,6 @@
|
||||
// Select Widget - maps to shadcn/ui Select
|
||||
import type { WidgetProps } from "@rjsf/utils";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
@ -21,9 +22,18 @@ export function SelectWidget(props: WidgetProps) {
|
||||
schema,
|
||||
} = props;
|
||||
|
||||
const { t } = useTranslation(["views/settings"]);
|
||||
const { enumOptions = [] } = options;
|
||||
const enumI18nPrefix = options["enumI18nPrefix"] as string | undefined;
|
||||
const fieldClassName = getSizedFieldClassName(options, "sm");
|
||||
|
||||
const getLabel = (option: { value: unknown; label: string }) => {
|
||||
if (enumI18nPrefix) {
|
||||
return t(`${enumI18nPrefix}.${option.value}`);
|
||||
}
|
||||
return option.label;
|
||||
};
|
||||
|
||||
return (
|
||||
<Select
|
||||
value={value?.toString() ?? ""}
|
||||
@ -42,7 +52,7 @@ export function SelectWidget(props: WidgetProps) {
|
||||
<SelectContent>
|
||||
{enumOptions.map((option: { value: unknown; label: string }) => (
|
||||
<SelectItem key={String(option.value)} value={String(option.value)}>
|
||||
{option.label}
|
||||
{getLabel(option)}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user