From f9c44c09537571f20a97e39631286a94d3399883 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Fri, 18 Dec 2020 08:01:35 +0100 Subject: [PATCH] initial version of the sessions sectino (#260) --- src/sessions/SessionsSection.tsx | 79 +++++++++++++++++++++++++++++--- src/sessions/messages.json | 8 +++- 2 files changed, 80 insertions(+), 7 deletions(-) diff --git a/src/sessions/SessionsSection.tsx b/src/sessions/SessionsSection.tsx index 5224ccc534..879e22c2ee 100644 --- a/src/sessions/SessionsSection.tsx +++ b/src/sessions/SessionsSection.tsx @@ -1,13 +1,80 @@ -import { PageSection } from "@patternfly/react-core"; import React from "react"; +import { Link } from "react-router-dom"; +import { PageSection } from "@patternfly/react-core"; +import moment from "moment"; +import UserSessionRepresentation from "keycloak-admin/lib/defs/userSessionRepresentation"; -export const SessionsSection = () => { +import { ViewHeader } from "../components/view-header/ViewHeader"; +import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable"; +import { useAdminClient } from "../context/auth/AdminClient"; + +const Clients = (row: UserSessionRepresentation) => { return ( <> - <> - The Sessions Page - - ; + {Object.values(row.clients!).map((client) => ( + + {client} + + ))} + + ); +}; + +export const SessionsSection = () => { + const adminClient = useAdminClient(); + + const loader = async () => { + const activeClients = await adminClient.sessions.find(); + const clientSessions = ( + await Promise.all( + activeClients.map((client) => + adminClient.clients.listSessions({ id: client.id }) + ) + ) + ).flat(); + + const userSessions = ( + await Promise.all( + clientSessions.map((session) => + adminClient.users.listSessions({ id: session.userId! }) + ) + ) + ).flat(); + + return userSessions; + }; + + return ( + <> + + + moment(row.lastAccess).fromNow(), + }, + { + name: "start", + displayKey: "sessions:startDate", + cellRenderer: (row) => moment(row.lastAccess).format("LLL"), + }, + { + name: "clients", + displayKey: "sessions:accessedClients", + cellRenderer: Clients, + }, + ]} + /> + ); }; diff --git a/src/sessions/messages.json b/src/sessions/messages.json index b450f23f45..fee0d80953 100644 --- a/src/sessions/messages.json +++ b/src/sessions/messages.json @@ -1,5 +1,11 @@ { "sessions": { - "title": "Sessions" + "title": "Sessions", + "sessionExplain": "Some description about sessions", + "searchForSession": "Search session", + "subject": "Subject", + "lastAccess": "Last access", + "startDate": "Start date", + "accessedClients": "Accessed clients" } } \ No newline at end of file