UNPKG

@keycloakify/keycloak-admin-ui

Version:
74 lines 4.34 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { KeycloakSelect } from "../ui-shared"; import { DropdownItem, PageSection, SelectOption, } from "@patternfly/react-core"; import { FilterIcon } from "@patternfly/react-icons"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { useAdminClient } from "../admin-client"; import { useAlerts } from "../ui-shared"; import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog"; import { ViewHeader } from "../components/view-header/ViewHeader"; import { fetchAdminUI } from "../context/auth/admin-ui-endpoint"; import { useRealm } from "../context/realm-context/RealmContext"; import helpUrls from "../help-urls"; import useToggle from "../utils/useToggle"; import { RevocationModal } from "../sessions/RevocationModal"; import SessionsTable from "../sessions/SessionsTable"; import "./SessionsSection.css"; const SessionFilter = ({ filterType, onChange }) => { const { t } = useTranslation(); const [open, toggle] = useToggle(); return (_jsxs(KeycloakSelect, { "data-testid": "filter-session-type-select", isOpen: open, onToggle: toggle, toggleIcon: _jsx(FilterIcon, {}), onSelect: (value) => { const filter = value; onChange(filter); toggle(); }, selections: filterType, children: [_jsx(SelectOption, { "data-testid": "all-sessions-option", value: "ALL", children: t("sessionsType.allSessions") }), _jsx(SelectOption, { "data-testid": "regular-sso-option", value: "REGULAR", children: t("sessionsType.regularSSO") }), _jsx(SelectOption, { "data-testid": "offline-option", value: "OFFLINE", children: t("sessionsType.offline") })] })); }; export default function SessionsSection() { const { adminClient } = useAdminClient(); const { t } = useTranslation(); const [key, setKey] = useState(0); const refresh = () => setKey(key + 1); const { addError } = useAlerts(); const { realm } = useRealm(); const [revocationModalOpen, setRevocationModalOpen] = useState(false); const [filterType, setFilterType] = useState("ALL"); const [noSessions, setNoSessions] = useState(false); const handleRevocationModalToggle = () => { setRevocationModalOpen(!revocationModalOpen); }; const loader = async (first, max, search) => { const data = await fetchAdminUI(adminClient, "ui-ext/sessions", { first: `${first}`, max: `${max}`, type: filterType, search: search || "", }); setNoSessions(data.length === 0); return data; }; const [toggleLogoutDialog, LogoutConfirm] = useConfirmDialog({ titleKey: "logoutAllSessions", messageKey: "logoutAllDescription", continueButtonLabel: "confirm", onConfirm: async () => { try { await adminClient.realms.logoutAll({ realm }); refresh(); } catch (error) { addError("logoutAllSessionsError", error); } }, }); return (_jsxs(_Fragment, { children: [_jsx(LogoutConfirm, {}), _jsx(ViewHeader, { dropdownItems: [ _jsx(DropdownItem, { "data-testid": "revocation", component: "button", onClick: () => handleRevocationModalToggle(), children: t("revocation") }, "toggle-modal"), _jsx(DropdownItem, { "data-testid": "logout-all", component: "button", isDisabled: noSessions, onClick: toggleLogoutDialog, children: t("signOutAllActiveSessions") }, "delete-role"), ], titleKey: "titleSessions", subKey: "sessionExplain", helpUrl: helpUrls.sessionsUrl }), _jsxs(PageSection, { variant: "light", className: "pf-v5-u-p-0", children: [revocationModalOpen && (_jsx(RevocationModal, { handleModalToggle: handleRevocationModalToggle, save: () => { handleRevocationModalToggle(); } })), _jsx(SessionsTable, { loader: loader, isSearching: filterType !== "ALL", isPaginated: true, filter: _jsx(SessionFilter, { filterType: filterType, onChange: (type) => { setFilterType(type); refresh(); } }) }, key)] })] })); } //# sourceMappingURL=SessionsSection.js.map