strapi-plugin-magic-sessionmanager 4.11.0 → 4.13.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.
- package/CHANGELOG.md +84 -1
- package/README.md +75 -24
- package/dist/admin/{Analytics-CBHeWeGn.js → Analytics-BikQQx_J.js} +45 -75
- package/dist/admin/{Analytics-D56O8Q6e.mjs → Analytics-DIY51RI_.mjs} +45 -75
- package/dist/admin/{App-EDIkLJdb.mjs → App-B3vaybSO.mjs} +584 -120
- package/dist/admin/{App-D4cBPwB_.js → App-BV1LM9Bp.js} +584 -120
- package/dist/admin/{OnlineUsersWidget-MwUutkKQ.mjs → OnlineUsersWidget-T-2upsDd.mjs} +18 -26
- package/dist/admin/{OnlineUsersWidget-BF2R2YIy.js → OnlineUsersWidget-fJogM1xl.js} +18 -26
- package/dist/admin/{Settings-CMzEF8EH.js → Settings-AyYka8wn.js} +1 -1
- package/dist/admin/{Settings-bLMyi0BN.mjs → Settings-BpBlXyMY.mjs} +1 -1
- package/dist/admin/{de-CxfuTF6C.mjs → de-BSCDuq1i.mjs} +41 -6
- package/dist/admin/{de-DVNTHmSo.js → de-z0aHRwdw.js} +41 -6
- package/dist/admin/{en-BcPIlQYL.mjs → en-B4Cuq9JN.mjs} +41 -6
- package/dist/admin/{en-BuVXIcHA.js → en-BWPOiiMt.js} +41 -6
- package/dist/admin/{es-CEteHmBO.js → es-CMskkUh-.js} +41 -6
- package/dist/admin/{es-DxHpaNA1.mjs → es-DBAmysKi.mjs} +41 -6
- package/dist/admin/{fr-Dw43lHg7.mjs → fr-BNGdtjEl.mjs} +41 -6
- package/dist/admin/{fr-BMd2-wW7.js → fr-ClJ2BkrE.js} +41 -6
- package/dist/admin/{index-DvNfekoR.js → index-DyE1rLW0.js} +22 -56
- package/dist/admin/{index-qa6Qnfkc.mjs → index-mCVi1j7e.mjs} +48 -82
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/admin/{pt-BvO63p01.js → pt-CRh_J7JS.js} +41 -6
- package/dist/admin/{pt-7jnxDSX-.mjs → pt-Cl7TWsOV.mjs} +41 -6
- package/dist/server/index.js +1495 -51
- package/dist/server/index.mjs +1495 -51
- package/package.json +10 -2
- package/pics/untracked-confirm-dialog.webp +0 -0
- package/pics/untracked-disclosure-warning-dark.webp +0 -0
- package/pics/untracked-disclosure-warning.webp +0 -0
- package/pics/untracked-mobile-notice-warning.webp +0 -0
- package/pics/untracked-notice-neutral.webp +0 -0
|
@@ -7,7 +7,7 @@ import { Typography, Flex, Loader, Button, Modal, Accordion, Box, IconButton, Li
|
|
|
7
7
|
import { Earth, Duplicate, Cross, Eye, Trash, More, CaretDown, Download, ArrowClockwise, Check, Clock, User, ChartBubble, Cog } from "@strapi/icons";
|
|
8
8
|
import { EmptyDocuments } from "@strapi/icons/symbols";
|
|
9
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
|
|
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 getDevicePresentation, u as useSessionFormatters, f as getSessionStatus, h as isNativeOnlySession, j as getSessionEndReasonPresentation, k as DeviceIcon, S as StatusBadge, P as PropertyList, C as ConfirmAction, t as toValidDate, l as pluginId, m as logSafeAdminError, n as PersistentAlert, R as ReadableText, M as MissingValue, V as ValueOrMissing, o as SESSION_STATES, q as SESSION_STATUS_PRESENTATION, r as isCancelledRequest, s as SESSION_FILTER_OPTIONS, E as END_REASON_FILTER_OPTIONS, v as PageShell, w as StatGrid, x as StatCard, y as restoreDialogFocus, z as requireSessionList, A as pluginPermissions } from "./index-mCVi1j7e.mjs";
|
|
11
11
|
const EndReason = ({ session, reason, variant = "omega", textColor = "neutral800" }) => {
|
|
12
12
|
const { formatMessage } = useIntl();
|
|
13
13
|
const key = reason || getSessionEndReason(session);
|
|
@@ -19,27 +19,76 @@ const EndReason = ({ session, reason, variant = "omega", textColor = "neutral800
|
|
|
19
19
|
});
|
|
20
20
|
return /* @__PURE__ */ jsx(Typography, { variant, textColor, "data-end-reason": presentation.reason, children: translate(presentation) });
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
const MAX_EXPORT_ROWS = 5e4;
|
|
23
|
+
const EXPORT_BATCH_SIZE = 1e3;
|
|
24
|
+
const EMPTY_SESSION_STATS = Object.freeze({
|
|
25
|
+
total: 0,
|
|
26
|
+
open: 0,
|
|
27
|
+
active: 0,
|
|
28
|
+
idle: 0,
|
|
29
|
+
ended: 0,
|
|
30
|
+
loggedOut: 0,
|
|
31
|
+
timedOut: 0,
|
|
32
|
+
otherReasons: 0,
|
|
33
|
+
usersOnline: 0,
|
|
34
|
+
nativeOnly: 0,
|
|
35
|
+
nativeOnlyAfterTracking: null
|
|
36
|
+
});
|
|
37
|
+
const COUNT_KEYS = Object.freeze(
|
|
38
|
+
Object.keys(EMPTY_SESSION_STATS).filter((key) => key !== "nativeOnlyAfterTracking")
|
|
39
|
+
);
|
|
40
|
+
function filterParams(query) {
|
|
41
|
+
const params = {};
|
|
42
|
+
if (query.status && query.status !== "all") params.status = query.status;
|
|
43
|
+
if (query.status === "ended" && query.reason && query.reason !== "all") {
|
|
44
|
+
params.reason = query.reason;
|
|
45
|
+
}
|
|
46
|
+
const search = typeof query.search === "string" ? query.search.trim().slice(0, 100) : "";
|
|
47
|
+
if (search) params.search = search;
|
|
48
|
+
return params;
|
|
49
|
+
}
|
|
50
|
+
function buildListParams(query) {
|
|
51
|
+
return {
|
|
52
|
+
page: String(Math.max(1, Number(query.page) || 1)),
|
|
53
|
+
pageSize: String(query.pageSize),
|
|
54
|
+
...filterParams(query)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function buildExportParams(query, cursor) {
|
|
58
|
+
return {
|
|
59
|
+
limit: String(EXPORT_BATCH_SIZE),
|
|
60
|
+
...filterParams(query),
|
|
61
|
+
...cursor ? { cursor } : {}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const isCount$1 = (value) => Number.isInteger(value) && value >= 0;
|
|
65
|
+
function readSessionPage(payload) {
|
|
66
|
+
const body = (
|
|
67
|
+
/** @type {any} */
|
|
68
|
+
payload
|
|
32
69
|
);
|
|
33
|
-
const
|
|
70
|
+
const pagination = body?.meta?.pagination;
|
|
71
|
+
if (!Array.isArray(body?.data) || !isCount$1(pagination?.total) || !isCount$1(pagination?.pageCount)) {
|
|
72
|
+
throw new Error("Invalid session page response");
|
|
73
|
+
}
|
|
34
74
|
return {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
pageCount,
|
|
38
|
-
startIndex: total === 0 ? 0 : offset + 1,
|
|
39
|
-
endIndex: Math.min(total, offset + normalizedSize),
|
|
40
|
-
total
|
|
75
|
+
rows: body.data,
|
|
76
|
+
pagination: { total: pagination.total, pageCount: Math.max(1, pagination.pageCount) }
|
|
41
77
|
};
|
|
42
78
|
}
|
|
79
|
+
function readSessionStats(payload) {
|
|
80
|
+
const data = (
|
|
81
|
+
/** @type {any} */
|
|
82
|
+
payload?.data
|
|
83
|
+
);
|
|
84
|
+
const stats = { ...EMPTY_SESSION_STATS };
|
|
85
|
+
for (const key of COUNT_KEYS) {
|
|
86
|
+
if (!isCount$1(data?.[key])) throw new Error("Invalid session statistics response");
|
|
87
|
+
stats[key] = data[key];
|
|
88
|
+
}
|
|
89
|
+
stats.nativeOnlyAfterTracking = isCount$1(data?.nativeOnlyAfterTracking) ? data.nativeOnlyAfterTracking : null;
|
|
90
|
+
return stats;
|
|
91
|
+
}
|
|
43
92
|
const CSV_HEADERS = Object.freeze([
|
|
44
93
|
"ID",
|
|
45
94
|
"Status",
|
|
@@ -55,7 +104,12 @@ const CSV_HEADERS = Object.freeze([
|
|
|
55
104
|
"Minutes Idle",
|
|
56
105
|
"End Reason"
|
|
57
106
|
]);
|
|
58
|
-
const
|
|
107
|
+
const FORMULA_START = /^[=+\-@\t\r]/;
|
|
108
|
+
const escapeCsvValue = (value) => {
|
|
109
|
+
const text = String(value ?? "");
|
|
110
|
+
const safe = typeof value === "string" && FORMULA_START.test(text) ? `'${text}` : text;
|
|
111
|
+
return `"${safe.replace(/"/g, '""')}"`;
|
|
112
|
+
};
|
|
59
113
|
function toIsoTimestamp(value) {
|
|
60
114
|
if (value === null || value === void 0 || value === "") return "";
|
|
61
115
|
const date = value instanceof Date ? value : new Date(
|
|
@@ -326,39 +380,6 @@ function hasActiveFilters(state) {
|
|
|
326
380
|
if (!state) return false;
|
|
327
381
|
return state.status !== DEFAULT_SESSION_FILTER || Boolean(state.reason) && state.reason !== DEFAULT_END_REASON_FILTER || Boolean(state.search);
|
|
328
382
|
}
|
|
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
383
|
function getSessionUserLabels(session) {
|
|
363
384
|
const username = presentText(session?.user?.username);
|
|
364
385
|
const email = presentText(session?.user?.email);
|
|
@@ -1207,7 +1228,7 @@ const SessionSearch = ({ value, onSearch }) => {
|
|
|
1207
1228
|
}
|
|
1208
1229
|
) });
|
|
1209
1230
|
};
|
|
1210
|
-
const Caret = styled(CaretDown)`
|
|
1231
|
+
const Caret$1 = styled(CaretDown)`
|
|
1211
1232
|
transform: rotate(${({ $open }) => $open ? "0deg" : "-90deg"});
|
|
1212
1233
|
`;
|
|
1213
1234
|
const Legend = styled.ul`
|
|
@@ -1246,7 +1267,7 @@ const HowSessionsWork = () => {
|
|
|
1246
1267
|
TextButton,
|
|
1247
1268
|
{
|
|
1248
1269
|
minHeight: "3.2rem",
|
|
1249
|
-
startIcon: /* @__PURE__ */ jsx(Caret, { $open: open, "aria-hidden": true, focusable: false }),
|
|
1270
|
+
startIcon: /* @__PURE__ */ jsx(Caret$1, { $open: open, "aria-hidden": true, focusable: false }),
|
|
1250
1271
|
"aria-expanded": open,
|
|
1251
1272
|
"aria-controls": contentId,
|
|
1252
1273
|
onClick: toggle,
|
|
@@ -1288,13 +1309,424 @@ const HowSessionsWork = () => {
|
|
|
1288
1309
|
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t(
|
|
1289
1310
|
"homepage.howItWorks.history",
|
|
1290
1311
|
"Ended sessions stay in the history until they are deleted."
|
|
1312
|
+
) }),
|
|
1313
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t(
|
|
1314
|
+
"homepage.howItWorks.untracked",
|
|
1315
|
+
"Strapi also keeps its own list of sign-ins (refresh tokens). A sign-in that has no session details here, for example one from before this plugin tracked sessions, is not in this list and is never counted as active or online. A notice above the cards shows how many there are and why."
|
|
1291
1316
|
) })
|
|
1292
1317
|
] }) : null
|
|
1293
1318
|
}
|
|
1294
1319
|
)
|
|
1295
1320
|
] });
|
|
1296
1321
|
};
|
|
1297
|
-
const
|
|
1322
|
+
const UNTRACKED_SUMMARY_PATH = "/magic-sessionmanager/sessions/native-only/summary";
|
|
1323
|
+
const UNTRACKED_END_PATH = "/magic-sessionmanager/sessions/native-only/end";
|
|
1324
|
+
const isCount = (value) => Number.isInteger(value) && value >= 0;
|
|
1325
|
+
function untrackedTone(stats) {
|
|
1326
|
+
return isCount(stats?.nativeOnlyAfterTracking) && stats.nativeOnlyAfterTracking > 0 ? "warning" : "neutral";
|
|
1327
|
+
}
|
|
1328
|
+
function readUntrackedSummary(payload) {
|
|
1329
|
+
const data = (
|
|
1330
|
+
/** @type {any} */
|
|
1331
|
+
payload?.data
|
|
1332
|
+
);
|
|
1333
|
+
const fail = () => {
|
|
1334
|
+
throw new Error("Invalid untracked session summary");
|
|
1335
|
+
};
|
|
1336
|
+
if (!data || typeof data !== "object") fail();
|
|
1337
|
+
const counts = [
|
|
1338
|
+
data.total,
|
|
1339
|
+
data.beforeTracking,
|
|
1340
|
+
data.afterTracking,
|
|
1341
|
+
data.earlier,
|
|
1342
|
+
data.bySource?.signIn,
|
|
1343
|
+
data.bySource?.passwordChange,
|
|
1344
|
+
data.bySource?.tokenOnly,
|
|
1345
|
+
data.byDevice?.desktop,
|
|
1346
|
+
data.byDevice?.mobile,
|
|
1347
|
+
data.byDevice?.unknown,
|
|
1348
|
+
data.deviceSample?.scanned,
|
|
1349
|
+
data.deviceSample?.limit,
|
|
1350
|
+
data.expiring?.within7Days,
|
|
1351
|
+
data.expiring?.within30Days
|
|
1352
|
+
];
|
|
1353
|
+
if (!counts.every(isCount)) fail();
|
|
1354
|
+
if (!Array.isArray(data.byMonth)) fail();
|
|
1355
|
+
const byMonth = data.byMonth.filter(
|
|
1356
|
+
(entry) => typeof entry?.month === "string" && /^\d{4}-\d{2}$/.test(entry.month)
|
|
1357
|
+
);
|
|
1358
|
+
if (!byMonth.every((entry) => isCount(entry.count))) fail();
|
|
1359
|
+
const since = typeof data.trackingSince === "string" ? new Date(data.trackingSince) : null;
|
|
1360
|
+
return {
|
|
1361
|
+
total: data.total,
|
|
1362
|
+
trackingSince: since && Number.isFinite(since.getTime()) ? since : null,
|
|
1363
|
+
beforeTracking: data.beforeTracking,
|
|
1364
|
+
afterTracking: data.afterTracking,
|
|
1365
|
+
byMonth,
|
|
1366
|
+
earlier: data.earlier,
|
|
1367
|
+
bySource: { ...data.bySource },
|
|
1368
|
+
byDevice: { ...data.byDevice },
|
|
1369
|
+
deviceSample: { ...data.deviceSample, complete: data.deviceSample.complete === true },
|
|
1370
|
+
expiring: { ...data.expiring }
|
|
1371
|
+
};
|
|
1372
|
+
}
|
|
1373
|
+
function shareOf(part, total) {
|
|
1374
|
+
if (!isCount(part) || !isCount(total) || total === 0) return 0;
|
|
1375
|
+
return Math.min(1, part / total);
|
|
1376
|
+
}
|
|
1377
|
+
function monthToDate(month) {
|
|
1378
|
+
const match = /^(\d{4})-(\d{2})$/.exec(month || "");
|
|
1379
|
+
if (!match) return null;
|
|
1380
|
+
return new Date(Date.UTC(Number(match[1]), Number(match[2]) - 1, 1));
|
|
1381
|
+
}
|
|
1382
|
+
function readEndResult(payload) {
|
|
1383
|
+
const data = (
|
|
1384
|
+
/** @type {any} */
|
|
1385
|
+
payload?.data
|
|
1386
|
+
);
|
|
1387
|
+
if (!isCount(data?.ended) || !isCount(data?.remaining) || !isCount(data?.limit)) {
|
|
1388
|
+
throw new Error("Invalid end response");
|
|
1389
|
+
}
|
|
1390
|
+
return { ended: data.ended, remaining: data.remaining, limit: data.limit };
|
|
1391
|
+
}
|
|
1392
|
+
const Caret = styled(CaretDown)`
|
|
1393
|
+
transform: rotate(${({ $open }) => $open ? "0deg" : "-90deg"});
|
|
1394
|
+
`;
|
|
1395
|
+
const Groups = styled.div`
|
|
1396
|
+
display: grid;
|
|
1397
|
+
grid-template-columns: minmax(0, 1fr);
|
|
1398
|
+
gap: ${({ theme }) => theme.spaces[6]};
|
|
1399
|
+
|
|
1400
|
+
${({ theme }) => theme.breakpoints.medium} {
|
|
1401
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
${({ theme }) => theme.breakpoints.large} {
|
|
1405
|
+
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
1406
|
+
}
|
|
1407
|
+
`;
|
|
1408
|
+
const Rows = styled.ul`
|
|
1409
|
+
list-style: none;
|
|
1410
|
+
margin: 0;
|
|
1411
|
+
padding: 0;
|
|
1412
|
+
display: flex;
|
|
1413
|
+
flex-direction: column;
|
|
1414
|
+
gap: ${({ theme }) => theme.spaces[2]};
|
|
1415
|
+
|
|
1416
|
+
&& > li {
|
|
1417
|
+
margin: 0;
|
|
1418
|
+
max-width: none;
|
|
1419
|
+
}
|
|
1420
|
+
`;
|
|
1421
|
+
const Row = ({ label, value }) => /* @__PURE__ */ jsxs(Flex, { tag: "li", justifyContent: "space-between", alignItems: "baseline", gap: 4, minWidth: 0, children: [
|
|
1422
|
+
/* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral700", minWidth: 0, children: label }),
|
|
1423
|
+
/* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", textColor: "neutral800", children: value })
|
|
1424
|
+
] });
|
|
1425
|
+
const Group = ({ title, children, hint }) => /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 3, minWidth: 0, children: [
|
|
1426
|
+
/* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "bold", tag: "h3", textColor: "neutral800", children: title }),
|
|
1427
|
+
/* @__PURE__ */ jsx(Rows, { children }),
|
|
1428
|
+
hint ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: hint }) : null
|
|
1429
|
+
] });
|
|
1430
|
+
const UntrackedSessionsNotice = ({ stats, onChanged, fallbackFocusRef }) => {
|
|
1431
|
+
const { formatMessage, formatNumber, formatDate } = useIntl();
|
|
1432
|
+
const { get, post } = useFetchClient();
|
|
1433
|
+
const { toggleNotification } = useNotification();
|
|
1434
|
+
const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
|
|
1435
|
+
const [open, setOpen] = useState(false);
|
|
1436
|
+
const [summary, setSummary] = useState(null);
|
|
1437
|
+
const [summaryState, setSummaryState] = useState("idle");
|
|
1438
|
+
const requestRef = useRef(0);
|
|
1439
|
+
const panelId = `untracked-sessions-${useId().replace(/:/g, "")}`;
|
|
1440
|
+
const count = stats?.nativeOnly || 0;
|
|
1441
|
+
const after = stats?.nativeOnlyAfterTracking;
|
|
1442
|
+
const tone = untrackedTone(stats);
|
|
1443
|
+
const loadSummary = async () => {
|
|
1444
|
+
const request = ++requestRef.current;
|
|
1445
|
+
setSummaryState("loading");
|
|
1446
|
+
try {
|
|
1447
|
+
const response = await get(UNTRACKED_SUMMARY_PATH);
|
|
1448
|
+
const next = readUntrackedSummary(response.data);
|
|
1449
|
+
if (request !== requestRef.current) return;
|
|
1450
|
+
setSummary(next);
|
|
1451
|
+
setSummaryState("ready");
|
|
1452
|
+
} catch (err) {
|
|
1453
|
+
if (request !== requestRef.current) return;
|
|
1454
|
+
logSafeAdminError("dashboard.untrackedSummary", err);
|
|
1455
|
+
setSummaryState("error");
|
|
1456
|
+
}
|
|
1457
|
+
};
|
|
1458
|
+
const toggle = () => {
|
|
1459
|
+
const next = !open;
|
|
1460
|
+
setOpen(next);
|
|
1461
|
+
if (next && summaryState !== "ready" && summaryState !== "loading") loadSummary();
|
|
1462
|
+
};
|
|
1463
|
+
const endSessions = async () => {
|
|
1464
|
+
try {
|
|
1465
|
+
const response = await post(UNTRACKED_END_PATH, {});
|
|
1466
|
+
const result = readEndResult(response.data);
|
|
1467
|
+
setSummary(null);
|
|
1468
|
+
setSummaryState("idle");
|
|
1469
|
+
if (open) loadSummary();
|
|
1470
|
+
await onChanged?.();
|
|
1471
|
+
toggleNotification({
|
|
1472
|
+
type: "success",
|
|
1473
|
+
message: result.remaining > 0 ? t(
|
|
1474
|
+
"homepage.untracked.end.partial",
|
|
1475
|
+
"{ended, plural, one {# untracked session ended.} other {# untracked sessions ended.}} {remaining, plural, one {# is left; run the action again to end it.} other {# are left; run the action again to end them.}}",
|
|
1476
|
+
{ ended: result.ended, remaining: result.remaining }
|
|
1477
|
+
) : t(
|
|
1478
|
+
"homepage.untracked.end.success",
|
|
1479
|
+
"{ended, plural, one {# untracked session ended.} other {# untracked sessions ended.}}",
|
|
1480
|
+
{ ended: result.ended }
|
|
1481
|
+
)
|
|
1482
|
+
});
|
|
1483
|
+
} catch (err) {
|
|
1484
|
+
logSafeAdminError("dashboard.untrackedEnd", err);
|
|
1485
|
+
toggleNotification({
|
|
1486
|
+
type: "danger",
|
|
1487
|
+
message: t(
|
|
1488
|
+
"homepage.untracked.end.error",
|
|
1489
|
+
"The untracked sessions could not be ended. Please try again."
|
|
1490
|
+
)
|
|
1491
|
+
});
|
|
1492
|
+
throw err;
|
|
1493
|
+
}
|
|
1494
|
+
};
|
|
1495
|
+
if (count <= 0) return null;
|
|
1496
|
+
const title = tone === "warning" ? t(
|
|
1497
|
+
"homepage.untracked.title.gap",
|
|
1498
|
+
"Possible tracking gap: {count, plural, one {# Strapi sign-in is} other {# Strapi sign-ins are}} not tracked",
|
|
1499
|
+
{ count }
|
|
1500
|
+
) : t(
|
|
1501
|
+
"homepage.untracked.title.legacy",
|
|
1502
|
+
"{count, plural, one {# older Strapi sign-in is} other {# older Strapi sign-ins are}} not tracked",
|
|
1503
|
+
{ count }
|
|
1504
|
+
);
|
|
1505
|
+
const body = tone === "warning" ? t(
|
|
1506
|
+
"homepage.untracked.body.gap",
|
|
1507
|
+
"Strapi still accepts these sign-ins (refresh tokens), but they are not in this list and are not active or online sessions. {after, plural, one {# was} other {# were}} created after this plugin started tracking, so one sign-in path may not be tracked. Select “Why?” for details.",
|
|
1508
|
+
{ after }
|
|
1509
|
+
) : t(
|
|
1510
|
+
"homepage.untracked.body.legacy",
|
|
1511
|
+
"Strapi still accepts these sign-ins (refresh tokens) until they expire, but they are not in this list and are not active or online sessions. They were created before this plugin tracked sessions."
|
|
1512
|
+
);
|
|
1513
|
+
const pct = (part, total) => formatNumber(shareOf(part, total), { style: "percent", maximumFractionDigits: 0 });
|
|
1514
|
+
const num = (value) => formatNumber(value);
|
|
1515
|
+
const actions = /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", children: [
|
|
1516
|
+
/* @__PURE__ */ jsx(
|
|
1517
|
+
Button,
|
|
1518
|
+
{
|
|
1519
|
+
size: "S",
|
|
1520
|
+
variant: "tertiary",
|
|
1521
|
+
startIcon: /* @__PURE__ */ jsx(Caret, { $open: open, "aria-hidden": true, focusable: false }),
|
|
1522
|
+
"aria-expanded": open,
|
|
1523
|
+
"aria-controls": panelId,
|
|
1524
|
+
onClick: toggle,
|
|
1525
|
+
children: t("homepage.untracked.why", "Why?")
|
|
1526
|
+
}
|
|
1527
|
+
),
|
|
1528
|
+
/* @__PURE__ */ jsx(
|
|
1529
|
+
ConfirmAction,
|
|
1530
|
+
{
|
|
1531
|
+
trigger: /* @__PURE__ */ jsx(Button, { size: "S", variant: "danger-light", children: t("homepage.untracked.end.action", "End these sessions") }),
|
|
1532
|
+
title: t(
|
|
1533
|
+
"homepage.untracked.end.title",
|
|
1534
|
+
"End {count, plural, one {# untracked Strapi sign-in} other {# untracked Strapi sign-ins}}?",
|
|
1535
|
+
{ count }
|
|
1536
|
+
),
|
|
1537
|
+
body: t(
|
|
1538
|
+
"homepage.untracked.end.body",
|
|
1539
|
+
"Strapi deletes these sign-ins now, so their refresh tokens stop working. Users on those devices must sign in again once their current access token expires, within minutes. Sessions listed here and Strapi administrator sessions are not affected. This cannot be undone."
|
|
1540
|
+
),
|
|
1541
|
+
confirmLabel: t("homepage.untracked.end.confirm", "End sessions"),
|
|
1542
|
+
onConfirm: endSessions,
|
|
1543
|
+
fallbackFocusRef
|
|
1544
|
+
}
|
|
1545
|
+
)
|
|
1546
|
+
] });
|
|
1547
|
+
let panel = null;
|
|
1548
|
+
if (summaryState === "loading" && !summary) {
|
|
1549
|
+
panel = /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 4, children: /* @__PURE__ */ jsx(Loader, { small: true, children: t("homepage.untracked.summary.loading", "Loading details") }) });
|
|
1550
|
+
} else if (summaryState === "error") {
|
|
1551
|
+
panel = /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", gap: 3, children: [
|
|
1552
|
+
/* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "danger600", role: "alert", children: t("homepage.untracked.summary.error", "The details could not be loaded.") }),
|
|
1553
|
+
/* @__PURE__ */ jsx(Button, { size: "S", variant: "secondary", onClick: loadSummary, children: t("common.tryAgain", "Try again") })
|
|
1554
|
+
] });
|
|
1555
|
+
} else if (summary) {
|
|
1556
|
+
const since = summary.trackingSince ? formatDate(summary.trackingSince, { dateStyle: "medium" }) : null;
|
|
1557
|
+
panel = /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
|
|
1558
|
+
/* @__PURE__ */ jsxs(Groups, { children: [
|
|
1559
|
+
/* @__PURE__ */ jsxs(
|
|
1560
|
+
Group,
|
|
1561
|
+
{
|
|
1562
|
+
title: t("homepage.untracked.summary.tracking", "Created before or after tracking"),
|
|
1563
|
+
hint: since ? t(
|
|
1564
|
+
"homepage.untracked.summary.trackingSince",
|
|
1565
|
+
"This plugin has linked new sign-ins since {date}.",
|
|
1566
|
+
{ date: since }
|
|
1567
|
+
) : t(
|
|
1568
|
+
"homepage.untracked.summary.trackingUnknown",
|
|
1569
|
+
"The tracking start date is not known yet."
|
|
1570
|
+
),
|
|
1571
|
+
children: [
|
|
1572
|
+
/* @__PURE__ */ jsx(
|
|
1573
|
+
Row,
|
|
1574
|
+
{
|
|
1575
|
+
label: t(
|
|
1576
|
+
"homepage.untracked.summary.before",
|
|
1577
|
+
"Before tracking (expire on their own)"
|
|
1578
|
+
),
|
|
1579
|
+
value: num(summary.beforeTracking)
|
|
1580
|
+
}
|
|
1581
|
+
),
|
|
1582
|
+
/* @__PURE__ */ jsx(
|
|
1583
|
+
Row,
|
|
1584
|
+
{
|
|
1585
|
+
label: t("homepage.untracked.summary.after", "After tracking (possible gap)"),
|
|
1586
|
+
value: num(summary.afterTracking)
|
|
1587
|
+
}
|
|
1588
|
+
)
|
|
1589
|
+
]
|
|
1590
|
+
}
|
|
1591
|
+
),
|
|
1592
|
+
/* @__PURE__ */ jsxs(
|
|
1593
|
+
Group,
|
|
1594
|
+
{
|
|
1595
|
+
title: t("homepage.untracked.summary.source", "How Strapi created them"),
|
|
1596
|
+
hint: t(
|
|
1597
|
+
"homepage.untracked.summary.sourceHint",
|
|
1598
|
+
"“Token only” comes from code that issues a token without Strapi’s sign-in details: GraphQL email confirmation, custom login routes or other plugins."
|
|
1599
|
+
),
|
|
1600
|
+
children: [
|
|
1601
|
+
/* @__PURE__ */ jsx(
|
|
1602
|
+
Row,
|
|
1603
|
+
{
|
|
1604
|
+
label: t("homepage.untracked.summary.signIn", "Sign-in with device details"),
|
|
1605
|
+
value: num(summary.bySource.signIn)
|
|
1606
|
+
}
|
|
1607
|
+
),
|
|
1608
|
+
/* @__PURE__ */ jsx(
|
|
1609
|
+
Row,
|
|
1610
|
+
{
|
|
1611
|
+
label: t("homepage.untracked.summary.passwordChange", "Password change or reset"),
|
|
1612
|
+
value: num(summary.bySource.passwordChange)
|
|
1613
|
+
}
|
|
1614
|
+
),
|
|
1615
|
+
/* @__PURE__ */ jsx(
|
|
1616
|
+
Row,
|
|
1617
|
+
{
|
|
1618
|
+
label: t("homepage.untracked.summary.tokenOnly", "Token only"),
|
|
1619
|
+
value: num(summary.bySource.tokenOnly)
|
|
1620
|
+
}
|
|
1621
|
+
)
|
|
1622
|
+
]
|
|
1623
|
+
}
|
|
1624
|
+
),
|
|
1625
|
+
/* @__PURE__ */ jsxs(Group, { title: t("homepage.untracked.summary.expiring", "Expiry"), children: [
|
|
1626
|
+
/* @__PURE__ */ jsx(
|
|
1627
|
+
Row,
|
|
1628
|
+
{
|
|
1629
|
+
label: t("homepage.untracked.summary.within7", "Expire within 7 days"),
|
|
1630
|
+
value: t("homepage.untracked.summary.share", "{count} ({share})", {
|
|
1631
|
+
count: num(summary.expiring.within7Days),
|
|
1632
|
+
share: pct(summary.expiring.within7Days, summary.total)
|
|
1633
|
+
})
|
|
1634
|
+
}
|
|
1635
|
+
),
|
|
1636
|
+
/* @__PURE__ */ jsx(
|
|
1637
|
+
Row,
|
|
1638
|
+
{
|
|
1639
|
+
label: t("homepage.untracked.summary.within30", "Expire within 30 days"),
|
|
1640
|
+
value: t("homepage.untracked.summary.share", "{count} ({share})", {
|
|
1641
|
+
count: num(summary.expiring.within30Days),
|
|
1642
|
+
share: pct(summary.expiring.within30Days, summary.total)
|
|
1643
|
+
})
|
|
1644
|
+
}
|
|
1645
|
+
)
|
|
1646
|
+
] }),
|
|
1647
|
+
/* @__PURE__ */ jsxs(Group, { title: t("homepage.untracked.summary.months", "Created per month"), children: [
|
|
1648
|
+
summary.byMonth.map((entry) => {
|
|
1649
|
+
const date = monthToDate(entry.month);
|
|
1650
|
+
return /* @__PURE__ */ jsx(
|
|
1651
|
+
Row,
|
|
1652
|
+
{
|
|
1653
|
+
label: date ? formatDate(date, { month: "long", year: "numeric", timeZone: "UTC" }) : entry.month,
|
|
1654
|
+
value: num(entry.count)
|
|
1655
|
+
},
|
|
1656
|
+
entry.month
|
|
1657
|
+
);
|
|
1658
|
+
}),
|
|
1659
|
+
summary.earlier > 0 ? /* @__PURE__ */ jsx(
|
|
1660
|
+
Row,
|
|
1661
|
+
{
|
|
1662
|
+
label: t("homepage.untracked.summary.earlier", "Earlier"),
|
|
1663
|
+
value: num(summary.earlier)
|
|
1664
|
+
}
|
|
1665
|
+
) : null
|
|
1666
|
+
] }),
|
|
1667
|
+
/* @__PURE__ */ jsxs(
|
|
1668
|
+
Group,
|
|
1669
|
+
{
|
|
1670
|
+
title: t("homepage.untracked.summary.devices", "Devices"),
|
|
1671
|
+
hint: summary.deviceSample.complete ? t(
|
|
1672
|
+
"homepage.untracked.summary.devicesHint",
|
|
1673
|
+
"From the device label Strapi stores; Strapi stores no device type."
|
|
1674
|
+
) : t(
|
|
1675
|
+
"homepage.untracked.summary.devicesSample",
|
|
1676
|
+
"From the device label Strapi stores, for the first {limit, number} sign-ins.",
|
|
1677
|
+
{ limit: summary.deviceSample.limit }
|
|
1678
|
+
),
|
|
1679
|
+
children: [
|
|
1680
|
+
/* @__PURE__ */ jsx(
|
|
1681
|
+
Row,
|
|
1682
|
+
{
|
|
1683
|
+
label: t("homepage.untracked.summary.desktop", "Desktop"),
|
|
1684
|
+
value: num(summary.byDevice.desktop)
|
|
1685
|
+
}
|
|
1686
|
+
),
|
|
1687
|
+
/* @__PURE__ */ jsx(
|
|
1688
|
+
Row,
|
|
1689
|
+
{
|
|
1690
|
+
label: t("homepage.untracked.summary.mobile", "Mobile"),
|
|
1691
|
+
value: num(summary.byDevice.mobile)
|
|
1692
|
+
}
|
|
1693
|
+
),
|
|
1694
|
+
/* @__PURE__ */ jsx(
|
|
1695
|
+
Row,
|
|
1696
|
+
{
|
|
1697
|
+
label: t("homepage.untracked.summary.unknownDevice", "Unknown device"),
|
|
1698
|
+
value: num(summary.byDevice.unknown)
|
|
1699
|
+
}
|
|
1700
|
+
)
|
|
1701
|
+
]
|
|
1702
|
+
}
|
|
1703
|
+
)
|
|
1704
|
+
] }),
|
|
1705
|
+
/* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral600", tag: "p", children: t(
|
|
1706
|
+
"homepage.untracked.summary.next",
|
|
1707
|
+
"Sessions created after tracking started point to a sign-in path this plugin does not see: a custom login route, GraphQL sign-ins or a plugin that issues tokens. The plugin documentation explains each case. Older sessions need no action."
|
|
1708
|
+
) })
|
|
1709
|
+
] });
|
|
1710
|
+
}
|
|
1711
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, "data-untracked-sessions": tone, children: [
|
|
1712
|
+
/* @__PURE__ */ jsx(PersistentAlert, { variant: tone, title, titleAs: "h2", stacked: true, action: actions, children: /* @__PURE__ */ jsx(ReadableText, { variant: "omega", textColor: "neutral800", tag: "span", children: body }) }),
|
|
1713
|
+
/* @__PURE__ */ jsx(
|
|
1714
|
+
Box,
|
|
1715
|
+
{
|
|
1716
|
+
id: panelId,
|
|
1717
|
+
hidden: !open,
|
|
1718
|
+
width: "100%",
|
|
1719
|
+
background: "neutral0",
|
|
1720
|
+
hasRadius: true,
|
|
1721
|
+
shadow: "tableShadow",
|
|
1722
|
+
padding: { initial: 4, medium: 6 },
|
|
1723
|
+
"aria-live": "polite",
|
|
1724
|
+
"aria-busy": summaryState === "loading",
|
|
1725
|
+
children: open ? panel : null
|
|
1726
|
+
}
|
|
1727
|
+
)
|
|
1728
|
+
] });
|
|
1729
|
+
};
|
|
1298
1730
|
const CLOCK_TICK_MS = 30 * 1e3;
|
|
1299
1731
|
const ANALYTICS_PATH = `/settings/${pluginId}/analytics`;
|
|
1300
1732
|
const CONFIGURATION_PATH = `/settings/${pluginId}/general`;
|
|
@@ -1332,7 +1764,9 @@ const HomePage = () => {
|
|
|
1332
1764
|
const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
|
|
1333
1765
|
const dashboard = parseDashboardQuery(query);
|
|
1334
1766
|
const [sessions, setSessions] = useState([]);
|
|
1335
|
-
const [
|
|
1767
|
+
const [pagination, setPagination] = useState({ total: 0, pageCount: 1 });
|
|
1768
|
+
const [stats, setStats] = useState(EMPTY_SESSION_STATS);
|
|
1769
|
+
const [exporting, setExporting] = useState(false);
|
|
1336
1770
|
const [loading, setLoading] = useState(true);
|
|
1337
1771
|
const [refreshing, setRefreshing] = useState(false);
|
|
1338
1772
|
const [loadError, setLoadError] = useState(false);
|
|
@@ -1352,6 +1786,16 @@ const HomePage = () => {
|
|
|
1352
1786
|
const mutationSnapshotRef = useRef([]);
|
|
1353
1787
|
const listHeadingId = `session-list-caption-${useId().replace(/:/g, "")}`;
|
|
1354
1788
|
const mutationPending = Boolean(terminatingSessionId || deletingSessionId);
|
|
1789
|
+
const listQuery = useMemo(
|
|
1790
|
+
() => ({
|
|
1791
|
+
page: dashboard.page,
|
|
1792
|
+
pageSize: dashboard.pageSize,
|
|
1793
|
+
status: dashboard.status,
|
|
1794
|
+
reason: dashboard.reason,
|
|
1795
|
+
search: dashboard.search
|
|
1796
|
+
}),
|
|
1797
|
+
[dashboard.page, dashboard.pageSize, dashboard.status, dashboard.reason, dashboard.search]
|
|
1798
|
+
);
|
|
1355
1799
|
useEffect(() => {
|
|
1356
1800
|
const timer = setInterval(() => setNow(Date.now()), CLOCK_TICK_MS);
|
|
1357
1801
|
return () => clearInterval(timer);
|
|
@@ -1362,11 +1806,16 @@ const HomePage = () => {
|
|
|
1362
1806
|
if (hasLoadedRef.current) setRefreshing(true);
|
|
1363
1807
|
else setLoading(true);
|
|
1364
1808
|
try {
|
|
1365
|
-
const
|
|
1366
|
-
|
|
1809
|
+
const [listResponse, statsResponse] = await Promise.all([
|
|
1810
|
+
get(`/${pluginId}/sessions`, { params: buildListParams(listQuery) }),
|
|
1811
|
+
get(`/${pluginId}/sessions/stats`)
|
|
1812
|
+
]);
|
|
1813
|
+
const page = readSessionPage(listResponse.data);
|
|
1814
|
+
const nextStats = readSessionStats(statsResponse.data);
|
|
1367
1815
|
if (requestId !== requestIdRef.current) return;
|
|
1368
|
-
setSessions(
|
|
1369
|
-
|
|
1816
|
+
setSessions(page.rows);
|
|
1817
|
+
setPagination(page.pagination);
|
|
1818
|
+
setStats(nextStats);
|
|
1370
1819
|
setLoadError(false);
|
|
1371
1820
|
setHasData(true);
|
|
1372
1821
|
setLastUpdated(Date.now());
|
|
@@ -1382,7 +1831,7 @@ const HomePage = () => {
|
|
|
1382
1831
|
setRefreshing(false);
|
|
1383
1832
|
}
|
|
1384
1833
|
}
|
|
1385
|
-
}, [get]);
|
|
1834
|
+
}, [get, listQuery]);
|
|
1386
1835
|
useEffect(() => {
|
|
1387
1836
|
fetchSessions();
|
|
1388
1837
|
}, [fetchSessions]);
|
|
@@ -1470,53 +1919,74 @@ const HomePage = () => {
|
|
|
1470
1919
|
setDeletingSessionId(null);
|
|
1471
1920
|
}
|
|
1472
1921
|
};
|
|
1473
|
-
const
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
),
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
const pageResult = paginateSessions(filteredSessions, dashboard.page, dashboard.pageSize);
|
|
1922
|
+
const pageSize = Number(dashboard.pageSize);
|
|
1923
|
+
const pageResult = {
|
|
1924
|
+
items: sessions,
|
|
1925
|
+
total: pagination.total,
|
|
1926
|
+
pageCount: pagination.pageCount,
|
|
1927
|
+
startIndex: pagination.total > 0 ? (dashboard.page - 1) * pageSize + 1 : 0,
|
|
1928
|
+
endIndex: pagination.total > 0 ? (dashboard.page - 1) * pageSize + sessions.length : 0
|
|
1929
|
+
};
|
|
1482
1930
|
const visibleIds = pageResult.items.map((session) => String(session.id));
|
|
1483
1931
|
useLayoutEffect(() => {
|
|
1484
1932
|
visibleIdsRef.current = visibleIds;
|
|
1485
1933
|
});
|
|
1486
|
-
const
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
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.")
|
|
1934
|
+
const fetchExportRows = async () => {
|
|
1935
|
+
const rows = [];
|
|
1936
|
+
let cursor = null;
|
|
1937
|
+
do {
|
|
1938
|
+
const { data } = await get(`/${pluginId}/sessions/export`, {
|
|
1939
|
+
params: buildExportParams(listQuery, cursor)
|
|
1499
1940
|
});
|
|
1500
|
-
|
|
1941
|
+
rows.push(...requireSessionList(data));
|
|
1942
|
+
cursor = typeof data?.meta?.nextCursor === "string" ? data.meta.nextCursor : null;
|
|
1943
|
+
} while (cursor && rows.length < MAX_EXPORT_ROWS);
|
|
1944
|
+
const capped = rows.length > MAX_EXPORT_ROWS || Boolean(cursor) && rows.length >= MAX_EXPORT_ROWS;
|
|
1945
|
+
return { rows: rows.slice(0, MAX_EXPORT_ROWS), capped };
|
|
1501
1946
|
};
|
|
1502
|
-
const
|
|
1947
|
+
const handleExport = async (format) => {
|
|
1948
|
+
if (exporting) return;
|
|
1949
|
+
setExporting(true);
|
|
1503
1950
|
try {
|
|
1504
|
-
const
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
}
|
|
1513
|
-
|
|
1951
|
+
const { rows, capped } = await fetchExportRows();
|
|
1952
|
+
if (format === "csv") {
|
|
1953
|
+
const csvContent = buildSessionCsv(rows, {
|
|
1954
|
+
unavailableValue: "",
|
|
1955
|
+
getDeviceInfo: getExportDeviceInfo,
|
|
1956
|
+
getSessionStatus
|
|
1957
|
+
});
|
|
1958
|
+
downloadFile(csvContent, "text/csv;charset=utf-8;", "csv");
|
|
1959
|
+
} else {
|
|
1960
|
+
const jsonContent = buildSessionJson(rows, {
|
|
1961
|
+
filterStatus: dashboard.status,
|
|
1962
|
+
totalSessions: stats.total,
|
|
1963
|
+
exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1964
|
+
unavailableValue: "",
|
|
1965
|
+
getDeviceInfo: getExportDeviceInfo,
|
|
1966
|
+
getSessionStatus,
|
|
1967
|
+
truncated: capped
|
|
1968
|
+
});
|
|
1969
|
+
downloadFile(jsonContent, "application/json", "json");
|
|
1970
|
+
}
|
|
1971
|
+
if (capped) {
|
|
1972
|
+
toggleNotification({
|
|
1973
|
+
type: "warning",
|
|
1974
|
+
message: t(
|
|
1975
|
+
"homepage.export.capped",
|
|
1976
|
+
"The export contains the newest {limit, number} sessions. Narrow the filter to export the rest.",
|
|
1977
|
+
{ limit: MAX_EXPORT_ROWS }
|
|
1978
|
+
)
|
|
1979
|
+
});
|
|
1980
|
+
}
|
|
1514
1981
|
} catch (err) {
|
|
1515
|
-
|
|
1982
|
+
if (isCancelledRequest(err)) return;
|
|
1983
|
+
logSafeAdminError(format === "csv" ? "dashboard.exportCsv" : "dashboard.exportJson", err);
|
|
1516
1984
|
toggleNotification({
|
|
1517
1985
|
type: "danger",
|
|
1518
1986
|
message: t("notifications.error.exportFailed", "The export could not be created.")
|
|
1519
1987
|
});
|
|
1988
|
+
} finally {
|
|
1989
|
+
setExporting(false);
|
|
1520
1990
|
}
|
|
1521
1991
|
};
|
|
1522
1992
|
const handleSessionClick = (session, opener) => {
|
|
@@ -1551,10 +2021,10 @@ const HomePage = () => {
|
|
|
1551
2021
|
[]
|
|
1552
2022
|
);
|
|
1553
2023
|
useEffect(() => {
|
|
1554
|
-
if (!loading && dashboard.page > pageResult.pageCount) {
|
|
2024
|
+
if (!loading && !refreshing && dashboard.page > pageResult.pageCount) {
|
|
1555
2025
|
setQuery({ page: String(pageResult.pageCount) }, "push", true);
|
|
1556
2026
|
}
|
|
1557
|
-
}, [loading, dashboard.page, pageResult.pageCount, setQuery]);
|
|
2027
|
+
}, [loading, refreshing, dashboard.page, pageResult.pageCount, setQuery]);
|
|
1558
2028
|
const handleStatusChange = (value) => {
|
|
1559
2029
|
const status = String(value);
|
|
1560
2030
|
setQuery({ status: status === "all" ? void 0 : status, reason: void 0, page: "1" });
|
|
@@ -1573,12 +2043,11 @@ const HomePage = () => {
|
|
|
1573
2043
|
setQuery({ search: void 0, _q: void 0, status: void 0, reason: void 0, page: "1" });
|
|
1574
2044
|
listHeadingRef.current?.focus();
|
|
1575
2045
|
};
|
|
1576
|
-
const stats = getSessionStats(sessions);
|
|
1577
2046
|
const showSessionData = !loading && hasData;
|
|
1578
|
-
const showToolbar = showSessionData &&
|
|
1579
|
-
const canExport = showSessionData &&
|
|
2047
|
+
const showToolbar = showSessionData && stats.total > 0;
|
|
2048
|
+
const canExport = showSessionData && pageResult.total > 0 && !exporting;
|
|
1580
2049
|
const filtersActive = hasActiveFilters(dashboard);
|
|
1581
|
-
const exportValues = { count:
|
|
2050
|
+
const exportValues = { count: Math.min(pageResult.total, MAX_EXPORT_ROWS) };
|
|
1582
2051
|
const exportMenu = /* @__PURE__ */ jsxs(
|
|
1583
2052
|
SimpleMenu,
|
|
1584
2053
|
{
|
|
@@ -1587,20 +2056,12 @@ const HomePage = () => {
|
|
|
1587
2056
|
startIcon: /* @__PURE__ */ jsx(Download, {}),
|
|
1588
2057
|
disabled: !canExport,
|
|
1589
2058
|
children: [
|
|
1590
|
-
/* @__PURE__ */ jsx(MenuItem, { onSelect:
|
|
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(
|
|
2059
|
+
/* @__PURE__ */ jsx(MenuItem, { onSelect: () => void handleExport("csv"), children: t(
|
|
1595
2060
|
"homepage.export.csv",
|
|
1596
2061
|
"{count, plural, one {Export # session as CSV} other {Export # sessions as CSV}}",
|
|
1597
2062
|
exportValues
|
|
1598
2063
|
) }),
|
|
1599
|
-
/* @__PURE__ */ jsx(MenuItem, { onSelect:
|
|
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(
|
|
2064
|
+
/* @__PURE__ */ jsx(MenuItem, { onSelect: () => void handleExport("json"), children: t(
|
|
1604
2065
|
"homepage.export.json",
|
|
1605
2066
|
"{count, plural, one {Export # session as JSON} other {Export # sessions as JSON}}",
|
|
1606
2067
|
exportValues
|
|
@@ -1732,13 +2193,16 @@ const HomePage = () => {
|
|
|
1732
2193
|
children: /* @__PURE__ */ jsx(ReadableText, { variant: "omega", textColor: "neutral800", tag: "span", children: t("homepage.error.load", "Sessions could not be loaded.") })
|
|
1733
2194
|
}
|
|
1734
2195
|
) : null,
|
|
1735
|
-
showSessionData &&
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
2196
|
+
showSessionData && stats.nativeOnly > 0 ? /* @__PURE__ */ jsx(
|
|
2197
|
+
UntrackedSessionsNotice,
|
|
2198
|
+
{
|
|
2199
|
+
stats,
|
|
2200
|
+
onChanged: fetchSessions,
|
|
2201
|
+
fallbackFocusRef: dashboardRef
|
|
2202
|
+
}
|
|
2203
|
+
) : null,
|
|
1740
2204
|
loading ? /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 8, children: /* @__PURE__ */ jsx(Loader, { children: t("homepage.loading", "Loading sessions") }) }) : null,
|
|
1741
|
-
showSessionData &&
|
|
2205
|
+
showSessionData && stats.total > 0 ? /* @__PURE__ */ jsx(HowSessionsWork, {}) : null,
|
|
1742
2206
|
showSessionData && /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
|
1743
2207
|
/* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx(Typography, { tag: "h2", children: t("homepage.stats.label", "Session statistics") }) }),
|
|
1744
2208
|
/* @__PURE__ */ jsxs(StatGrid, { label: t("homepage.stats.label", "Session statistics"), children: [
|
|
@@ -1827,7 +2291,7 @@ const HomePage = () => {
|
|
|
1827
2291
|
),
|
|
1828
2292
|
lastUpdatedLine
|
|
1829
2293
|
] }),
|
|
1830
|
-
|
|
2294
|
+
pageResult.total > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1831
2295
|
isBelowMedium ? /* @__PURE__ */ jsx(SessionCardList, { ...listProps }) : /* @__PURE__ */ jsx(
|
|
1832
2296
|
SessionTable,
|
|
1833
2297
|
{
|
|
@@ -1859,7 +2323,7 @@ const HomePage = () => {
|
|
|
1859
2323
|
}
|
|
1860
2324
|
)
|
|
1861
2325
|
] }),
|
|
1862
|
-
showSessionData &&
|
|
2326
|
+
showSessionData && stats.total === 0 && /* @__PURE__ */ jsx(
|
|
1863
2327
|
EmptyStateLayout,
|
|
1864
2328
|
{
|
|
1865
2329
|
icon: /* @__PURE__ */ jsx(EmptyDocuments, { width: "16rem", height: "8.8rem", "aria-hidden": "true" }),
|