mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-09-26 04:38:58 +03:00
* backend * frontend * docs * fix none default role casing and name reserved roles in the error * reserve every casing of none as a role name
60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
import { useMemo } from "react";
|
|
import type { WidgetProps } from "@rjsf/utils";
|
|
import { useTranslation } from "react-i18next";
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from "@/components/ui/select";
|
|
import type { ConfigFormContext } from "@/types/configForm";
|
|
import { getSizedFieldClassName } from "../utils";
|
|
|
|
const BUILT_IN_ROLES = ["admin", "viewer"];
|
|
const NONE_ROLE = "none";
|
|
|
|
export function DefaultRoleWidget(props: WidgetProps) {
|
|
const { id, value, disabled, readonly, onChange, schema, options, registry } =
|
|
props;
|
|
const { t } = useTranslation(["views/settings"]);
|
|
|
|
const fieldClassName = getSizedFieldClassName(options, "sm");
|
|
|
|
const formContext = registry?.formContext as ConfigFormContext | undefined;
|
|
const roles = useMemo<string[]>(() => {
|
|
const configured = Object.keys(formContext?.fullConfig?.auth?.roles ?? {});
|
|
// Keep admin/viewer first, then any custom roles in config order.
|
|
const custom = configured.filter((r) => !BUILT_IN_ROLES.includes(r));
|
|
return [...BUILT_IN_ROLES, ...custom, NONE_ROLE];
|
|
}, [formContext]);
|
|
|
|
const selectedValue = typeof value === "string" && value ? value : "viewer";
|
|
|
|
const getLabel = (role: string) =>
|
|
BUILT_IN_ROLES.includes(role) || role === NONE_ROLE
|
|
? t(`configForm.defaultRole.${role}`)
|
|
: role;
|
|
|
|
return (
|
|
<Select
|
|
value={selectedValue}
|
|
onValueChange={onChange}
|
|
disabled={disabled || readonly}
|
|
>
|
|
<SelectTrigger id={id} className={fieldClassName}>
|
|
<SelectValue placeholder={schema.title} />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
{roles.map((role) => (
|
|
<SelectItem key={role} value={role}>
|
|
{getLabel(role)}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
);
|
|
}
|
|
|
|
export default DefaultRoleWidget;
|