@abtnode/ux 1.15.17 → 1.16.0-beta-b16cb035
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/lib/actions.js +111 -0
- package/lib/blocklet/access/config-access.js +303 -0
- package/lib/blocklet/access/index.js +221 -0
- package/lib/blocklet/actions.js +438 -0
- package/lib/blocklet/add-cert.js +191 -0
- package/lib/blocklet/agreement-app.js +30 -0
- package/lib/blocklet/agreement.js +72 -0
- package/lib/blocklet/app-avatar.js +74 -0
- package/lib/blocklet/audit-logs.js +197 -0
- package/lib/blocklet/blocklet-source.js +56 -0
- package/lib/blocklet/bundle-avatar.js +80 -0
- package/lib/blocklet/component/add.js +1063 -0
- package/lib/blocklet/component/configuration.js +124 -0
- package/lib/blocklet/component/delete.js +117 -0
- package/lib/blocklet/component/environment.js +289 -0
- package/lib/blocklet/component/expiration.js +53 -0
- package/lib/blocklet/component/index.js +804 -0
- package/lib/blocklet/component/line.js +28 -0
- package/lib/blocklet/component/navigation/locale-tabs.js +218 -0
- package/lib/blocklet/component/navigation/navigation-actions.js +120 -0
- package/lib/blocklet/component/navigation/navigation-dialog.js +620 -0
- package/lib/blocklet/component/navigation/navigation-preview.js +102 -0
- package/lib/blocklet/component/navigation/simple-select.js +131 -0
- package/lib/blocklet/component/select-store.js +153 -0
- package/lib/blocklet/component/setting.js +151 -0
- package/lib/blocklet/component/sortable-tree.js +138 -0
- package/lib/blocklet/component/space-gateway-selector.js +174 -0
- package/lib/blocklet/component/store-blocklet-list.js +205 -0
- package/lib/blocklet/config-navigation.js +344 -0
- package/lib/blocklet/configuration.js +574 -0
- package/lib/blocklet/disk-info.js +91 -0
- package/lib/blocklet/icons.js +26 -0
- package/lib/blocklet/install-from-url.js +347 -0
- package/lib/blocklet/log.js +62 -0
- package/lib/blocklet/migration.js +153 -0
- package/lib/blocklet/mode.js +35 -0
- package/lib/blocklet/monitor.js +186 -0
- package/lib/blocklet/overview.js +236 -0
- package/lib/blocklet/preferences/app-sk.js +131 -0
- package/lib/blocklet/preferences/index.js +238 -0
- package/lib/blocklet/preferences/wallet-type.js +107 -0
- package/lib/blocklet/purchase/common.js +103 -0
- package/lib/blocklet/purchase/component-purchase.js +253 -0
- package/lib/blocklet/purchase/index.js +13 -0
- package/lib/blocklet/router/action/add-domain-alias.js +173 -0
- package/lib/blocklet/router/action/add-rule.js +204 -0
- package/lib/blocklet/router/action/config-routing-rule.js +129 -0
- package/lib/blocklet/router/action/delete-domain-alias.js +107 -0
- package/lib/blocklet/router/action/delete-rule.js +114 -0
- package/lib/blocklet/router/action/update-rule.js +203 -0
- package/lib/blocklet/router/domain-actions.js +71 -0
- package/lib/blocklet/router/domain-status.js +96 -0
- package/lib/blocklet/router/rule-actions.js +77 -0
- package/lib/blocklet/router/rule-list.js +181 -0
- package/lib/blocklet/router/util.js +146 -0
- package/lib/blocklet/runtime-info.js +87 -0
- package/lib/blocklet/status.js +105 -0
- package/lib/blocklet/storage.js +322 -0
- package/lib/blocklet/types.js +25 -0
- package/lib/blocklet/util.js +213 -0
- package/lib/blocklet/version.js +156 -0
- package/lib/card-selector.js +109 -0
- package/lib/certificate.js +110 -0
- package/lib/click-to-copy.js +38 -0
- package/lib/confirm.js +149 -0
- package/lib/contexts/audit-log.js +141 -0
- package/lib/contexts/blocklet.js +19 -0
- package/lib/contexts/deleting-blocklets.js +78 -0
- package/lib/contexts/node.js +30 -0
- package/lib/contexts/session.js +20 -0
- package/lib/contexts/team.js +19 -0
- package/lib/delete-confirm.js +127 -0
- package/lib/did-address.js +77 -0
- package/lib/dot.js +18 -0
- package/lib/form/form-text-input.js +266 -0
- package/lib/form/form-wrapper.js +13 -0
- package/lib/form/required.js +13 -0
- package/lib/hooks/blocklet.js +231 -0
- package/lib/hooks/mobile-width.js +19 -0
- package/lib/hooks/url-evaluation.js +168 -0
- package/lib/hooks/use-app-logo.js +25 -0
- package/lib/hooks/use-bundle-logo.js +36 -0
- package/lib/hooks/use-navigation.js +355 -0
- package/lib/hooks/use-passport-id.js +21 -0
- package/lib/hooks/use-subscription.js +28 -0
- package/lib/icons/long-arrow.svg +5 -0
- package/lib/index.js +0 -3
- package/lib/invitation/invitation-app.js +51 -0
- package/lib/invitation/invitation-login.js +47 -0
- package/lib/invitation/invitation-passport.js +130 -0
- package/lib/invitation/invitation-receive.js +108 -0
- package/lib/invitation/invitation-success.js +82 -0
- package/lib/invitation/invitation-user.js +79 -0
- package/lib/invitation/invitation.js +80 -0
- package/lib/issue-passport.js +84 -84
- package/lib/launch-blocklet/content-layout.js +33 -0
- package/lib/launch-blocklet/page-header.js +38 -0
- package/lib/layout/addon.js +100 -0
- package/lib/layout/feedback.js +55 -0
- package/lib/locales/en.js +1221 -10
- package/lib/locales/index.js +3 -4
- package/lib/locales/zh.js +1232 -15
- package/lib/logs/clock.js +19 -0
- package/lib/logs/download.js +139 -0
- package/lib/logs/log-terminal.js +183 -0
- package/lib/lost-passport.js +191 -195
- package/lib/monitor/card.js +73 -0
- package/lib/monitor/cpu.js +109 -0
- package/lib/monitor/disk.js +122 -0
- package/lib/monitor/memory.js +144 -0
- package/lib/nav-logo.js +120 -0
- package/lib/passport-tag.js +43 -0
- package/lib/permission.js +70 -0
- package/lib/relative-time.js +61 -0
- package/lib/schema-form/color-input.js +105 -0
- package/lib/schema-form/common-prop-types.js +21 -0
- package/lib/schema-form/index.js +229 -0
- package/lib/schema-form/passport-input.js +66 -0
- package/lib/schema-form/text-input.js +72 -0
- package/lib/store/add.js +185 -0
- package/lib/store/delete.js +102 -0
- package/lib/store/item.js +84 -0
- package/lib/table-icons.js +42 -0
- package/lib/table.js +13 -0
- package/lib/tag.js +37 -0
- package/lib/team/members/actions.js +99 -0
- package/lib/team/members/index.js +503 -0
- package/lib/team/members/invitations.js +196 -0
- package/lib/team/members/invite-member.js +212 -0
- package/lib/team/members/issue-passport.js +155 -0
- package/lib/team/members/member.js +300 -0
- package/lib/team/members/passport-issuances.js +154 -0
- package/lib/team/members/passports.js +336 -0
- package/lib/team/members/toggle-user-approval.js +128 -0
- package/lib/team/members/transfer-node.js +262 -0
- package/lib/team/members/util.js +20 -0
- package/lib/team/passports/color.js +132 -0
- package/lib/team/passports/detail.js +271 -0
- package/lib/team/passports/index.js +233 -0
- package/lib/team/passports/mutate-role.js +204 -0
- package/lib/team/passports/trusted-issuer.js +297 -0
- package/lib/team/passports/trusted-issuers.js +240 -0
- package/lib/team/search-input.js +38 -0
- package/lib/team/styles/dialog.js +13 -0
- package/lib/team/styles/list-header.js +13 -0
- package/lib/toast.js +86 -0
- package/lib/util/api.js +21 -0
- package/lib/util/constants.js +10 -0
- package/lib/util/index.js +703 -0
- package/lib/util/locales.js +28 -0
- package/lib/util/mode.js +11 -0
- package/lib/who-can-access/config.js +46 -0
- package/lib/wrap-locale.js +12 -13
- package/package.json +69 -17
|
@@ -0,0 +1,109 @@
|
|
|
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 _ahooks = require("ahooks");
|
|
10
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
11
|
+
var _Sparkline = _interopRequireDefault(require("@arcblock/ux/lib/Sparkline"));
|
|
12
|
+
var _card = _interopRequireDefault(require("./card"));
|
|
13
|
+
var _util = require("../util");
|
|
14
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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
|
+
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
|
+
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
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
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) {
|
|
23
|
+
let {
|
|
24
|
+
cpus,
|
|
25
|
+
currentLoad,
|
|
26
|
+
history,
|
|
27
|
+
hideDescription
|
|
28
|
+
} = _ref;
|
|
29
|
+
const {
|
|
30
|
+
t
|
|
31
|
+
} = (0, _react.useContext)(_context.LocaleContext);
|
|
32
|
+
const svgRef = (0, _react.useRef)(null);
|
|
33
|
+
const tooltipRef = (0, _react.useRef)(null);
|
|
34
|
+
const tooltipState = (0, _ahooks.useReactive)({
|
|
35
|
+
style: {
|
|
36
|
+
top: 0,
|
|
37
|
+
left: 0
|
|
38
|
+
},
|
|
39
|
+
hidden: true,
|
|
40
|
+
textContent: ''
|
|
41
|
+
});
|
|
42
|
+
const [cpuDom, setCpuDom] = (0, _react.useState)();
|
|
43
|
+
const size = (0, _ahooks.useSize)(cpuDom) || {};
|
|
44
|
+
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;
|
|
51
|
+
tooltipState.hidden = false;
|
|
52
|
+
},
|
|
53
|
+
onmouseout() {
|
|
54
|
+
tooltipState.hidden = true;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
(0, _react.useEffect)(() => {
|
|
58
|
+
// if (!loading) {
|
|
59
|
+
// // see: https://github.com/alibaba/hooks/issues/838
|
|
60
|
+
// }
|
|
61
|
+
setTimeout(() => {
|
|
62
|
+
setCpuDom(document.querySelector('.cpu-sparkline'));
|
|
63
|
+
setTimeout(() => {
|
|
64
|
+
if (svgRef.current) {
|
|
65
|
+
// sparkline(svgRef.current, downloads, sparklineOptions);
|
|
66
|
+
(0, _Sparkline.default)(svgRef.current, history || [], sparklineOptions);
|
|
67
|
+
}
|
|
68
|
+
}, 400);
|
|
69
|
+
});
|
|
70
|
+
}, [history]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
71
|
+
|
|
72
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_card.default, {
|
|
73
|
+
title: t('common.cpu'),
|
|
74
|
+
value: "".concat(Math.floor(currentLoad || 0), "%"),
|
|
75
|
+
graph: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
76
|
+
className: "card-sparkline cpu-sparkline",
|
|
77
|
+
style: {
|
|
78
|
+
marginTop: 16
|
|
79
|
+
},
|
|
80
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {
|
|
81
|
+
ref: svgRef,
|
|
82
|
+
className: "sparkline",
|
|
83
|
+
width: size.width || 100,
|
|
84
|
+
height: 30,
|
|
85
|
+
strokeWidth: "2"
|
|
86
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
87
|
+
className: "tooltip",
|
|
88
|
+
ref: tooltipRef,
|
|
89
|
+
hidden: tooltipState.hidden,
|
|
90
|
+
style: _objectSpread({}, tooltipState.style),
|
|
91
|
+
children: tooltipState.textContent
|
|
92
|
+
})]
|
|
93
|
+
}),
|
|
94
|
+
description: "".concat(t('system.cores'), ": ").concat((cpus === null || cpus === void 0 ? void 0 : cpus.length) || 0),
|
|
95
|
+
hideDescription: hideDescription
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
CpuMonitor.propTypes = {
|
|
99
|
+
cpus: _propTypes.default.array,
|
|
100
|
+
currentLoad: _propTypes.default.number,
|
|
101
|
+
history: _propTypes.default.array,
|
|
102
|
+
hideDescription: _propTypes.default.bool
|
|
103
|
+
};
|
|
104
|
+
CpuMonitor.defaultProps = {
|
|
105
|
+
cpus: [],
|
|
106
|
+
currentLoad: 0,
|
|
107
|
+
history: [],
|
|
108
|
+
hideDescription: false
|
|
109
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = DiskMonitor;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _styles = require("@mui/styles");
|
|
10
|
+
var _Typography = _interopRequireDefault(require("@mui/material/Typography"));
|
|
11
|
+
var _LinearProgress = _interopRequireDefault(require("@mui/material/LinearProgress"));
|
|
12
|
+
var _Box = _interopRequireDefault(require("@mui/material/Box"));
|
|
13
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
14
|
+
var _card = _interopRequireDefault(require("./card"));
|
|
15
|
+
var _index = require("../util/index");
|
|
16
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
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; }
|
|
19
|
+
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; }
|
|
20
|
+
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; }
|
|
21
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
22
|
+
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); }
|
|
23
|
+
const BorderLinearProgress = (0, _styles.withStyles)(theme => ({
|
|
24
|
+
root: {
|
|
25
|
+
height: 10
|
|
26
|
+
},
|
|
27
|
+
colorPrimary: {
|
|
28
|
+
backgroundColor: theme.palette.grey[theme.palette.mode === 'light' ? 200 : 700]
|
|
29
|
+
},
|
|
30
|
+
bar: {
|
|
31
|
+
backgroundColor: theme.palette.secondary.main
|
|
32
|
+
}
|
|
33
|
+
}))(_LinearProgress.default);
|
|
34
|
+
function LinearProgressWithLabel(props) {
|
|
35
|
+
const {
|
|
36
|
+
value
|
|
37
|
+
} = props;
|
|
38
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
|
|
39
|
+
display: "flex",
|
|
40
|
+
alignItems: "center",
|
|
41
|
+
mt: 2,
|
|
42
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
|
|
43
|
+
width: "100%",
|
|
44
|
+
style: {
|
|
45
|
+
overflow: 'hidden'
|
|
46
|
+
},
|
|
47
|
+
mr: 1,
|
|
48
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(BorderLinearProgress, _objectSpread({
|
|
49
|
+
variant: "determinate"
|
|
50
|
+
}, props))
|
|
51
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
|
|
52
|
+
minWidth: 35,
|
|
53
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
54
|
+
variant: "body2",
|
|
55
|
+
color: "textSecondary",
|
|
56
|
+
children: "".concat(Math.round(value), "%")
|
|
57
|
+
})
|
|
58
|
+
})]
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
LinearProgressWithLabel.propTypes = {
|
|
62
|
+
value: _propTypes.default.number.isRequired
|
|
63
|
+
};
|
|
64
|
+
function DiskMonitor(_ref) {
|
|
65
|
+
let {
|
|
66
|
+
disk,
|
|
67
|
+
platform
|
|
68
|
+
} = _ref;
|
|
69
|
+
const {
|
|
70
|
+
t
|
|
71
|
+
} = (0, _react.useContext)(_context.LocaleContext);
|
|
72
|
+
const metrics = [{
|
|
73
|
+
id: 1,
|
|
74
|
+
className: 'used',
|
|
75
|
+
title: t('system.used'),
|
|
76
|
+
metric: (0, _index.formatDiskSize)(disk.used, platform)
|
|
77
|
+
}, {
|
|
78
|
+
id: 2,
|
|
79
|
+
className: 'free',
|
|
80
|
+
title: t('system.free'),
|
|
81
|
+
metric: (0, _index.formatDiskSize)(disk.free, platform)
|
|
82
|
+
}, {
|
|
83
|
+
id: 3,
|
|
84
|
+
className: 'total',
|
|
85
|
+
title: t('system.total'),
|
|
86
|
+
metric: (0, _index.formatDiskSize)(disk.total, platform)
|
|
87
|
+
}];
|
|
88
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_card.default, {
|
|
89
|
+
title: "".concat(t('common.disk'), " (").concat(disk.device, ")"),
|
|
90
|
+
value: (0, _index.formatDiskSize)(disk.used, platform),
|
|
91
|
+
graph: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
|
|
92
|
+
mt: 3,
|
|
93
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(LinearProgressWithLabel, {
|
|
94
|
+
value: disk.used / disk.total * 100
|
|
95
|
+
})
|
|
96
|
+
}),
|
|
97
|
+
description: metrics.map((x, index) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
|
|
98
|
+
sx: {
|
|
99
|
+
marginLeft: index === 0 ? 0 : 2
|
|
100
|
+
},
|
|
101
|
+
children: [x.title, ": ", x.metric]
|
|
102
|
+
}, x.title))
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
DiskMonitor.propTypes = {
|
|
106
|
+
disk: _propTypes.default.shape({
|
|
107
|
+
used: _propTypes.default.number,
|
|
108
|
+
free: _propTypes.default.number,
|
|
109
|
+
total: _propTypes.default.number,
|
|
110
|
+
device: _propTypes.default.string
|
|
111
|
+
}),
|
|
112
|
+
platform: _propTypes.default.string
|
|
113
|
+
};
|
|
114
|
+
DiskMonitor.defaultProps = {
|
|
115
|
+
disk: {
|
|
116
|
+
used: 0,
|
|
117
|
+
free: 0,
|
|
118
|
+
total: 1,
|
|
119
|
+
device: ''
|
|
120
|
+
},
|
|
121
|
+
platform: ''
|
|
122
|
+
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = MemoryMonitor;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _filesize = _interopRequireDefault(require("filesize"));
|
|
10
|
+
var _ahooks = require("ahooks");
|
|
11
|
+
var _Box = _interopRequireDefault(require("@mui/material/Box"));
|
|
12
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
13
|
+
var _Sparkline = _interopRequireDefault(require("@arcblock/ux/lib/Sparkline"));
|
|
14
|
+
var _card = _interopRequireDefault(require("./card"));
|
|
15
|
+
var _util = require("../util");
|
|
16
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
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; }
|
|
19
|
+
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; }
|
|
20
|
+
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; }
|
|
21
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
22
|
+
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); }
|
|
23
|
+
const formatNumber = x => (0, _filesize.default)(x);
|
|
24
|
+
function MemoryMonitor(_ref) {
|
|
25
|
+
let {
|
|
26
|
+
instanceCount,
|
|
27
|
+
title,
|
|
28
|
+
total,
|
|
29
|
+
used,
|
|
30
|
+
history,
|
|
31
|
+
hideDescription
|
|
32
|
+
} = _ref;
|
|
33
|
+
const {
|
|
34
|
+
t
|
|
35
|
+
} = (0, _react.useContext)(_context.LocaleContext);
|
|
36
|
+
const svgRef = (0, _react.useRef)(null);
|
|
37
|
+
const tooltipRef = (0, _react.useRef)(null);
|
|
38
|
+
const tooltipState = (0, _ahooks.useReactive)({
|
|
39
|
+
style: {
|
|
40
|
+
top: 0,
|
|
41
|
+
left: 0
|
|
42
|
+
},
|
|
43
|
+
hidden: true,
|
|
44
|
+
textContent: ''
|
|
45
|
+
});
|
|
46
|
+
const [dom, setDom] = (0, _react.useState)();
|
|
47
|
+
const size = (0, _ahooks.useSize)(dom) || {};
|
|
48
|
+
const showPercent = !!total;
|
|
49
|
+
const available = total - used;
|
|
50
|
+
const memoryPercent = showPercent ? "(".concat(Math.floor(used / total * 100), "%)") : '';
|
|
51
|
+
const memoryList = [];
|
|
52
|
+
if (instanceCount) {
|
|
53
|
+
memoryList.push({
|
|
54
|
+
title: t('system.instances'),
|
|
55
|
+
metric: instanceCount
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
memoryList.push({
|
|
59
|
+
title: t('system.used'),
|
|
60
|
+
metric: (0, _filesize.default)(used)
|
|
61
|
+
});
|
|
62
|
+
if (showPercent) {
|
|
63
|
+
memoryList.push({
|
|
64
|
+
title: t('system.free'),
|
|
65
|
+
metric: (0, _filesize.default)(available)
|
|
66
|
+
}, {
|
|
67
|
+
title: t('system.total'),
|
|
68
|
+
metric: (0, _filesize.default)(total)
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const sparklineOptions = {
|
|
72
|
+
onmousemove(event, dataPoint) {
|
|
73
|
+
const date = (0, _util.formatTime)(dataPoint.date, 'HH:mm');
|
|
74
|
+
const left = '80px';
|
|
75
|
+
tooltipState.textContent = "".concat(date, ": ").concat(formatNumber(dataPoint.value));
|
|
76
|
+
tooltipState.style.top = '-30px';
|
|
77
|
+
tooltipState.style.left = left;
|
|
78
|
+
tooltipState.hidden = false;
|
|
79
|
+
},
|
|
80
|
+
onmouseout() {
|
|
81
|
+
tooltipState.hidden = true;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
(0, _react.useEffect)(() => {
|
|
85
|
+
// if (!loading) {
|
|
86
|
+
// // see: https://github.com/alibaba/hooks/issues/838
|
|
87
|
+
// }
|
|
88
|
+
setTimeout(() => {
|
|
89
|
+
setDom(document.querySelector('.mem-sparkline'));
|
|
90
|
+
setTimeout(() => {
|
|
91
|
+
if (svgRef.current) {
|
|
92
|
+
(0, _Sparkline.default)(svgRef.current, history, sparklineOptions);
|
|
93
|
+
}
|
|
94
|
+
}, 400);
|
|
95
|
+
});
|
|
96
|
+
}, [history]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
97
|
+
|
|
98
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_card.default, {
|
|
99
|
+
title: title || t('common.memory'),
|
|
100
|
+
value: "".concat((0, _filesize.default)(Math.floor(used || 0)), " ").concat(memoryPercent),
|
|
101
|
+
graph: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
102
|
+
className: "card-sparkline mem-sparkline",
|
|
103
|
+
style: {
|
|
104
|
+
marginTop: 16
|
|
105
|
+
},
|
|
106
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {
|
|
107
|
+
ref: svgRef,
|
|
108
|
+
className: "sparkline",
|
|
109
|
+
width: size.width || 100,
|
|
110
|
+
height: 30,
|
|
111
|
+
strokeWidth: "2"
|
|
112
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
113
|
+
className: "tooltip",
|
|
114
|
+
ref: tooltipRef,
|
|
115
|
+
hidden: tooltipState.hidden,
|
|
116
|
+
style: _objectSpread({}, tooltipState.style),
|
|
117
|
+
children: tooltipState.textContent
|
|
118
|
+
})]
|
|
119
|
+
}),
|
|
120
|
+
description: memoryList.map((x, index) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
|
|
121
|
+
sx: {
|
|
122
|
+
marginLeft: index === 0 ? 0 : 2
|
|
123
|
+
},
|
|
124
|
+
children: [x.title, ": ", x.metric]
|
|
125
|
+
}, x.title)),
|
|
126
|
+
hideDescription: hideDescription
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
MemoryMonitor.propTypes = {
|
|
130
|
+
title: _propTypes.default.string,
|
|
131
|
+
instanceCount: _propTypes.default.number,
|
|
132
|
+
total: _propTypes.default.number,
|
|
133
|
+
used: _propTypes.default.number,
|
|
134
|
+
history: _propTypes.default.array,
|
|
135
|
+
hideDescription: _propTypes.default.bool
|
|
136
|
+
};
|
|
137
|
+
MemoryMonitor.defaultProps = {
|
|
138
|
+
title: '',
|
|
139
|
+
instanceCount: null,
|
|
140
|
+
total: null,
|
|
141
|
+
used: null,
|
|
142
|
+
history: [],
|
|
143
|
+
hideDescription: false
|
|
144
|
+
};
|
package/lib/nav-logo.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = LogoContainer;
|
|
7
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
+
var _styled = _interopRequireDefault(require("@emotion/styled"));
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
var _templateObject, _templateObject2;
|
|
11
|
+
const _excluded = ["logo", "name", "subname", "previousData"],
|
|
12
|
+
_excluded2 = ["logo"];
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
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; }
|
|
16
|
+
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; }
|
|
17
|
+
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; }
|
|
18
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
19
|
+
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); }
|
|
20
|
+
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; }
|
|
21
|
+
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; }
|
|
22
|
+
function LogoContainer(_ref) {
|
|
23
|
+
let {
|
|
24
|
+
logo,
|
|
25
|
+
name,
|
|
26
|
+
subname,
|
|
27
|
+
previousData
|
|
28
|
+
} = _ref,
|
|
29
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
30
|
+
let logoEle = /*#__PURE__*/(0, _jsxRuntime.jsx)(LogoImg, {
|
|
31
|
+
logo: logo
|
|
32
|
+
});
|
|
33
|
+
let nameEle = name;
|
|
34
|
+
let subnameEle = subname;
|
|
35
|
+
if (previousData.logo) {
|
|
36
|
+
logoEle = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
37
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(LogoImg, {
|
|
38
|
+
logo: logo,
|
|
39
|
+
className: "left-fade-in-ele"
|
|
40
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(LogoImg, {
|
|
41
|
+
logo: previousData.logo,
|
|
42
|
+
className: "postion-abs left-fade-out-ele"
|
|
43
|
+
})]
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (previousData.name && previousData.name !== name) {
|
|
47
|
+
nameEle = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
48
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
49
|
+
className: "right-fade-in-ele",
|
|
50
|
+
style: {
|
|
51
|
+
display: 'inline-block'
|
|
52
|
+
},
|
|
53
|
+
children: name
|
|
54
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
55
|
+
className: "postion-abs right-fade-out-ele",
|
|
56
|
+
children: previousData.name
|
|
57
|
+
})]
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (previousData.subname && previousData.subname !== subname) {
|
|
61
|
+
subnameEle = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
62
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
63
|
+
className: "right-fade-in-ele",
|
|
64
|
+
style: {
|
|
65
|
+
display: 'inline-block'
|
|
66
|
+
},
|
|
67
|
+
children: subname
|
|
68
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
69
|
+
className: "postion-abs right-fade-out-ele",
|
|
70
|
+
children: previousData.subname
|
|
71
|
+
})]
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Container, _objectSpread(_objectSpread({}, rest), {}, {
|
|
75
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
76
|
+
className: "logo-inner",
|
|
77
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
78
|
+
className: "logo-img-content",
|
|
79
|
+
children: logoEle
|
|
80
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
81
|
+
className: "logo-info ".concat(!name && !subname ? 'zero-left' : ''),
|
|
82
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
83
|
+
className: "logo-name",
|
|
84
|
+
children: nameEle
|
|
85
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
86
|
+
className: "logo-subname",
|
|
87
|
+
children: subnameEle
|
|
88
|
+
})]
|
|
89
|
+
})]
|
|
90
|
+
})
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
LogoContainer.propTypes = {
|
|
94
|
+
logo: _propTypes.default.element.isRequired,
|
|
95
|
+
name: _propTypes.default.string,
|
|
96
|
+
subname: _propTypes.default.string,
|
|
97
|
+
previousData: _propTypes.default.object
|
|
98
|
+
};
|
|
99
|
+
LogoContainer.defaultProps = {
|
|
100
|
+
name: '',
|
|
101
|
+
subname: '',
|
|
102
|
+
previousData: {
|
|
103
|
+
logo: '',
|
|
104
|
+
name: '',
|
|
105
|
+
subname: ''
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// eslint-disable-next-line react/prop-types
|
|
110
|
+
function LogoImg(_ref2) {
|
|
111
|
+
let {
|
|
112
|
+
logo
|
|
113
|
+
} = _ref2,
|
|
114
|
+
rest = _objectWithoutProperties(_ref2, _excluded2);
|
|
115
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(LogoImgDiv, _objectSpread(_objectSpread({}, rest), {}, {
|
|
116
|
+
children: logo
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
const LogoImgDiv = _styled.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: block;\n > * {\n display: block;\n }\n"])));
|
|
120
|
+
const Container = _styled.default.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: relative;\n display: block;\n\n .logo-inner {\n display: flex;\n align-items: center;\n height: 100%;\n .logo-img-content {\n position: relative;\n display: block;\n }\n .logo-info {\n display: flex;\n flex-direction: column;\n justify-content: center;\n margin-left: 10px;\n letter-spacing: 0.1px;\n &.zero-left {\n margin-left: 0%;\n }\n .logo-name {\n position: relative;\n line-height: 16px;\n font-size: 16px;\n color: #121319;\n }\n .logo-subname {\n position: relative;\n line-height: 13px;\n font-size: 13px;\n color: #7d8085;\n }\n }\n }\n\n .postion-abs {\n position: absolute;\n left: 0;\n top: 0;\n height: 100%;\n }\n\n .right-fade-out-ele {\n animation: right-fade-out ease 0.5s;\n animation-delay: 2s;\n animation-fill-mode: forwards;\n }\n\n .right-fade-in-ele {\n animation: right-fade-in ease 0.5s;\n animation-delay: 2s;\n animation-fill-mode: both;\n }\n\n @keyframes right-fade-out {\n 0% {\n opacity: 1;\n transform: translate(0, 0);\n }\n 100% {\n opacity: 0;\n transform: translate(8px, 0);\n }\n }\n\n @keyframes right-fade-in {\n 0% {\n opacity: 0;\n transform: translate(8px, 0);\n }\n 100% {\n opacity: 1;\n transform: translate(0, 0);\n }\n }\n\n .left-fade-out-ele {\n animation: left-fade-out ease 0.5s;\n animation-delay: 2s;\n animation-fill-mode: forwards;\n }\n\n .left-fade-in-ele {\n animation: left-fade-in ease 0.5s;\n animation-delay: 2s;\n animation-fill-mode: both;\n }\n\n @keyframes left-fade-out {\n 0% {\n opacity: 1;\n transform: translate(0, 0);\n }\n 100% {\n opacity: 0;\n transform: translate(-8px, 0);\n }\n }\n\n @keyframes left-fade-in {\n 0% {\n opacity: 0;\n transform: translate(-8px, 0);\n }\n 100% {\n opacity: 1;\n transform: translate(0, 0);\n }\n }\n"])));
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = PassportTag;
|
|
7
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
+
var _styled = _interopRequireDefault(require("@emotion/styled"));
|
|
9
|
+
var _Close = _interopRequireDefault(require("@mui/icons-material/Close"));
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
var _templateObject;
|
|
12
|
+
const _excluded = ["passport", "onDelete"];
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
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; }
|
|
16
|
+
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; }
|
|
17
|
+
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; }
|
|
18
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
19
|
+
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); }
|
|
20
|
+
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; }
|
|
21
|
+
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; }
|
|
22
|
+
function PassportTag(props) {
|
|
23
|
+
const {
|
|
24
|
+
passport,
|
|
25
|
+
onDelete
|
|
26
|
+
} = props,
|
|
27
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
28
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Tag, _objectSpread(_objectSpread({}, rest), {}, {
|
|
29
|
+
children: [passport.title || passport.name, ' ', !!onDelete && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Close.default, {
|
|
30
|
+
"data-cy": "delete-issuance",
|
|
31
|
+
className: "delete",
|
|
32
|
+
onClick: onDelete
|
|
33
|
+
})]
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
PassportTag.propTypes = {
|
|
37
|
+
passport: _propTypes.default.object.isRequired,
|
|
38
|
+
onDelete: _propTypes.default.func
|
|
39
|
+
};
|
|
40
|
+
PassportTag.defaultProps = {
|
|
41
|
+
onDelete: null
|
|
42
|
+
};
|
|
43
|
+
const Tag = _styled.default.span(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: inline-flex;\n padding: 2px 8px;\n background: ", ";\n border-radius: 100vw;\n font-weight: 400;\n font-size: 12px;\n line-height: 22px;\n color: #fff;\n align-items: center;\n .delete {\n font-size: 1em;\n margin-left: 6px;\n cursor: pointer;\n }\n"])), props => props.theme.palette.primary.main);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = Permission;
|
|
7
|
+
exports.withPermission = withPermission;
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _session = require("./contexts/session");
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
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; }
|
|
13
|
+
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; }
|
|
14
|
+
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; }
|
|
15
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
16
|
+
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); }
|
|
17
|
+
function Permission(_ref) {
|
|
18
|
+
let {
|
|
19
|
+
permission,
|
|
20
|
+
role,
|
|
21
|
+
component,
|
|
22
|
+
children
|
|
23
|
+
} = _ref;
|
|
24
|
+
const {
|
|
25
|
+
session
|
|
26
|
+
} = (0, _session.useSessionContext)();
|
|
27
|
+
let can = true;
|
|
28
|
+
const permissions = [].concat(permission).filter(Boolean);
|
|
29
|
+
const roles = [].concat(role).filter(Boolean);
|
|
30
|
+
if (permissions.length) {
|
|
31
|
+
const userPermissions = session.user && session.user.permissions || [];
|
|
32
|
+
can = permissions.some(p => userPermissions.includes(p));
|
|
33
|
+
}
|
|
34
|
+
if (can && roles.length) {
|
|
35
|
+
can = roles.includes(session.user.role);
|
|
36
|
+
}
|
|
37
|
+
if (typeof component === 'function') {
|
|
38
|
+
return component(can);
|
|
39
|
+
}
|
|
40
|
+
if (typeof children === 'function') {
|
|
41
|
+
return children(can);
|
|
42
|
+
}
|
|
43
|
+
if (can) {
|
|
44
|
+
return component || children || null;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
function withPermission(Component, permissionName, role) {
|
|
49
|
+
return function WithPermission(props) {
|
|
50
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Permission, {
|
|
51
|
+
permission: permissionName,
|
|
52
|
+
role: role,
|
|
53
|
+
children: hasPermission => /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, _objectSpread(_objectSpread({}, props), {}, {
|
|
54
|
+
hasPermission: hasPermission
|
|
55
|
+
}))
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
Permission.propTypes = {
|
|
60
|
+
permission: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
61
|
+
role: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
62
|
+
component: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.node]),
|
|
63
|
+
children: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.node])
|
|
64
|
+
};
|
|
65
|
+
Permission.defaultProps = {
|
|
66
|
+
permission: '',
|
|
67
|
+
role: '',
|
|
68
|
+
component: null,
|
|
69
|
+
children: null
|
|
70
|
+
};
|