@abtnode/ux 1.16.11-next-8a4df821 → 1.16.11-next-ca5f18b5

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.
@@ -3,436 +3,27 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = Storage;
6
+ exports.default = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
- var _Box = _interopRequireDefault(require("@mui/material/Box"));
9
- var _context = require("@arcblock/ux/lib/Locale/context");
10
- var _constant = require("@blocklet/constant");
11
- var _styled = _interopRequireDefault(require("@emotion/styled"));
12
- var _Typography = _interopRequireDefault(require("@mui/material/Typography"));
13
- var _material = require("@mui/material");
14
- var _Button = _interopRequireDefault(require("@arcblock/ux/lib/Button"));
15
- var _Datatable = _interopRequireDefault(require("@arcblock/ux/lib/Datatable"));
16
- var _ahooks = require("ahooks");
17
- var _Tag = _interopRequireDefault(require("@arcblock/ux/lib/Tag"));
18
- var _dayjs = _interopRequireDefault(require("dayjs"));
19
- var _HelpOutline = _interopRequireDefault(require("@mui/icons-material/HelpOutline"));
20
- var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
21
- var _lodash = require("lodash");
22
- var _node = require("../../contexts/node");
23
8
  var _blocklet = require("../../../lib/contexts/blocklet");
24
- var _switchDidSpaces = _interopRequireDefault(require("./switch-did-spaces"));
25
9
  var _spaces = require("../../util/spaces");
26
- var _switchControl = _interopRequireDefault(require("../component/switch-control"));
10
+ var _disconnect = _interopRequireDefault(require("./disconnect"));
11
+ var _connected = _interopRequireDefault(require("./connected"));
27
12
  var _jsxRuntime = require("react/jsx-runtime");
28
- var _templateObject;
29
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
31
15
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
32
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
33
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
34
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
36
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
37
- function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
38
- const Container = (0, _styled.default)('div')(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n height: 100%;\n overflow-y: auto;\n"])));
39
-
40
- /**
41
- * @description 实时显示备份的进度
42
- * @param {{appDid: string}} {appDid}
43
- * @return {{message: string, progress: number, completed: boolean}}
44
- */
45
- function useBackupProgress(_ref) {
46
- let {
47
- appDid
48
- } = _ref;
49
- const [progress, setProgress] = (0, _react.useState)({
50
- message: '',
51
- progress: 0,
52
- completed: false
53
- });
54
- const node = (0, _node.useNodeContext)();
55
- const {
56
- ws: {
57
- useSubscription
58
- }
59
- } = node;
60
- useSubscription(_constant.BlockletEvents.backupProgress, data => {
61
- setProgress(() => _objectSpread({}, data));
62
- }, [appDid]);
63
- return progress;
64
- }
65
-
66
- /**
67
- * @description
68
- * @param {{ blocklet: import('@abtnode/client').BlockletState }} { blocklet }
69
- * @return {{backups: import('@abtnode/client').Backup[]}}
70
- */
71
- function useBackups(_ref2) {
72
- let {
73
- blocklet,
74
- loading,
75
- progress
76
- } = _ref2;
77
- const [backups, setBackups] = (0, _react.useState)([]);
78
- const {
79
- api
80
- } = (0, _node.useNodeContext)();
81
- // eslint-disable-next-line react-hooks/exhaustive-deps
82
- const fetchBackups = (0, _react.useCallback)((0, _lodash.throttle)(async () => {
83
- var _blocklet$meta;
84
- const {
85
- backups: data
86
- } = await api.getBlockletBackups({
87
- input: {
88
- did: blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$meta = blocklet.meta) === null || _blocklet$meta === void 0 ? void 0 : _blocklet$meta.did
89
- }
90
- });
91
- setBackups(data !== null && data !== void 0 ? data : []);
92
- }, 2000), []);
93
- (0, _ahooks.useAsyncEffect)(async () => {
94
- fetchBackups();
95
- }, [blocklet, progress, loading]);
96
- return {
97
- backups
98
- };
99
- }
100
- function useSpaceGateways(_ref3) {
101
- let {
102
- blocklet
103
- } = _ref3;
104
- const [spaceGateways, setSpaceGateways] = (0, _react.useState)( /** @type {SpaceGateway[]} */
105
- []);
106
- const {
107
- api
108
- } = (0, _node.useNodeContext)();
109
- (0, _ahooks.useAsyncEffect)(async () => {
110
- const {
111
- spaceGateways: _spaceGateways
112
- } = await api.getBlockletSpaceGateways({
113
- input: {
114
- did: blocklet.meta.did
115
- }
116
- });
117
- setSpaceGateways([{
118
- name: 'Prod DID Spaces',
119
- url: 'https://www.didspaces.com/app',
120
- protected: true
121
- }, ...(_spaceGateways !== null && _spaceGateways !== void 0 ? _spaceGateways : [])]);
122
- }, [blocklet]);
123
- return {
124
- spaceGateways
125
- };
126
- }
127
- function Storage() {
128
- /** @type {{ api: import('@abtnode/client').ABTNodeClient, info: import('@abtnode/client').NodeState }} */
129
- const {
130
- api
131
- } = (0, _node.useNodeContext)();
132
- const {
133
- t,
134
- locale
135
- } = (0, _react.useContext)(_context.LocaleContext);
16
+ function NewStorage() {
136
17
  /** @type {{ blocklet: import('@abtnode/client').BlockletState }} */
137
18
  const {
138
19
  blocklet
139
20
  } = (0, _blocklet.useBlockletContext)();
140
21
  const endpoint = (0, _react.useMemo)(() => (0, _spaces.getSpaceBackupEndpoint)(blocklet === null || blocklet === void 0 ? void 0 : blocklet.environments), [blocklet]);
141
- const progress = useBackupProgress({
142
- appDid: blocklet === null || blocklet === void 0 ? void 0 : blocklet.appDid
143
- });
144
- const [loading, setLoading] = (0, _react.useState)(false);
145
- const {
146
- backups
147
- } = useBackups({
148
- blocklet,
149
- progress,
150
- loading
151
- });
152
- const {
153
- spaceGateways
154
- } = useSpaceGateways({
155
- blocklet
156
- });
157
- const handleManualBackup = async () => {
158
- try {
159
- if (loading) {
160
- return;
161
- }
162
- setLoading(true);
163
- await api.backupBlocklet({
164
- input: {
165
- appDid: blocklet.appDid,
166
- to: 'spaces'
167
- }
168
- });
169
- } catch (error) {
170
- _Toast.default.error(error.message);
171
- console.error(error);
172
- }
173
- };
174
- const columns = [{
175
- label: 'DID Spaces',
176
- name: 'target',
177
- options: {
178
- // eslint-disable-next-line react/no-unstable-nested-components
179
- customBodyRenderLite: index => {
180
- var _spaceGateways$find$n, _spaceGateways$find;
181
- // eslint-disable-next-line no-unused-vars
182
- const {
183
- targetUrl
184
- } = backups[index];
185
- const spaceName = (_spaceGateways$find$n = (_spaceGateways$find = spaceGateways.find(spaceGateway => targetUrl === null || targetUrl === void 0 ? void 0 : targetUrl.includes(spaceGateway === null || spaceGateway === void 0 ? void 0 : spaceGateway.url))) === null || _spaceGateways$find === void 0 ? void 0 : _spaceGateways$find.name) !== null && _spaceGateways$find$n !== void 0 ? _spaceGateways$find$n : 'DID Spaces';
186
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Link, {
187
- fontSize: "16px",
188
- href: targetUrl,
189
- target: "_blank",
190
- children: spaceName
191
- });
192
- }
193
- }
194
- }, {
195
- label: t('common.strategy'),
196
- name: 'strategy',
197
- options: {
198
- /**
199
- * @param {0 | 1} strategy
200
- * @returns {React.ReactNode}
201
- */
202
- // eslint-disable-next-line react/no-unstable-nested-components
203
- customBodyRender: strategy => {
204
- const text = strategy === 0 ? t('common.auto') : t('common.manual');
205
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tag.default, {
206
- children: text
207
- });
208
- }
209
- }
210
- }, {
211
- label: t('common.startTime'),
212
- name: 'createdAt',
213
- options: {
214
- /**
215
- * @param {0 | 1} strategy
216
- * @returns {React.ReactNode}
217
- */
218
- // eslint-disable-next-line react/no-unstable-nested-components
219
- customBodyRender: createdAt => {
220
- return (0, _dayjs.default)(createdAt).format('YYYY-MM-DD HH:mm:ss');
221
- }
222
- }
223
- }, {
224
- label: t('common.endTime'),
225
- name: 'updatedAt',
226
- options: {
227
- /**
228
- * @param {string} updatedAt
229
- * @returns {React.ReactNode}
230
- */
231
- // eslint-disable-next-line react/no-unstable-nested-components
232
- customBodyRender: updatedAt => {
233
- if ((0, _lodash.isEmpty)(updatedAt)) {
234
- return '';
235
- }
236
- return (0, _dayjs.default)(updatedAt).format('YYYY-MM-DD HH:mm:ss');
237
- }
238
- }
239
- }, {
240
- label: t('common.status'),
241
- name: 'status',
242
- options: {
243
- /**
244
- * @param {string} status
245
- * @returns {React.ReactNode}
246
- */
247
- // eslint-disable-next-line react/no-unstable-nested-components
248
- customBodyRenderLite: index => {
249
- var _backups$index;
250
- const {
251
- status,
252
- message
253
- } = (_backups$index = backups === null || backups === void 0 ? void 0 : backups[index]) !== null && _backups$index !== void 0 ? _backups$index : {};
254
- if ((0, _lodash.isNull)(status)) {
255
- return t('common.progress');
256
- }
257
- const node = !status ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tag.default, {
258
- type: "success",
259
- children: t('common.succeeded')
260
- }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
261
- display: "inline-flex",
262
- alignItems: "center",
263
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Tag.default, {
264
- type: "error",
265
- children: t('common.failed')
266
- }), " \xA0", /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Tooltip, {
267
- style: {
268
- display: 'flex',
269
- alignItems: 'center'
270
- },
271
- title: message,
272
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Icon, {
273
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_HelpOutline.default, {
274
- color: "error"
275
- })
276
- })
277
- })]
278
- });
279
- return node;
280
- }
281
- }
282
- }];
283
- (0, _react.useEffect)(() => {
284
- if (progress !== null && progress !== void 0 && progress.completed) {
285
- if ((progress === null || progress === void 0 ? void 0 : progress.progress) === 100) {
286
- _Toast.default.success(t('storage.spaces.backupSuccessfully'));
287
- } else if ((progress === null || progress === void 0 ? void 0 : progress.progress) === -1) {
288
- _Toast.default.error(progress === null || progress === void 0 ? void 0 : progress.message);
289
- }
290
- setLoading(false);
291
- progress.progress = 0;
292
- } else if (progress.progress) {
293
- setLoading(true);
294
- }
295
- // eslint-disable-next-line react-hooks/exhaustive-deps
296
- }, [progress]);
297
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Container, {
298
- style: {
299
- maxWidth: '1280px'
300
- },
301
- children: [endpoint && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
302
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
303
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
304
- sx: {
305
- display: 'flex',
306
- alignItems: 'center'
307
- },
308
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
309
- fontSize: "1.2rem",
310
- fontWeight: "bold",
311
- sx: {
312
- flexGrow: 1
313
- },
314
- children: t('storage.spaces.strategy.title')
315
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, {
316
- size: "small",
317
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
318
- variant: "contained",
319
- size: "small",
320
- onClick: handleManualBackup,
321
- loading: loading && Boolean(progress === null || progress === void 0 ? void 0 : progress.progress),
322
- children: t('storage.spaces.strategy.backupNow')
323
- })
324
- })]
325
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_switchControl.default, {
326
- name: "enable-auto-backup",
327
- disabled: true,
328
- labelProps: {
329
- label: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
330
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
331
- children: t('storage.spaces.strategy.autoBackup')
332
- })
333
- })
334
- },
335
- style: {
336
- marginTop: 16
337
- }
338
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
339
- marginTop: "16px",
340
- display: "flex",
341
- alignItems: "center",
342
- children: (backups === null || backups === void 0 ? void 0 : backups.some(b => !b.status && (b === null || b === void 0 ? void 0 : b.targetUrl.includes((0, _spaces.getSpaceGatewayFromEndpoint)(endpoint))))) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
343
- variant: "outlined",
344
- size: "small",
345
- onClick: () => window.open((0, _spaces.getBackupFilesUrlFromEndpoint)(endpoint)),
346
- children: t('storage.spaces.strategy.viewBackupFiles')
347
- })
348
- })]
349
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
350
- marginTop: "16px",
351
- hidden: !(loading && progress !== null && progress !== void 0 && progress.progress),
352
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
353
- marginTop: "8px",
354
- marginBottom: "8px",
355
- fontSize: "1.2rem",
356
- fontWeight: "bold",
357
- children: t('storage.spaces.progress.title')
358
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {}), loading && !!(progress !== null && progress !== void 0 && progress.progress) ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
359
- sx: {
360
- overflow: 'hidden'
361
- },
362
- display: "flex",
363
- flexDirection: "column",
364
- justifyContent: "center",
365
- textAlign: "center",
366
- marginTop: "24px",
367
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
368
- color: "primary",
369
- children: progress === null || progress === void 0 ? void 0 : progress.message
370
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
371
- sx: {
372
- display: 'flex',
373
- alignItems: 'center'
374
- },
375
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
376
- sx: {
377
- width: '100%',
378
- mr: 1
379
- },
380
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.LinearProgress, {
381
- color: "primary",
382
- variant: "determinate",
383
- value: progress === null || progress === void 0 ? void 0 : progress.progress
384
- })
385
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
386
- sx: {
387
- minWidth: 35
388
- },
389
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Typography.default, {
390
- variant: "body2",
391
- color: "text.secondary",
392
- children: [progress === null || progress === void 0 ? void 0 : progress.progress, "%"]
393
- })
394
- })]
395
- })]
396
- }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
397
- marginTop: "16px",
398
- display: "flex",
399
- justifyContent: "center",
400
- alignContent: "center",
401
- height: "44px",
402
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
403
- children: t('storage.spaces.notYet')
404
- })
405
- })]
406
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
407
- marginTop: "24px",
408
- hidden: !(backups !== null && backups !== void 0 && backups.length),
409
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
410
- marginTop: "8px",
411
- marginBottom: "8px",
412
- fontSize: "1.2rem",
413
- fontWeight: "bold",
414
- children: t('storage.spaces.record.title')
415
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Datatable.default, {
416
- data: backups,
417
- columns: columns,
418
- emptyNode: t('storage.spaces.record.emptyData', locale),
419
- options: {
420
- download: false,
421
- filter: false,
422
- print: false
423
- }
424
- })]
425
- })]
426
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
427
- marginTop: endpoint ? '24px' : '0px',
428
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
429
- marginBottom: "8px",
430
- fontSize: "1.2rem",
431
- fontWeight: "bold",
432
- children: t('storage.spaces.gateway.connect.title')
433
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_switchDidSpaces.default, {
434
- mode: endpoint ? 'switch' : 'add'
435
- })]
436
- })]
437
- });
438
- }
22
+ if (endpoint) {
23
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_connected.default, {});
24
+ }
25
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_disconnect.default, {});
26
+ }
27
+ NewStorage.propTypes = {};
28
+ var _default = NewStorage;
29
+ exports.default = _default;