@abtnode/ux 1.16.21-beta-445a8baa → 1.16.21-beta-93c6e42b

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.
@@ -39,6 +39,7 @@ import BlockletSource from '../blocklet-source';
39
39
  import BlockletStatus from '../status';
40
40
  import BlockletVersion from '../version';
41
41
  import Confirm from '../../confirm';
42
+ import AutoCheckUpdate from '../storage/auto-check-update';
42
43
  import { useNodeContext } from '../../contexts/node';
43
44
  import { formatPerson, formatError, sleep, BlockletAdminRoles, formatToDatetime } from '../../util';
44
45
  import Permission from '../../permission';
@@ -52,6 +53,7 @@ import AddComponent from './add';
52
53
  import AddRule from '../router/action/add-rule';
53
54
  import RuleList from '../router/rule-list';
54
55
  import Actions from '../../actions';
56
+ import { useCheckUpdateByUrl } from '../../hooks/use-check-update-by-url';
55
57
  import { jsx as _jsx } from "react/jsx-runtime";
56
58
  import { jsxs as _jsxs } from "react/jsx-runtime";
57
59
  const getEngineRows = (engine, t) => {
@@ -726,6 +728,7 @@ export default function BlockletComponent({
726
728
  };
727
729
  });
728
730
  };
731
+ useCheckUpdateByUrl(checkForUpdates);
729
732
  return /*#__PURE__*/_jsxs(Div, {
730
733
  component: "div",
731
734
  ...rest,
@@ -733,36 +736,44 @@ export default function BlockletComponent({
733
736
  display: "flex",
734
737
  justifyContent: "space-between",
735
738
  alignItems: "center",
736
- children: [/*#__PURE__*/_jsxs("div", {
739
+ children: [/*#__PURE__*/_jsxs(Box, {
737
740
  className: "title",
741
+ flexDirection: "row",
742
+ display: "flex",
743
+ alignItems: "center",
744
+ style: {
745
+ marginLeft: '1em'
746
+ },
738
747
  children: [t('common.components'), !needMigration && /*#__PURE__*/_jsx(Permission, {
739
748
  permission: inService ? '' : 'mutate_blocklets',
740
749
  role: inService ? BlockletAdminRoles : [],
741
- children: /*#__PURE__*/_jsx(StyledBadge, {
742
- top: 1.2,
743
- right: 0.4,
744
- color: "error",
745
- badgeContent: "",
746
- variant: "dot",
747
- invisible: !showUpdateDot,
748
- children: /*#__PURE__*/_jsxs(Button, {
749
- disabled: loading || isInProgress(blocklet.status),
750
- color: "secondary",
751
- onClick: () => {
752
- checkForUpdates();
753
- },
754
- "data-cy": "check-for-updates",
755
- children: [/*#__PURE__*/_jsx(Box, {
756
- mr: 0.5,
757
- display: "flex",
758
- children: loading ? /*#__PURE__*/_jsx(Spinner, {
759
- size: 16
760
- }) : /*#__PURE__*/_jsx(UpdateIcon, {
761
- style: {
762
- fontSize: '1em'
763
- }
764
- })
765
- }), t('blocklet.component.checkUpdateTitle')]
750
+ children: /*#__PURE__*/_jsx(AutoCheckUpdate, {
751
+ children: /*#__PURE__*/_jsx(StyledBadge, {
752
+ top: 1.2,
753
+ right: 0.4,
754
+ color: "error",
755
+ badgeContent: "",
756
+ variant: "dot",
757
+ invisible: !showUpdateDot,
758
+ children: /*#__PURE__*/_jsxs(Button, {
759
+ disabled: loading || isInProgress(blocklet.status),
760
+ color: "secondary",
761
+ onClick: () => {
762
+ checkForUpdates();
763
+ },
764
+ "data-cy": "check-for-updates",
765
+ children: [/*#__PURE__*/_jsx(Box, {
766
+ mr: 0.5,
767
+ display: "flex",
768
+ children: loading ? /*#__PURE__*/_jsx(Spinner, {
769
+ size: 16
770
+ }) : /*#__PURE__*/_jsx(UpdateIcon, {
771
+ style: {
772
+ fontSize: '1em'
773
+ }
774
+ })
775
+ }), t('blocklet.component.checkUpdateTitle')]
776
+ })
766
777
  })
767
778
  })
768
779
  })]
@@ -0,0 +1,70 @@
1
+ import React from 'react';
2
+ import { Box } from '@mui/material';
3
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
4
+ import Toast from '@arcblock/ux/lib/Toast';
5
+ import PropTypes from 'prop-types';
6
+ import Tooltip from '@mui/material/Tooltip';
7
+ import SwitchControl from '../component/switch-control';
8
+ import { useBlockletStorageContext } from '../../contexts/blocklet-storage';
9
+
10
+ /**
11
+ * @description
12
+ * @param {{
13
+ * style: import('react').CSSProperties
14
+ * }} {...rest}
15
+ * @return {*}
16
+ */
17
+ import { jsx as _jsx } from "react/jsx-runtime";
18
+ import { jsxs as _jsxs } from "react/jsx-runtime";
19
+ function AutoCheckUpdate({
20
+ children,
21
+ ...rest
22
+ }) {
23
+ const {
24
+ t
25
+ } = useLocaleContext();
26
+ const {
27
+ updateAutoCheckUpdate,
28
+ autoCheckUpdate
29
+ } = useBlockletStorageContext();
30
+ const configAutoBackup = async () => {
31
+ try {
32
+ const enabled = !autoCheckUpdate?.enabled;
33
+ await updateAutoCheckUpdate({
34
+ enabled
35
+ });
36
+ Toast.success(enabled ? t('storage.spaces.autoCheckUpdate.enabled') : t('storage.spaces.autoCheckUpdate.disabled'));
37
+ } catch (error) {
38
+ Toast.error(error.message);
39
+ }
40
+ };
41
+ const enabled = Boolean(autoCheckUpdate?.enabled);
42
+ return /*#__PURE__*/_jsxs(Box, {
43
+ display: "flex",
44
+ flexDirection: "row",
45
+ alignItems: "center",
46
+ children: [children, /*#__PURE__*/_jsx(Tooltip, {
47
+ title: t('storage.spaces.autoCheckUpdate.title'),
48
+ arrow: true,
49
+ placement: "right",
50
+ children: /*#__PURE__*/_jsx("div", {
51
+ children: /*#__PURE__*/_jsx(SwitchControl, {
52
+ checked: enabled,
53
+ onChange: configAutoBackup,
54
+ name: "enableWelcomePage",
55
+ style: {
56
+ ...rest.style,
57
+ zoom: 0.8
58
+ }
59
+ })
60
+ })
61
+ })]
62
+ });
63
+ }
64
+ AutoCheckUpdate.propTypes = {
65
+ children: PropTypes.any
66
+ };
67
+ AutoCheckUpdate.defaultProps = {
68
+ children: null
69
+ };
70
+ export default AutoCheckUpdate;
@@ -10,6 +10,7 @@ import { useNodeContext } from './node';
10
10
  import useBackupProgress from '../hooks/use-backup-progress';
11
11
  import useBackups from '../hooks/use-backups';
12
12
  import { useAutoBackup } from '../hooks/use-auto-backup';
13
+ import { useAutoCheckUpdate } from '../hooks/use-auto-check-update';
13
14
 
14
15
  /**
15
16
  * @typedef {import('../blocklet/storage/connected').SpaceGateway} SpaceGateway
@@ -86,6 +87,10 @@ function BlockletStorageProvider({
86
87
  const autoBackup = useAutoBackup({
87
88
  deps: [autoBackupRefresh]
88
89
  });
90
+ const [autoCheckUpdateRefresh, setAutoCheckUpdateRefresh] = useState(false);
91
+ const autoCheckUpdate = useAutoCheckUpdate({
92
+ deps: [autoCheckUpdateRefresh]
93
+ });
89
94
  const refreshSpaceGateways = () => {
90
95
  setSpaceGatewaysRefresh(p => !p);
91
96
  };
@@ -95,6 +100,9 @@ function BlockletStorageProvider({
95
100
  const refreshAutoBackup = () => {
96
101
  setAutoBackupRefresh(x => !x);
97
102
  };
103
+ const refreshAutoCheckUpdate = () => {
104
+ setAutoCheckUpdateRefresh(x => !x);
105
+ };
98
106
 
99
107
  /**
100
108
  * @description
@@ -200,6 +208,15 @@ function BlockletStorageProvider({
200
208
  });
201
209
  refreshAutoBackup();
202
210
  };
211
+ const updateAutoCheckUpdate = async value => {
212
+ await api.updateAutoCheckUpdate({
213
+ input: {
214
+ did: blocklet.meta.did,
215
+ autoCheckUpdate: value
216
+ }
217
+ });
218
+ refreshAutoCheckUpdate();
219
+ };
203
220
  return /*#__PURE__*/_jsx(Provider, {
204
221
  value: {
205
222
  spaceGateways,
@@ -211,6 +228,8 @@ function BlockletStorageProvider({
211
228
  spaceGatewaysLoading,
212
229
  spaceGatewayIsSelected,
213
230
  updateAutoBackup,
231
+ updateAutoCheckUpdate,
232
+ autoCheckUpdate,
214
233
  backupEndpoint,
215
234
  backupProgress,
216
235
  backups,
@@ -0,0 +1,33 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ import { useAsyncEffect } from 'ahooks';
3
+ import { useState } from 'react';
4
+ import { useBlockletContext } from '../contexts/blocklet';
5
+ import { useNodeContext } from '../contexts/node';
6
+ export function useAutoCheckUpdate({
7
+ deps
8
+ } = {
9
+ deps: []
10
+ }) {
11
+ /** @type {{ blocklet: import('@abtnode/client').BlockletState }} */
12
+ const {
13
+ blocklet
14
+ } = useBlockletContext();
15
+ /** @type {{api: import('@abtnode/client')}} */
16
+ const {
17
+ api
18
+ } = useNodeContext();
19
+ const [autoCheckUpdate, setAutoCheckUpdate] = useState(null);
20
+ useAsyncEffect(async () => {
21
+ if (blocklet?.meta?.did) {
22
+ const {
23
+ autoCheckUpdate: data
24
+ } = await api.getAutoCheckUpdate({
25
+ input: {
26
+ did: blocklet.meta.did
27
+ }
28
+ });
29
+ setAutoCheckUpdate(data);
30
+ }
31
+ }, [blocklet?.meta?.did].concat(deps));
32
+ return autoCheckUpdate;
33
+ }
@@ -0,0 +1,28 @@
1
+ import { useEffect } from 'react';
2
+ import Toast from '@arcblock/ux/lib/Toast';
3
+ import { useNavigate } from 'react-router-dom';
4
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
5
+ import useEventListen from './use-event-listen';
6
+ export function dispatchCheckUpdate() {
7
+ window.dispatchEvent(new CustomEvent('checkUpdate'));
8
+ }
9
+ export function useCheckUpdateByUrl(event) {
10
+ const navigate = useNavigate();
11
+ const {
12
+ t
13
+ } = useLocaleContext();
14
+ const handle = () => {
15
+ const params = new URLSearchParams(window.location.search);
16
+ if (params.get('checkUpdate')) {
17
+ params.delete('checkUpdate');
18
+ navigate(params.toString());
19
+ event();
20
+ Toast.success(t('notification.checkingForUpdates'));
21
+ }
22
+ };
23
+
24
+ // eslint-disable-next-line react-hooks/exhaustive-deps
25
+ useEffect(handle, []);
26
+ useEventListen('checkUpdate', handle);
27
+ }
28
+ export default useCheckUpdateByUrl;
@@ -0,0 +1,11 @@
1
+ import { useRef, useEffect } from 'react';
2
+ function useEventListen(key, callback) {
3
+ // reduce rerender
4
+ const ref = useRef(callback);
5
+ useEffect(() => {
6
+ const event = e => ref.current(e.detail);
7
+ window.addEventListener(key, event);
8
+ return () => window.removeEventListener(key, event);
9
+ }, [key]);
10
+ }
11
+ export default useEventListen;
package/es/locales/en.js CHANGED
@@ -842,6 +842,8 @@ export default {
842
842
  showRead: 'Show Read',
843
843
  markAllAsRead: 'Mark All as Read',
844
844
  markAsRead: 'Mark As Read',
845
+ proceed: 'Proceed',
846
+ checkingForUpdates: 'Checking for updates...',
845
847
  email: {
846
848
  enable: 'Enable email notification',
847
849
  from: 'Email sender',
@@ -1524,6 +1526,11 @@ export default {
1524
1526
  enabled: 'Automatic backup is on',
1525
1527
  disabled: 'Automatic backup is off'
1526
1528
  },
1529
+ autoCheckUpdate: {
1530
+ title: 'Automatically check for new version notification',
1531
+ enabled: 'Automatically check for new version is on',
1532
+ disabled: 'Automatically check for new version is off'
1533
+ },
1527
1534
  backupSuccessfully: 'Backup successfully',
1528
1535
  restore: 'Restore',
1529
1536
  restoreSuccessfully: 'Restore successfully',
package/es/locales/zh.js CHANGED
@@ -845,6 +845,8 @@ export default {
845
845
  showRead: '显示已读',
846
846
  markAllAsRead: '全部标记为已读',
847
847
  markAsRead: '标记为已读',
848
+ proceed: '处理',
849
+ checkingForUpdates: '正在检查更新...',
848
850
  email: {
849
851
  enable: '是否开启 Email 通知',
850
852
  from: '发件人邮箱',
@@ -1529,6 +1531,11 @@ export default {
1529
1531
  enabled: '自动备份已开启',
1530
1532
  disabled: '自动备份已关闭'
1531
1533
  },
1534
+ autoCheckUpdate: {
1535
+ title: '自动检测新版本提醒',
1536
+ enabled: '自动检测新版本提醒已开启',
1537
+ disabled: '自动检测新版本提醒已关闭'
1538
+ },
1532
1539
  backupSuccessfully: '备份成功',
1533
1540
  restore: '还原',
1534
1541
  restoreSuccessfully: '还原成功',
@@ -22,6 +22,7 @@ import Permission from '../permission';
22
22
  import RelativeTime from '../relative-time';
23
23
  import { useNodeContext } from '../contexts/node';
24
24
  import { BlockletAdminRoles } from '../util';
25
+ import { dispatchCheckUpdate } from '../hooks/use-check-update-by-url';
25
26
  import { jsx as _jsx } from "react/jsx-runtime";
26
27
  import { jsxs as _jsxs } from "react/jsx-runtime";
27
28
  import { Fragment as _Fragment } from "react/jsx-runtime";
@@ -87,6 +88,12 @@ export default function NotificationsList({
87
88
  onHide(e);
88
89
  navigate(viewAllUrl);
89
90
  };
91
+ const handleCheckForUpdates = (event, action) => {
92
+ event.preventDefault();
93
+ event.stopPropagation();
94
+ navigate(action);
95
+ dispatchCheckUpdate();
96
+ };
90
97
  return /*#__PURE__*/_jsxs(Div, {
91
98
  children: [/*#__PURE__*/_jsxs(Typography, {
92
99
  component: "h3",
@@ -142,14 +149,30 @@ export default function NotificationsList({
142
149
  'text-overflow': 'ellipsis'
143
150
  },
144
151
  children: x.description
145
- }), /*#__PURE__*/_jsx(RelativeTime, {
146
- value: x.createdAt,
147
- locale: locale,
148
- style: {
149
- color: theme.palette.text.secondary,
150
- fontSize: '0.875rem',
151
- marginTop: '4px'
152
- }
152
+ }), /*#__PURE__*/_jsxs(Box, {
153
+ display: "flex",
154
+ flexDirection: "row",
155
+ justifyContent: "space-between",
156
+ alignItems: "center",
157
+ children: [/*#__PURE__*/_jsx(RelativeTime, {
158
+ value: x.createdAt,
159
+ locale: locale,
160
+ style: {
161
+ color: theme.palette.text.secondary,
162
+ fontSize: '0.875rem',
163
+ marginTop: '4px'
164
+ }
165
+ }), x.action && !x.read ? /*#__PURE__*/_jsx(Button, {
166
+ color: "primary",
167
+ variant: "outlined",
168
+ onPointerDown: event => {
169
+ event.stopPropagation();
170
+ event.preventDefault();
171
+ },
172
+ onClick: e => handleCheckForUpdates(e, x.action),
173
+ "data-cy": "check-for-updates",
174
+ children: t('notification.proceed')
175
+ }) : null]
153
176
  })]
154
177
  })
155
178
  })]
@@ -45,6 +45,7 @@ var _blockletSource = _interopRequireDefault(require("../blocklet-source"));
45
45
  var _status = _interopRequireDefault(require("../status"));
46
46
  var _version = _interopRequireDefault(require("../version"));
47
47
  var _confirm = _interopRequireDefault(require("../../confirm"));
48
+ var _autoCheckUpdate = _interopRequireDefault(require("../storage/auto-check-update"));
48
49
  var _node = require("../../contexts/node");
49
50
  var _util2 = require("../../util");
50
51
  var _permission = _interopRequireDefault(require("../../permission"));
@@ -58,6 +59,7 @@ var _add = _interopRequireDefault(require("./add"));
58
59
  var _addRule = _interopRequireDefault(require("../router/action/add-rule"));
59
60
  var _ruleList = _interopRequireDefault(require("../router/rule-list"));
60
61
  var _actions = _interopRequireDefault(require("../../actions"));
62
+ var _useCheckUpdateByUrl = require("../../hooks/use-check-update-by-url");
61
63
  var _jsxRuntime = require("react/jsx-runtime");
62
64
  const _excluded = ["blocklet", "onUpdate", "getComponentUrl"];
63
65
  var _templateObject, _templateObject2, _templateObject3;
@@ -735,6 +737,7 @@ function BlockletComponent(_ref4) {
735
737
  });
736
738
  });
737
739
  };
740
+ (0, _useCheckUpdateByUrl.useCheckUpdateByUrl)(checkForUpdates);
738
741
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Div, _objectSpread(_objectSpread({
739
742
  component: "div"
740
743
  }, rest), {}, {
@@ -742,36 +745,44 @@ function BlockletComponent(_ref4) {
742
745
  display: "flex",
743
746
  justifyContent: "space-between",
744
747
  alignItems: "center",
745
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
748
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
746
749
  className: "title",
750
+ flexDirection: "row",
751
+ display: "flex",
752
+ alignItems: "center",
753
+ style: {
754
+ marginLeft: '1em'
755
+ },
747
756
  children: [t('common.components'), !needMigration && /*#__PURE__*/(0, _jsxRuntime.jsx)(_permission.default, {
748
757
  permission: inService ? '' : 'mutate_blocklets',
749
758
  role: inService ? _util2.BlockletAdminRoles : [],
750
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledBadge, {
751
- top: 1.2,
752
- right: 0.4,
753
- color: "error",
754
- badgeContent: "",
755
- variant: "dot",
756
- invisible: !showUpdateDot,
757
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Button.default, {
758
- disabled: loading || (0, _util.isInProgress)(blocklet.status),
759
- color: "secondary",
760
- onClick: () => {
761
- checkForUpdates();
762
- },
763
- "data-cy": "check-for-updates",
764
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
765
- mr: 0.5,
766
- display: "flex",
767
- children: loading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_CircularProgress.default, {
768
- size: 16
769
- }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Update.default, {
770
- style: {
771
- fontSize: '1em'
772
- }
773
- })
774
- }), t('blocklet.component.checkUpdateTitle')]
759
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_autoCheckUpdate.default, {
760
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledBadge, {
761
+ top: 1.2,
762
+ right: 0.4,
763
+ color: "error",
764
+ badgeContent: "",
765
+ variant: "dot",
766
+ invisible: !showUpdateDot,
767
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Button.default, {
768
+ disabled: loading || (0, _util.isInProgress)(blocklet.status),
769
+ color: "secondary",
770
+ onClick: () => {
771
+ checkForUpdates();
772
+ },
773
+ "data-cy": "check-for-updates",
774
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
775
+ mr: 0.5,
776
+ display: "flex",
777
+ children: loading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_CircularProgress.default, {
778
+ size: 16
779
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Update.default, {
780
+ style: {
781
+ fontSize: '1em'
782
+ }
783
+ })
784
+ }), t('blocklet.component.checkUpdateTitle')]
785
+ })
775
786
  })
776
787
  })
777
788
  })]
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _material = require("@mui/material");
9
+ var _context = require("@arcblock/ux/lib/Locale/context");
10
+ var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
11
+ var _propTypes = _interopRequireDefault(require("prop-types"));
12
+ var _Tooltip = _interopRequireDefault(require("@mui/material/Tooltip"));
13
+ var _switchControl = _interopRequireDefault(require("../component/switch-control"));
14
+ var _blockletStorage = require("../../contexts/blocklet-storage");
15
+ var _jsxRuntime = require("react/jsx-runtime");
16
+ const _excluded = ["children"];
17
+ /**
18
+ * @description
19
+ * @param {{
20
+ * style: import('react').CSSProperties
21
+ * }} {...rest}
22
+ * @return {*}
23
+ */
24
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
26
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
27
+ 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; }
28
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
29
+ 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); }
30
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
31
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
32
+ function AutoCheckUpdate(_ref) {
33
+ let {
34
+ children
35
+ } = _ref,
36
+ rest = _objectWithoutProperties(_ref, _excluded);
37
+ const {
38
+ t
39
+ } = (0, _context.useLocaleContext)();
40
+ const {
41
+ updateAutoCheckUpdate,
42
+ autoCheckUpdate
43
+ } = (0, _blockletStorage.useBlockletStorageContext)();
44
+ const configAutoBackup = async () => {
45
+ try {
46
+ const enabled = !(autoCheckUpdate !== null && autoCheckUpdate !== void 0 && autoCheckUpdate.enabled);
47
+ await updateAutoCheckUpdate({
48
+ enabled
49
+ });
50
+ _Toast.default.success(enabled ? t('storage.spaces.autoCheckUpdate.enabled') : t('storage.spaces.autoCheckUpdate.disabled'));
51
+ } catch (error) {
52
+ _Toast.default.error(error.message);
53
+ }
54
+ };
55
+ const enabled = Boolean(autoCheckUpdate === null || autoCheckUpdate === void 0 ? void 0 : autoCheckUpdate.enabled);
56
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
57
+ display: "flex",
58
+ flexDirection: "row",
59
+ alignItems: "center",
60
+ children: [children, /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
61
+ title: t('storage.spaces.autoCheckUpdate.title'),
62
+ arrow: true,
63
+ placement: "right",
64
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
65
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_switchControl.default, {
66
+ checked: enabled,
67
+ onChange: configAutoBackup,
68
+ name: "enableWelcomePage",
69
+ style: _objectSpread(_objectSpread({}, rest.style), {}, {
70
+ zoom: 0.8
71
+ })
72
+ })
73
+ })
74
+ })]
75
+ });
76
+ }
77
+ AutoCheckUpdate.propTypes = {
78
+ children: _propTypes.default.any
79
+ };
80
+ AutoCheckUpdate.defaultProps = {
81
+ children: null
82
+ };
83
+ var _default = exports.default = AutoCheckUpdate;
@@ -18,6 +18,7 @@ var _node = require("./node");
18
18
  var _useBackupProgress = _interopRequireDefault(require("../hooks/use-backup-progress"));
19
19
  var _useBackups = _interopRequireDefault(require("../hooks/use-backups"));
20
20
  var _useAutoBackup = require("../hooks/use-auto-backup");
21
+ var _useAutoCheckUpdate = require("../hooks/use-auto-check-update");
21
22
  var _jsxRuntime = require("react/jsx-runtime");
22
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
24
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -96,6 +97,10 @@ function BlockletStorageProvider(_ref) {
96
97
  const autoBackup = (0, _useAutoBackup.useAutoBackup)({
97
98
  deps: [autoBackupRefresh]
98
99
  });
100
+ const [autoCheckUpdateRefresh, setAutoCheckUpdateRefresh] = (0, _react.useState)(false);
101
+ const autoCheckUpdate = (0, _useAutoCheckUpdate.useAutoCheckUpdate)({
102
+ deps: [autoCheckUpdateRefresh]
103
+ });
99
104
  const refreshSpaceGateways = () => {
100
105
  setSpaceGatewaysRefresh(p => !p);
101
106
  };
@@ -105,6 +110,9 @@ function BlockletStorageProvider(_ref) {
105
110
  const refreshAutoBackup = () => {
106
111
  setAutoBackupRefresh(x => !x);
107
112
  };
113
+ const refreshAutoCheckUpdate = () => {
114
+ setAutoCheckUpdateRefresh(x => !x);
115
+ };
108
116
 
109
117
  /**
110
118
  * @description
@@ -210,6 +218,15 @@ function BlockletStorageProvider(_ref) {
210
218
  });
211
219
  refreshAutoBackup();
212
220
  };
221
+ const updateAutoCheckUpdate = async value => {
222
+ await api.updateAutoCheckUpdate({
223
+ input: {
224
+ did: blocklet.meta.did,
225
+ autoCheckUpdate: value
226
+ }
227
+ });
228
+ refreshAutoCheckUpdate();
229
+ };
213
230
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(Provider, {
214
231
  value: {
215
232
  spaceGateways,
@@ -221,6 +238,8 @@ function BlockletStorageProvider(_ref) {
221
238
  spaceGatewaysLoading,
222
239
  spaceGatewayIsSelected,
223
240
  updateAutoBackup,
241
+ updateAutoCheckUpdate,
242
+ autoCheckUpdate,
224
243
  backupEndpoint,
225
244
  backupProgress,
226
245
  backups,
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useAutoCheckUpdate = useAutoCheckUpdate;
7
+ var _ahooks = require("ahooks");
8
+ var _react = require("react");
9
+ var _blocklet = require("../contexts/blocklet");
10
+ var _node = require("../contexts/node");
11
+ /* eslint-disable import/prefer-default-export */
12
+
13
+ function useAutoCheckUpdate() {
14
+ var _blocklet$meta2;
15
+ let {
16
+ deps
17
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
18
+ deps: []
19
+ };
20
+ /** @type {{ blocklet: import('@abtnode/client').BlockletState }} */
21
+ const {
22
+ blocklet
23
+ } = (0, _blocklet.useBlockletContext)();
24
+ /** @type {{api: import('@abtnode/client')}} */
25
+ const {
26
+ api
27
+ } = (0, _node.useNodeContext)();
28
+ const [autoCheckUpdate, setAutoCheckUpdate] = (0, _react.useState)(null);
29
+ (0, _ahooks.useAsyncEffect)(async () => {
30
+ var _blocklet$meta;
31
+ if (blocklet !== null && blocklet !== void 0 && (_blocklet$meta = blocklet.meta) !== null && _blocklet$meta !== void 0 && _blocklet$meta.did) {
32
+ const {
33
+ autoCheckUpdate: data
34
+ } = await api.getAutoCheckUpdate({
35
+ input: {
36
+ did: blocklet.meta.did
37
+ }
38
+ });
39
+ setAutoCheckUpdate(data);
40
+ }
41
+ }, [blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$meta2 = blocklet.meta) === null || _blocklet$meta2 === void 0 ? void 0 : _blocklet$meta2.did].concat(deps));
42
+ return autoCheckUpdate;
43
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ exports.dispatchCheckUpdate = dispatchCheckUpdate;
8
+ exports.useCheckUpdateByUrl = useCheckUpdateByUrl;
9
+ var _react = require("react");
10
+ var _Toast = _interopRequireDefault(require("@arcblock/ux/lib/Toast"));
11
+ var _reactRouterDom = require("react-router-dom");
12
+ var _context = require("@arcblock/ux/lib/Locale/context");
13
+ var _useEventListen = _interopRequireDefault(require("./use-event-listen"));
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ function dispatchCheckUpdate() {
16
+ window.dispatchEvent(new CustomEvent('checkUpdate'));
17
+ }
18
+ function useCheckUpdateByUrl(event) {
19
+ const navigate = (0, _reactRouterDom.useNavigate)();
20
+ const {
21
+ t
22
+ } = (0, _context.useLocaleContext)();
23
+ const handle = () => {
24
+ const params = new URLSearchParams(window.location.search);
25
+ if (params.get('checkUpdate')) {
26
+ params.delete('checkUpdate');
27
+ navigate(params.toString());
28
+ event();
29
+ _Toast.default.success(t('notification.checkingForUpdates'));
30
+ }
31
+ };
32
+
33
+ // eslint-disable-next-line react-hooks/exhaustive-deps
34
+ (0, _react.useEffect)(handle, []);
35
+ (0, _useEventListen.default)('checkUpdate', handle);
36
+ }
37
+ var _default = exports.default = useCheckUpdateByUrl;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = require("react");
8
+ function useEventListen(key, callback) {
9
+ // reduce rerender
10
+ const ref = (0, _react.useRef)(callback);
11
+ (0, _react.useEffect)(() => {
12
+ const event = e => ref.current(e.detail);
13
+ window.addEventListener(key, event);
14
+ return () => window.removeEventListener(key, event);
15
+ }, [key]);
16
+ }
17
+ var _default = exports.default = useEventListen;
package/lib/locales/en.js CHANGED
@@ -848,6 +848,8 @@ var _default = exports.default = {
848
848
  showRead: 'Show Read',
849
849
  markAllAsRead: 'Mark All as Read',
850
850
  markAsRead: 'Mark As Read',
851
+ proceed: 'Proceed',
852
+ checkingForUpdates: 'Checking for updates...',
851
853
  email: {
852
854
  enable: 'Enable email notification',
853
855
  from: 'Email sender',
@@ -1530,6 +1532,11 @@ var _default = exports.default = {
1530
1532
  enabled: 'Automatic backup is on',
1531
1533
  disabled: 'Automatic backup is off'
1532
1534
  },
1535
+ autoCheckUpdate: {
1536
+ title: 'Automatically check for new version notification',
1537
+ enabled: 'Automatically check for new version is on',
1538
+ disabled: 'Automatically check for new version is off'
1539
+ },
1533
1540
  backupSuccessfully: 'Backup successfully',
1534
1541
  restore: 'Restore',
1535
1542
  restoreSuccessfully: 'Restore successfully',
package/lib/locales/zh.js CHANGED
@@ -851,6 +851,8 @@ var _default = exports.default = {
851
851
  showRead: '显示已读',
852
852
  markAllAsRead: '全部标记为已读',
853
853
  markAsRead: '标记为已读',
854
+ proceed: '处理',
855
+ checkingForUpdates: '正在检查更新...',
854
856
  email: {
855
857
  enable: '是否开启 Email 通知',
856
858
  from: '发件人邮箱',
@@ -1535,6 +1537,11 @@ var _default = exports.default = {
1535
1537
  enabled: '自动备份已开启',
1536
1538
  disabled: '自动备份已关闭'
1537
1539
  },
1540
+ autoCheckUpdate: {
1541
+ title: '自动检测新版本提醒',
1542
+ enabled: '自动检测新版本提醒已开启',
1543
+ disabled: '自动检测新版本提醒已关闭'
1544
+ },
1538
1545
  backupSuccessfully: '备份成功',
1539
1546
  restore: '还原',
1540
1547
  restoreSuccessfully: '还原成功',
@@ -27,6 +27,7 @@ var _permission = _interopRequireDefault(require("../permission"));
27
27
  var _relativeTime = _interopRequireDefault(require("../relative-time"));
28
28
  var _node = require("../contexts/node");
29
29
  var _util = require("../util");
30
+ var _useCheckUpdateByUrl = require("../hooks/use-check-update-by-url");
30
31
  var _jsxRuntime = require("react/jsx-runtime");
31
32
  var _templateObject;
32
33
  /* eslint-disable operator-linebreak */
@@ -95,6 +96,12 @@ function NotificationsList(_ref) {
95
96
  onHide(e);
96
97
  navigate(viewAllUrl);
97
98
  };
99
+ const handleCheckForUpdates = (event, action) => {
100
+ event.preventDefault();
101
+ event.stopPropagation();
102
+ navigate(action);
103
+ (0, _useCheckUpdateByUrl.dispatchCheckUpdate)();
104
+ };
98
105
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Div, {
99
106
  children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Typography.default, {
100
107
  component: "h3",
@@ -150,14 +157,30 @@ function NotificationsList(_ref) {
150
157
  'text-overflow': 'ellipsis'
151
158
  },
152
159
  children: x.description
153
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_relativeTime.default, {
154
- value: x.createdAt,
155
- locale: locale,
156
- style: {
157
- color: theme.palette.text.secondary,
158
- fontSize: '0.875rem',
159
- marginTop: '4px'
160
- }
160
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
161
+ display: "flex",
162
+ flexDirection: "row",
163
+ justifyContent: "space-between",
164
+ alignItems: "center",
165
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_relativeTime.default, {
166
+ value: x.createdAt,
167
+ locale: locale,
168
+ style: {
169
+ color: theme.palette.text.secondary,
170
+ fontSize: '0.875rem',
171
+ marginTop: '4px'
172
+ }
173
+ }), x.action && !x.read ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
174
+ color: "primary",
175
+ variant: "outlined",
176
+ onPointerDown: event => {
177
+ event.stopPropagation();
178
+ event.preventDefault();
179
+ },
180
+ onClick: e => handleCheckForUpdates(e, x.action),
181
+ "data-cy": "check-for-updates",
182
+ children: t('notification.proceed')
183
+ }) : null]
161
184
  })]
162
185
  })
163
186
  })]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abtnode/ux",
3
- "version": "1.16.21-beta-445a8baa",
3
+ "version": "1.16.21-beta-93c6e42b",
4
4
  "description": "UX components shared across abtnode packages",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -27,9 +27,9 @@
27
27
  "author": "linchen <linchen1987@foxmail.com> (http://github.com/linchen1987)",
28
28
  "license": "Apache-2.0",
29
29
  "dependencies": {
30
- "@abtnode/auth": "1.16.21-beta-445a8baa",
31
- "@abtnode/constant": "1.16.21-beta-445a8baa",
32
- "@abtnode/util": "1.16.21-beta-445a8baa",
30
+ "@abtnode/auth": "1.16.21-beta-93c6e42b",
31
+ "@abtnode/constant": "1.16.21-beta-93c6e42b",
32
+ "@abtnode/util": "1.16.21-beta-93c6e42b",
33
33
  "@ahooksjs/use-url-state": "^3.5.1",
34
34
  "@arcblock/did": "^1.18.107",
35
35
  "@arcblock/did-connect": "^2.8.23",
@@ -39,10 +39,10 @@
39
39
  "@arcblock/react-hooks": "^2.8.23",
40
40
  "@arcblock/terminal": "^2.8.23",
41
41
  "@arcblock/ux": "^2.8.23",
42
- "@blocklet/constant": "1.16.21-beta-445a8baa",
42
+ "@blocklet/constant": "1.16.21-beta-93c6e42b",
43
43
  "@blocklet/launcher-layout": "2.2.48",
44
44
  "@blocklet/list": "^0.12.60",
45
- "@blocklet/meta": "1.16.21-beta-445a8baa",
45
+ "@blocklet/meta": "1.16.21-beta-93c6e42b",
46
46
  "@blocklet/ui-react": "^2.8.23",
47
47
  "@blocklet/uploader": "^0.0.56",
48
48
  "@emotion/react": "^11.10.4",
@@ -102,7 +102,7 @@
102
102
  "babel-plugin-inline-react-svg": "^1.1.2",
103
103
  "glob": "^10.3.3"
104
104
  },
105
- "gitHead": "7a7ff8be7f424775c3bde0eead773d8e6177fa1a",
105
+ "gitHead": "80619ce49f5a9224d3d817e5faea4422072b0553",
106
106
  "exports": {
107
107
  ".": {
108
108
  "import": "./es/index.js",