@abtnode/ux 1.16.13-beta-d17a7de4 → 1.16.13-beta-90ded76f

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.
@@ -45,6 +45,7 @@ var _tag = _interopRequireDefault(require("../../tag"));
45
45
  var _blockletSource = _interopRequireDefault(require("../blocklet-source"));
46
46
  var _status = _interopRequireDefault(require("../status"));
47
47
  var _version = _interopRequireDefault(require("../version"));
48
+ var _confirm = _interopRequireDefault(require("../../confirm"));
48
49
  var _node = require("../../contexts/node");
49
50
  var _util2 = require("../../util");
50
51
  var _permission = _interopRequireDefault(require("../../permission"));
@@ -152,12 +153,14 @@ function ComponentItem(_ref) {
152
153
  app
153
154
  } = _ref;
154
155
  const {
155
- t
156
+ t,
157
+ locale
156
158
  } = (0, _react.useContext)(_context.LocaleContext);
157
159
  const [expand, setExpand] = (0, _react.useState)(true);
158
160
  const [componentInfo, setComponentInfo] = (0, _react.useState)();
159
161
  const [showDeleteConfirm, setShowDeleteConfirm] = (0, _react.useState)(false);
160
162
  const [loading, setLoading] = (0, _react.useState)(false);
163
+ const [confirmSetting, setConfirmSetting] = (0, _react.useState)(null);
161
164
  const {
162
165
  deletingBlocklets: deletingComponents
163
166
  } = (0, _deletingBlocklets.useDeletingBlockletContext)();
@@ -215,10 +218,10 @@ function ComponentItem(_ref) {
215
218
  })
216
219
  }, blocklet.status === 'running' ? {
217
220
  name: t('blocklet.startedAt'),
218
- value: (0, _util2.formatToDatetime)(blocklet.startedAt)
221
+ value: (0, _util2.formatToDatetime)(blocklet.startedAt, locale)
219
222
  } : null, blocklet.status !== 'running' ? {
220
223
  name: t('blocklet.stoppedAt'),
221
- value: (0, _util2.formatToDatetime)(blocklet.stoppedAt)
224
+ value: (0, _util2.formatToDatetime)(blocklet.stoppedAt, locale)
222
225
  } : null, {
223
226
  name: t('common.mountPoint'),
224
227
  value: mountPoint
@@ -427,10 +430,19 @@ function ComponentItem(_ref) {
427
430
  }, {
428
431
  icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Replay.default, {}),
429
432
  text: t('common.restart'),
430
- onClick: async () => {
431
- setLoading(true);
432
- await onRestart(blocklet);
433
- setLoading(false);
433
+ onClick: () => {
434
+ setConfirmSetting({
435
+ title: "".concat(t('common.restart'), " ").concat(blocklet.meta.title),
436
+ description: t('blocklet.action.restartDescription'),
437
+ confirm: t('blocklet.action.confirmRestart'),
438
+ cancel: t('common.cancel'),
439
+ onConfirm: async () => {
440
+ setLoading(true);
441
+ await onRestart(blocklet);
442
+ setLoading(false);
443
+ },
444
+ onCancel: () => setConfirmSetting(null)
445
+ });
434
446
  },
435
447
  disabled: appInProgress || componentInProgress || blocklet.status !== 'running'
436
448
  }, {
@@ -501,6 +513,14 @@ function ComponentItem(_ref) {
501
513
  tip: deleteDisabledTip,
502
514
  hideBtn: true,
503
515
  showConfirm: showDeleteConfirm
516
+ }), confirmSetting && /*#__PURE__*/(0, _jsxRuntime.jsx)(_confirm.default, {
517
+ title: confirmSetting.title,
518
+ description: confirmSetting.description,
519
+ confirm: confirmSetting.confirm,
520
+ cancel: confirmSetting.cancel,
521
+ params: confirmSetting.params,
522
+ onConfirm: confirmSetting.onConfirm,
523
+ onCancel: confirmSetting.onCancel
504
524
  })];
505
525
  }
506
526
  ComponentItem.propTypes = {
@@ -93,7 +93,8 @@ const LinkDiv = _styled.default.span(_templateObject || (_templateObject = _tagg
93
93
  function BlockletOverview() {
94
94
  var _blocklet$environment, _blocklet$controller, _blocklet$controller2, _blocklet$controller3, _blocklet$settings, _blocklet$site;
95
95
  const {
96
- t
96
+ t,
97
+ locale
97
98
  } = (0, _context.useLocaleContext)();
98
99
  const {
99
100
  info: nodeInfo,
@@ -153,7 +154,7 @@ function BlockletOverview() {
153
154
  })
154
155
  } : null, {
155
156
  name: t('blocklet.installedAt'),
156
- value: (0, _util2.formatToDatetime)(blocklet.installedAt)
157
+ value: (0, _util2.formatToDatetime)(blocklet.installedAt, locale)
157
158
  }, {
158
159
  name: t('blocklet.overview.accessControl'),
159
160
  value: t("team.whoCanAccess.".concat((0, _util.getWhoCanAccess)(blocklet), ".title"))
@@ -8,8 +8,8 @@ var _styled = _interopRequireDefault(require("@emotion/styled"));
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _Typography = _interopRequireDefault(require("@mui/material/Typography"));
10
10
  var _Grid = _interopRequireDefault(require("@mui/material/Grid"));
11
- var _cpu = _interopRequireDefault(require("../monitor/cpu"));
12
- var _memory = _interopRequireDefault(require("../monitor/memory"));
11
+ var _cpu = _interopRequireDefault(require("../insights/cpu"));
12
+ var _memory = _interopRequireDefault(require("../insights/memory"));
13
13
  var _jsxRuntime = require("react/jsx-runtime");
14
14
  var _templateObject;
15
15
  const _excluded = ["blocklet", "cpuHistory", "memoryHistory"];
@@ -48,8 +48,7 @@ function BlockletRuntimeInfo(_ref) {
48
48
  history: cpuHistory,
49
49
  style: {
50
50
  height: 150
51
- },
52
- hideDescription: true
51
+ }
53
52
  })
54
53
  }, "cpu"), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Grid.default, {
55
54
  item: true,
@@ -62,8 +61,7 @@ function BlockletRuntimeInfo(_ref) {
62
61
  history: memoryHistory,
63
62
  style: {
64
63
  height: 150
65
- },
66
- hideDescription: true
64
+ }
67
65
  })
68
66
  }, "memory")]
69
67
  })
@@ -11,7 +11,7 @@ var _material = require("@mui/material");
11
11
  var _react = _interopRequireWildcard(require("react"));
12
12
  var _lodash = require("lodash");
13
13
  var _ahooks = require("ahooks");
14
- var _dayjs = _interopRequireDefault(require("dayjs"));
14
+ var _dayjs = _interopRequireDefault(require("@abtnode/util/lib/dayjs"));
15
15
  var _HelpOutline = _interopRequireDefault(require("@mui/icons-material/HelpOutline"));
16
16
  var _propTypes = require("prop-types");
17
17
  var _node = require("../../contexts/node");
@@ -208,35 +208,23 @@ function SpacesBackupRecords(_ref2) {
208
208
  }
209
209
  }
210
210
  }];
211
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
212
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, _objectSpread(_objectSpread({
213
- display: "flex",
214
- flexDirection: "row",
215
- alignItems: "center",
216
- justifyContent: "space-between"
217
- }, rest), {}, {
218
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
219
- fontSize: "1.2rem",
220
- fontWeight: "bold",
221
- children: t('storage.spaces.backup.records')
222
- })
223
- })), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
224
- children: backups !== null && backups !== void 0 && backups.length ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Datatable.default, {
225
- data: backups,
226
- columns: columns,
227
- emptyNode: t('storage.spaces.record.emptyData', locale),
228
- options: {
229
- download: false,
230
- filter: false,
231
- print: false
232
- }
233
- }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
234
- color: "#9397A1",
235
- marginTop: "24px",
236
- children: t('storage.spaces.record.emptyData')
237
- })
238
- })]
239
- });
211
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, _objectSpread(_objectSpread({}, rest), {}, {
212
+ children: backups !== null && backups !== void 0 && backups.length ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Datatable.default, {
213
+ title: t('storage.spaces.backup.records'),
214
+ data: backups,
215
+ columns: columns,
216
+ emptyNode: t('storage.spaces.record.emptyData', locale),
217
+ options: {
218
+ download: false,
219
+ filter: false,
220
+ print: false
221
+ }
222
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
223
+ color: "#9397A1",
224
+ marginTop: "24px",
225
+ children: t('storage.spaces.record.emptyData')
226
+ })
227
+ }));
240
228
  }
241
229
  SpacesBackupRecords.propTypes = {
242
230
  progress: _propTypes.object.isRequired,
@@ -17,6 +17,7 @@ var _node = require("../../contexts/node");
17
17
  var _spaces = require("../../util/spaces");
18
18
  var _useBackupProgress = _interopRequireDefault(require("../../hooks/use-backup-progress"));
19
19
  var _spaceGateway = require("../../util/space-gateway");
20
+ var _diskInfo = _interopRequireDefault(require("../disk-info"));
20
21
  var _util = require("../../util");
21
22
  var _jsxRuntime = require("react/jsx-runtime");
22
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -192,6 +193,13 @@ function Connected() {
192
193
  },
193
194
  spaceGateways: spaceGateways,
194
195
  progress: progress
196
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
197
+ fontSize: "1.2rem",
198
+ fontWeight: "bold",
199
+ mb: 2,
200
+ children: t('common.dataStorage')
201
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_diskInfo.default, {
202
+ blocklet: blocklet
195
203
  })]
196
204
  });
197
205
  }
@@ -7,7 +7,9 @@ exports.default = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  var _material = require("@mui/material");
9
9
  var _context = require("@arcblock/ux/lib/Locale/context");
10
+ var _blocklet = require("../../../lib/contexts/blocklet");
10
11
  var _connectTo = _interopRequireDefault(require("./connect-to"));
12
+ var _diskInfo = _interopRequireDefault(require("../disk-info"));
11
13
  var _jsxRuntime = require("react/jsx-runtime");
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
15
  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; }
@@ -210,23 +212,35 @@ function Disconnect() {
210
212
  const {
211
213
  t
212
214
  } = (0, _context.useLocaleContext)();
215
+ const {
216
+ blocklet
217
+ } = (0, _blocklet.useBlockletContext)();
213
218
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
214
- minHeight: "50vh",
215
- display: "flex",
216
- flexDirection: "column",
217
- justifyContent: "center",
218
- alignItems: "center",
219
- alignContent: "center",
220
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(EmptySpacesNFT, {
221
- style: {
222
- width: 200,
223
- height: 250
224
- }
219
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
220
+ minHeight: "40vh",
221
+ display: "flex",
222
+ flexDirection: "column",
223
+ justifyContent: "center",
224
+ alignItems: "center",
225
+ alignContent: "center",
226
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(EmptySpacesNFT, {
227
+ style: {
228
+ width: 200,
229
+ height: 250
230
+ }
231
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
232
+ marginTop: "24px",
233
+ marginBottom: "24px",
234
+ children: t('storage.spaces.connect.provider')
235
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_connectTo.default, {})]
225
236
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
226
- marginTop: "24px",
227
- marginBottom: "24px",
228
- children: t('storage.spaces.connect.provider')
229
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_connectTo.default, {})]
237
+ fontSize: "1.2rem",
238
+ fontWeight: "bold",
239
+ mb: 2,
240
+ children: t('common.dataStorage')
241
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_diskInfo.default, {
242
+ blocklet: blocklet
243
+ })]
230
244
  });
231
245
  }
232
246
  Disconnect.propTypes = {};
@@ -38,12 +38,10 @@ function TransferOwner(_ref) {
38
38
  } = (0, _react.useContext)(_session.SessionContext);
39
39
  const [loading, setLoading] = (0, _react.useState)(false);
40
40
  const {
41
+ t,
41
42
  locale
42
43
  } = (0, _context.useLocaleContext)();
43
44
  const [error, setError] = (0, _react.useState)('');
44
- const {
45
- t
46
- } = (0, _context.useLocaleContext)();
47
45
  const [openTransferOwner, setOpenTransferOwner] = (0, _react.useState)(false);
48
46
  const [activeStep, setActiveStep] = (0, _react.useState)(0);
49
47
  const [result, setResult] = (0, _react.useState)('');
@@ -131,7 +129,7 @@ function TransferOwner(_ref) {
131
129
  mt: 2,
132
130
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Bold, {
133
131
  children: t('team.transferApp.transferDialog.createSuccessTip2', {
134
- expireDate: (0, _util.formatToDatetime)(result.expireDate)
132
+ expireDate: (0, _util.formatToDatetime)(result.expireDate, locale)
135
133
  })
136
134
  })
137
135
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
@@ -24,7 +24,8 @@ function Certificate(_ref) {
24
24
  const [anchorEl, setAnchorEl] = (0, _react.useState)(null);
25
25
  const node = (0, _node.useNodeContext)();
26
26
  const {
27
- t
27
+ t,
28
+ locale
28
29
  } = (0, _context.useLocaleContext)();
29
30
  const handlePopoverOpen = event => {
30
31
  setAnchorEl(event.currentTarget);
@@ -91,10 +92,10 @@ function Certificate(_ref) {
91
92
  children: "".concat(t('common.issuer'), ": ").concat((0, _get.default)(certificate, 'issuer.commonName', ''))
92
93
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
93
94
  component: "div",
94
- children: "".concat(t('router.cert.issuedOn'), ": ").concat((0, _util.formatToDate)(certificate.validFrom))
95
+ children: "".concat(t('router.cert.issuedOn'), ": ").concat((0, _util.formatToDate)(certificate.validFrom, locale))
95
96
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
96
97
  component: "div",
97
- children: "".concat(t('router.cert.expiryOn'), ": ").concat((0, _util.formatToDate)(certificate.validTo))
98
+ children: "".concat(t('router.cert.expiryOn'), ": ").concat((0, _util.formatToDate)(certificate.validTo, locale))
98
99
  })]
99
100
  })]
100
101
  })
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = MonitCard;
6
+ exports.default = InsightCard;
7
7
  var _propTypes = _interopRequireDefault(require("prop-types"));
8
8
  var _styled = _interopRequireDefault(require("@emotion/styled"));
9
9
  var _Card = _interopRequireDefault(require("@mui/material/Card"));
@@ -19,14 +19,13 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
19
19
  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; }
20
20
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
21
21
  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); }
22
- function MonitCard(_ref) {
22
+ function InsightCard(_ref) {
23
23
  let {
24
24
  style,
25
25
  title,
26
26
  value,
27
27
  graph,
28
- description,
29
- hideDescription
28
+ description
30
29
  } = _ref;
31
30
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledCard, {
32
31
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_CardContent.default, {
@@ -42,7 +41,7 @@ function MonitCard(_ref) {
42
41
  component: "div",
43
42
  mt: 1,
44
43
  children: value
45
- }), graph, !hideDescription && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
44
+ }), graph, !!description && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
46
45
  display: "flex",
47
46
  sx: {
48
47
  fontSize: 12,
@@ -54,20 +53,18 @@ function MonitCard(_ref) {
54
53
  })
55
54
  });
56
55
  }
57
- MonitCard.propTypes = {
56
+ InsightCard.propTypes = {
58
57
  style: _propTypes.default.object,
59
58
  title: _propTypes.default.node,
60
59
  value: _propTypes.default.node,
61
60
  graph: _propTypes.default.node,
62
- description: _propTypes.default.node,
63
- hideDescription: _propTypes.default.bool
61
+ description: _propTypes.default.any
64
62
  };
65
- MonitCard.defaultProps = {
63
+ InsightCard.defaultProps = {
66
64
  style: {},
67
65
  title: null,
68
66
  value: null,
69
67
  graph: null,
70
- description: null,
71
- hideDescription: false
68
+ description: null
72
69
  };
73
70
  const StyledCard = (0, _styled.default)(_Card.default)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n .card-content {\n height: 150px;\n }\n\n .card-sparkline {\n flex: 2;\n display: flex;\n position: relative;\n *[hidden] {\n display: none;\n }\n }\n .sparkline {\n stroke: ", ";\n fill: ", "1A;\n }\n .tooltip {\n position: absolute;\n background: rgba(0, 0, 0, 0.7);\n color: #fff;\n padding: 2px 5px;\n font-size: 12px;\n white-space: nowrap;\n z-index: 9999;\n }\n .sparkline--cursor {\n stroke: orange;\n }\n\n .sparkline--spot {\n fill: red;\n stroke: red;\n }\n"])), props => props.theme.palette.primary.main, props => props.theme.palette.primary.main);
@@ -3,32 +3,31 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = CpuMonitor;
7
- var _react = require("react");
6
+ exports.default = InsightChart;
7
+ var _react = _interopRequireWildcard(require("react"));
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _ahooks = require("ahooks");
10
- var _context = require("@arcblock/ux/lib/Locale/context");
11
10
  var _Sparkline = _interopRequireDefault(require("@arcblock/ux/lib/Sparkline"));
12
11
  var _card = _interopRequireDefault(require("./card"));
13
- var _util = require("../util");
14
12
  var _jsxRuntime = require("react/jsx-runtime");
15
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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); }
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; }
16
16
  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; }
17
17
  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; }
18
18
  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; }
19
19
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
20
20
  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); }
21
- const formatNumber = x => "".concat(x, "%");
22
- function CpuMonitor(_ref) {
21
+ function InsightChart(_ref) {
23
22
  let {
24
- cpus,
25
- currentLoad,
26
- history,
27
- hideDescription
23
+ id,
24
+ title,
25
+ current,
26
+ description,
27
+ data,
28
+ dateFn,
29
+ valueFn
28
30
  } = _ref;
29
- const {
30
- t
31
- } = (0, _react.useContext)(_context.LocaleContext);
32
31
  const svgRef = (0, _react.useRef)(null);
33
32
  const tooltipRef = (0, _react.useRef)(null);
34
33
  const tooltipState = (0, _ahooks.useReactive)({
@@ -39,15 +38,17 @@ function CpuMonitor(_ref) {
39
38
  hidden: true,
40
39
  textContent: ''
41
40
  });
42
- const [cpuDom, setCpuDom] = (0, _react.useState)();
43
- const size = (0, _ahooks.useSize)(cpuDom) || {};
41
+ const [container, setContainer] = (0, _react.useState)(null);
42
+ const size = (0, _ahooks.useSize)(container);
44
43
  const sparklineOptions = {
45
- onmousemove(event, dataPoint) {
46
- const date = (0, _util.formatTime)(dataPoint.date, 'HH:mm');
47
- const left = '80px';
48
- tooltipState.textContent = "".concat(date, ": ").concat(formatNumber(dataPoint.value));
49
- tooltipState.style.top = '-30px';
50
- tooltipState.style.left = left;
44
+ onmousemove(e, dataPoint) {
45
+ const {
46
+ date,
47
+ value
48
+ } = dataPoint;
49
+ tooltipState.textContent = "".concat(dateFn(date), ": ").concat(valueFn(value));
50
+ tooltipState.style.top = -30;
51
+ tooltipState.style.left = 80;
51
52
  tooltipState.hidden = false;
52
53
  },
53
54
  onmouseout() {
@@ -55,32 +56,28 @@ function CpuMonitor(_ref) {
55
56
  }
56
57
  };
57
58
  (0, _react.useEffect)(() => {
58
- // if (!loading) {
59
- // // see: https://github.com/alibaba/hooks/issues/838
60
- // }
61
59
  setTimeout(() => {
62
- setCpuDom(document.querySelector('.cpu-sparkline'));
60
+ setContainer(document.querySelector(".".concat(id)));
63
61
  setTimeout(() => {
64
62
  if (svgRef.current) {
65
- // sparkline(svgRef.current, downloads, sparklineOptions);
66
- (0, _Sparkline.default)(svgRef.current, history || [], sparklineOptions);
63
+ (0, _Sparkline.default)(svgRef.current, data || [], sparklineOptions);
67
64
  }
68
65
  }, 400);
69
66
  });
70
- }, [history]); // eslint-disable-line react-hooks/exhaustive-deps
67
+ }, [data]); // eslint-disable-line react-hooks/exhaustive-deps
71
68
 
72
69
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_card.default, {
73
- title: t('common.cpu'),
74
- value: "".concat(Math.floor(currentLoad || 0), "%"),
70
+ title: title,
71
+ value: current,
75
72
  graph: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
76
- className: "card-sparkline cpu-sparkline",
73
+ className: "card-sparkline ".concat(id),
77
74
  style: {
78
75
  marginTop: 16
79
76
  },
80
77
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {
81
78
  ref: svgRef,
82
79
  className: "sparkline",
83
- width: size.width || 100,
80
+ width: (size === null || size === void 0 ? void 0 : size.width) || 100,
84
81
  height: 30,
85
82
  strokeWidth: "2"
86
83
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
@@ -91,19 +88,21 @@ function CpuMonitor(_ref) {
91
88
  children: tooltipState.textContent
92
89
  })]
93
90
  }),
94
- description: "".concat(t('system.cores'), ": ").concat((cpus === null || cpus === void 0 ? void 0 : cpus.length) || 0),
95
- hideDescription: hideDescription
91
+ description: description
96
92
  });
97
93
  }
98
- CpuMonitor.propTypes = {
99
- cpus: _propTypes.default.array,
100
- currentLoad: _propTypes.default.number,
101
- history: _propTypes.default.array,
102
- hideDescription: _propTypes.default.bool
94
+ InsightChart.propTypes = {
95
+ id: _propTypes.default.string.isRequired,
96
+ title: _propTypes.default.string.isRequired,
97
+ current: _propTypes.default.any.isRequired,
98
+ description: _propTypes.default.any,
99
+ data: _propTypes.default.array,
100
+ dateFn: _propTypes.default.func,
101
+ valueFn: _propTypes.default.func
103
102
  };
104
- CpuMonitor.defaultProps = {
105
- cpus: [],
106
- currentLoad: 0,
107
- history: [],
108
- hideDescription: false
103
+ InsightChart.defaultProps = {
104
+ description: null,
105
+ data: [],
106
+ dateFn: x => x,
107
+ valueFn: x => x
109
108
  };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = CpuMonitor;
7
+ var _react = require("react");
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ var _context = require("@arcblock/ux/lib/Locale/context");
10
+ var _chart = _interopRequireDefault(require("./chart"));
11
+ var _util = require("../util");
12
+ var _jsxRuntime = require("react/jsx-runtime");
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ const formatNumber = x => "".concat(x, "%");
15
+ function CpuMonitor(_ref) {
16
+ let {
17
+ cpus,
18
+ currentLoad,
19
+ history
20
+ } = _ref;
21
+ const {
22
+ t,
23
+ locale
24
+ } = (0, _react.useContext)(_context.LocaleContext);
25
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_chart.default, {
26
+ id: "cpu-sparkline",
27
+ title: t('common.cpu'),
28
+ current: "".concat(Math.floor(currentLoad || 0), "%"),
29
+ data: history,
30
+ description: "".concat(t('system.cores'), ": ").concat((cpus === null || cpus === void 0 ? void 0 : cpus.length) || 0),
31
+ dateFn: v => (0, _util.formatTime)(v, 'HH:mm', locale),
32
+ valueFn: formatNumber
33
+ });
34
+ }
35
+ CpuMonitor.propTypes = {
36
+ cpus: _propTypes.default.array,
37
+ currentLoad: _propTypes.default.number,
38
+ history: _propTypes.default.array
39
+ };
40
+ CpuMonitor.defaultProps = {
41
+ cpus: [],
42
+ currentLoad: 0,
43
+ history: []
44
+ };
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = MemoryMonitor;
7
+ var _propTypes = _interopRequireDefault(require("prop-types"));
8
+ var _filesize = _interopRequireDefault(require("filesize"));
9
+ var _Box = _interopRequireDefault(require("@mui/material/Box"));
10
+ var _context = require("@arcblock/ux/lib/Locale/context");
11
+ var _chart = _interopRequireDefault(require("./chart"));
12
+ var _util = require("../util");
13
+ var _jsxRuntime = require("react/jsx-runtime");
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ /* eslint-disable react/jsx-one-expression-per-line */
16
+
17
+ function MemoryMonitor(_ref) {
18
+ let {
19
+ instanceCount,
20
+ title,
21
+ total,
22
+ used,
23
+ history
24
+ } = _ref;
25
+ const {
26
+ t,
27
+ locale
28
+ } = (0, _context.useLocaleContext)();
29
+ const showPercent = !!total;
30
+ const available = total - used;
31
+ const memoryPercent = showPercent ? "(".concat(Math.floor(used / total * 100), "%)") : '';
32
+ const memoryList = [];
33
+ if (instanceCount) {
34
+ memoryList.push({
35
+ title: t('system.instances'),
36
+ metric: instanceCount
37
+ });
38
+ }
39
+ memoryList.push({
40
+ title: t('system.used'),
41
+ metric: (0, _filesize.default)(used)
42
+ });
43
+ if (showPercent) {
44
+ memoryList.push({
45
+ title: t('system.free'),
46
+ metric: (0, _filesize.default)(available)
47
+ }, {
48
+ title: t('system.total'),
49
+ metric: (0, _filesize.default)(total)
50
+ });
51
+ }
52
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_chart.default, {
53
+ id: "mem-sparkline",
54
+ title: title || t('common.memory'),
55
+ current: "".concat((0, _filesize.default)(Math.floor(used || 0)), " ").concat(memoryPercent),
56
+ data: history,
57
+ description: memoryList.map((x, index) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
58
+ sx: {
59
+ marginLeft: index === 0 ? 0 : 2
60
+ },
61
+ children: [x.title, ": ", x.metric]
62
+ }, x.title)),
63
+ dateFn: v => (0, _util.formatTime)(v, 'HH:mm', locale),
64
+ valueFn: _filesize.default
65
+ });
66
+ }
67
+ MemoryMonitor.propTypes = {
68
+ title: _propTypes.default.string,
69
+ instanceCount: _propTypes.default.number,
70
+ total: _propTypes.default.number,
71
+ used: _propTypes.default.number,
72
+ history: _propTypes.default.array
73
+ };
74
+ MemoryMonitor.defaultProps = {
75
+ title: '',
76
+ instanceCount: null,
77
+ total: null,
78
+ used: null,
79
+ history: []
80
+ };