UNPKG

@keycloakify/keycloak-admin-ui

Version:
31 lines 2.54 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { useFetch } from "../../ui-shared"; import { Dropdown, DropdownItem, DropdownList, MenuToggle, Tooltip, } from "@patternfly/react-core"; import { PlusIcon } from "@patternfly/react-icons"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { useAdminClient } from "../../admin-client"; import { AddStepModal } from "../../authentication/components/modals/AddStepModal"; import { AddSubFlowModal } from "../../authentication/components/modals/AddSubFlowModal"; export const AddFlowDropdown = ({ execution, onAddExecution, onAddFlow, }) => { const { adminClient } = useAdminClient(); const { t } = useTranslation(); const [open, setOpen] = useState(false); const [type, setType] = useState(); const [providerId, setProviderId] = useState(); useFetch(() => adminClient.authenticationManagement.getFlow({ flowId: execution.flowId, }), ({ providerId }) => setProviderId(providerId), []); return (_jsx(Tooltip, { content: t("add"), children: _jsxs(_Fragment, { children: [_jsx(Dropdown, { popperProps: { position: "right", }, isOpen: open, onOpenChange: (isOpen) => setOpen(isOpen), toggle: (ref) => (_jsx(MenuToggle, { ref: ref, variant: "plain", onClick: () => setOpen(!open), "aria-label": t("add"), "data-testid": `${execution.displayName}-edit-dropdown`, children: _jsx(PlusIcon, {}) })), onSelect: () => setOpen(false), children: _jsxs(DropdownList, { children: [_jsx(DropdownItem, { onClick: () => setType(providerId === "form-flow" ? "form" : "basic"), children: t("addStep") }, "addStep"), _jsx(DropdownItem, { onClick: () => setType("condition"), children: t("addCondition") }, "addCondition"), _jsx(DropdownItem, { onClick: () => setType("subFlow"), children: t("addSubFlow") }, "addSubFlow")] }) }), type && type !== "subFlow" && (_jsx(AddStepModal, { name: execution.displayName, type: type, onSelect: (type) => { if (type) { onAddExecution(execution, type); } setType(undefined); } })), type === "subFlow" && (_jsx(AddSubFlowModal, { name: execution.displayName, onCancel: () => setType(undefined), onConfirm: (flow) => { onAddFlow(execution, flow); setType(undefined); } }))] }) })); }; //# sourceMappingURL=AddFlowDropdown.js.map