import type PolicyProviderRepresentation from "@keycloak/keycloak-admin-client/lib/defs/policyProviderRepresentation"; import { ActionGroup, Button, Dropdown, DropdownToggle, Form, FormGroup, Select, SelectOption, SelectVariant, } from "@patternfly/react-core"; import { useEffect } from "react"; import { Controller, useForm } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { KeycloakTextInput } from "../../components/keycloak-text-input/KeycloakTextInput"; import useToggle from "../../utils/useToggle"; import "./search-dropdown.css"; export type SearchForm = { name?: string; resource?: string; scope?: string; type?: string; uri?: string; owner?: 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 && ( ( )} /> )}
); };