From 422c271da3f87b3b67227f6cd526e455ac2c7b42 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Fri, 27 May 2022 11:27:30 +0200 Subject: [PATCH] Added logout all sessions to user session tab (#2696) --- public/resources/en/sessions.json | 1 + src/sessions/SessionsTable.tsx | 24 +++++++++++++++++++++++- src/user/UserSessions.tsx | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/public/resources/en/sessions.json b/public/resources/en/sessions.json index 2ee794f2d1..9195bd4345 100644 --- a/public/resources/en/sessions.json +++ b/public/resources/en/sessions.json @@ -22,6 +22,7 @@ "signOutAllActiveSessions": "Sign out all active sessions", "signOutAllActiveSessionsQuestion": "Sign out all active sessions?", "setToNow": "Set to now", + "logoutAllSessions": "Logout all sessions", "logoutAllDescription": "If you sign out all active sessions, active subjects in this realm will be signed out.", "logoutAllSessionsError": "Error! Failed to log out of all sessions: {{error}}.", "setToNowError": "Error! Failed to set notBefore to current date and time.", diff --git a/src/sessions/SessionsTable.tsx b/src/sessions/SessionsTable.tsx index 6f41bd10bd..89af613ceb 100644 --- a/src/sessions/SessionsTable.tsx +++ b/src/sessions/SessionsTable.tsx @@ -1,5 +1,11 @@ import type UserSessionRepresentation from "@keycloak/keycloak-admin-client/lib/defs/userSessionRepresentation"; -import { List, ListItem, ListVariant } from "@patternfly/react-core"; +import { + Button, + List, + ListItem, + ListVariant, + ToolbarItem, +} from "@patternfly/react-core"; import { CubesIcon } from "@patternfly/react-icons"; import React, { useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; @@ -24,12 +30,14 @@ export type SessionsTableProps = { loader: LoaderFunction; hiddenColumns?: ColumnName[]; emptyInstructions?: string; + logoutUser?: string; }; export default function SessionsTable({ loader, hiddenColumns = [], emptyInstructions, + logoutUser, }: SessionsTableProps) { const { realm } = useRealm(); const { whoAmI } = useWhoAmI(); @@ -106,6 +114,20 @@ export default function SessionsTable({ loader={loader} ariaLabelKey="sessions:title" searchPlaceholderKey="sessions:searchForSession" + toolbarItem={ + logoutUser && ( + + + + ) + } columns={columns} actions={[ { diff --git a/src/user/UserSessions.tsx b/src/user/UserSessions.tsx index d976405e0a..d650514c83 100644 --- a/src/user/UserSessions.tsx +++ b/src/user/UserSessions.tsx @@ -22,6 +22,7 @@ export const UserSessions = () => { loader={loader} hiddenColumns={["username"]} emptyInstructions={t("noSessionsForUser")} + logoutUser={id} /> );