@blocklet/ui-react 3.1.24 → 3.1.26
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.
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { UserSession } from '@blocklet/js-sdk';
|
|
2
2
|
import { User } from '../../@types';
|
|
3
|
-
export default function UserSessions({ user, showAction, showUser, getUserSessions, showOffline, }: {
|
|
3
|
+
export default function UserSessions({ user, showAction, showUser, getUserSessions, showOffline, showAppPid, }: {
|
|
4
4
|
readonly user: User & {
|
|
5
5
|
userSessions?: any[];
|
|
6
6
|
};
|
|
7
7
|
readonly showAction?: boolean;
|
|
8
8
|
readonly showUser?: boolean;
|
|
9
9
|
readonly showOffline?: boolean;
|
|
10
|
+
readonly showAppPid?: boolean;
|
|
10
11
|
readonly getUserSessions: (params: {
|
|
11
12
|
page: number;
|
|
12
13
|
pageSize: number;
|
|
@@ -1,42 +1,43 @@
|
|
|
1
1
|
import { jsx as n, jsxs as s, Fragment as A } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
-
import { useReactive as z, useMemoizedFn as
|
|
4
|
-
import { translate as
|
|
5
|
-
import { useLocaleContext as
|
|
2
|
+
import $ from "@arcblock/ux/lib/Datatable";
|
|
3
|
+
import { useReactive as z, useMemoizedFn as v, useMount as J, useRequest as K, useCreation as w } from "ahooks";
|
|
4
|
+
import { translate as X } from "@arcblock/ux/lib/Locale/util";
|
|
5
|
+
import { useLocaleContext as O } from "@arcblock/ux/lib/Locale/context";
|
|
6
6
|
import T from "@arcblock/ux/lib/RelativeTime";
|
|
7
7
|
import S from "ua-parser-js";
|
|
8
|
-
import { getVisitorId as
|
|
9
|
-
import { useConfirm as
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
|
|
8
|
+
import { getVisitorId as Y } from "@arcblock/ux/lib/Util";
|
|
9
|
+
import { useConfirm as Z } from "@arcblock/ux/lib/Dialog";
|
|
10
|
+
import _ from "@arcblock/ux/lib/DID";
|
|
11
|
+
import ee from "p-queue";
|
|
12
|
+
import { Box as d, Typography as a, CircularProgress as te, useMediaQuery as oe, Tooltip as ne, Button as k, RadioGroup as re, FormControlLabel as B, Radio as C } from "@mui/material";
|
|
13
|
+
import { memo as ie, useEffect as se } from "react";
|
|
14
|
+
import { mergeSx as P } from "@arcblock/ux/lib/Util/style";
|
|
15
|
+
import ae from "../../hooks/use-mobile.js";
|
|
16
|
+
import le from "./user-session-info.js";
|
|
17
|
+
import { client as M } from "../../libs/client.js";
|
|
18
|
+
import { translations as ce } from "../libs/locales.js";
|
|
19
|
+
import { ip2Region as de } from "../libs/utils.js";
|
|
20
|
+
const W = (p) => new S(p, {
|
|
20
21
|
// eslint-disable-next-line no-useless-escape
|
|
21
22
|
browser: [[/(ArcWallet)\/([\w\.]+)/i], [S.BROWSER.NAME, S.BROWSER.VERSION]]
|
|
22
|
-
}).getResult(),
|
|
23
|
+
}).getResult(), D = {
|
|
23
24
|
display: "flex",
|
|
24
25
|
justifyContent: "flex-end",
|
|
25
26
|
textAlign: "right"
|
|
26
|
-
},
|
|
27
|
+
}, pe = new ee({ concurrency: 1 }), ue = ie(({ userSession: p, isMobile: h = !1 }) => {
|
|
27
28
|
const l = z({
|
|
28
29
|
loading: !0,
|
|
29
30
|
ipRegion: ""
|
|
30
|
-
}), { t: f } =
|
|
31
|
-
return
|
|
32
|
-
|
|
31
|
+
}), { t: f } = O();
|
|
32
|
+
return se(() => {
|
|
33
|
+
pe.add(async () => {
|
|
33
34
|
try {
|
|
34
|
-
l.ipRegion = await
|
|
35
|
+
l.ipRegion = await de(p.lastLoginIp);
|
|
35
36
|
} finally {
|
|
36
37
|
l.loading = !1;
|
|
37
38
|
}
|
|
38
39
|
});
|
|
39
|
-
}, [l,
|
|
40
|
+
}, [l, p.lastLoginIp]), /* @__PURE__ */ n(
|
|
40
41
|
d,
|
|
41
42
|
{
|
|
42
43
|
...h && {
|
|
@@ -48,60 +49,61 @@ const W = (u) => new S(u, {
|
|
|
48
49
|
},
|
|
49
50
|
children: l.ipRegion ? /* @__PURE__ */ s(A, { children: [
|
|
50
51
|
/* @__PURE__ */ n(a, { variant: "body2", children: l.ipRegion }),
|
|
51
|
-
/* @__PURE__ */ n(a, { variant: "body2", color: "grey", children:
|
|
52
|
+
/* @__PURE__ */ n(a, { variant: "body2", color: "grey", children: p.lastLoginIp || f("unknown") })
|
|
52
53
|
] }) : /* @__PURE__ */ s(A, { children: [
|
|
53
|
-
/* @__PURE__ */ n(a, { children:
|
|
54
|
-
l.loading ? /* @__PURE__ */ n(a, { variant: "body2", color: "grey", sx: { textAlign: "center" }, children: /* @__PURE__ */ n(
|
|
54
|
+
/* @__PURE__ */ n(a, { children: p.lastLoginIp || f("unknown") }),
|
|
55
|
+
l.loading ? /* @__PURE__ */ n(a, { variant: "body2", color: "grey", sx: { textAlign: "center" }, children: /* @__PURE__ */ n(te, { size: 12, color: "inherit" }) }) : null
|
|
55
56
|
] })
|
|
56
57
|
}
|
|
57
58
|
);
|
|
58
59
|
});
|
|
59
|
-
function
|
|
60
|
-
user:
|
|
60
|
+
function Pe({
|
|
61
|
+
user: p,
|
|
61
62
|
showAction: h = !0,
|
|
62
63
|
showUser: l = !0,
|
|
63
64
|
getUserSessions: f,
|
|
64
|
-
showOffline: I = !1
|
|
65
|
+
showOffline: I = !1,
|
|
66
|
+
showAppPid: j = !1
|
|
65
67
|
}) {
|
|
66
68
|
const r = z({
|
|
67
69
|
status: "online",
|
|
68
70
|
page: 1,
|
|
69
71
|
pageSize: 10
|
|
70
|
-
}),
|
|
72
|
+
}), u = z({
|
|
71
73
|
online: 0,
|
|
72
74
|
expired: 0,
|
|
73
75
|
offline: 0
|
|
74
|
-
}), y =
|
|
76
|
+
}), y = Y(), { locale: b } = O(), m = ae({ key: "md" }), H = oe((e) => e.breakpoints.down("lg")), { confirmApi: R, confirmHolder: E } = Z(), t = v((e, o = {}) => X(ce, e, b, "en", o)), F = v(async () => {
|
|
75
77
|
const e = await f({
|
|
76
78
|
page: r.page,
|
|
77
79
|
pageSize: r.pageSize,
|
|
78
80
|
status: r.status
|
|
79
81
|
}), o = e?.paging?.total || 0;
|
|
80
|
-
return
|
|
82
|
+
return u[r.status] = o, {
|
|
81
83
|
total: o,
|
|
82
84
|
list: e?.list || []
|
|
83
85
|
};
|
|
84
86
|
});
|
|
85
|
-
|
|
87
|
+
J(async () => {
|
|
86
88
|
const e = await f({
|
|
87
89
|
page: 1,
|
|
88
90
|
pageSize: 1,
|
|
89
91
|
status: "expired"
|
|
90
92
|
});
|
|
91
|
-
|
|
93
|
+
u.expired = e?.paging?.total || 0;
|
|
92
94
|
const o = await f({
|
|
93
95
|
page: 1,
|
|
94
96
|
pageSize: 1,
|
|
95
97
|
status: "offline"
|
|
96
98
|
});
|
|
97
|
-
|
|
99
|
+
u.offline = o?.paging?.total || 0;
|
|
98
100
|
});
|
|
99
|
-
const c =
|
|
101
|
+
const c = K(F, {
|
|
100
102
|
refreshDeps: [r.status, r.page, r.pageSize]
|
|
101
|
-
}), i =
|
|
103
|
+
}), i = w(() => c.data?.list || [], [c.data?.list]), N = w(() => {
|
|
102
104
|
const e = r.status;
|
|
103
|
-
return e === "online" ?
|
|
104
|
-
}, [i, y]), x =
|
|
105
|
+
return e === "online" ? u[e] <= 1 : u[e] === 0;
|
|
106
|
+
}, [i, y]), x = w(() => P({}, m ? D : {}), [m]), U = v(({ visitorId: e }) => {
|
|
105
107
|
R.open({
|
|
106
108
|
title: t("logoutThisSession"),
|
|
107
109
|
content: t("logoutThisSessionConfirm"),
|
|
@@ -111,15 +113,15 @@ function Ae({
|
|
|
111
113
|
},
|
|
112
114
|
cancelButtonText: t("cancel"),
|
|
113
115
|
onConfirm: async () => {
|
|
114
|
-
await
|
|
116
|
+
await M.user.logout({
|
|
115
117
|
visitorId: e,
|
|
116
118
|
includeFederated: !0
|
|
117
119
|
});
|
|
118
|
-
const { page: o = 0 } = r, { list: g = [] } = c.data || {},
|
|
119
|
-
o > 1 &&
|
|
120
|
+
const { page: o = 0 } = r, { list: g = [] } = c.data || {}, G = g.length || 0;
|
|
121
|
+
o > 1 && G === 1 && (r.page = Math.max(o - 1, 1)), c.refresh(), R.close();
|
|
120
122
|
}
|
|
121
123
|
});
|
|
122
|
-
}),
|
|
124
|
+
}), V = v(() => {
|
|
123
125
|
R.open({
|
|
124
126
|
title: t("logoutAllSession", {
|
|
125
127
|
type: t(r.status)
|
|
@@ -133,7 +135,7 @@ function Ae({
|
|
|
133
135
|
},
|
|
134
136
|
cancelButtonText: t("cancel"),
|
|
135
137
|
onConfirm: async () => {
|
|
136
|
-
await
|
|
138
|
+
await M.user.logout({
|
|
137
139
|
status: r.status,
|
|
138
140
|
visitorId: y,
|
|
139
141
|
includeFederated: !0
|
|
@@ -143,7 +145,7 @@ function Ae({
|
|
|
143
145
|
}), L = [];
|
|
144
146
|
h && L.push(
|
|
145
147
|
/* @__PURE__ */ n(
|
|
146
|
-
|
|
148
|
+
ne,
|
|
147
149
|
{
|
|
148
150
|
title: t("logoutAllTips", {
|
|
149
151
|
type: t(r.status)
|
|
@@ -155,8 +157,8 @@ function Ae({
|
|
|
155
157
|
size: "small",
|
|
156
158
|
variant: "contained",
|
|
157
159
|
color: "error",
|
|
158
|
-
onClick:
|
|
159
|
-
disabled:
|
|
160
|
+
onClick: V,
|
|
161
|
+
disabled: N,
|
|
160
162
|
children: t("logoutAll", {
|
|
161
163
|
type: t(r.status)
|
|
162
164
|
})
|
|
@@ -166,7 +168,7 @@ function Ae({
|
|
|
166
168
|
"logoutAll"
|
|
167
169
|
)
|
|
168
170
|
);
|
|
169
|
-
const
|
|
171
|
+
const q = w(() => ({
|
|
170
172
|
// viewColumns: false,
|
|
171
173
|
search: !1,
|
|
172
174
|
sort: !1,
|
|
@@ -178,7 +180,7 @@ function Ae({
|
|
|
178
180
|
page: r.page - 1,
|
|
179
181
|
rowsPerPage: r.pageSize,
|
|
180
182
|
count: c.data?.total || 0
|
|
181
|
-
}), [c.data?.total, r.page, r.pageSize]),
|
|
183
|
+
}), [c.data?.total, r.page, r.pageSize]), Q = [
|
|
182
184
|
{
|
|
183
185
|
label: t("platform"),
|
|
184
186
|
name: "platform",
|
|
@@ -209,13 +211,23 @@ function Ae({
|
|
|
209
211
|
}
|
|
210
212
|
}
|
|
211
213
|
},
|
|
214
|
+
j && {
|
|
215
|
+
label: "App Pid",
|
|
216
|
+
name: "appPid",
|
|
217
|
+
options: {
|
|
218
|
+
customBodyRenderLite: (e) => {
|
|
219
|
+
const o = i[e];
|
|
220
|
+
return o.appPid ? /* @__PURE__ */ n(_, { size: 14, responsive: !1, compact: !0, did: o.appPid }) : null;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
},
|
|
212
224
|
l && {
|
|
213
225
|
label: t("user"),
|
|
214
226
|
name: "user",
|
|
215
227
|
options: {
|
|
216
228
|
customBodyRenderLite: (e) => {
|
|
217
229
|
const o = i[e];
|
|
218
|
-
return /* @__PURE__ */ n(d, { sx:
|
|
230
|
+
return /* @__PURE__ */ n(d, { sx: P({ minWidth: 150, maxWidth: 250 }, m ? D : {}), children: /* @__PURE__ */ n(le, { sessionUser: o.user, user: p }) });
|
|
219
231
|
}
|
|
220
232
|
}
|
|
221
233
|
},
|
|
@@ -245,7 +257,7 @@ function Ae({
|
|
|
245
257
|
options: {
|
|
246
258
|
customBodyRenderLite: (e) => {
|
|
247
259
|
const o = i[e];
|
|
248
|
-
return /* @__PURE__ */ n(
|
|
260
|
+
return /* @__PURE__ */ n(ue, { userSession: o, isMobile: m });
|
|
249
261
|
}
|
|
250
262
|
}
|
|
251
263
|
},
|
|
@@ -268,7 +280,7 @@ function Ae({
|
|
|
268
280
|
variant: "outlined",
|
|
269
281
|
size: "small",
|
|
270
282
|
color: "error",
|
|
271
|
-
onClick: () =>
|
|
283
|
+
onClick: () => U({ visitorId: o.visitorId }),
|
|
272
284
|
children: o.status === "expired" ? t("remove") : y === o.visitorId ? t("currentSession") : t("logout")
|
|
273
285
|
}
|
|
274
286
|
) });
|
|
@@ -323,20 +335,20 @@ function Ae({
|
|
|
323
335
|
}
|
|
324
336
|
},
|
|
325
337
|
children: [
|
|
326
|
-
|
|
338
|
+
E,
|
|
327
339
|
/* @__PURE__ */ n(
|
|
328
|
-
|
|
340
|
+
$,
|
|
329
341
|
{
|
|
330
342
|
count: c.data?.total || 0,
|
|
331
343
|
locale: b,
|
|
332
344
|
data: i,
|
|
333
|
-
columns:
|
|
345
|
+
columns: Q,
|
|
334
346
|
customButtons: L,
|
|
335
|
-
options:
|
|
347
|
+
options: q,
|
|
336
348
|
loading: c.loading,
|
|
337
349
|
className: "pc-user-sessions-table",
|
|
338
350
|
title: /* @__PURE__ */ s(
|
|
339
|
-
|
|
351
|
+
re,
|
|
340
352
|
{
|
|
341
353
|
row: !0,
|
|
342
354
|
sx: { lineHeight: 1, ml: 1 },
|
|
@@ -353,7 +365,7 @@ function Ae({
|
|
|
353
365
|
t("online"),
|
|
354
366
|
/* @__PURE__ */ s(a, { component: "span", sx: { ml: 0.5, color: "text.secondary" }, children: [
|
|
355
367
|
"(",
|
|
356
|
-
|
|
368
|
+
u.online,
|
|
357
369
|
")"
|
|
358
370
|
] })
|
|
359
371
|
] })
|
|
@@ -368,7 +380,7 @@ function Ae({
|
|
|
368
380
|
t("expired"),
|
|
369
381
|
/* @__PURE__ */ s(a, { component: "span", sx: { ml: 0.5, color: "text.secondary" }, children: [
|
|
370
382
|
"(",
|
|
371
|
-
|
|
383
|
+
u.expired,
|
|
372
384
|
")"
|
|
373
385
|
] })
|
|
374
386
|
] })
|
|
@@ -383,7 +395,7 @@ function Ae({
|
|
|
383
395
|
t("offline"),
|
|
384
396
|
/* @__PURE__ */ s(a, { component: "span", sx: { ml: 0.5, color: "text.secondary" }, children: [
|
|
385
397
|
"(",
|
|
386
|
-
|
|
398
|
+
u.offline,
|
|
387
399
|
")"
|
|
388
400
|
] })
|
|
389
401
|
] })
|
|
@@ -402,5 +414,5 @@ function Ae({
|
|
|
402
414
|
);
|
|
403
415
|
}
|
|
404
416
|
export {
|
|
405
|
-
|
|
417
|
+
Pe as default
|
|
406
418
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/ui-react",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.26",
|
|
4
4
|
"description": "Some useful front-end web components that can be used in Blocklets.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@abtnode/constant": "^1.16.48",
|
|
37
37
|
"@abtnode/util": "^1.16.48",
|
|
38
|
-
"@arcblock/bridge": "3.1.
|
|
39
|
-
"@arcblock/icons": "3.1.
|
|
40
|
-
"@arcblock/react-hooks": "3.1.
|
|
38
|
+
"@arcblock/bridge": "3.1.26",
|
|
39
|
+
"@arcblock/icons": "3.1.26",
|
|
40
|
+
"@arcblock/react-hooks": "3.1.26",
|
|
41
41
|
"@arcblock/ws": "^1.21.3",
|
|
42
42
|
"@blocklet/constant": "^1.16.48",
|
|
43
43
|
"@blocklet/did-space-react": "^1.1.16",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"access": "public"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
-
"@arcblock/did-connect-react": "3.1.
|
|
87
|
+
"@arcblock/did-connect-react": "3.1.26",
|
|
88
88
|
"@types/dompurify": "^3.2.0",
|
|
89
89
|
"@types/ua-parser-js": "^0.7.39",
|
|
90
90
|
"@types/validator": "^13.15.2",
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
"jest": "^29.7.0",
|
|
93
93
|
"unbuild": "^2.0.0"
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "2c9fa3385e138df1e652ef111353d1986e37b360"
|
|
96
96
|
}
|
|
@@ -8,6 +8,7 @@ import RelativeTime from '@arcblock/ux/lib/RelativeTime';
|
|
|
8
8
|
import UAParser from 'ua-parser-js';
|
|
9
9
|
import { getVisitorId } from '@arcblock/ux/lib/Util';
|
|
10
10
|
import { useConfirm } from '@arcblock/ux/lib/Dialog';
|
|
11
|
+
import DidAddress from '@arcblock/ux/lib/DID';
|
|
11
12
|
import PQueue from 'p-queue';
|
|
12
13
|
import {
|
|
13
14
|
Box,
|
|
@@ -102,6 +103,7 @@ export default function UserSessions({
|
|
|
102
103
|
showUser = true,
|
|
103
104
|
getUserSessions,
|
|
104
105
|
showOffline = false,
|
|
106
|
+
showAppPid = false,
|
|
105
107
|
}: {
|
|
106
108
|
readonly user: User & {
|
|
107
109
|
userSessions?: any[];
|
|
@@ -109,6 +111,7 @@ export default function UserSessions({
|
|
|
109
111
|
readonly showAction?: boolean;
|
|
110
112
|
readonly showUser?: boolean;
|
|
111
113
|
readonly showOffline?: boolean;
|
|
114
|
+
readonly showAppPid?: boolean;
|
|
112
115
|
readonly getUserSessions: (params: {
|
|
113
116
|
page: number;
|
|
114
117
|
pageSize: number;
|
|
@@ -319,6 +322,16 @@ export default function UserSessions({
|
|
|
319
322
|
},
|
|
320
323
|
},
|
|
321
324
|
},
|
|
325
|
+
showAppPid && {
|
|
326
|
+
label: 'App Pid',
|
|
327
|
+
name: 'appPid',
|
|
328
|
+
options: {
|
|
329
|
+
customBodyRenderLite: (rawIndex: number) => {
|
|
330
|
+
const x = safeData[rawIndex];
|
|
331
|
+
return x.appPid ? <DidAddress size={14} responsive={false} compact did={x.appPid} /> : null;
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
},
|
|
322
335
|
showUser && {
|
|
323
336
|
label: t('user'),
|
|
324
337
|
name: 'user',
|