strapi-plugin-magic-sessionmanager 4.7.2 → 4.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/README.md +380 -663
  3. package/dist/admin/Analytics-B6d-39Qh.js +420 -0
  4. package/dist/admin/Analytics-DxOWXHn8.mjs +418 -0
  5. package/dist/admin/App-ZsSGj7n8.mjs +1894 -0
  6. package/dist/admin/App-mRFV50K6.js +1896 -0
  7. package/dist/admin/License-BE6UQ_V3.mjs +443 -0
  8. package/dist/admin/License-DXt2oi6u.js +443 -0
  9. package/dist/admin/OnlineUsersWidget-CFvM3Vbp.js +273 -0
  10. package/dist/admin/OnlineUsersWidget-_tJ6aeWl.mjs +254 -0
  11. package/dist/admin/SectionCard-BlWv8CRt.js +54 -0
  12. package/dist/admin/SectionCard-D51bv4Hi.mjs +55 -0
  13. package/dist/admin/Settings-BUc12TP5.js +3570 -0
  14. package/dist/admin/Settings-dtW7cjTX.mjs +3568 -0
  15. package/dist/admin/de-BFKoGEVT.js +544 -0
  16. package/dist/admin/de-j0oZH9Pz.mjs +544 -0
  17. package/dist/admin/en-UY4Tb5tE.mjs +544 -0
  18. package/dist/admin/en-s7Ksdkcg.js +544 -0
  19. package/dist/admin/es-07OGMe_5.js +544 -0
  20. package/dist/admin/es-DGBcZwQy.mjs +544 -0
  21. package/dist/admin/fr-B6-DWhGO.mjs +544 -0
  22. package/dist/admin/fr-ETj_2UBY.js +544 -0
  23. package/dist/admin/index-C_SyRULc.mjs +1750 -0
  24. package/dist/admin/index-D4kEnXSp.js +1751 -0
  25. package/dist/admin/index.js +1 -1
  26. package/dist/admin/index.mjs +2 -2
  27. package/dist/admin/maskSensitiveValue-BWcSjow7.js +9 -0
  28. package/dist/admin/maskSensitiveValue-lLRhN_S7.mjs +10 -0
  29. package/dist/admin/pt-C7PwrQtV.js +544 -0
  30. package/dist/admin/pt-YMRLm9gx.mjs +544 -0
  31. package/dist/server/index.js +3555 -6350
  32. package/dist/server/index.mjs +3555 -6350
  33. package/package.json +30 -19
  34. package/pics/analytics.png +0 -0
  35. package/pics/dashboard-dark.png +0 -0
  36. package/pics/dashboard.png +0 -0
  37. package/pics/dashboardsessionmodal.png +0 -0
  38. package/pics/mobile-dashboard.png +0 -0
  39. package/pics/mobile-session.png +0 -0
  40. package/pics/sessioninfopanel.png +0 -0
  41. package/pics/settings1.png +0 -0
  42. package/pics/settings2.png +0 -0
  43. package/pics/widget.png +0 -0
  44. package/scripts/geoip-updater.cjs +266 -36
  45. package/scripts/update-geoip-db.mjs +3 -0
  46. package/dist/admin/Analytics-CsrpxJwQ.mjs +0 -497
  47. package/dist/admin/Analytics-D03ZNNMR.js +0 -499
  48. package/dist/admin/App-B2VCS3cz.js +0 -1481
  49. package/dist/admin/App-qxKnK7G2.mjs +0 -1479
  50. package/dist/admin/License-ClW7sZLR.mjs +0 -318
  51. package/dist/admin/License-fixnQ7wF.js +0 -320
  52. package/dist/admin/OnlineUsersWidget-mR_OMiwi.mjs +0 -185
  53. package/dist/admin/OnlineUsersWidget-qb9utPBy.js +0 -185
  54. package/dist/admin/Settings-U3V4eGMo.mjs +0 -2038
  55. package/dist/admin/Settings-gv2BF54w.js +0 -2040
  56. package/dist/admin/StyledButtons-Cz8oYhmc.mjs +0 -418
  57. package/dist/admin/StyledButtons-DDuxnYz8.js +0 -419
  58. package/dist/admin/de-BnqGCokx.js +0 -316
  59. package/dist/admin/de-JBE-iylO.mjs +0 -316
  60. package/dist/admin/en-BRmVwd8-.js +0 -316
  61. package/dist/admin/en-kQWtdEai.mjs +0 -316
  62. package/dist/admin/es-CH691xcL.js +0 -301
  63. package/dist/admin/es-DOQvBxih.mjs +0 -301
  64. package/dist/admin/fr-CLExO0w_.js +0 -301
  65. package/dist/admin/fr-CmfCpepX.mjs +0 -301
  66. package/dist/admin/index-B_lFjUAg.mjs +0 -551
  67. package/dist/admin/index-Duc7cR_d.js +0 -552
  68. package/dist/admin/pt-BJ_F0yNi.js +0 -301
  69. package/dist/admin/pt-BSzZdyAH.mjs +0 -301
  70. package/dist/admin/sessionStatus-D_fWEzgj.js +0 -11
  71. package/dist/admin/sessionStatus-kwggjEMw.mjs +0 -12
@@ -0,0 +1,1894 @@
1
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import { useMemo, useState, useEffect, useRef, useCallback, useId, useLayoutEffect } from "react";
3
+ import { useIntl } from "react-intl";
4
+ import { NavLink, Link as Link$1 } from "react-router-dom";
5
+ import { useFetchClient, useNotification, useClipboard, useQueryParams, Pagination, Page } from "@strapi/strapi/admin";
6
+ import { Typography, Flex, Loader, Button, Modal, Accordion, Box, IconButton, Link, IconButtonGroup, SimpleMenu, MenuItem, Grid, Table, Thead, Tr, Th, VisuallyHidden, Tbody, Td, Tooltip, SearchForm, Searchbar, TextButton, SingleSelect, SingleSelectOption, EmptyStateLayout, LinkButton } from "@strapi/design-system";
7
+ import { Earth, Duplicate, Cross, Eye, Trash, More, CaretDown, Download, ArrowClockwise, Check, Clock, User, ChartBubble, Cog } from "@strapi/icons";
8
+ import { EmptyDocuments } from "@strapi/icons/symbols";
9
+ import styled, { useTheme } from "styled-components";
10
+ import { g as getSessionEndReason, a as getEndReasonPresentation, b as getTranslation, p as presentText, i as isSessionFilter, D as DEFAULT_SESSION_FILTER, c as isEndReasonFilter, d as DEFAULT_END_REASON_FILTER, e as getSessionState, f as getDevicePresentation, u as useSessionFormatters, h as getSessionStatus, j as isNativeOnlySession, k as getSessionEndReasonPresentation, l as DeviceIcon, S as StatusBadge, P as PropertyList, C as ConfirmAction, t as toValidDate, m as pluginId, n as logSafeAdminError, o as PersistentAlert, R as ReadableText, M as MissingValue, V as ValueOrMissing, q as SESSION_STATES, r as SESSION_STATUS_PRESENTATION, s as requireSessionList, v as filterSessionsBySearch, w as filterSessionsByStatus, x as SESSION_FILTER_OPTIONS, E as END_REASON_FILTER_OPTIONS, y as PageShell, z as StatGrid, A as StatCard, B as restoreDialogFocus, F as pluginPermissions } from "./index-C_SyRULc.mjs";
11
+ const EndReason = ({ session, reason, variant = "omega", textColor = "neutral800" }) => {
12
+ const { formatMessage } = useIntl();
13
+ const key = reason || getSessionEndReason(session);
14
+ if (!key) return null;
15
+ const presentation = getEndReasonPresentation(key);
16
+ const translate = (descriptor) => formatMessage({
17
+ id: getTranslation(descriptor.messageId),
18
+ defaultMessage: descriptor.defaultMessage
19
+ });
20
+ return /* @__PURE__ */ jsx(Typography, { variant, textColor, "data-end-reason": presentation.reason, children: translate(presentation) });
21
+ };
22
+ function paginateSessions(sessions = [], currentPage = 1, pageSize = 25) {
23
+ const items = Array.isArray(sessions) ? sessions : [];
24
+ const requestedSize = Number(pageSize);
25
+ const normalizedSize = Number.isFinite(requestedSize) && requestedSize > 0 ? Math.floor(requestedSize) : 1;
26
+ const total = items.length;
27
+ const pageCount = Math.max(1, Math.ceil(total / normalizedSize));
28
+ const requestedPage = Number(currentPage);
29
+ const page = Math.min(
30
+ pageCount,
31
+ Math.max(1, Number.isFinite(requestedPage) ? Math.floor(requestedPage) : 1)
32
+ );
33
+ const offset = (page - 1) * normalizedSize;
34
+ return {
35
+ items: items.slice(offset, offset + normalizedSize),
36
+ page,
37
+ pageCount,
38
+ startIndex: total === 0 ? 0 : offset + 1,
39
+ endIndex: Math.min(total, offset + normalizedSize),
40
+ total
41
+ };
42
+ }
43
+ const CSV_HEADERS = Object.freeze([
44
+ "ID",
45
+ "Status",
46
+ "User Email",
47
+ "Username",
48
+ "Device",
49
+ "Browser",
50
+ "OS",
51
+ "IP Address",
52
+ "Login Time",
53
+ "Last Active",
54
+ "Logout Time",
55
+ "Minutes Idle",
56
+ "End Reason"
57
+ ]);
58
+ const escapeCsvValue = (value) => `"${String(value ?? "").replace(/"/g, '""')}"`;
59
+ function toIsoTimestamp(value) {
60
+ if (value === null || value === void 0 || value === "") return "";
61
+ const date = value instanceof Date ? value : new Date(
62
+ /** @type {any} */
63
+ value
64
+ );
65
+ return Number.isFinite(date.getTime()) ? date.toISOString() : "";
66
+ }
67
+ function buildSessionCsv(sessions, {
68
+ unavailableValue,
69
+ getDeviceInfo,
70
+ getSessionStatus: getSessionStatus2,
71
+ getSessionEndReason: getSessionEndReason$1 = getSessionEndReason
72
+ }) {
73
+ const rows = Array.isArray(sessions) ? sessions : [];
74
+ const csvRows = rows.map((session) => {
75
+ const deviceInfo = getDeviceInfo(session, unavailableValue);
76
+ const minutesIdle = Number.isFinite(session.minutesSinceActive) ? session.minutesSinceActive : "";
77
+ return [
78
+ session.id,
79
+ getSessionStatus2(session),
80
+ session.user?.email || "",
81
+ session.user?.username || "",
82
+ deviceInfo.device,
83
+ deviceInfo.browser,
84
+ deviceInfo.os,
85
+ session.ipAddress || unavailableValue,
86
+ toIsoTimestamp(session.loginTime),
87
+ toIsoTimestamp(session.lastActive || session.loginTime),
88
+ toIsoTimestamp(session.logoutTime),
89
+ minutesIdle,
90
+ getSessionEndReason$1(session) || ""
91
+ ];
92
+ });
93
+ return [
94
+ CSV_HEADERS.map(escapeCsvValue).join(","),
95
+ ...csvRows.map((row) => row.map(escapeCsvValue).join(","))
96
+ ].join("\n");
97
+ }
98
+ function buildSessionJson(sessions, {
99
+ filterStatus,
100
+ totalSessions,
101
+ exportedAt,
102
+ unavailableValue,
103
+ getDeviceInfo,
104
+ getSessionStatus: getSessionStatus2,
105
+ getSessionEndReason: getSessionEndReason$1 = getSessionEndReason,
106
+ truncated = false
107
+ }) {
108
+ const rows = Array.isArray(sessions) ? sessions : [];
109
+ const exportData = {
110
+ exportedAt,
111
+ filter: filterStatus,
112
+ totalSessions,
113
+ exportedSessions: rows.length,
114
+ ...truncated ? { truncated: true } : {},
115
+ sessions: rows.map((session) => {
116
+ const deviceInfo = getDeviceInfo(session, unavailableValue);
117
+ return {
118
+ id: session.id,
119
+ status: getSessionStatus2(session),
120
+ endReason: getSessionEndReason$1(session) || null,
121
+ user: {
122
+ id: session.user?.documentId || session.user?.id,
123
+ email: session.user?.email,
124
+ username: session.user?.username
125
+ },
126
+ device: {
127
+ type: deviceInfo.device,
128
+ browser: deviceInfo.browser,
129
+ browserVersion: deviceInfo.browserVersion,
130
+ os: deviceInfo.os
131
+ },
132
+ ipAddress: session.ipAddress || unavailableValue,
133
+ loginTime: session.loginTime,
134
+ lastActive: session.lastActive,
135
+ logoutTime: session.logoutTime,
136
+ minutesSinceActive: session.minutesSinceActive,
137
+ isActive: session.isActive,
138
+ isTrulyActive: session.isTrulyActive
139
+ };
140
+ })
141
+ };
142
+ return JSON.stringify(exportData, null, 2);
143
+ }
144
+ const DS_BREAKPOINTS = Object.freeze({
145
+ small: "@media(min-width: 520px)",
146
+ medium: "@media(min-width: 768px)",
147
+ large: "@media(min-width: 1080px)"
148
+ });
149
+ const BREAKPOINT_ORDER = Object.freeze(["initial", "small", "medium", "large"]);
150
+ function mediaQueryFromBreakpoint(breakpoint) {
151
+ if (typeof breakpoint !== "string") return "";
152
+ const query = breakpoint.replace(/^\s*@media\s*/i, "").trim();
153
+ return /^\(.*\)$/.test(query) ? query : "";
154
+ }
155
+ function getBreakpointQueries(theme) {
156
+ const source = theme?.breakpoints || {};
157
+ return {
158
+ small: mediaQueryFromBreakpoint(source.small) || mediaQueryFromBreakpoint(DS_BREAKPOINTS.small),
159
+ medium: mediaQueryFromBreakpoint(source.medium) || mediaQueryFromBreakpoint(DS_BREAKPOINTS.medium),
160
+ large: mediaQueryFromBreakpoint(source.large) || mediaQueryFromBreakpoint(DS_BREAKPOINTS.large)
161
+ };
162
+ }
163
+ function resolveBreakpoint(matches = {}) {
164
+ if (matches.large) return "large";
165
+ if (matches.medium) return "medium";
166
+ if (matches.small) return "small";
167
+ return "initial";
168
+ }
169
+ function isBelowBreakpoint(current, target) {
170
+ return BREAKPOINT_ORDER.indexOf(current) < BREAKPOINT_ORDER.indexOf(target);
171
+ }
172
+ const readMatches = (queries) => {
173
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
174
+ return { small: true, medium: true, large: true };
175
+ }
176
+ return {
177
+ small: window.matchMedia(queries.small).matches,
178
+ medium: window.matchMedia(queries.medium).matches,
179
+ large: window.matchMedia(queries.large).matches
180
+ };
181
+ };
182
+ function useBreakpoint() {
183
+ const theme = useTheme();
184
+ const queries = useMemo(() => getBreakpointQueries(theme), [theme]);
185
+ const [matches, setMatches] = useState(() => readMatches(queries));
186
+ useEffect(() => {
187
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") return void 0;
188
+ const lists = ["small", "medium", "large"].map((name) => window.matchMedia(queries[name]));
189
+ const update = () => setMatches(readMatches(queries));
190
+ update();
191
+ lists.forEach((list) => list.addEventListener?.("change", update));
192
+ return () => lists.forEach((list) => list.removeEventListener?.("change", update));
193
+ }, [queries]);
194
+ const breakpoint = resolveBreakpoint(matches);
195
+ return {
196
+ breakpoint,
197
+ isBelowSmall: isBelowBreakpoint(breakpoint, "small"),
198
+ isBelowMedium: isBelowBreakpoint(breakpoint, "medium"),
199
+ isBelowLarge: isBelowBreakpoint(breakpoint, "large")
200
+ };
201
+ }
202
+ function useElementWidth() {
203
+ const [width, setWidth] = useState(0);
204
+ const observerRef = useRef(null);
205
+ const ref = useCallback((node) => {
206
+ observerRef.current?.disconnect();
207
+ observerRef.current = null;
208
+ if (!node || typeof ResizeObserver === "undefined") return;
209
+ const observer = new ResizeObserver((entries) => {
210
+ const next = Math.round(entries[0]?.contentRect?.width || 0);
211
+ setWidth((previous) => previous === next ? previous : next);
212
+ });
213
+ observer.observe(node);
214
+ observerRef.current = observer;
215
+ }, []);
216
+ useEffect(() => () => observerRef.current?.disconnect(), []);
217
+ return [ref, width];
218
+ }
219
+ const RISK_LEVEL_MESSAGES = Object.freeze({
220
+ none: Object.freeze({ messageId: "modal.security.risk.none", defaultMessage: "None" }),
221
+ low: Object.freeze({ messageId: "modal.security.risk.low", defaultMessage: "Low" }),
222
+ medium: Object.freeze({ messageId: "modal.security.risk.medium", defaultMessage: "Medium" }),
223
+ mediumHigh: Object.freeze({
224
+ messageId: "modal.security.risk.mediumHigh",
225
+ defaultMessage: "Medium-high"
226
+ }),
227
+ high: Object.freeze({ messageId: "modal.security.risk.high", defaultMessage: "High" })
228
+ });
229
+ const RISK_ALIASES = Object.freeze({
230
+ none: "none",
231
+ low: "low",
232
+ medium: "medium",
233
+ "medium high": "mediumHigh",
234
+ mediumhigh: "mediumHigh",
235
+ high: "high"
236
+ });
237
+ function normalizeRiskLevel(value) {
238
+ if (typeof value !== "string") return "";
239
+ const key = value.trim().toLowerCase().replace(/[\s_-]+/g, " ");
240
+ return RISK_ALIASES[key] || RISK_ALIASES[key.replace(/ /g, "")] || "";
241
+ }
242
+ const booleanOrNull = (value) => typeof value === "boolean" ? value : null;
243
+ function normalizeGeoData(geo, fallback = {}) {
244
+ if (!geo || typeof geo !== "object") return null;
245
+ const country = presentText(geo.country) || presentText(geo.country_code);
246
+ const city = presentText(geo.city);
247
+ const timezone = presentText(geo.timezone);
248
+ if (!country && !city && !timezone) return null;
249
+ const rawScore = typeof geo.securityScore === "number" ? geo.securityScore : fallback?.securityScore;
250
+ const securityScore = typeof rawScore === "number" && Number.isFinite(rawScore) ? rawScore : null;
251
+ return {
252
+ country,
253
+ city,
254
+ timezone,
255
+ securityScore,
256
+ riskLevel: normalizeRiskLevel(geo.riskLevel),
257
+ isVpn: booleanOrNull(geo.isVpn),
258
+ isProxy: booleanOrNull(geo.isProxy)
259
+ };
260
+ }
261
+ function getStoredGeoData(session) {
262
+ let geoLocation = session?.geoLocation;
263
+ if (typeof geoLocation === "string") {
264
+ try {
265
+ geoLocation = JSON.parse(geoLocation);
266
+ } catch {
267
+ geoLocation = null;
268
+ }
269
+ }
270
+ if (!geoLocation || typeof geoLocation !== "object") return null;
271
+ const {
272
+ securityScore: _ignored,
273
+ riskLevel: _ignoredLevel,
274
+ isVpn: _ignoredVpn,
275
+ isProxy: _ignoredProxy,
276
+ ...facts
277
+ } = geoLocation;
278
+ return normalizeGeoData(facts, { securityScore: session?.securityScore });
279
+ }
280
+ function interpretLookupResult(payload) {
281
+ const data = (
282
+ /** @type {any} */
283
+ payload?.data
284
+ );
285
+ if (!data || typeof data !== "object") return { status: "failed", geo: null };
286
+ if (data._status === "disabled") return { status: "disabled", geo: null };
287
+ if (data._status && data._status !== "ok") return { status: "failed", geo: null };
288
+ const geo = normalizeGeoData(data);
289
+ return geo ? { status: "ok", geo } : { status: "failed", geo: null };
290
+ }
291
+ const PAGE_SIZE_OPTIONS = Object.freeze(["10", "25", "50", "100"]);
292
+ const DEFAULT_PAGE_SIZE = "25";
293
+ const DASHBOARD_TABLE_COLUMNS = 7;
294
+ const DASHBOARD_COMPACT_TABLE_COLUMNS = 5;
295
+ const AUTO_REFRESH_INTERVAL_MS = 10 * 60 * 1e3;
296
+ const HOW_IT_WORKS_STORAGE_KEY = "magic-sessionmanager.dashboard.howSessionsWork";
297
+ const USER_EDIT_PATH = "/content-manager/collection-types/plugin::users-permissions.user/";
298
+ const readQueryText = (value) => {
299
+ if (typeof value !== "string") return "";
300
+ try {
301
+ return decodeURIComponent(value).trim();
302
+ } catch {
303
+ return value.trim();
304
+ }
305
+ };
306
+ function parseDashboardQuery(query = {}) {
307
+ const source = query || {};
308
+ const page = Number.parseInt(String(source.page ?? "1"), 10);
309
+ const pageSize = PAGE_SIZE_OPTIONS.includes(String(source.pageSize)) ? String(source.pageSize) : DEFAULT_PAGE_SIZE;
310
+ const status = isSessionFilter(source.status) ? (
311
+ /** @type {string} */
312
+ source.status
313
+ ) : DEFAULT_SESSION_FILTER;
314
+ const reason = status === "ended" && isEndReasonFilter(source.reason) ? (
315
+ /** @type {string} */
316
+ source.reason
317
+ ) : DEFAULT_END_REASON_FILTER;
318
+ const search = readQueryText(source.search) || readQueryText(source._q);
319
+ return { page: Number.isFinite(page) && page >= 1 ? page : 1, pageSize, status, reason, search };
320
+ }
321
+ function encodeSearchQuery(value) {
322
+ const text = typeof value === "string" ? value.trim() : "";
323
+ return text ? encodeURIComponent(text) : void 0;
324
+ }
325
+ function hasActiveFilters(state) {
326
+ if (!state) return false;
327
+ return state.status !== DEFAULT_SESSION_FILTER || Boolean(state.reason) && state.reason !== DEFAULT_END_REASON_FILTER || Boolean(state.search);
328
+ }
329
+ const getUserKey = (session) => {
330
+ const user = session?.user;
331
+ return presentText(user?.documentId) || presentText(user?.id) || presentText(user?.email);
332
+ };
333
+ function getSessionStats(sessions) {
334
+ const rows = Array.isArray(sessions) ? sessions : [];
335
+ const stats = {
336
+ active: 0,
337
+ idle: 0,
338
+ ended: 0,
339
+ total: rows.length,
340
+ usersOnline: 0,
341
+ loggedOut: 0,
342
+ timedOut: 0,
343
+ otherReasons: 0
344
+ };
345
+ const onlineUsers = /* @__PURE__ */ new Set();
346
+ for (const session of rows) {
347
+ const state = getSessionState(session);
348
+ stats[state] += 1;
349
+ if (state === "active") {
350
+ const key = getUserKey(session);
351
+ if (key) onlineUsers.add(key);
352
+ } else if (state === "ended") {
353
+ const reason = getSessionEndReason(session);
354
+ if (reason === "logout") stats.loggedOut += 1;
355
+ else if (reason === "idle") stats.timedOut += 1;
356
+ else stats.otherReasons += 1;
357
+ }
358
+ }
359
+ stats.usersOnline = onlineUsers.size;
360
+ return stats;
361
+ }
362
+ function getSessionUserLabels(session) {
363
+ const username = presentText(session?.user?.username);
364
+ const email = presentText(session?.user?.email);
365
+ const primary = username || email;
366
+ return {
367
+ primary,
368
+ secondary: username && email ? email : "",
369
+ accessible: primary || presentText(session?.id)
370
+ };
371
+ }
372
+ function getUserEditPath(session) {
373
+ const documentId = presentText(session?.user?.documentId);
374
+ return documentId ? `${USER_EDIT_PATH}${encodeURIComponent(documentId)}` : null;
375
+ }
376
+ function getExportDeviceInfo(session, unavailableValue = "") {
377
+ const device = getDevicePresentation(session);
378
+ return {
379
+ device: device.deviceType || unavailableValue,
380
+ browser: device.browser || unavailableValue,
381
+ browserVersion: device.browserVersion || "",
382
+ os: device.os || unavailableValue
383
+ };
384
+ }
385
+ function readDisclosureOpen(storage) {
386
+ try {
387
+ return storage?.getItem(HOW_IT_WORKS_STORAGE_KEY) === "open";
388
+ } catch {
389
+ return false;
390
+ }
391
+ }
392
+ function writeDisclosureOpen(storage, open) {
393
+ try {
394
+ storage?.setItem(HOW_IT_WORKS_STORAGE_KEY, open ? "open" : "closed");
395
+ } catch {
396
+ }
397
+ }
398
+ function getBrowserStorage() {
399
+ try {
400
+ return typeof window !== "undefined" ? window.localStorage : null;
401
+ } catch {
402
+ return null;
403
+ }
404
+ }
405
+ function shouldIsolateActionKey(key, fromInsideGroup) {
406
+ if (!fromInsideGroup) return true;
407
+ return key === "Enter" || key === " " || key === "Spacebar";
408
+ }
409
+ const FULL_TABLE_MIN_WIDTH = 1200;
410
+ function shouldUseCompactTable(listWidth, isBelowLarge) {
411
+ if (isBelowLarge) return true;
412
+ if (!Number.isFinite(listWidth) || listWidth <= 0) return false;
413
+ return listWidth < FULL_TABLE_MIN_WIDTH;
414
+ }
415
+ function shouldRedispatchEscape(key, fromInsideGroup) {
416
+ return !fromInsideGroup && key === "Escape";
417
+ }
418
+ function pickFocusSessionId(previousIds, currentIds, sessionId) {
419
+ const current = Array.isArray(currentIds) ? currentIds.map(String) : [];
420
+ if (current.length === 0) return null;
421
+ const target = String(sessionId);
422
+ if (current.includes(target)) return target;
423
+ const previous = Array.isArray(previousIds) ? previousIds.map(String) : [];
424
+ const index = previous.indexOf(target);
425
+ if (index >= 0) {
426
+ for (let next = index + 1; next < previous.length; next += 1) {
427
+ if (current.includes(previous[next])) return previous[next];
428
+ }
429
+ for (let before = index - 1; before >= 0; before -= 1) {
430
+ if (current.includes(previous[before])) return previous[before];
431
+ }
432
+ }
433
+ return current[0];
434
+ }
435
+ function getErrorStatus(error) {
436
+ const err = (
437
+ /** @type {any} */
438
+ error
439
+ );
440
+ const status = err?.status ?? err?.response?.status;
441
+ return typeof status === "number" ? status : null;
442
+ }
443
+ const TargetLink = styled(Link)`
444
+ min-height: 3.2rem;
445
+ display: inline-flex;
446
+ align-items: center;
447
+
448
+ ${({ theme }) => theme.breakpoints.medium} {
449
+ min-height: 2.4rem;
450
+ }
451
+ `;
452
+ const MONOSPACE$2 = { fontFamily: "monospace", overflowWrap: "anywhere", minWidth: 0 };
453
+ const IDLE_LOOKUP = { status: "idle", geo: null };
454
+ const DetailSection = ({ title, children }) => /* @__PURE__ */ jsxs(Flex, { tag: "section", direction: "column", alignItems: "stretch", gap: 3, minWidth: 0, children: [
455
+ /* @__PURE__ */ jsx(Typography, { variant: "delta", tag: "h3", textColor: "neutral800", children: title }),
456
+ children
457
+ ] });
458
+ const getMinutesSinceActive = (session, now) => {
459
+ const fromServer = Number(session.minutesSinceActive);
460
+ if (session.minutesSinceActive !== null && session.minutesSinceActive !== void 0 && Number.isFinite(fromServer)) {
461
+ return fromServer;
462
+ }
463
+ const last = toValidDate(session.lastActive || session.loginTime);
464
+ return last ? Math.max(0, Math.floor((now - last.getTime()) / 6e4)) : null;
465
+ };
466
+ const SessionDetailModal = ({ session, now, onClose, onCloseAutoFocus, onEndSession }) => {
467
+ const { formatMessage } = useIntl();
468
+ const { get } = useFetchClient();
469
+ const { toggleNotification } = useNotification();
470
+ const { copy } = useClipboard();
471
+ const { formatDate, formatRelativeTime, deviceTypeLabel, deviceSummary } = useSessionFormatters();
472
+ const [lookupState, setLookupState] = useState({ sessionId: null, ...IDLE_LOOKUP });
473
+ const lookup = lookupState.sessionId === session?.id ? lookupState : IDLE_LOOKUP;
474
+ const lookupRequest = useRef(0);
475
+ const endedReasonId = `session-ended-reason-${useId().replace(/:/g, "")}`;
476
+ const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
477
+ useEffect(() => {
478
+ lookupRequest.current += 1;
479
+ }, [session?.id]);
480
+ if (!session) return null;
481
+ const status = getSessionStatus(session);
482
+ const device = getDevicePresentation(session);
483
+ const canEnd = session.isActive === true;
484
+ const native = isNativeOnlySession(session);
485
+ const userAgent = presentText(session.userAgent);
486
+ const sessionId = presentText(session.id);
487
+ const ipAddress = presentText(session.ipAddress);
488
+ const user = getSessionUserLabels(session);
489
+ const userEditPath = getUserEditPath(session);
490
+ const storedGeo = getStoredGeoData(session);
491
+ const liveGeo = lookup.status === "ok" ? lookup.geo : null;
492
+ const geo = liveGeo || storedGeo;
493
+ const minutes = getMinutesSinceActive(session, now);
494
+ const reason = getSessionEndReasonPresentation(session);
495
+ const translate = (descriptor, values) => formatMessage(
496
+ { id: getTranslation(descriptor.messageId), defaultMessage: descriptor.defaultMessage },
497
+ values
498
+ );
499
+ const formatTimestamp = (value) => toValidDate(value) ? formatDate(value) : null;
500
+ const handleLookup = async () => {
501
+ if (!ipAddress) return;
502
+ const requestId = lookupRequest.current + 1;
503
+ lookupRequest.current = requestId;
504
+ const setLookup = (next) => setLookupState({ ...next, sessionId: session.id });
505
+ setLookup({ status: "loading", geo: null });
506
+ try {
507
+ const { data } = await get(`/${pluginId}/geolocation/${encodeURIComponent(ipAddress)}`);
508
+ if (requestId !== lookupRequest.current) return;
509
+ setLookup(interpretLookupResult(data));
510
+ } catch (err) {
511
+ logSafeAdminError("sessionDetails.geolocation", err);
512
+ if (requestId === lookupRequest.current) setLookup({ status: "failed", geo: null });
513
+ }
514
+ };
515
+ const handleTerminate = async () => {
516
+ await onEndSession(session);
517
+ onClose();
518
+ };
519
+ const handleCopyId = async () => {
520
+ const copied = sessionId ? await copy(sessionId) : false;
521
+ toggleNotification({
522
+ type: copied ? "success" : "danger",
523
+ message: copied ? t("modal.copy.success", "Record ID copied.") : t("modal.copy.error", "The record ID could not be copied.")
524
+ });
525
+ };
526
+ const stateSentence = () => {
527
+ if (status === "active") {
528
+ return /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral800", children: t("modal.state.active", "Active. Last request {time}.", {
529
+ time: formatRelativeTime(session.lastActive || session.loginTime)
530
+ }) });
531
+ }
532
+ if (status === "idle") {
533
+ return /* @__PURE__ */ jsx(PersistentAlert, { variant: "warning", closeLabel: t("common.close", "Close"), children: /* @__PURE__ */ jsx(ReadableText, { variant: "omega", tag: "span", children: t(
534
+ "modal.state.idle",
535
+ "Not used for {minutes} min. It ends on its next request or at the next idle check.",
536
+ {
537
+ minutes: minutes ?? 0
538
+ }
539
+ ) }) });
540
+ }
541
+ const endedAt = formatTimestamp(session.logoutTime);
542
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 1, children: [
543
+ /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral800", children: endedAt ? t("modal.state.ended", "Ended {endedAt} · {reason}.", {
544
+ endedAt,
545
+ reason: translate(reason)
546
+ }) : t("modal.state.endedNoTime", "Ended · {reason}.", { reason: translate(reason) }) }),
547
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: translate(reason.description) })
548
+ ] });
549
+ };
550
+ const yesNoText = (value) => typeof value === "boolean" ? /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral800", children: value ? t("common.yes", "Yes") : t("common.no", "No") }) : void 0;
551
+ const notStoredForPast = /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral600", children: t("modal.security.notStored", "Not stored for past sign-ins") });
552
+ const score = typeof geo?.securityScore === "number" ? geo.securityScore : typeof session.securityScore === "number" && Number.isFinite(session.securityScore) ? session.securityScore : null;
553
+ const riskMessage = liveGeo ? RISK_LEVEL_MESSAGES[liveGeo.riskLevel] : null;
554
+ const locationItems = [
555
+ { id: "country", label: t("modal.security.country", "Country"), value: geo?.country },
556
+ { id: "city", label: t("modal.security.city", "City"), value: geo?.city },
557
+ { id: "timezone", label: t("modal.security.timezone", "Time zone"), value: geo?.timezone },
558
+ {
559
+ id: "score",
560
+ label: t("modal.security.score", "Security score"),
561
+ value: score === null ? null : t("modal.security.scoreValue", "{score}/100", { score })
562
+ },
563
+ {
564
+ id: "vpn",
565
+ label: t("modal.security.vpn", "VPN"),
566
+ render: liveGeo ? yesNoText(liveGeo.isVpn) : storedGeo ? notStoredForPast : void 0
567
+ },
568
+ {
569
+ id: "proxy",
570
+ label: t("modal.security.proxy", "Proxy"),
571
+ render: liveGeo ? yesNoText(liveGeo.isProxy) : storedGeo ? notStoredForPast : void 0
572
+ },
573
+ riskMessage ? {
574
+ id: "risk",
575
+ label: t("modal.security.riskLevel", "Risk level"),
576
+ value: translate(riskMessage),
577
+ fullWidth: true
578
+ } : null
579
+ ];
580
+ const canLookUp = !geo && Boolean(ipAddress) && !native;
581
+ const hasLocationData = Boolean(geo) || score !== null || !canLookUp;
582
+ const lookupControls = canLookUp ? /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", gap: 2, children: [
583
+ lookup.status === "loading" ? /* @__PURE__ */ jsx(Loader, { small: true, role: "status", "aria-live": "polite", children: t("modal.security.loading", "Looking up the location") }) : /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "S", startIcon: /* @__PURE__ */ jsx(Earth, {}), onClick: handleLookup, children: t("modal.security.lookup", "Look up location") }),
584
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t(
585
+ "modal.security.lookupHint",
586
+ "Sends the IP address to the configured lookup service, which can be ipapi.co."
587
+ ) }),
588
+ lookup.status === "disabled" ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral800", role: "status", children: t("modal.security.lookupOff", "IP location lookup is off.") }) : null,
589
+ lookup.status === "failed" ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "danger600", role: "status", children: t("modal.security.lookupFailed", "The location could not be determined.") }) : null
590
+ ] }) : null;
591
+ return /* @__PURE__ */ jsx(Modal.Root, { open: true, onOpenChange: onClose, children: /* @__PURE__ */ jsxs(Modal.Content, { onCloseAutoFocus, "aria-describedby": void 0, children: [
592
+ /* @__PURE__ */ jsx(Modal.Header, { closeLabel: t("common.close", "Close"), children: /* @__PURE__ */ jsxs(Flex, { gap: 3, alignItems: "center", wrap: "wrap", minWidth: 0, children: [
593
+ /* @__PURE__ */ jsx(Flex, { padding: 2, background: "neutral100", hasRadius: true, shrink: 0, "aria-hidden": true, children: /* @__PURE__ */ jsx(DeviceIcon, { icon: device.icon }) }),
594
+ /* @__PURE__ */ jsx(Modal.Title, { children: t("modal.title", "Session details") }),
595
+ /* @__PURE__ */ jsx(StatusBadge, { session, status, size: "S" })
596
+ ] }) }),
597
+ /* @__PURE__ */ jsx(Modal.Body, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 6, minWidth: 0, children: [
598
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, "data-state-sentence": "", children: [
599
+ stateSentence(),
600
+ canEnd ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t(
601
+ "modal.state.maxAgeNote",
602
+ "Sessions older than the maximum session age end on their next request."
603
+ ) }) : null
604
+ ] }),
605
+ /* @__PURE__ */ jsx(DetailSection, { title: t("modal.section.user", "User"), children: /* @__PURE__ */ jsx(
606
+ PropertyList,
607
+ {
608
+ items: [
609
+ {
610
+ id: "username",
611
+ label: t("modal.user.username", "Username"),
612
+ value: session.user?.username,
613
+ render: presentText(session.user?.username) && userEditPath ? /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "baseline", wrap: "wrap", children: [
614
+ /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral800", children: session.user.username }),
615
+ /* @__PURE__ */ jsx(
616
+ TargetLink,
617
+ {
618
+ tag: NavLink,
619
+ to: userEditPath,
620
+ "aria-label": t("modal.user.openFor", "Open user {user}", {
621
+ user: user.accessible
622
+ }),
623
+ children: t("modal.user.open", "Open user")
624
+ }
625
+ )
626
+ ] }) : void 0
627
+ },
628
+ {
629
+ id: "email",
630
+ label: t("modal.user.email", "Email"),
631
+ value: session.user?.email,
632
+ kind: "email"
633
+ }
634
+ ]
635
+ }
636
+ ) }),
637
+ /* @__PURE__ */ jsx(DetailSection, { title: t("modal.section.session", "Session"), children: /* @__PURE__ */ jsx(
638
+ PropertyList,
639
+ {
640
+ items: [
641
+ {
642
+ id: "login",
643
+ label: t("modal.timeline.signedIn", "Signed in"),
644
+ value: formatTimestamp(session.loginTime)
645
+ },
646
+ {
647
+ id: "lastActive",
648
+ label: t("modal.timeline.lastActive", "Last active"),
649
+ value: formatTimestamp(session.lastActive || session.loginTime)
650
+ },
651
+ !canEnd ? {
652
+ id: "endedAt",
653
+ label: t("modal.timeline.endedAt", "Ended at"),
654
+ value: formatTimestamp(session.logoutTime)
655
+ } : null,
656
+ !canEnd ? {
657
+ id: "endReason",
658
+ label: t("modal.timeline.endReason", "End reason"),
659
+ render: /* @__PURE__ */ jsx(EndReason, { session })
660
+ } : null
661
+ ]
662
+ }
663
+ ) }),
664
+ /* @__PURE__ */ jsx(DetailSection, { title: t("modal.section.device", "Device"), children: /* @__PURE__ */ jsx(
665
+ PropertyList,
666
+ {
667
+ items: [
668
+ {
669
+ id: "device",
670
+ label: t("modal.device.device", "Device type"),
671
+ value: native ? null : deviceTypeLabel(session)
672
+ },
673
+ {
674
+ id: "browser",
675
+ label: t("modal.device.browser", "Browser"),
676
+ value: device.browser
677
+ },
678
+ { id: "os", label: t("modal.device.os", "Operating system"), value: device.os },
679
+ {
680
+ id: "ip",
681
+ label: t("modal.device.ip", "IP address"),
682
+ value: session.ipAddress,
683
+ kind: "id",
684
+ render: ipAddress ? /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral800", style: MONOSPACE$2, children: ipAddress }) : void 0
685
+ }
686
+ ]
687
+ }
688
+ ) }),
689
+ /* @__PURE__ */ jsxs(DetailSection, { title: t("modal.section.security", "Location and security"), children: [
690
+ hasLocationData ? /* @__PURE__ */ jsx(PropertyList, { items: locationItems }) : null,
691
+ score !== null ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", "data-score-note": "", children: t(
692
+ "modal.security.scoreNote",
693
+ "Higher is safer. Below 70 can trigger a suspicious-sign-in email and below 50 a rejection, if those settings are on. Local database results are always 100."
694
+ ) }) : null,
695
+ lookupControls
696
+ ] }),
697
+ /* @__PURE__ */ jsx(Accordion.Root, { collapsible: true, size: "S", children: /* @__PURE__ */ jsxs(Accordion.Item, { value: "technical", children: [
698
+ /* @__PURE__ */ jsx(Accordion.Header, { children: /* @__PURE__ */ jsx(Accordion.Trigger, { children: t("modal.section.technical", "Technical details") }) }),
699
+ /* @__PURE__ */ jsx(Accordion.Content, { children: /* @__PURE__ */ jsx(Box, { padding: 4, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
700
+ native ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t(
701
+ "common.status.nativeSession.help",
702
+ "Created by Strapi’s own session store. No device or location details were recorded."
703
+ ) }) : null,
704
+ /* @__PURE__ */ jsx(
705
+ PropertyList,
706
+ {
707
+ columns: 1,
708
+ items: [
709
+ {
710
+ id: "sessionId",
711
+ label: t("modal.technical.recordId", "Record ID"),
712
+ value: sessionId,
713
+ kind: "id",
714
+ render: sessionId ? /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", minWidth: 0, children: [
715
+ /* @__PURE__ */ jsx(
716
+ Typography,
717
+ {
718
+ variant: "omega",
719
+ textColor: "neutral800",
720
+ style: MONOSPACE$2,
721
+ children: sessionId
722
+ }
723
+ ),
724
+ /* @__PURE__ */ jsx(
725
+ IconButton,
726
+ {
727
+ label: t("modal.actions.copyId", "Copy record ID"),
728
+ onClick: handleCopyId,
729
+ children: /* @__PURE__ */ jsx(Duplicate, {})
730
+ }
731
+ )
732
+ ] }) : void 0
733
+ },
734
+ {
735
+ id: "userId",
736
+ label: t("modal.user.id", "User ID"),
737
+ value: session.user?.documentId || session.user?.id,
738
+ kind: "id"
739
+ },
740
+ {
741
+ id: "userAgent",
742
+ label: t("modal.technical.userAgent", "User agent"),
743
+ value: userAgent || null,
744
+ kind: "id"
745
+ }
746
+ ]
747
+ }
748
+ )
749
+ ] }) }) })
750
+ ] }) })
751
+ ] }) }),
752
+ /* @__PURE__ */ jsx(Modal.Footer, { children: /* @__PURE__ */ jsxs(
753
+ Flex,
754
+ {
755
+ justifyContent: "space-between",
756
+ alignItems: "center",
757
+ gap: 3,
758
+ wrap: "wrap-reverse",
759
+ width: "100%",
760
+ children: [
761
+ /* @__PURE__ */ jsx(Modal.Close, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", children: t("modal.actions.close", "Close") }) }),
762
+ canEnd ? /* @__PURE__ */ jsx(
763
+ ConfirmAction,
764
+ {
765
+ title: t("homepage.confirm.end.title", "End this session?"),
766
+ body: t(
767
+ "homepage.confirm.end.body",
768
+ "{user} will be signed out on {device}. Their other sessions stay open. The record stays in the history. This cannot be undone.",
769
+ {
770
+ user: user.accessible,
771
+ device: deviceSummary(session) || deviceTypeLabel(session)
772
+ }
773
+ ),
774
+ confirmLabel: t("homepage.actions.end", "End session"),
775
+ onConfirm: handleTerminate,
776
+ disabled: !canEnd,
777
+ trigger: /* @__PURE__ */ jsx(Button, { variant: "danger-light", startIcon: /* @__PURE__ */ jsx(Cross, {}), disabled: !canEnd, children: t("homepage.actions.end", "End session") })
778
+ }
779
+ ) : /* @__PURE__ */ jsx(Typography, { id: endedReasonId, variant: "pi", textColor: "neutral600", children: t("modal.actions.alreadyEnded", "This session has already ended.") })
780
+ ]
781
+ }
782
+ ) })
783
+ ] }) });
784
+ };
785
+ const isolateActionKeys = (event) => {
786
+ const fromInsideGroup = event.currentTarget.contains(
787
+ /** @type {Node} */
788
+ event.target
789
+ );
790
+ if (!shouldIsolateActionKey(event.key, fromInsideGroup)) return;
791
+ event.stopPropagation();
792
+ if (shouldRedispatchEscape(event.key, fromInsideGroup)) {
793
+ const { ownerDocument } = event.currentTarget;
794
+ ownerDocument.dispatchEvent(
795
+ new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true })
796
+ );
797
+ }
798
+ };
799
+ const getConfirmationCopy = (t, { user, device, isOpen }) => ({
800
+ end: {
801
+ title: t("homepage.confirm.end.title", "End this session?"),
802
+ body: t(
803
+ "homepage.confirm.end.body",
804
+ "{user} will be signed out on {device}. Their other sessions stay open. The record stays in the history. This cannot be undone.",
805
+ { user, device }
806
+ ),
807
+ confirmLabel: t("homepage.actions.end", "End session")
808
+ },
809
+ remove: isOpen ? {
810
+ title: t("homepage.confirm.deleteOpen.title", "Delete record and end session?"),
811
+ body: t(
812
+ "homepage.confirm.deleteOpen.body",
813
+ "This session is still open. {user} will be signed out on {device}, and the record is removed from history, statistics and exports. This cannot be undone.",
814
+ { user, device }
815
+ ),
816
+ confirmLabel: t("homepage.actions.deleteAndEnd", "Delete and end")
817
+ } : {
818
+ title: t("homepage.confirm.deleteEnded.title", "Delete this session record?"),
819
+ body: t(
820
+ "homepage.confirm.deleteEnded.body",
821
+ "The record is removed permanently from history, statistics and exports. This cannot be undone."
822
+ ),
823
+ confirmLabel: t("homepage.actions.deleteRecord", "Delete record")
824
+ }
825
+ });
826
+ const SessionActions = ({
827
+ session,
828
+ layout,
829
+ onView,
830
+ onEnd,
831
+ onDelete,
832
+ mutationPending,
833
+ focusFallback
834
+ }) => {
835
+ const { formatMessage } = useIntl();
836
+ const { deviceSummary, deviceTypeLabel } = useSessionFormatters();
837
+ const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
838
+ const [deleteOpen, setDeleteOpen] = useState(false);
839
+ const moreRef = useRef(null);
840
+ const user = getSessionUserLabels(session).accessible;
841
+ const canEnd = session.isActive === true;
842
+ const device = deviceSummary(session) || deviceTypeLabel(session);
843
+ const copy = getConfirmationCopy(t, { user, device, isOpen: canEnd });
844
+ const viewLabel = t("homepage.actions.viewFor", "View details for {user}", { user });
845
+ const endLabel = t("homepage.actions.endFor", "End session of {user}", { user });
846
+ const endedLabel = t(
847
+ "homepage.actions.alreadyEndedFor",
848
+ "The session of {user} has already ended",
849
+ { user }
850
+ );
851
+ const moreLabel = t("homepage.actions.moreFor", "More actions for {user}", { user });
852
+ const deleteLabel = t("homepage.actions.deleteRecord", "Delete record");
853
+ const endConfirm = { ...copy.end, onConfirm: () => onEnd(session) };
854
+ const deleteConfirm = /* @__PURE__ */ jsx(
855
+ ConfirmAction,
856
+ {
857
+ ...copy.remove,
858
+ onConfirm: () => onDelete(session),
859
+ isOpen: deleteOpen,
860
+ onOpenChange: setDeleteOpen,
861
+ returnFocusRef: moreRef,
862
+ fallbackFocusRef: focusFallback
863
+ }
864
+ );
865
+ const endKey = `end-${session.id}-${canEnd ? "open" : "ended"}`;
866
+ if (layout === "table") {
867
+ return /* @__PURE__ */ jsxs(IconButtonGroup, { onKeyDown: isolateActionKeys, onClick: (event) => event.stopPropagation(), children: [
868
+ /* @__PURE__ */ jsx(
869
+ IconButton,
870
+ {
871
+ label: viewLabel,
872
+ "data-session-view": session.id,
873
+ onClick: (event) => onView(session, event.currentTarget),
874
+ children: /* @__PURE__ */ jsx(Eye, {})
875
+ }
876
+ ),
877
+ /* @__PURE__ */ jsx(
878
+ ConfirmAction,
879
+ {
880
+ ...endConfirm,
881
+ disabled: !canEnd || mutationPending,
882
+ fallbackFocusRef: focusFallback,
883
+ trigger: /* @__PURE__ */ jsx(
884
+ IconButton,
885
+ {
886
+ label: canEnd ? endLabel : endedLabel,
887
+ variant: "danger-light",
888
+ disabled: !canEnd || mutationPending,
889
+ children: /* @__PURE__ */ jsx(Cross, {})
890
+ }
891
+ )
892
+ },
893
+ endKey
894
+ ),
895
+ /* @__PURE__ */ jsx(
896
+ SimpleMenu,
897
+ {
898
+ ref: moreRef,
899
+ tag: IconButton,
900
+ icon: /* @__PURE__ */ jsx(More, {}),
901
+ label: moreLabel,
902
+ disabled: mutationPending,
903
+ children: /* @__PURE__ */ jsx(MenuItem, { startIcon: /* @__PURE__ */ jsx(Trash, {}), variant: "danger", onSelect: () => setDeleteOpen(true), children: deleteLabel })
904
+ }
905
+ ),
906
+ deleteConfirm
907
+ ] });
908
+ }
909
+ const span = canEnd ? 4 : 6;
910
+ return /* @__PURE__ */ jsxs(Grid.Root, { gap: 2, children: [
911
+ /* @__PURE__ */ jsx(Grid.Item, { col: span, m: span, s: span, xs: 12, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsx(
912
+ Button,
913
+ {
914
+ fullWidth: true,
915
+ variant: "secondary",
916
+ startIcon: /* @__PURE__ */ jsx(Eye, {}),
917
+ "aria-label": viewLabel,
918
+ "data-session-view": session.id,
919
+ onClick: (event) => onView(session, event.currentTarget),
920
+ children: t("homepage.actions.details", "Details")
921
+ }
922
+ ) }),
923
+ canEnd ? /* @__PURE__ */ jsx(Grid.Item, { col: span, m: span, s: span, xs: 12, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsx(
924
+ ConfirmAction,
925
+ {
926
+ ...endConfirm,
927
+ disabled: !canEnd || mutationPending,
928
+ fallbackFocusRef: focusFallback,
929
+ trigger: /* @__PURE__ */ jsx(
930
+ Button,
931
+ {
932
+ fullWidth: true,
933
+ variant: "danger-light",
934
+ startIcon: /* @__PURE__ */ jsx(Cross, {}),
935
+ "aria-label": endLabel,
936
+ disabled: !canEnd || mutationPending,
937
+ children: t("homepage.actions.end", "End session")
938
+ }
939
+ )
940
+ },
941
+ endKey
942
+ ) }) : null,
943
+ /* @__PURE__ */ jsxs(Grid.Item, { col: span, m: span, s: span, xs: 12, direction: "column", alignItems: "stretch", children: [
944
+ /* @__PURE__ */ jsx(
945
+ SimpleMenu,
946
+ {
947
+ ref: moreRef,
948
+ label: t("homepage.actions.more", "More"),
949
+ "aria-label": moreLabel,
950
+ variant: "tertiary",
951
+ fullWidth: true,
952
+ endIcon: /* @__PURE__ */ jsx(More, {}),
953
+ disabled: mutationPending,
954
+ children: /* @__PURE__ */ jsx(MenuItem, { startIcon: /* @__PURE__ */ jsx(Trash, {}), variant: "danger", onSelect: () => setDeleteOpen(true), children: deleteLabel })
955
+ }
956
+ ),
957
+ deleteConfirm
958
+ ] })
959
+ ] });
960
+ };
961
+ const SHRINKING_USER_CELL = { maxWidth: 0, width: "30%" };
962
+ const SHRINKING_DEVICE_CELL = { maxWidth: 0, width: "25%" };
963
+ const COMPACT_STATUS_CELL = { width: "24%", whiteSpace: "normal" };
964
+ const MONOSPACE$1 = { fontFamily: "monospace" };
965
+ const LastActive = ({ value }) => {
966
+ const { formatDate, formatRelativeTime } = useSessionFormatters();
967
+ const date = toValidDate(value);
968
+ if (!date) return /* @__PURE__ */ jsx(MissingValue, { variant: "omega" });
969
+ return /* @__PURE__ */ jsx(Tooltip, { label: formatDate(date), children: /* @__PURE__ */ jsx(Typography, { tag: "time", dateTime: date.toISOString(), variant: "omega", textColor: "neutral800", children: formatRelativeTime(date) }) });
970
+ };
971
+ const SignedIn = ({ value }) => {
972
+ const { formatDate } = useSessionFormatters();
973
+ const date = toValidDate(value);
974
+ if (!date) return /* @__PURE__ */ jsx(MissingValue, { variant: "omega" });
975
+ return /* @__PURE__ */ jsx(Typography, { tag: "time", dateTime: date.toISOString(), variant: "omega", textColor: "neutral800", children: formatDate(date) });
976
+ };
977
+ const DeviceSummary = ({ session }) => {
978
+ const { deviceTypeLabel, deviceSummary } = useSessionFormatters();
979
+ if (isNativeOnlySession(session)) return /* @__PURE__ */ jsx(MissingValue, { variant: "omega" });
980
+ const device = getDevicePresentation(session);
981
+ const typeLabel = deviceTypeLabel(session);
982
+ const summary = device.hasSummary ? deviceSummary(session) : typeLabel;
983
+ return /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", minWidth: 0, children: [
984
+ /* @__PURE__ */ jsx(Flex, { shrink: 0, color: "neutral600", "aria-hidden": true, children: /* @__PURE__ */ jsx(DeviceIcon, { icon: device.icon }) }),
985
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", minWidth: 0, children: [
986
+ /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral800", ellipsis: true, title: summary, children: summary }),
987
+ device.hasSummary && device.hasDeviceType ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", ellipsis: true, title: typeLabel, children: typeLabel }) : null
988
+ ] })
989
+ ] });
990
+ };
991
+ const SessionTable = ({
992
+ sessions,
993
+ labelledBy,
994
+ busy,
995
+ compact = false,
996
+ onView,
997
+ onEnd,
998
+ onDelete,
999
+ mutationPending,
1000
+ getFocusFallback
1001
+ }) => {
1002
+ const { formatMessage } = useIntl();
1003
+ const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
1004
+ const header = (id, defaultMessage) => /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: t(id, defaultMessage) });
1005
+ return /* @__PURE__ */ jsxs(
1006
+ Table,
1007
+ {
1008
+ colCount: compact ? DASHBOARD_COMPACT_TABLE_COLUMNS : DASHBOARD_TABLE_COLUMNS,
1009
+ rowCount: sessions.length + 1,
1010
+ "aria-labelledby": labelledBy,
1011
+ "aria-busy": busy,
1012
+ children: [
1013
+ /* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
1014
+ /* @__PURE__ */ jsx(Th, { style: compact ? COMPACT_STATUS_CELL : void 0, children: header("homepage.table.status", "Status") }),
1015
+ /* @__PURE__ */ jsx(Th, { children: header("homepage.table.user", "User") }),
1016
+ /* @__PURE__ */ jsx(Th, { children: header("homepage.table.device", "Device") }),
1017
+ compact ? null : /* @__PURE__ */ jsx(Th, { children: header("homepage.table.ipAddress", "IP address") }),
1018
+ compact ? null : /* @__PURE__ */ jsx(Th, { children: header("homepage.table.signedIn", "Signed in") }),
1019
+ /* @__PURE__ */ jsx(Th, { children: header("homepage.table.lastActive", "Last active") }),
1020
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(VisuallyHidden, { children: t("homepage.table.actions", "Actions") }) })
1021
+ ] }) }),
1022
+ /* @__PURE__ */ jsx(Tbody, { children: sessions.map((session) => {
1023
+ const user = getSessionUserLabels(session);
1024
+ return /* @__PURE__ */ jsxs(
1025
+ Tr,
1026
+ {
1027
+ style: { cursor: "pointer" },
1028
+ onClick: (event) => {
1029
+ const opener = event.currentTarget.querySelector("[data-session-view]");
1030
+ onView(session, opener || event.currentTarget);
1031
+ },
1032
+ children: [
1033
+ /* @__PURE__ */ jsx(Td, { style: compact ? COMPACT_STATUS_CELL : void 0, children: /* @__PURE__ */ jsx(StatusBadge, { session, size: "S", detail: true }) }),
1034
+ /* @__PURE__ */ jsx(Td, { style: SHRINKING_USER_CELL, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", minWidth: 0, children: [
1035
+ user.primary ? /* @__PURE__ */ jsx(
1036
+ Typography,
1037
+ {
1038
+ fontWeight: "semiBold",
1039
+ textColor: "neutral800",
1040
+ ellipsis: true,
1041
+ title: user.primary,
1042
+ children: user.primary
1043
+ }
1044
+ ) : /* @__PURE__ */ jsx(MissingValue, { variant: "omega" }),
1045
+ user.secondary ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", ellipsis: true, title: user.secondary, children: user.secondary }) : null
1046
+ ] }) }),
1047
+ /* @__PURE__ */ jsx(Td, { style: SHRINKING_DEVICE_CELL, children: /* @__PURE__ */ jsx(DeviceSummary, { session }) }),
1048
+ compact ? null : /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral800", style: MONOSPACE$1, children: /* @__PURE__ */ jsx(ValueOrMissing, { value: session.ipAddress }) }) }),
1049
+ compact ? null : /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(SignedIn, { value: session.loginTime }) }),
1050
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(LastActive, { value: session.lastActive || session.loginTime }) }),
1051
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
1052
+ SessionActions,
1053
+ {
1054
+ layout: "table",
1055
+ session,
1056
+ onView,
1057
+ onEnd,
1058
+ onDelete,
1059
+ mutationPending,
1060
+ focusFallback: getFocusFallback(session.id)
1061
+ }
1062
+ ) }) })
1063
+ ]
1064
+ },
1065
+ session.id
1066
+ );
1067
+ }) })
1068
+ ]
1069
+ }
1070
+ );
1071
+ };
1072
+ const CardList = styled.ul`
1073
+ display: flex;
1074
+ flex-direction: column;
1075
+ gap: ${({ theme }) => theme.spaces[4]};
1076
+ list-style: none;
1077
+ margin: 0;
1078
+ padding: 0;
1079
+ min-width: 0;
1080
+
1081
+ /* The page text rhythm caps list items at 72ch and adds li + li margins;
1082
+ cards use the full list width and the flex gap only. */
1083
+ && > li {
1084
+ max-width: none;
1085
+ margin: 0;
1086
+ }
1087
+ `;
1088
+ const MONOSPACE = { fontFamily: "monospace" };
1089
+ const SessionCardList = ({
1090
+ sessions,
1091
+ labelledBy,
1092
+ busy,
1093
+ onView,
1094
+ onEnd,
1095
+ onDelete,
1096
+ mutationPending,
1097
+ getFocusFallback
1098
+ }) => /* @__PURE__ */ jsx(CardList, { "aria-labelledby": labelledBy, "aria-busy": busy, children: sessions.map((session) => {
1099
+ const user = getSessionUserLabels(session);
1100
+ return /* @__PURE__ */ jsx(
1101
+ Box,
1102
+ {
1103
+ tag: "li",
1104
+ background: "neutral0",
1105
+ hasRadius: true,
1106
+ shadow: "tableShadow",
1107
+ padding: 4,
1108
+ minWidth: 0,
1109
+ children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 3, children: [
1110
+ /* @__PURE__ */ jsx(StatusBadge, { session, size: "S", detail: true }),
1111
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", minWidth: 0, children: [
1112
+ /* @__PURE__ */ jsx(
1113
+ Typography,
1114
+ {
1115
+ variant: "delta",
1116
+ tag: "h3",
1117
+ textColor: "neutral800",
1118
+ style: { overflowWrap: "anywhere" },
1119
+ children: user.primary || /* @__PURE__ */ jsx(MissingValue, { variant: "delta" })
1120
+ }
1121
+ ),
1122
+ user.secondary ? /* @__PURE__ */ jsx(
1123
+ Typography,
1124
+ {
1125
+ variant: "pi",
1126
+ textColor: "neutral600",
1127
+ style: { overflowWrap: "anywhere" },
1128
+ children: user.secondary
1129
+ }
1130
+ ) : null
1131
+ ] }),
1132
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", wrap: "wrap", minWidth: 0, children: [
1133
+ /* @__PURE__ */ jsx(Box, { minWidth: 0, flex: "1 1 auto", children: /* @__PURE__ */ jsx(DeviceSummary, { session }) }),
1134
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", style: MONOSPACE, children: /* @__PURE__ */ jsx(ValueOrMissing, { value: session.ipAddress }) })
1135
+ ] }),
1136
+ /* @__PURE__ */ jsx(
1137
+ SessionActions,
1138
+ {
1139
+ layout: "card",
1140
+ session,
1141
+ onView,
1142
+ onEnd,
1143
+ onDelete,
1144
+ mutationPending,
1145
+ focusFallback: getFocusFallback(session.id)
1146
+ }
1147
+ )
1148
+ ] })
1149
+ },
1150
+ session.id
1151
+ );
1152
+ }) });
1153
+ const SearchWrapper = styled(Box)`
1154
+ & button {
1155
+ min-width: 2.4rem;
1156
+ min-height: 2.4rem;
1157
+ justify-content: center;
1158
+ }
1159
+ `;
1160
+ const SEARCH_DEBOUNCE_MS = 300;
1161
+ const SessionSearch = ({ value, onSearch }) => {
1162
+ const { formatMessage } = useIntl();
1163
+ const t = (id, defaultMessage) => formatMessage({ id: getTranslation(id), defaultMessage });
1164
+ const [draft, setDraft] = useState(value);
1165
+ const lastApplied = useRef(value);
1166
+ useEffect(() => {
1167
+ if (value !== lastApplied.current) {
1168
+ lastApplied.current = value;
1169
+ setDraft(value);
1170
+ }
1171
+ }, [value]);
1172
+ useEffect(() => {
1173
+ const next = draft.trim();
1174
+ if (next === lastApplied.current) return void 0;
1175
+ const timer = setTimeout(() => {
1176
+ lastApplied.current = next;
1177
+ onSearch(next);
1178
+ }, SEARCH_DEBOUNCE_MS);
1179
+ return () => clearTimeout(timer);
1180
+ }, [draft, onSearch]);
1181
+ const apply = (next) => {
1182
+ lastApplied.current = next;
1183
+ onSearch(next);
1184
+ };
1185
+ return /* @__PURE__ */ jsx(SearchWrapper, { width: "100%", "data-session-search": "", children: /* @__PURE__ */ jsx(
1186
+ SearchForm,
1187
+ {
1188
+ onSubmit: (event) => {
1189
+ event.preventDefault();
1190
+ apply(draft.trim());
1191
+ },
1192
+ children: /* @__PURE__ */ jsx(
1193
+ Searchbar,
1194
+ {
1195
+ name: "search",
1196
+ value: draft,
1197
+ onChange: (event) => setDraft(event.target.value),
1198
+ onClear: () => {
1199
+ setDraft("");
1200
+ apply("");
1201
+ },
1202
+ clearLabel: t("homepage.search.clear", "Clear search"),
1203
+ placeholder: t("homepage.search.placeholder", "Search user, email, IP or device"),
1204
+ children: t("homepage.search.label", "Search sessions")
1205
+ }
1206
+ )
1207
+ }
1208
+ ) });
1209
+ };
1210
+ const Caret = styled(CaretDown)`
1211
+ transform: rotate(${({ $open }) => $open ? "0deg" : "-90deg"});
1212
+ `;
1213
+ const Legend = styled.ul`
1214
+ display: grid;
1215
+ grid-template-columns: minmax(0, 1fr);
1216
+ gap: ${({ theme }) => theme.spaces[4]};
1217
+ list-style: none;
1218
+ margin: 0;
1219
+ padding: 0;
1220
+
1221
+ /* The page text rhythm spaces stacked list items; grid cells use the gap. */
1222
+ && > li {
1223
+ margin: 0;
1224
+ max-width: none;
1225
+ }
1226
+
1227
+ ${({ theme }) => theme.breakpoints.medium} {
1228
+ grid-template-columns: repeat(3, minmax(0, 1fr));
1229
+ gap: ${({ theme }) => theme.spaces[6]};
1230
+ }
1231
+ `;
1232
+ const HowSessionsWork = () => {
1233
+ const { formatMessage } = useIntl();
1234
+ const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
1235
+ const [open, setOpen] = useState(() => readDisclosureOpen(getBrowserStorage()));
1236
+ const contentId = `how-sessions-work-${useId().replace(/:/g, "")}`;
1237
+ const toggle = () => {
1238
+ setOpen((previous) => {
1239
+ const next = !previous;
1240
+ writeDisclosureOpen(getBrowserStorage(), next);
1241
+ return next;
1242
+ });
1243
+ };
1244
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", gap: 2, "data-how-sessions-work": "", children: [
1245
+ /* @__PURE__ */ jsx(
1246
+ TextButton,
1247
+ {
1248
+ minHeight: "3.2rem",
1249
+ startIcon: /* @__PURE__ */ jsx(Caret, { $open: open, "aria-hidden": true, focusable: false }),
1250
+ "aria-expanded": open,
1251
+ "aria-controls": contentId,
1252
+ onClick: toggle,
1253
+ children: t("homepage.howItWorks.toggle", "How sessions work")
1254
+ }
1255
+ ),
1256
+ /* @__PURE__ */ jsx(
1257
+ Box,
1258
+ {
1259
+ id: contentId,
1260
+ hidden: !open,
1261
+ width: "100%",
1262
+ background: "neutral0",
1263
+ hasRadius: true,
1264
+ shadow: "tableShadow",
1265
+ padding: { initial: 4, medium: 6 },
1266
+ children: open ? /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 4, children: [
1267
+ /* @__PURE__ */ jsx(Legend, { children: SESSION_STATES.map((state) => {
1268
+ const { definition } = SESSION_STATUS_PRESENTATION[state];
1269
+ return /* @__PURE__ */ jsxs(
1270
+ Flex,
1271
+ {
1272
+ tag: "li",
1273
+ direction: "column",
1274
+ alignItems: "flex-start",
1275
+ gap: 2,
1276
+ minWidth: 0,
1277
+ children: [
1278
+ /* @__PURE__ */ jsx(StatusBadge, { status: state, size: "S" }),
1279
+ /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral800", children: formatMessage({
1280
+ id: getTranslation(definition.messageId),
1281
+ defaultMessage: definition.defaultMessage
1282
+ }) })
1283
+ ]
1284
+ },
1285
+ state
1286
+ );
1287
+ }) }),
1288
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t(
1289
+ "homepage.howItWorks.history",
1290
+ "Ended sessions stay in the history until they are deleted."
1291
+ ) })
1292
+ ] }) : null
1293
+ }
1294
+ )
1295
+ ] });
1296
+ };
1297
+ const LOADED_SESSIONS_LIMIT = 1e3;
1298
+ const CLOCK_TICK_MS = 30 * 1e3;
1299
+ const ANALYTICS_PATH = `/settings/${pluginId}/analytics`;
1300
+ const CONFIGURATION_PATH = `/settings/${pluginId}/general`;
1301
+ const PaginationTargets = styled.div`
1302
+ nav a {
1303
+ min-width: 3.2rem;
1304
+ }
1305
+
1306
+ & > div {
1307
+ flex-wrap: wrap;
1308
+ gap: ${({ theme }) => theme.spaces[2]} ${({ theme }) => theme.spaces[4]};
1309
+ }
1310
+
1311
+ & > div > div > span {
1312
+ white-space: nowrap;
1313
+ }
1314
+ `;
1315
+ const downloadFile = (content, type, extension) => {
1316
+ const blob = new Blob([content], { type });
1317
+ const url = URL.createObjectURL(blob);
1318
+ const link = document.createElement("a");
1319
+ link.href = url;
1320
+ link.download = `sessions-export-${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}.${extension}`;
1321
+ link.click();
1322
+ window.setTimeout(() => URL.revokeObjectURL(url), 0);
1323
+ };
1324
+ const HomePage = () => {
1325
+ const { formatMessage } = useIntl();
1326
+ const { get, post, del } = useFetchClient();
1327
+ const { toggleNotification } = useNotification();
1328
+ const formatters = useSessionFormatters();
1329
+ const { isBelowSmall, isBelowMedium, isBelowLarge } = useBreakpoint();
1330
+ const [listWidthRef, listWidth] = useElementWidth();
1331
+ const [{ query }, setQuery] = useQueryParams();
1332
+ const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
1333
+ const dashboard = parseDashboardQuery(query);
1334
+ const [sessions, setSessions] = useState([]);
1335
+ const [truncated, setTruncated] = useState(false);
1336
+ const [loading, setLoading] = useState(true);
1337
+ const [refreshing, setRefreshing] = useState(false);
1338
+ const [loadError, setLoadError] = useState(false);
1339
+ const [hasData, setHasData] = useState(false);
1340
+ const [lastUpdated, setLastUpdated] = useState(null);
1341
+ const [now, setNow] = useState(() => Date.now());
1342
+ const [selectedSession, setSelectedSession] = useState(null);
1343
+ const [showDetailModal, setShowDetailModal] = useState(false);
1344
+ const [terminatingSessionId, setTerminatingSessionId] = useState(null);
1345
+ const [deletingSessionId, setDeletingSessionId] = useState(null);
1346
+ const openerRef = useRef(null);
1347
+ const dashboardRef = useRef(null);
1348
+ const listHeadingRef = useRef(null);
1349
+ const hasLoadedRef = useRef(false);
1350
+ const requestIdRef = useRef(0);
1351
+ const visibleIdsRef = useRef([]);
1352
+ const mutationSnapshotRef = useRef([]);
1353
+ const listHeadingId = `session-list-caption-${useId().replace(/:/g, "")}`;
1354
+ const mutationPending = Boolean(terminatingSessionId || deletingSessionId);
1355
+ useEffect(() => {
1356
+ const timer = setInterval(() => setNow(Date.now()), CLOCK_TICK_MS);
1357
+ return () => clearInterval(timer);
1358
+ }, []);
1359
+ const fetchSessions = useCallback(async () => {
1360
+ const requestId = requestIdRef.current + 1;
1361
+ requestIdRef.current = requestId;
1362
+ if (hasLoadedRef.current) setRefreshing(true);
1363
+ else setLoading(true);
1364
+ try {
1365
+ const { data } = await get(`/${pluginId}/sessions`);
1366
+ const list = requireSessionList(data);
1367
+ if (requestId !== requestIdRef.current) return;
1368
+ setSessions(list);
1369
+ setTruncated(data?.meta?.truncated === true);
1370
+ setLoadError(false);
1371
+ setHasData(true);
1372
+ setLastUpdated(Date.now());
1373
+ setNow(Date.now());
1374
+ hasLoadedRef.current = true;
1375
+ } catch (err) {
1376
+ if (requestId !== requestIdRef.current) return;
1377
+ setLoadError(true);
1378
+ logSafeAdminError("dashboard.loadSessions", err);
1379
+ } finally {
1380
+ if (requestId === requestIdRef.current) {
1381
+ setLoading(false);
1382
+ setRefreshing(false);
1383
+ }
1384
+ }
1385
+ }, [get]);
1386
+ useEffect(() => {
1387
+ fetchSessions();
1388
+ }, [fetchSessions]);
1389
+ useEffect(() => {
1390
+ if (showDetailModal || mutationPending) return void 0;
1391
+ const interval = setInterval(() => {
1392
+ fetchSessions();
1393
+ }, AUTO_REFRESH_INTERVAL_MS);
1394
+ return () => clearInterval(interval);
1395
+ }, [showDetailModal, mutationPending, fetchSessions]);
1396
+ const handleTerminateSession = async (session) => {
1397
+ if (terminatingSessionId || deletingSessionId) return;
1398
+ const sessionId = session.id;
1399
+ mutationSnapshotRef.current = visibleIdsRef.current;
1400
+ setTerminatingSessionId(sessionId);
1401
+ try {
1402
+ await post(`/${pluginId}/sessions/${sessionId}/terminate`);
1403
+ await fetchSessions();
1404
+ toggleNotification({
1405
+ type: "success",
1406
+ message: t("notifications.success.sessionEnded", "Session ended.")
1407
+ });
1408
+ } catch (err) {
1409
+ logSafeAdminError("dashboard.terminateSession", err);
1410
+ if (getErrorStatus(err) === 404) {
1411
+ await fetchSessions();
1412
+ toggleNotification({
1413
+ type: "warning",
1414
+ message: t(
1415
+ "notifications.error.sessionGone",
1416
+ "This session no longer exists. The list was refreshed."
1417
+ )
1418
+ });
1419
+ return;
1420
+ }
1421
+ toggleNotification({
1422
+ type: "danger",
1423
+ message: t(
1424
+ "notifications.error.endSession",
1425
+ "The session could not be ended. Please try again."
1426
+ )
1427
+ });
1428
+ throw err;
1429
+ } finally {
1430
+ setTerminatingSessionId(null);
1431
+ }
1432
+ };
1433
+ const handleDeleteSession = async (session) => {
1434
+ if (terminatingSessionId || deletingSessionId) return;
1435
+ const sessionId = session.id;
1436
+ mutationSnapshotRef.current = visibleIdsRef.current;
1437
+ setDeletingSessionId(sessionId);
1438
+ try {
1439
+ await del(`/${pluginId}/sessions/${sessionId}`);
1440
+ await fetchSessions();
1441
+ toggleNotification({
1442
+ type: "success",
1443
+ message: t(
1444
+ "notifications.success.recordDeleted",
1445
+ "Session record deleted. Its token stays revoked."
1446
+ )
1447
+ });
1448
+ } catch (err) {
1449
+ logSafeAdminError("dashboard.deleteSession", err);
1450
+ if (getErrorStatus(err) === 404) {
1451
+ await fetchSessions();
1452
+ toggleNotification({
1453
+ type: "warning",
1454
+ message: t(
1455
+ "notifications.error.sessionGone",
1456
+ "This session no longer exists. The list was refreshed."
1457
+ )
1458
+ });
1459
+ return;
1460
+ }
1461
+ toggleNotification({
1462
+ type: "danger",
1463
+ message: t(
1464
+ "notifications.error.deleteRecord",
1465
+ "The record could not be deleted. Please try again."
1466
+ )
1467
+ });
1468
+ throw err;
1469
+ } finally {
1470
+ setDeletingSessionId(null);
1471
+ }
1472
+ };
1473
+ const filteredSessions = useMemo(
1474
+ () => filterSessionsBySearch(
1475
+ filterSessionsByStatus(sessions, dashboard.status, dashboard.reason),
1476
+ dashboard.search,
1477
+ formatters.deviceTypeLabel
1478
+ ),
1479
+ [sessions, dashboard.status, dashboard.reason, dashboard.search, formatters]
1480
+ );
1481
+ const pageResult = paginateSessions(filteredSessions, dashboard.page, dashboard.pageSize);
1482
+ const visibleIds = pageResult.items.map((session) => String(session.id));
1483
+ useLayoutEffect(() => {
1484
+ visibleIdsRef.current = visibleIds;
1485
+ });
1486
+ const handleExportCSV = () => {
1487
+ try {
1488
+ const csvContent = buildSessionCsv(filteredSessions, {
1489
+ unavailableValue: "",
1490
+ getDeviceInfo: getExportDeviceInfo,
1491
+ getSessionStatus
1492
+ });
1493
+ downloadFile(csvContent, "text/csv;charset=utf-8;", "csv");
1494
+ } catch (err) {
1495
+ logSafeAdminError("dashboard.exportCsv", err);
1496
+ toggleNotification({
1497
+ type: "danger",
1498
+ message: t("notifications.error.exportFailed", "The export could not be created.")
1499
+ });
1500
+ }
1501
+ };
1502
+ const handleExportJSON = () => {
1503
+ try {
1504
+ const jsonContent = buildSessionJson(filteredSessions, {
1505
+ filterStatus: dashboard.status,
1506
+ totalSessions: sessions.length,
1507
+ exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
1508
+ unavailableValue: "",
1509
+ getDeviceInfo: getExportDeviceInfo,
1510
+ getSessionStatus,
1511
+ truncated
1512
+ });
1513
+ downloadFile(jsonContent, "application/json", "json");
1514
+ } catch (err) {
1515
+ logSafeAdminError("dashboard.exportJson", err);
1516
+ toggleNotification({
1517
+ type: "danger",
1518
+ message: t("notifications.error.exportFailed", "The export could not be created.")
1519
+ });
1520
+ }
1521
+ };
1522
+ const handleSessionClick = (session, opener) => {
1523
+ openerRef.current = opener;
1524
+ setSelectedSession(session);
1525
+ setShowDetailModal(true);
1526
+ };
1527
+ const handleModalClose = () => {
1528
+ setShowDetailModal(false);
1529
+ setSelectedSession(null);
1530
+ };
1531
+ const handleCloseAutoFocus = (event) => {
1532
+ restoreDialogFocus(event, openerRef.current, listHeadingRef.current || dashboardRef.current);
1533
+ };
1534
+ const getFocusFallback = useCallback(
1535
+ (sessionId) => ({
1536
+ get current() {
1537
+ const targetId = pickFocusSessionId(
1538
+ mutationSnapshotRef.current,
1539
+ visibleIdsRef.current,
1540
+ sessionId
1541
+ );
1542
+ const root = dashboardRef.current;
1543
+ if (targetId && root) {
1544
+ const escaped = typeof CSS !== "undefined" && CSS.escape ? CSS.escape(targetId) : targetId;
1545
+ const button = root.querySelector(`[data-session-view="${escaped}"]`);
1546
+ if (button) return button;
1547
+ }
1548
+ return listHeadingRef.current;
1549
+ }
1550
+ }),
1551
+ []
1552
+ );
1553
+ useEffect(() => {
1554
+ if (!loading && dashboard.page > pageResult.pageCount) {
1555
+ setQuery({ page: String(pageResult.pageCount) }, "push", true);
1556
+ }
1557
+ }, [loading, dashboard.page, pageResult.pageCount, setQuery]);
1558
+ const handleStatusChange = (value) => {
1559
+ const status = String(value);
1560
+ setQuery({ status: status === "all" ? void 0 : status, reason: void 0, page: "1" });
1561
+ };
1562
+ const handleReasonChange = (value) => {
1563
+ const reason = String(value);
1564
+ setQuery({ reason: reason === "all" ? void 0 : reason, page: "1" });
1565
+ };
1566
+ const handleSearch = useCallback(
1567
+ (value) => {
1568
+ setQuery({ search: encodeSearchQuery(value), _q: void 0, page: "1" }, "push", true);
1569
+ },
1570
+ [setQuery]
1571
+ );
1572
+ const handleClearFilters = () => {
1573
+ setQuery({ search: void 0, _q: void 0, status: void 0, reason: void 0, page: "1" });
1574
+ listHeadingRef.current?.focus();
1575
+ };
1576
+ const stats = getSessionStats(sessions);
1577
+ const showSessionData = !loading && hasData;
1578
+ const showToolbar = showSessionData && sessions.length > 0;
1579
+ const canExport = showSessionData && filteredSessions.length > 0;
1580
+ const filtersActive = hasActiveFilters(dashboard);
1581
+ const exportValues = { count: filteredSessions.length, limit: LOADED_SESSIONS_LIMIT };
1582
+ const exportMenu = /* @__PURE__ */ jsxs(
1583
+ SimpleMenu,
1584
+ {
1585
+ label: t("homepage.export.label", "Export"),
1586
+ variant: "secondary",
1587
+ startIcon: /* @__PURE__ */ jsx(Download, {}),
1588
+ disabled: !canExport,
1589
+ children: [
1590
+ /* @__PURE__ */ jsx(MenuItem, { onSelect: handleExportCSV, children: truncated ? t(
1591
+ "homepage.export.csvTruncated",
1592
+ "{count, plural, one {Export # session as CSV} other {Export # sessions as CSV}} (latest {limit, number} sessions only)",
1593
+ exportValues
1594
+ ) : t(
1595
+ "homepage.export.csv",
1596
+ "{count, plural, one {Export # session as CSV} other {Export # sessions as CSV}}",
1597
+ exportValues
1598
+ ) }),
1599
+ /* @__PURE__ */ jsx(MenuItem, { onSelect: handleExportJSON, children: truncated ? t(
1600
+ "homepage.export.jsonTruncated",
1601
+ "{count, plural, one {Export # session as JSON} other {Export # sessions as JSON}} (latest {limit, number} sessions only)",
1602
+ exportValues
1603
+ ) : t(
1604
+ "homepage.export.json",
1605
+ "{count, plural, one {Export # session as JSON} other {Export # sessions as JSON}}",
1606
+ exportValues
1607
+ ) })
1608
+ ]
1609
+ }
1610
+ );
1611
+ const exportAction = canExport || !showSessionData ? exportMenu : /* @__PURE__ */ jsx(Tooltip, { label: t("homepage.export.disabledHint", "No sessions match the current filter."), children: /* @__PURE__ */ jsx("span", { children: exportMenu }) });
1612
+ const analyticsLabel = t("homepage.links.analytics", "Analytics");
1613
+ const settingsLabel = t("homepage.links.settings", "Settings");
1614
+ const primaryAction = /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", justifyContent: "flex-end", children: [
1615
+ isBelowSmall ? /* @__PURE__ */ jsx(IconButton, { tag: Link$1, to: ANALYTICS_PATH, label: analyticsLabel, variant: "tertiary", children: /* @__PURE__ */ jsx(ChartBubble, {}) }) : /* @__PURE__ */ jsx(
1616
+ LinkButton,
1617
+ {
1618
+ tag: Link$1,
1619
+ to: ANALYTICS_PATH,
1620
+ variant: "tertiary",
1621
+ size: "S",
1622
+ startIcon: /* @__PURE__ */ jsx(ChartBubble, {}),
1623
+ children: analyticsLabel
1624
+ }
1625
+ ),
1626
+ isBelowSmall ? /* @__PURE__ */ jsx(IconButton, { tag: Link$1, to: CONFIGURATION_PATH, label: settingsLabel, variant: "tertiary", children: /* @__PURE__ */ jsx(Cog, {}) }) : /* @__PURE__ */ jsx(
1627
+ LinkButton,
1628
+ {
1629
+ tag: Link$1,
1630
+ to: CONFIGURATION_PATH,
1631
+ variant: "tertiary",
1632
+ size: "S",
1633
+ startIcon: /* @__PURE__ */ jsx(Cog, {}),
1634
+ children: settingsLabel
1635
+ }
1636
+ ),
1637
+ exportAction
1638
+ ] });
1639
+ const filterSlot = isBelowMedium ? { flex: "1 1 auto", minWidth: 0 } : void 0;
1640
+ const filterControls = /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", wrap: isBelowMedium ? "nowrap" : "wrap", shrink: 0, children: [
1641
+ /* @__PURE__ */ jsx(Box, { ...filterSlot, children: /* @__PURE__ */ jsx(
1642
+ SingleSelect,
1643
+ {
1644
+ size: "S",
1645
+ "aria-label": t("homepage.filter.label", "Status"),
1646
+ value: dashboard.status,
1647
+ onChange: handleStatusChange,
1648
+ children: SESSION_FILTER_OPTIONS.map((option) => /* @__PURE__ */ jsxs(SingleSelectOption, { value: option, children: [
1649
+ option === "all" && t("homepage.filter.all", "All sessions"),
1650
+ option === "open" && t("homepage.filter.open", "Open"),
1651
+ option !== "all" && option !== "open" && formatters.statusLabel(option)
1652
+ ] }, option))
1653
+ }
1654
+ ) }),
1655
+ dashboard.status === "ended" ? /* @__PURE__ */ jsx(Box, { ...filterSlot, children: /* @__PURE__ */ jsx(
1656
+ SingleSelect,
1657
+ {
1658
+ size: "S",
1659
+ "aria-label": t("homepage.filter.reasonLabel", "End reason"),
1660
+ value: dashboard.reason,
1661
+ onChange: handleReasonChange,
1662
+ children: END_REASON_FILTER_OPTIONS.map((option) => /* @__PURE__ */ jsx(SingleSelectOption, { value: option, children: option === "all" ? t("homepage.filter.allReasons", "All reasons") : formatters.endReasonLabel(option) }, option))
1663
+ }
1664
+ ) }) : null,
1665
+ /* @__PURE__ */ jsx(
1666
+ IconButton,
1667
+ {
1668
+ label: t("homepage.actions.refresh", "Refresh sessions"),
1669
+ onClick: () => fetchSessions(),
1670
+ children: /* @__PURE__ */ jsx(ArrowClockwise, {})
1671
+ }
1672
+ )
1673
+ ] });
1674
+ const toolbar = /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, "data-session-toolbar": "", children: /* @__PURE__ */ jsxs(
1675
+ Flex,
1676
+ {
1677
+ direction: { initial: "column", medium: "row" },
1678
+ alignItems: { initial: "stretch", medium: "center" },
1679
+ gap: 2,
1680
+ children: [
1681
+ /* @__PURE__ */ jsx(Flex, { flex: "1 1 auto", minWidth: 0, direction: "column", alignItems: "stretch", children: /* @__PURE__ */ jsx(SessionSearch, { value: dashboard.search, onSearch: handleSearch }) }),
1682
+ filterControls
1683
+ ]
1684
+ }
1685
+ ) });
1686
+ const lastUpdatedLine = lastUpdated ? /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", wrap: "wrap", justifyContent: "flex-end", children: [
1687
+ refreshing ? /* @__PURE__ */ jsx(Loader, { small: true, role: "status", "aria-live": "polite", children: t("homepage.refreshing", "Updating sessions") }) : null,
1688
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", "data-last-updated": "", children: t("homepage.lastUpdated", "Last updated {time}", {
1689
+ time: formatters.formatRelativeTime(lastUpdated, now)
1690
+ }) })
1691
+ ] }) : null;
1692
+ const listProps = {
1693
+ sessions: pageResult.items,
1694
+ labelledBy: listHeadingId,
1695
+ busy: refreshing,
1696
+ onView: handleSessionClick,
1697
+ onEnd: handleTerminateSession,
1698
+ onDelete: handleDeleteSession,
1699
+ mutationPending,
1700
+ getFocusFallback
1701
+ };
1702
+ const statusCard = (status) => ({
1703
+ onClick: () => handleStatusChange(status),
1704
+ pressed: dashboard.status === status
1705
+ });
1706
+ return /* @__PURE__ */ jsx(
1707
+ PageShell,
1708
+ {
1709
+ headingId: "magic-sessionmanager-dashboard-title",
1710
+ title: t("homepage.title", "Sessions"),
1711
+ subtitle: t(
1712
+ "homepage.subtitle",
1713
+ "Sign-ins of your app’s users (Users & Permissions). Strapi administrators are not listed."
1714
+ ),
1715
+ primaryAction,
1716
+ children: /* @__PURE__ */ jsxs(
1717
+ Flex,
1718
+ {
1719
+ ref: dashboardRef,
1720
+ tabIndex: -1,
1721
+ direction: "column",
1722
+ alignItems: "stretch",
1723
+ gap: 6,
1724
+ minWidth: 0,
1725
+ children: [
1726
+ !loading && loadError ? /* @__PURE__ */ jsx(
1727
+ PersistentAlert,
1728
+ {
1729
+ variant: "danger",
1730
+ closeLabel: t("common.close", "Close"),
1731
+ action: /* @__PURE__ */ jsx(Button, { size: "S", variant: "secondary", onClick: fetchSessions, children: t("common.tryAgain", "Try again") }),
1732
+ children: /* @__PURE__ */ jsx(ReadableText, { variant: "omega", textColor: "neutral800", tag: "span", children: t("homepage.error.load", "Sessions could not be loaded.") })
1733
+ }
1734
+ ) : null,
1735
+ showSessionData && truncated ? /* @__PURE__ */ jsx(PersistentAlert, { variant: "default", closeLabel: t("common.close", "Close"), children: /* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral700", tag: "span", children: t(
1736
+ "homepage.truncated.body",
1737
+ "Only the latest {limit, number} sessions are loaded. Counts, filters and exports cover these sessions only.",
1738
+ { limit: LOADED_SESSIONS_LIMIT }
1739
+ ) }) }) : null,
1740
+ loading ? /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 8, children: /* @__PURE__ */ jsx(Loader, { children: t("homepage.loading", "Loading sessions") }) }) : null,
1741
+ showSessionData && sessions.length > 0 ? /* @__PURE__ */ jsx(HowSessionsWork, {}) : null,
1742
+ showSessionData && /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
1743
+ /* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx(Typography, { tag: "h2", children: t("homepage.stats.label", "Session statistics") }) }),
1744
+ /* @__PURE__ */ jsxs(StatGrid, { label: t("homepage.stats.label", "Session statistics"), children: [
1745
+ /* @__PURE__ */ jsx(
1746
+ StatCard,
1747
+ {
1748
+ icon: Check,
1749
+ tone: "success",
1750
+ label: t("homepage.stats.active", "Active sessions"),
1751
+ value: stats.active,
1752
+ description: t(
1753
+ "homepage.stats.usersOnline",
1754
+ "{count, plural, one {# user online} other {# users online}}",
1755
+ {
1756
+ count: stats.usersOnline
1757
+ }
1758
+ ),
1759
+ ...statusCard("active")
1760
+ }
1761
+ ),
1762
+ /* @__PURE__ */ jsx(
1763
+ StatCard,
1764
+ {
1765
+ icon: Clock,
1766
+ tone: "warning",
1767
+ label: t("homepage.stats.idle", "Idle sessions"),
1768
+ value: stats.idle,
1769
+ ...statusCard("idle")
1770
+ }
1771
+ ),
1772
+ /* @__PURE__ */ jsx(
1773
+ StatCard,
1774
+ {
1775
+ icon: Cross,
1776
+ tone: "neutral",
1777
+ label: t("homepage.stats.ended", "Ended sessions"),
1778
+ value: stats.ended,
1779
+ description: t(
1780
+ "homepage.stats.endedBreakdown",
1781
+ "{loggedOut, number} logged out · {timedOut, number} timed out · {other, number} other reasons",
1782
+ {
1783
+ loggedOut: stats.loggedOut,
1784
+ timedOut: stats.timedOut,
1785
+ other: stats.otherReasons
1786
+ }
1787
+ ),
1788
+ ...statusCard("ended")
1789
+ }
1790
+ ),
1791
+ /* @__PURE__ */ jsx(
1792
+ StatCard,
1793
+ {
1794
+ icon: User,
1795
+ tone: "primary",
1796
+ label: t("homepage.stats.total", "All sessions"),
1797
+ value: stats.total,
1798
+ ...statusCard("all")
1799
+ }
1800
+ )
1801
+ ] })
1802
+ ] }),
1803
+ showToolbar && /* @__PURE__ */ jsxs(Flex, { ref: listWidthRef, direction: "column", alignItems: "stretch", gap: 4, minWidth: 0, children: [
1804
+ /* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx(Typography, { variant: "delta", tag: "h2", children: t("homepage.list.heading", "Session list") }) }),
1805
+ toolbar,
1806
+ /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", gap: 4, wrap: "wrap", children: [
1807
+ /* @__PURE__ */ jsx(
1808
+ Typography,
1809
+ {
1810
+ id: listHeadingId,
1811
+ ref: listHeadingRef,
1812
+ tabIndex: -1,
1813
+ variant: "pi",
1814
+ textColor: "neutral600",
1815
+ "aria-live": "polite",
1816
+ "data-session-caption": "",
1817
+ children: pageResult.total > 0 ? t(
1818
+ "homepage.caption",
1819
+ "{from, number}–{to, number} of {total, plural, one {# session} other {# sessions}}",
1820
+ {
1821
+ from: pageResult.startIndex,
1822
+ to: pageResult.endIndex,
1823
+ total: pageResult.total
1824
+ }
1825
+ ) : t("homepage.captionNone", "0 sessions")
1826
+ }
1827
+ ),
1828
+ lastUpdatedLine
1829
+ ] }),
1830
+ filteredSessions.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
1831
+ isBelowMedium ? /* @__PURE__ */ jsx(SessionCardList, { ...listProps }) : /* @__PURE__ */ jsx(
1832
+ SessionTable,
1833
+ {
1834
+ ...listProps,
1835
+ compact: shouldUseCompactTable(listWidth, isBelowLarge)
1836
+ }
1837
+ ),
1838
+ /* @__PURE__ */ jsx(PaginationTargets, { children: /* @__PURE__ */ jsxs(
1839
+ Pagination.Root,
1840
+ {
1841
+ pageCount: pageResult.pageCount,
1842
+ total: pageResult.total,
1843
+ defaultPageSize: Number(DEFAULT_PAGE_SIZE),
1844
+ children: [
1845
+ /* @__PURE__ */ jsx(Pagination.PageSize, { options: [...PAGE_SIZE_OPTIONS] }),
1846
+ /* @__PURE__ */ jsx(Pagination.Links, {})
1847
+ ]
1848
+ }
1849
+ ) })
1850
+ ] }) : /* @__PURE__ */ jsx(
1851
+ EmptyStateLayout,
1852
+ {
1853
+ icon: /* @__PURE__ */ jsx(EmptyDocuments, { width: "16rem", height: "8.8rem", "aria-hidden": "true" }),
1854
+ content: t(
1855
+ "homepage.noResults.description",
1856
+ "No sessions match your search or filter."
1857
+ ),
1858
+ action: filtersActive ? /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: handleClearFilters, children: t("homepage.noResults.reset", "Clear filters") }) : null
1859
+ }
1860
+ )
1861
+ ] }),
1862
+ showSessionData && sessions.length === 0 && /* @__PURE__ */ jsx(
1863
+ EmptyStateLayout,
1864
+ {
1865
+ icon: /* @__PURE__ */ jsx(EmptyDocuments, { width: "16rem", height: "8.8rem", "aria-hidden": "true" }),
1866
+ content: t(
1867
+ "homepage.empty.description",
1868
+ "No sessions yet. Sessions appear here when users of your app sign in."
1869
+ )
1870
+ }
1871
+ ),
1872
+ showDetailModal && selectedSession && /* @__PURE__ */ jsx(
1873
+ SessionDetailModal,
1874
+ {
1875
+ session: selectedSession,
1876
+ now,
1877
+ onClose: handleModalClose,
1878
+ onCloseAutoFocus: handleCloseAutoFocus,
1879
+ onEndSession: handleTerminateSession
1880
+ }
1881
+ )
1882
+ ]
1883
+ }
1884
+ )
1885
+ }
1886
+ );
1887
+ };
1888
+ const LicenseGuard = ({ children }) => /* @__PURE__ */ jsx(Fragment, { children });
1889
+ const App = () => {
1890
+ return /* @__PURE__ */ jsx(Page.Protect, { permissions: pluginPermissions.access, children: /* @__PURE__ */ jsx(LicenseGuard, { children: /* @__PURE__ */ jsx(HomePage, {}) }) });
1891
+ };
1892
+ export {
1893
+ App as default
1894
+ };