/* eslint-disable */ // @ts-nocheck import { useTranslation } from "react-i18next"; import { FormGroup, Radio } from "../../../shared/@patternfly/react-core"; import { HelpItem } from "../../../shared/keycloak-ui-shared"; import { useFormContext } from "react-hook-form"; import { useState, type JSX } from "react"; import { GroupSelect } from "./GroupSelect"; import { UserSelect } from "../../components/users/UserSelect"; import { RoleSelect } from "./RoleSelect"; import { ClientSelectComponent } from "./ClientSelectComponent"; type ResourceTypeProps = { withEnforceAccessTo?: boolean; resourceType: string; }; export const COMPONENTS: { [index: string]: (props: any) => JSX.Element; } = { users: UserSelect, clients: ClientSelectComponent, groups: GroupSelect, roles: RoleSelect, } as const; export const isValidComponentType = (value: string) => value in COMPONENTS; export const ResourceType = ({ resourceType, withEnforceAccessTo = true, }: ResourceTypeProps) => { const { t } = useTranslation(); const form = useFormContext(); const resourceIds: string[] = form.getValues("resources"); const normalizedResourceType = resourceType.toLowerCase(); const [isSpecificResources, setIsSpecificResources] = useState( // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- resourceIds is undefined when form field "resources" has no default value resourceIds?.some((id) => id !== resourceType) || !withEnforceAccessTo, ); function getComponentType() { if (isValidComponentType(normalizedResourceType)) { return COMPONENTS[normalizedResourceType]; } return null; } const ComponentType = getComponentType(); return ( <> {withEnforceAccessTo && ( } fieldId="EnforceAccessTo" hasNoPaddingTop isRequired > { setIsSpecificResources(false); form.setValue("resources", []); }} className="pf-v5-u-mb-md" /> { setIsSpecificResources(true); form.setValue("resources", []); }} className="pf-v5-u-mb-md" /> )} {isSpecificResources && ComponentType && ( )} ); };