@blocklet/did-space-react 1.0.13 → 1.0.15
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/dist/cjs/components/space-card/audit-log-bar.d.ts +6 -2
- package/dist/cjs/components/space-card/audit-log-bar.js +5 -2
- package/dist/cjs/components/space-card/index.js +3 -2
- package/dist/cjs/hooks/use-audit-log.d.ts +4 -1
- package/dist/cjs/hooks/use-audit-log.js +21 -5
- package/dist/cjs/hooks/use-space-info.js +1 -1
- package/dist/cjs/package.json.js +1 -1
- package/dist/es/components/space-card/audit-log-bar.d.ts +6 -2
- package/dist/es/components/space-card/audit-log-bar.js +5 -2
- package/dist/es/components/space-card/index.js +4 -3
- package/dist/es/hooks/use-audit-log.d.ts +4 -1
- package/dist/es/hooks/use-audit-log.js +21 -5
- package/dist/es/hooks/use-space-info.js +1 -1
- package/dist/es/package.json.js +1 -1
- package/package.json +3 -3
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { DIDSpaceStatus } from '../../types';
|
|
2
|
+
export interface AuditLogBarProps {
|
|
2
3
|
endpoint: string;
|
|
4
|
+
spaceStatus: DIDSpaceStatus;
|
|
5
|
+
errorCode: number;
|
|
3
6
|
deps?: any[];
|
|
4
|
-
}
|
|
7
|
+
}
|
|
8
|
+
export declare function AuditLogBar({ endpoint, spaceStatus, errorCode, deps }: AuditLogBarProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -4,19 +4,22 @@ const jsxRuntime = require('react/jsx-runtime');
|
|
|
4
4
|
const material = require('@mui/material');
|
|
5
5
|
const OpenInNewIcon = require('@mui/icons-material/OpenInNew');
|
|
6
6
|
const ufo = require('ufo');
|
|
7
|
+
const index = require('../../types/index.js');
|
|
7
8
|
const util = require('../../libs/util.js');
|
|
8
9
|
const useLocale = require('../../hooks/use-locale.js');
|
|
9
10
|
const useAuditLog = require('../../hooks/use-audit-log.js');
|
|
10
11
|
|
|
11
|
-
function AuditLogBar({ endpoint, deps = [] }) {
|
|
12
|
+
function AuditLogBar({ endpoint, spaceStatus, errorCode, deps = [] }) {
|
|
12
13
|
const { t } = useLocale();
|
|
13
14
|
const { loading, data: auditLogs } = useAuditLog({
|
|
14
15
|
endpoint,
|
|
16
|
+
spaceStatus,
|
|
17
|
+
errorCode,
|
|
15
18
|
deps
|
|
16
19
|
});
|
|
17
20
|
const { baseUrl, spaceDid, appDid } = util.getSpaceEndpointContext(endpoint);
|
|
18
21
|
const latestLog = auditLogs?.[0];
|
|
19
|
-
if (loading) {
|
|
22
|
+
if (loading || spaceStatus === index.DIDSpaceStatus.LOADING) {
|
|
20
23
|
return /* @__PURE__ */ jsxRuntime.jsx(material.Skeleton, { variant: "text", sx: { width: "100%", fontSize: "1rem" } });
|
|
21
24
|
}
|
|
22
25
|
if (!latestLog) {
|
|
@@ -99,7 +99,8 @@ function Status({
|
|
|
99
99
|
ErrorLink,
|
|
100
100
|
{
|
|
101
101
|
title: t("storage.spaces.error.incompatible", {
|
|
102
|
-
spaceVersion,
|
|
102
|
+
spaceVersion: spaceVersion || " < 0.5.77",
|
|
103
|
+
// version 字段是在 0.5.77 版本添加的
|
|
103
104
|
expectVersion
|
|
104
105
|
}),
|
|
105
106
|
url: ufo.joinURL(new URL(spaceUrl).origin, ".well-known/service/admin/components")
|
|
@@ -238,7 +239,7 @@ function DIDSpaceConnection({
|
|
|
238
239
|
}
|
|
239
240
|
return action;
|
|
240
241
|
};
|
|
241
|
-
const originalFooter = /* @__PURE__ */ jsxRuntime.jsx(auditLogBar.AuditLogBar, { endpoint, deps: refreshDeps });
|
|
242
|
+
const originalFooter = /* @__PURE__ */ jsxRuntime.jsx(auditLogBar.AuditLogBar, { endpoint, spaceStatus: spaceStatus.current, errorCode, deps: refreshDeps });
|
|
242
243
|
const renderFooter = () => {
|
|
243
244
|
if (typeof footer === "function") {
|
|
244
245
|
return footer({
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { AuditLogModel } from '@did-space/core';
|
|
2
2
|
import { AuditLogAction, AuditLogStatus } from '@did-space/core/model';
|
|
3
|
+
import { DIDSpaceStatus } from '../types';
|
|
3
4
|
export interface AuditLogModelExtra extends AuditLogModel {
|
|
4
5
|
description: React.ReactNode;
|
|
5
6
|
}
|
|
6
|
-
export default function useAuditLog({ endpoint, size, status, actionType, deps, }: {
|
|
7
|
+
export default function useAuditLog({ endpoint, spaceStatus, errorCode, size, status, actionType, deps, }: {
|
|
7
8
|
endpoint: string;
|
|
9
|
+
spaceStatus: DIDSpaceStatus;
|
|
10
|
+
errorCode: number;
|
|
8
11
|
size?: number;
|
|
9
12
|
status?: AuditLogStatus | AuditLogStatus[];
|
|
10
13
|
actionType?: AuditLogAction | AuditLogAction[];
|
|
@@ -5,11 +5,13 @@ const ahooks = require('ahooks');
|
|
|
5
5
|
const model = require('@did-space/core/model');
|
|
6
6
|
const ufo = require('ufo');
|
|
7
7
|
const xbytes = require('xbytes');
|
|
8
|
+
const constants = require('@did-space/core/constants');
|
|
8
9
|
const api = require('../libs/api.js');
|
|
9
10
|
const useLocale = require('./use-locale.js');
|
|
10
11
|
const util = require('../libs/util.js');
|
|
12
|
+
const index = require('../types/index.js');
|
|
11
13
|
|
|
12
|
-
const
|
|
14
|
+
const translateKeyMap = {
|
|
13
15
|
[model.AuditLogAction.APP_BACKUP]: {
|
|
14
16
|
description: "auditLog.backup.description"
|
|
15
17
|
},
|
|
@@ -26,11 +28,19 @@ const TranslateKeyMap = {
|
|
|
26
28
|
description: "auditLog.objectsSync.description"
|
|
27
29
|
}
|
|
28
30
|
};
|
|
31
|
+
const unreachableErrorCodes = [
|
|
32
|
+
constants.SPACE_CONNECT_ERROR_CODE.CORS_BLOCKED,
|
|
33
|
+
constants.SPACE_CONNECT_ERROR_CODE.NETWORK_ERROR,
|
|
34
|
+
constants.SPACE_CONNECT_ERROR_CODE.INCOMPATIBLE
|
|
35
|
+
];
|
|
36
|
+
const defaultActionTypes = [model.AuditLogAction.APP_BACKUP, model.AuditLogAction.APP_RESTORE, model.AuditLogAction.APP_OBJECTS_SYNC];
|
|
29
37
|
function useAuditLog({
|
|
30
38
|
endpoint,
|
|
39
|
+
spaceStatus,
|
|
40
|
+
errorCode,
|
|
31
41
|
size = 1,
|
|
32
42
|
status = model.AuditLogStatus.SUCCEEDED,
|
|
33
|
-
actionType =
|
|
43
|
+
actionType = defaultActionTypes,
|
|
34
44
|
deps = []
|
|
35
45
|
}) {
|
|
36
46
|
const { t, locale } = useLocale();
|
|
@@ -39,8 +49,14 @@ function useAuditLog({
|
|
|
39
49
|
if (!isUrl(endpoint)) {
|
|
40
50
|
return void 0;
|
|
41
51
|
}
|
|
52
|
+
if (spaceStatus === index.DIDSpaceStatus.LOADING) {
|
|
53
|
+
return void 0;
|
|
54
|
+
}
|
|
55
|
+
if (unreachableErrorCodes.includes(errorCode)) {
|
|
56
|
+
return void 0;
|
|
57
|
+
}
|
|
42
58
|
const { data: res } = await api.get(
|
|
43
|
-
ufo.joinURL(window.location.origin, "/.well-known/service/api/did-space/audit-
|
|
59
|
+
ufo.joinURL(window.location.origin, "/.well-known/service/api/did-space/audit-logs"),
|
|
44
60
|
{
|
|
45
61
|
timeout: 1e3 * 30,
|
|
46
62
|
params: {
|
|
@@ -54,7 +70,7 @@ function useAuditLog({
|
|
|
54
70
|
return res.data.rows;
|
|
55
71
|
},
|
|
56
72
|
{
|
|
57
|
-
refreshDeps: [endpoint, size]
|
|
73
|
+
refreshDeps: [endpoint, spaceStatus, errorCode, size, status, actionType, ...deps],
|
|
58
74
|
onError(err) {
|
|
59
75
|
console.error(err);
|
|
60
76
|
}
|
|
@@ -68,7 +84,7 @@ function useAuditLog({
|
|
|
68
84
|
}
|
|
69
85
|
const result = {
|
|
70
86
|
...v,
|
|
71
|
-
description: t(
|
|
87
|
+
description: t(translateKeyMap[v.actionType].description, {
|
|
72
88
|
...extraData,
|
|
73
89
|
relativeTime: util.formatRelativeTime(v.createdAt, locale)
|
|
74
90
|
})
|
package/dist/cjs/package.json.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { DIDSpaceStatus } from '../../types';
|
|
2
|
+
export interface AuditLogBarProps {
|
|
2
3
|
endpoint: string;
|
|
4
|
+
spaceStatus: DIDSpaceStatus;
|
|
5
|
+
errorCode: number;
|
|
3
6
|
deps?: any[];
|
|
4
|
-
}
|
|
7
|
+
}
|
|
8
|
+
export declare function AuditLogBar({ endpoint, spaceStatus, errorCode, deps }: AuditLogBarProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -2,19 +2,22 @@ import { jsx, jsxs } from 'react/jsx-runtime';
|
|
|
2
2
|
import { Skeleton, Box, Link } from '@mui/material';
|
|
3
3
|
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
|
|
4
4
|
import { joinURL } from 'ufo';
|
|
5
|
+
import { DIDSpaceStatus } from '../../types/index.js';
|
|
5
6
|
import { getSpaceEndpointContext } from '../../libs/util.js';
|
|
6
7
|
import useLocale from '../../hooks/use-locale.js';
|
|
7
8
|
import useAuditLog from '../../hooks/use-audit-log.js';
|
|
8
9
|
|
|
9
|
-
function AuditLogBar({ endpoint, deps = [] }) {
|
|
10
|
+
function AuditLogBar({ endpoint, spaceStatus, errorCode, deps = [] }) {
|
|
10
11
|
const { t } = useLocale();
|
|
11
12
|
const { loading, data: auditLogs } = useAuditLog({
|
|
12
13
|
endpoint,
|
|
14
|
+
spaceStatus,
|
|
15
|
+
errorCode,
|
|
13
16
|
deps
|
|
14
17
|
});
|
|
15
18
|
const { baseUrl, spaceDid, appDid } = getSpaceEndpointContext(endpoint);
|
|
16
19
|
const latestLog = auditLogs?.[0];
|
|
17
|
-
if (loading) {
|
|
20
|
+
if (loading || spaceStatus === DIDSpaceStatus.LOADING) {
|
|
18
21
|
return /* @__PURE__ */ jsx(Skeleton, { variant: "text", sx: { width: "100%", fontSize: "1rem" } });
|
|
19
22
|
}
|
|
20
23
|
if (!latestLog) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import isUndefined from 'lodash/isUndefined';
|
|
3
3
|
import { withQuery, joinURL } from 'ufo';
|
|
4
4
|
import { Box, Stack, Tooltip, Link, Skeleton } from '@mui/material';
|
|
@@ -97,7 +97,8 @@ function Status({
|
|
|
97
97
|
ErrorLink,
|
|
98
98
|
{
|
|
99
99
|
title: t("storage.spaces.error.incompatible", {
|
|
100
|
-
spaceVersion,
|
|
100
|
+
spaceVersion: spaceVersion || " < 0.5.77",
|
|
101
|
+
// version 字段是在 0.5.77 版本添加的
|
|
101
102
|
expectVersion
|
|
102
103
|
}),
|
|
103
104
|
url: joinURL(new URL(spaceUrl).origin, ".well-known/service/admin/components")
|
|
@@ -236,7 +237,7 @@ function DIDSpaceConnection({
|
|
|
236
237
|
}
|
|
237
238
|
return action;
|
|
238
239
|
};
|
|
239
|
-
const originalFooter = /* @__PURE__ */ jsx(AuditLogBar, { endpoint, deps: refreshDeps });
|
|
240
|
+
const originalFooter = /* @__PURE__ */ jsx(AuditLogBar, { endpoint, spaceStatus: spaceStatus.current, errorCode, deps: refreshDeps });
|
|
240
241
|
const renderFooter = () => {
|
|
241
242
|
if (typeof footer === "function") {
|
|
242
243
|
return footer({
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { AuditLogModel } from '@did-space/core';
|
|
2
2
|
import { AuditLogAction, AuditLogStatus } from '@did-space/core/model';
|
|
3
|
+
import { DIDSpaceStatus } from '../types';
|
|
3
4
|
export interface AuditLogModelExtra extends AuditLogModel {
|
|
4
5
|
description: React.ReactNode;
|
|
5
6
|
}
|
|
6
|
-
export default function useAuditLog({ endpoint, size, status, actionType, deps, }: {
|
|
7
|
+
export default function useAuditLog({ endpoint, spaceStatus, errorCode, size, status, actionType, deps, }: {
|
|
7
8
|
endpoint: string;
|
|
9
|
+
spaceStatus: DIDSpaceStatus;
|
|
10
|
+
errorCode: number;
|
|
8
11
|
size?: number;
|
|
9
12
|
status?: AuditLogStatus | AuditLogStatus[];
|
|
10
13
|
actionType?: AuditLogAction | AuditLogAction[];
|
|
@@ -3,11 +3,13 @@ import { useRequest, useCreation } from 'ahooks';
|
|
|
3
3
|
import { AuditLogAction, AuditLogStatus } from '@did-space/core/model';
|
|
4
4
|
import { joinURL } from 'ufo';
|
|
5
5
|
import xbytes from 'xbytes';
|
|
6
|
+
import { SPACE_CONNECT_ERROR_CODE } from '@did-space/core/constants';
|
|
6
7
|
import api from '../libs/api.js';
|
|
7
8
|
import useLocale from './use-locale.js';
|
|
8
9
|
import { formatRelativeTime } from '../libs/util.js';
|
|
10
|
+
import { DIDSpaceStatus } from '../types/index.js';
|
|
9
11
|
|
|
10
|
-
const
|
|
12
|
+
const translateKeyMap = {
|
|
11
13
|
[AuditLogAction.APP_BACKUP]: {
|
|
12
14
|
description: "auditLog.backup.description"
|
|
13
15
|
},
|
|
@@ -24,11 +26,19 @@ const TranslateKeyMap = {
|
|
|
24
26
|
description: "auditLog.objectsSync.description"
|
|
25
27
|
}
|
|
26
28
|
};
|
|
29
|
+
const unreachableErrorCodes = [
|
|
30
|
+
SPACE_CONNECT_ERROR_CODE.CORS_BLOCKED,
|
|
31
|
+
SPACE_CONNECT_ERROR_CODE.NETWORK_ERROR,
|
|
32
|
+
SPACE_CONNECT_ERROR_CODE.INCOMPATIBLE
|
|
33
|
+
];
|
|
34
|
+
const defaultActionTypes = [AuditLogAction.APP_BACKUP, AuditLogAction.APP_RESTORE, AuditLogAction.APP_OBJECTS_SYNC];
|
|
27
35
|
function useAuditLog({
|
|
28
36
|
endpoint,
|
|
37
|
+
spaceStatus,
|
|
38
|
+
errorCode,
|
|
29
39
|
size = 1,
|
|
30
40
|
status = AuditLogStatus.SUCCEEDED,
|
|
31
|
-
actionType =
|
|
41
|
+
actionType = defaultActionTypes,
|
|
32
42
|
deps = []
|
|
33
43
|
}) {
|
|
34
44
|
const { t, locale } = useLocale();
|
|
@@ -37,8 +47,14 @@ function useAuditLog({
|
|
|
37
47
|
if (!isUrl(endpoint)) {
|
|
38
48
|
return void 0;
|
|
39
49
|
}
|
|
50
|
+
if (spaceStatus === DIDSpaceStatus.LOADING) {
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
if (unreachableErrorCodes.includes(errorCode)) {
|
|
54
|
+
return void 0;
|
|
55
|
+
}
|
|
40
56
|
const { data: res } = await api.get(
|
|
41
|
-
joinURL(window.location.origin, "/.well-known/service/api/did-space/audit-
|
|
57
|
+
joinURL(window.location.origin, "/.well-known/service/api/did-space/audit-logs"),
|
|
42
58
|
{
|
|
43
59
|
timeout: 1e3 * 30,
|
|
44
60
|
params: {
|
|
@@ -52,7 +68,7 @@ function useAuditLog({
|
|
|
52
68
|
return res.data.rows;
|
|
53
69
|
},
|
|
54
70
|
{
|
|
55
|
-
refreshDeps: [endpoint, size]
|
|
71
|
+
refreshDeps: [endpoint, spaceStatus, errorCode, size, status, actionType, ...deps],
|
|
56
72
|
onError(err) {
|
|
57
73
|
console.error(err);
|
|
58
74
|
}
|
|
@@ -66,7 +82,7 @@ function useAuditLog({
|
|
|
66
82
|
}
|
|
67
83
|
const result = {
|
|
68
84
|
...v,
|
|
69
|
-
description: t(
|
|
85
|
+
description: t(translateKeyMap[v.actionType].description, {
|
|
70
86
|
...extraData,
|
|
71
87
|
relativeTime: formatRelativeTime(v.createdAt, locale)
|
|
72
88
|
})
|
package/dist/es/package.json.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/did-space-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
4
4
|
"description": "Reusable react components for did space",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
},
|
|
82
82
|
"dependencies": {
|
|
83
83
|
"@arcblock/did": "^1.19.9",
|
|
84
|
-
"@did-space/core": "^1.0.
|
|
84
|
+
"@did-space/core": "^1.0.15",
|
|
85
85
|
"@mui/icons-material": "^5.16.14",
|
|
86
86
|
"@mui/lab": "^5.0.0-alpha.175",
|
|
87
87
|
"@mui/material": "^5.16.14",
|
|
@@ -150,5 +150,5 @@
|
|
|
150
150
|
"vite-plugin-node-polyfills": "^0.22.0",
|
|
151
151
|
"vitest": "^3.0.5"
|
|
152
152
|
},
|
|
153
|
-
"gitHead": "
|
|
153
|
+
"gitHead": "5b7c651163212bec81066afdd2f43cda21dbc9e7"
|
|
154
154
|
}
|