/* eslint-disable */ // @ts-nocheck import PolicyRepresentation from "@keycloak/keycloak-admin-client/lib/defs/policyRepresentation"; import UserRepresentation from "@keycloak/keycloak-admin-client/lib/defs/userRepresentation"; import { SelectControl, TextControl } from "../../../shared/keycloak-ui-shared"; import { ActionGroup, Button, Dropdown, Form, MenuToggle, } from "../../../shared/@patternfly/react-core"; import { useEffect, useRef, useState } from "react"; import { FormProvider, useForm, useWatch } from "react-hook-form"; import { useTranslation } from "react-i18next"; import useToggle from "../../utils/useToggle"; import { ResourceType } from "./ResourceType"; export type SearchForm = { name?: string; resources?: string; scope?: string; type?: string; uri?: string; owner?: string; resourceType?: string; }; type SearchDropdownProps = { resources?: UserRepresentation[]; types: PolicyRepresentation[]; search: SearchForm; onSearch: (form: SearchForm) => void; resourceType?: string; }; export const SearchDropdown = ({ types, search, onSearch, }: SearchDropdownProps) => { const { t } = useTranslation(); const form = useForm({ mode: "onChange", defaultValues: search, }); const { reset, formState: { isDirty }, handleSubmit, } = form; const [open, toggle] = useToggle(); const [resourceScopes, setResourceScopes] = useState([]); const selectedType = useWatch({ control: form.control, name: "resourceType", defaultValue: "", }); const [key, setKey] = useState(0); const ref = useRef("clients"); const submit = (form: SearchForm) => { toggle(); onSearch(form); }; useEffect(() => { const type = types.find((item) => item.type === selectedType); setResourceScopes(type?.scopes || []); }, [selectedType, types]); useEffect(() => { reset(search); setKey((prevKey) => prevKey + 1); }, [search]); return ( ( {t("searchClientAuthorizationPermission")} )} isOpen={open} >
({ key: type!, value: name! || type!, })), ]} onSelect={(value, onChange) => { if (ref.current !== value) { ref.current = value as string; form.setValue("resources", undefined); } onChange(value); }} /> {selectedType !== "" && ( <> ({ key: resourceScope!, value: resourceScope!, })), ]} /> )}
); };