2022-05-18 09:16:20 +00:00
|
|
|
import type ClientRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientRepresentation";
|
|
|
|
import type UserSessionRepresentation from "@keycloak/keycloak-admin-client/lib/defs/userSessionRepresentation";
|
|
|
|
import { PageSection } from "@patternfly/react-core";
|
|
|
|
import { useTranslation } from "react-i18next";
|
2023-05-03 13:51:02 +00:00
|
|
|
import { adminClient } from "../admin-client";
|
2022-05-18 09:16:20 +00:00
|
|
|
import type { LoaderFunction } from "../components/table-toolbar/KeycloakDataTable";
|
|
|
|
import SessionsTable from "../sessions/SessionsTable";
|
|
|
|
|
|
|
|
type ClientSessionsProps = {
|
|
|
|
client: ClientRepresentation;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ClientSessions = ({ client }: ClientSessionsProps) => {
|
|
|
|
const { t } = useTranslation("sessions");
|
|
|
|
|
2023-02-10 16:28:22 +00:00
|
|
|
const loader: LoaderFunction<UserSessionRepresentation> = async (
|
|
|
|
first,
|
|
|
|
max
|
|
|
|
) => {
|
|
|
|
const mapSessionsToType =
|
|
|
|
(type: string) => (sessions: UserSessionRepresentation[]) =>
|
|
|
|
sessions.map((session) => ({
|
|
|
|
type,
|
|
|
|
...session,
|
|
|
|
}));
|
|
|
|
|
|
|
|
const allSessions = await Promise.all([
|
|
|
|
adminClient.clients
|
|
|
|
.listSessions({ id: client.id!, first, max })
|
|
|
|
.then(mapSessionsToType(t("sessions:sessionsType.regularSSO"))),
|
|
|
|
adminClient.clients
|
|
|
|
.listOfflineSessions({
|
|
|
|
id: client.id!,
|
|
|
|
first,
|
|
|
|
max,
|
|
|
|
})
|
|
|
|
.then(mapSessionsToType(t("sessions:sessionsType.offline"))),
|
|
|
|
]);
|
|
|
|
|
|
|
|
return allSessions.flat();
|
|
|
|
};
|
2022-05-18 09:16:20 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<PageSection variant="light" className="pf-u-p-0">
|
|
|
|
<SessionsTable
|
|
|
|
loader={loader}
|
|
|
|
hiddenColumns={["clients"]}
|
|
|
|
emptyInstructions={t("noSessionsForClient")}
|
|
|
|
/>
|
|
|
|
</PageSection>
|
|
|
|
);
|
|
|
|
};
|