import { useEffect } from "react"; import { useTranslation } from "react-i18next"; import { Controller, useForm } from "react-hook-form"; import { ActionGroup, Button, Dropdown, DropdownToggle, Form, FormGroup, Select, SelectOption, SelectVariant, } from "@patternfly/react-core"; import type PolicyProviderRepresentation from "@keycloak/keycloak-admin-client/lib/defs/policyProviderRepresentation"; import useToggle from "../../utils/useToggle"; import { KeycloakTextInput } from "../../components/keycloak-text-input/KeycloakTextInput"; import "./search-dropdown.css"; export type SearchForm = { name?: string; resource?: string; scope?: string; type?: string; }; type SearchDropdownProps = { types?: PolicyProviderRepresentation[] | PolicyProviderRepresentation[]; search: SearchForm; onSearch: (form: SearchForm) => void; isResource?: boolean; }; export const SearchDropdown = ({ types, search, onSearch, isResource = false, }: SearchDropdownProps) => { const { t } = useTranslation("clients"); const { register, control, reset, formState: { isDirty }, handleSubmit, } = useForm({ mode: "onChange" }); const [open, toggle] = useToggle(); const [typeOpen, toggleType] = useToggle(); const submit = (form: SearchForm) => { toggle(); onSearch(form); }; useEffect(() => reset(search), [search]); const typeOptions = (value: string) => [ {t("allTypes")} , ...(types || []).map((type) => ( {type.name} )), ]; return ( {t("searchForPermission")} } isOpen={open} >
{isResource && ( <> )} {!isResource && ( )} {!isResource && ( ( )} /> )}
); };