UNPKG

@keycloakify/keycloak-admin-ui

Version:
29 lines 2.75 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { SelectControl, TextControl } from "../../ui-shared"; import { ActionGroup, Button, Dropdown, Form, MenuToggle, } from "@patternfly/react-core"; import { useEffect } from "react"; import { FormProvider, useForm } from "react-hook-form"; import { useTranslation } from "react-i18next"; import useToggle from "../../utils/useToggle"; import "./search-dropdown.css"; export const SearchDropdown = ({ types, search, onSearch, type, }) => { const { t } = useTranslation(); const form = useForm({ mode: "onChange" }); const { reset, formState: { isDirty }, handleSubmit, } = form; const [open, toggle] = useToggle(); const submit = (form) => { toggle(); onSearch(form); }; useEffect(() => reset(search), [search]); return (_jsx(Dropdown, { onOpenChange: toggle, toggle: (ref) => (_jsxs(MenuToggle, { "data-testid": "searchdropdown_dorpdown", ref: ref, onClick: toggle, className: "keycloak__client_authentication__searchdropdown", children: [type === "resource" && t("searchClientAuthorizationResource"), type === "policy" && t("searchClientAuthorizationPolicy"), type === "permission" && t("searchClientAuthorizationPermission")] })), isOpen: open, children: _jsx(FormProvider, { ...form, children: _jsxs(Form, { isHorizontal: true, className: "keycloak__client_authentication__searchdropdown_form", onSubmit: handleSubmit(submit), children: [_jsx(TextControl, { name: "name", label: t("name") }), type === "resource" && (_jsxs(_Fragment, { children: [_jsx(TextControl, { name: "type", label: t("type") }), _jsx(TextControl, { name: "uris", label: t("uris") }), _jsx(TextControl, { name: "owner", label: t("owner") })] })), type !== "resource" && type !== "policy" && (_jsx(TextControl, { name: "resource", label: t("resource") })), type !== "policy" && _jsx(TextControl, { name: "scope", label: t("scope") }), type !== "resource" && (_jsx(SelectControl, { name: "type", label: t("type"), controller: { defaultValue: "", }, options: [ { key: "", value: t("allTypes") }, ...(types || []).map(({ type, name }) => ({ key: type, value: name, })), ] })), _jsxs(ActionGroup, { children: [_jsx(Button, { variant: "primary", type: "submit", "data-testid": "search-btn", isDisabled: !isDirty, children: t("search") }), _jsx(Button, { variant: "link", "data-testid": "revert-btn", onClick: () => onSearch({}), children: t("clear") })] })] }) }) })); }; //# sourceMappingURL=SearchDropdown.js.map