@abtnode/ux 1.16.14-beta-c308dc3b → 1.16.14-beta-963cb583

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.
Files changed (213) hide show
  1. package/es/actions.js +97 -0
  2. package/es/analytics/card.js +92 -0
  3. package/es/analytics/chart.js +96 -0
  4. package/es/analytics/cpu.js +36 -0
  5. package/es/analytics/disk.js +111 -0
  6. package/es/analytics/memory.js +72 -0
  7. package/es/analytics/runtime.js +173 -0
  8. package/es/analytics/traffic.js +259 -0
  9. package/es/blocklet/access/config-access.js +307 -0
  10. package/es/blocklet/access/index.js +216 -0
  11. package/es/blocklet/actions.js +474 -0
  12. package/es/blocklet/add-cert.js +177 -0
  13. package/es/blocklet/agreement-app.js +21 -0
  14. package/es/blocklet/agreement.js +127 -0
  15. package/es/blocklet/app-avatar.js +57 -0
  16. package/es/blocklet/audit-logs.js +259 -0
  17. package/es/blocklet/blocklet-source.js +48 -0
  18. package/es/blocklet/bundle-avatar.js +64 -0
  19. package/es/blocklet/component/add.js +1313 -0
  20. package/es/blocklet/component/configuration.js +122 -0
  21. package/es/blocklet/component/delete.js +134 -0
  22. package/es/blocklet/component/environment.js +370 -0
  23. package/es/blocklet/component/index.js +975 -0
  24. package/es/blocklet/component/line.js +20 -0
  25. package/es/blocklet/component/navigation/locale-tabs.js +225 -0
  26. package/es/blocklet/component/navigation/navigation-actions.js +112 -0
  27. package/es/blocklet/component/navigation/navigation-dialog.js +607 -0
  28. package/es/blocklet/component/navigation/navigation-preview.js +101 -0
  29. package/es/blocklet/component/navigation/simple-select.js +124 -0
  30. package/es/blocklet/component/select-store.js +155 -0
  31. package/es/blocklet/component/selected/index.js +94 -0
  32. package/es/blocklet/component/setting.js +109 -0
  33. package/es/blocklet/component/sortable-tree.js +126 -0
  34. package/es/blocklet/component/space-connector.js +199 -0
  35. package/es/blocklet/component/space-selector.js +178 -0
  36. package/es/blocklet/component/start.js +101 -0
  37. package/es/blocklet/component/store-blocklet-list.js +200 -0
  38. package/es/blocklet/component/switch-control.js +57 -0
  39. package/es/blocklet/config-navigation.js +331 -0
  40. package/es/blocklet/configuration.js +603 -0
  41. package/es/blocklet/disk-info.js +75 -0
  42. package/es/blocklet/icons.js +18 -0
  43. package/es/blocklet/install-from-url.js +337 -0
  44. package/es/blocklet/log.js +90 -0
  45. package/es/blocklet/migration.js +149 -0
  46. package/es/blocklet/mode.js +19 -0
  47. package/es/blocklet/notification/email.js +257 -0
  48. package/es/blocklet/notification/index.js +49 -0
  49. package/es/blocklet/oauth/auth0.js +145 -0
  50. package/es/blocklet/oauth/common-settings.js +133 -0
  51. package/es/blocklet/oauth/federated-detail-dialog.js +175 -0
  52. package/es/blocklet/oauth/federated-invite-dialog.js +83 -0
  53. package/es/blocklet/oauth/federated-join-dialog.js +111 -0
  54. package/es/blocklet/oauth/federated-site-list.js +338 -0
  55. package/es/blocklet/oauth/federated.js +81 -0
  56. package/es/blocklet/oauth/index.js +69 -0
  57. package/es/blocklet/overview.js +293 -0
  58. package/es/blocklet/page-group.js +19 -0
  59. package/es/blocklet/preferences/app-sk.js +142 -0
  60. package/es/blocklet/preferences/index.js +305 -0
  61. package/es/blocklet/purchase/common.js +95 -0
  62. package/es/blocklet/purchase/component-purchase.js +237 -0
  63. package/es/blocklet/purchase/index.js +4 -0
  64. package/es/blocklet/router/action/add-domain-alias.js +167 -0
  65. package/es/blocklet/router/action/add-rule.js +211 -0
  66. package/es/blocklet/router/action/config-routing-rule.js +232 -0
  67. package/es/blocklet/router/action/delete-domain-alias.js +99 -0
  68. package/es/blocklet/router/action/delete-rule.js +108 -0
  69. package/es/blocklet/router/action/update-rule.js +209 -0
  70. package/es/blocklet/router/domain-actions.js +64 -0
  71. package/es/blocklet/router/domain-status.js +88 -0
  72. package/es/blocklet/router/rule-actions.js +66 -0
  73. package/es/blocklet/router/rule-list.js +190 -0
  74. package/es/blocklet/router/util.js +131 -0
  75. package/es/blocklet/runtime-info.js +68 -0
  76. package/es/blocklet/status.js +91 -0
  77. package/es/blocklet/storage/action.js +134 -0
  78. package/es/blocklet/storage/backups.js +241 -0
  79. package/es/blocklet/storage/connect-to.js +372 -0
  80. package/es/blocklet/storage/connected.js +198 -0
  81. package/es/blocklet/storage/delete.js +113 -0
  82. package/es/blocklet/storage/disconnect.js +243 -0
  83. package/es/blocklet/storage/index.js +19 -0
  84. package/es/blocklet/storage/item.js +558 -0
  85. package/es/blocklet/storage/preview-nft.js +286 -0
  86. package/es/blocklet/transfer-owner.js +198 -0
  87. package/es/blocklet/types.js +18 -0
  88. package/es/blocklet/util.js +145 -0
  89. package/es/blocklet/version.js +141 -0
  90. package/es/card-selector.js +134 -0
  91. package/es/certificate.js +105 -0
  92. package/es/chain.js +13 -0
  93. package/es/click-to-copy.js +22 -0
  94. package/es/confirm.js +149 -0
  95. package/es/contexts/audit-log.js +152 -0
  96. package/es/contexts/blocklet.js +10 -0
  97. package/es/contexts/deleting-blocklets.js +70 -0
  98. package/es/contexts/node.js +17 -0
  99. package/es/contexts/session.js +8 -0
  100. package/es/contexts/team.js +10 -0
  101. package/es/delete-confirm.js +121 -0
  102. package/es/did-address.js +46 -0
  103. package/es/dot.js +14 -0
  104. package/es/exchange-passport.js +102 -0
  105. package/es/form/form-select-input.js +184 -0
  106. package/es/form/form-text-input.js +178 -0
  107. package/es/form/form-wrapper.js +88 -0
  108. package/es/form/input-triggers.js +98 -0
  109. package/es/form/required.js +8 -0
  110. package/es/hooks/blocklet.js +229 -0
  111. package/es/hooks/confirm.js +90 -0
  112. package/es/hooks/mobile-width.js +11 -0
  113. package/es/hooks/url-evaluation.js +155 -0
  114. package/es/hooks/use-app-logo.js +16 -0
  115. package/es/hooks/use-backup-progress.js +31 -0
  116. package/es/hooks/use-blocklet-info-for-connect-did-spaces.js +50 -0
  117. package/es/hooks/use-bundle-logo.js +27 -0
  118. package/es/hooks/use-navigation.js +347 -0
  119. package/es/hooks/use-passport-id.js +14 -0
  120. package/es/hooks/use-subscription.js +22 -0
  121. package/es/icons/empty-space-nft.svg +59 -0
  122. package/es/icons/empty-spaces-nft.svg +58 -0
  123. package/es/icons/long-arrow.svg +5 -0
  124. package/es/icons/space-connected.svg +3 -0
  125. package/es/icons/space-disconnect.svg +3 -0
  126. package/es/index.js +3 -0
  127. package/es/invitation/invitation-app.js +58 -0
  128. package/es/invitation/invitation-login.js +68 -0
  129. package/es/invitation/invitation-passport.js +146 -0
  130. package/es/invitation/invitation-receive.js +138 -0
  131. package/es/invitation/invitation-success.js +93 -0
  132. package/es/invitation/invitation-user.js +90 -0
  133. package/es/invitation/invitation.js +90 -0
  134. package/es/issue-passport.js +142 -0
  135. package/es/launch-blocklet/content-layout.js +58 -0
  136. package/es/launch-blocklet/page-header.js +43 -0
  137. package/es/layout/addon.js +114 -0
  138. package/es/layout/feedback.js +55 -0
  139. package/es/locales/en.js +1541 -0
  140. package/es/locales/index.js +9 -0
  141. package/es/locales/zh.js +1544 -0
  142. package/es/logs/clock.js +11 -0
  143. package/es/logs/download.js +132 -0
  144. package/es/logs/log-terminal.js +253 -0
  145. package/es/lost-passport.js +452 -0
  146. package/es/nav-logo.js +219 -0
  147. package/es/passport-tag.js +43 -0
  148. package/es/permission.js +57 -0
  149. package/es/relative-time.js +53 -0
  150. package/es/result-message.js +11 -0
  151. package/es/schema-form/color-input.js +98 -0
  152. package/es/schema-form/common-prop-types.js +13 -0
  153. package/es/schema-form/index.js +215 -0
  154. package/es/schema-form/passport-input.js +55 -0
  155. package/es/schema-form/text-input.js +57 -0
  156. package/es/store/add.js +179 -0
  157. package/es/store/delete.js +96 -0
  158. package/es/store/item.js +76 -0
  159. package/es/subscription.js +144 -0
  160. package/es/table-icons.js +34 -0
  161. package/es/table.js +52 -0
  162. package/es/tag.js +21 -0
  163. package/es/team/members/actions.js +89 -0
  164. package/es/team/members/index.js +636 -0
  165. package/es/team/members/invitations.js +188 -0
  166. package/es/team/members/invite-member.js +208 -0
  167. package/es/team/members/issue-passport.js +152 -0
  168. package/es/team/members/member.js +408 -0
  169. package/es/team/members/passport-issuances.js +155 -0
  170. package/es/team/members/passports.js +364 -0
  171. package/es/team/members/toggle-user-approval.js +122 -0
  172. package/es/team/members/transfer-node.js +256 -0
  173. package/es/team/members/util.js +14 -0
  174. package/es/team/passports/color.js +127 -0
  175. package/es/team/passports/detail.js +312 -0
  176. package/es/team/passports/index.js +282 -0
  177. package/es/team/passports/mutate-role.js +198 -0
  178. package/es/team/passports/trusted-factories.js +221 -0
  179. package/es/team/passports/trusted-factory.js +343 -0
  180. package/es/team/passports/trusted-issuer.js +296 -0
  181. package/es/team/passports/trusted-issuers.js +226 -0
  182. package/es/team/search-input.js +46 -0
  183. package/es/team/styles/dialog.js +72 -0
  184. package/es/team/styles/list-header.js +31 -0
  185. package/es/util/api.js +6 -0
  186. package/es/util/constants.js +2 -0
  187. package/es/util/index.js +598 -0
  188. package/es/util/mode.js +4 -0
  189. package/es/util/space-gateway.js +51 -0
  190. package/es/util/spaces.js +160 -0
  191. package/es/who-can-access/config.js +38 -0
  192. package/es/wrap-locale.js +15 -0
  193. package/lib/blocklet/component/add.js +5 -0
  194. package/lib/blocklet/component/selected/index.js +47 -0
  195. package/lib/blocklet/component/space-connector.js +1 -1
  196. package/lib/blocklet/component/space-selector.js +1 -1
  197. package/lib/blocklet/storage/backups.js +1 -1
  198. package/lib/blocklet/storage/connect-to.js +6 -7
  199. package/lib/blocklet/storage/connected.js +1 -1
  200. package/lib/blocklet/storage/disconnect.js +1 -1
  201. package/lib/blocklet/storage/index.js +1 -1
  202. package/lib/blocklet/storage/item.js +1 -1
  203. package/lib/card-selector.js +14 -14
  204. package/lib/invitation/invitation-passport.js +7 -6
  205. package/lib/invitation/invitation-receive.js +1 -1
  206. package/lib/locales/en.js +12 -5
  207. package/lib/locales/zh.js +10 -3
  208. package/lib/lost-passport.js +2 -2
  209. package/lib/schema-form/passport-input.js +12 -11
  210. package/lib/team/passports/color.js +14 -14
  211. package/lib/team/passports/trusted-factory.js +1 -1
  212. package/lib/util/spaces.js +13 -1
  213. package/package.json +88 -21
@@ -0,0 +1,256 @@
1
+ /* eslint-disable react/no-unstable-nested-components */
2
+ import { useContext, useState } from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import styled from '@emotion/styled';
5
+ import useAsync from 'react-use/lib/useAsync';
6
+ import get from 'lodash/get';
7
+ import Dialog from '@arcblock/ux/lib/Dialog';
8
+ import Spinner from '@mui/material/CircularProgress';
9
+ import DialogContentText from '@mui/material/DialogContentText';
10
+ import Typography from '@mui/material/Typography';
11
+ import TextField from '@mui/material/TextField';
12
+ import Connect from '@arcblock/did-connect/lib/Connect';
13
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
14
+ import Button from '@arcblock/ux/lib/Button';
15
+ import Alert from '@arcblock/ux/lib/Alert';
16
+ import ClickToCopy from '../../click-to-copy';
17
+ import { useNodeContext } from '../../contexts/node';
18
+ import { formatError, getInviteLink, formatToDatetime, getWebWalletUrl } from '../../util';
19
+ import { SessionContext } from '../../contexts/session';
20
+ import { jsx as _jsx } from "react/jsx-runtime";
21
+ import { jsxs as _jsxs } from "react/jsx-runtime";
22
+ import { Fragment as _Fragment } from "react/jsx-runtime";
23
+ export default function TransferMember({
24
+ teamDid,
25
+ onCancel,
26
+ onSuccess,
27
+ onError,
28
+ endpoint
29
+ }) {
30
+ const {
31
+ api,
32
+ info
33
+ } = useNodeContext();
34
+ const {
35
+ api: sessionAPI
36
+ } = useContext(SessionContext);
37
+ const [loading, setLoading] = useState(false);
38
+ const {
39
+ t,
40
+ locale
41
+ } = useLocaleContext();
42
+ const [error, setError] = useState('');
43
+ const [openTransferNFTAuth, setOpenTransferNFTAuth] = useState(false);
44
+ const [activeStep, setActiveStep] = useState(0);
45
+ const [inviteInfo, setInviteInfo] = useState('');
46
+ const [remark, setRemark] = useState('');
47
+ const needTransferNFT = !!get(info, 'ownerNft.did');
48
+ const delegationState = useAsync(async () => {
49
+ if (needTransferNFT) {
50
+ const {
51
+ state
52
+ } = await api.getDelegationState();
53
+ return state;
54
+ }
55
+ return {
56
+ delegated: true
57
+ };
58
+ });
59
+ if (delegationState.loading) {
60
+ return /*#__PURE__*/_jsx(Dialog, {
61
+ title: t('team.transferNode.inviteDialog.title'),
62
+ fullWidth: true,
63
+ open: true,
64
+ onClose: onCancel,
65
+ children: /*#__PURE__*/_jsx("div", {
66
+ style: {
67
+ display: 'flex',
68
+ justifyContent: 'center'
69
+ },
70
+ children: /*#__PURE__*/_jsx(Spinner, {})
71
+ })
72
+ });
73
+ }
74
+ if (delegationState.error) {
75
+ return /*#__PURE__*/_jsx(Dialog, {
76
+ title: t('team.transferNode.inviteDialog.title'),
77
+ fullWidth: true,
78
+ open: true,
79
+ onClose: onCancel,
80
+ children: /*#__PURE__*/_jsx(Alert, {
81
+ type: "error",
82
+ variant: "icon",
83
+ children: formatError(delegationState.error)
84
+ })
85
+ });
86
+ }
87
+ const onCreate = async () => {
88
+ setError(null);
89
+ setLoading(true);
90
+ try {
91
+ const {
92
+ inviteInfo: tmpInviteInfo
93
+ } = await api.createTransferInvitation({
94
+ input: {
95
+ teamDid,
96
+ role: 'owner',
97
+ remark: remark.trim()
98
+ }
99
+ });
100
+ setInviteInfo(tmpInviteInfo);
101
+ setActiveStep(steps.length - 1); // 跳转到最后一步
102
+ } catch (err) {
103
+ const errMsg = formatError(err);
104
+ setError(errMsg);
105
+ onError(err);
106
+ } finally {
107
+ setLoading(false);
108
+ }
109
+ };
110
+ const handleTransferNFT = () => {
111
+ setOpenTransferNFTAuth(true);
112
+ setActiveStep(1);
113
+ };
114
+ const handleCancelTransferNFT = () => {
115
+ setOpenTransferNFTAuth(false);
116
+ setActiveStep(0);
117
+ };
118
+ const steps = [{
119
+ body: /*#__PURE__*/_jsxs(Typography, {
120
+ component: "div",
121
+ children: [/*#__PURE__*/_jsxs(Alert, {
122
+ type: "warning",
123
+ children: [/*#__PURE__*/_jsx(Typography, {
124
+ children: t('team.transferNode.inviteDialog.tips.progress')
125
+ }), /*#__PURE__*/_jsx(Typography, {
126
+ children: t('team.transferNode.inviteDialog.tips.newOwnerPermissions')
127
+ })]
128
+ }), /*#__PURE__*/_jsx(Alert, {
129
+ type: "warning",
130
+ children: /*#__PURE__*/_jsx(Typography, {
131
+ children: t('team.transferNode.inviteDialog.tips.revoke')
132
+ })
133
+ }), /*#__PURE__*/_jsx("div", {
134
+ style: {
135
+ marginTop: 20,
136
+ marginBottom: 10
137
+ }
138
+ }), /*#__PURE__*/_jsx(TextField, {
139
+ label: t('common.remark'),
140
+ autoComplete: "off",
141
+ variant: "outlined",
142
+ fullWidth: true,
143
+ style: {
144
+ marginBottom: 8
145
+ },
146
+ value: remark,
147
+ onChange: e => {
148
+ setError(null);
149
+ setRemark(e.target.value);
150
+ },
151
+ disabled: loading,
152
+ "data-cy": "transfer-node-input-remark"
153
+ }), /*#__PURE__*/_jsx("div", {
154
+ style: {
155
+ marginTop: 20,
156
+ marginBottom: 10
157
+ }
158
+ })]
159
+ }),
160
+ cancel: t('common.cancel'),
161
+ confirm: t('team.transferNode.inviteDialog.createInviteLink'),
162
+ onCancel,
163
+ onConfirm: needTransferNFT && !get(delegationState, 'value.delegated') ? handleTransferNFT : onCreate
164
+ }, {
165
+ body: () => {
166
+ return /*#__PURE__*/_jsx(Connect, {
167
+ action: "delegate-transfer-nft",
168
+ open: openTransferNFTAuth,
169
+ locale: locale,
170
+ checkFn: sessionAPI.get,
171
+ onClose: handleCancelTransferNFT,
172
+ onSuccess: onCreate,
173
+ checkTimeout: 5 * 60 * 1000,
174
+ webWalletUrl: getWebWalletUrl(info),
175
+ extraParams: {
176
+ targetDID: info.did
177
+ },
178
+ messages: {
179
+ title: t('team.transferNode.delegateDialog.title'),
180
+ scan: t('team.transferNode.delegateDialog.scan'),
181
+ confirm: t('team.transferNode.delegateDialog.confirm'),
182
+ success: t('team.transferNode.delegateDialog.success')
183
+ },
184
+ popup: true
185
+ });
186
+ }
187
+ }, {
188
+ body: () => {
189
+ const link = getInviteLink({
190
+ inviteId: inviteInfo.inviteId,
191
+ endpoint
192
+ });
193
+ return /*#__PURE__*/_jsxs("div", {
194
+ children: [/*#__PURE__*/_jsx(Bold, {
195
+ children: t('team.transferNode.inviteDialog.createSuccessTip', {
196
+ expireDate: formatToDatetime(inviteInfo.expireDate, locale)
197
+ })
198
+ }), /*#__PURE__*/_jsx("div", {
199
+ style: {
200
+ marginTop: '40px'
201
+ }
202
+ }), /*#__PURE__*/_jsx(ClickToCopy, {
203
+ children: link
204
+ })]
205
+ });
206
+ },
207
+ confirm: t('common.confirm'),
208
+ onConfirm: onSuccess
209
+ }];
210
+ const step = steps[activeStep];
211
+ return /*#__PURE__*/_jsxs(Dialog, {
212
+ title: t('team.transferNode.inviteDialog.title'),
213
+ fullWidth: true,
214
+ open: true,
215
+ showCloseButton: false,
216
+ actions: /*#__PURE__*/_jsxs(_Fragment, {
217
+ children: [step.cancel && /*#__PURE__*/_jsx(Button, {
218
+ onClick: step.onCancel,
219
+ color: "inherit",
220
+ children: step.cancel
221
+ }), /*#__PURE__*/_jsxs(Button, {
222
+ onClick: step.onConfirm,
223
+ color: "primary",
224
+ disabled: loading,
225
+ variant: "contained",
226
+ autoFocus: true,
227
+ children: [loading && /*#__PURE__*/_jsx(Spinner, {
228
+ size: 16
229
+ }), step.confirm]
230
+ })]
231
+ }),
232
+ children: [/*#__PURE__*/_jsx(DialogContentText, {
233
+ component: "div",
234
+ children: typeof step.body === 'function' ? step.body() : step.body
235
+ }), !!error && /*#__PURE__*/_jsx(Alert, {
236
+ type: "error",
237
+ variant: "icon",
238
+ children: error
239
+ })]
240
+ });
241
+ }
242
+ TransferMember.propTypes = {
243
+ teamDid: PropTypes.string.isRequired,
244
+ onCancel: PropTypes.func.isRequired,
245
+ onSuccess: PropTypes.func.isRequired,
246
+ onError: PropTypes.func,
247
+ endpoint: PropTypes.string
248
+ };
249
+ TransferMember.defaultProps = {
250
+ onError: () => {},
251
+ endpoint: ''
252
+ };
253
+ const Bold = styled.div`
254
+ font-size: 16px;
255
+ font-weight: bold;
256
+ `;
@@ -0,0 +1,14 @@
1
+ import joinUrl from 'url-join';
2
+ import { USER_AVATAR_URL_PREFIX, USER_AVATAR_PATH_PREFIX } from '@abtnode/constant';
3
+
4
+ // eslint-disable-next-line import/prefer-default-export
5
+ export function parseAvatar(avatar, teamDid, inService) {
6
+ if (avatar && avatar.startsWith(USER_AVATAR_URL_PREFIX)) {
7
+ const prefix = window.env.apiPrefix || '/';
8
+ if (inService) {
9
+ return joinUrl(prefix, USER_AVATAR_PATH_PREFIX, avatar.replace(USER_AVATAR_URL_PREFIX, ''));
10
+ }
11
+ return joinUrl(prefix, USER_AVATAR_PATH_PREFIX, teamDid, avatar.replace(USER_AVATAR_URL_PREFIX, ''));
12
+ }
13
+ return avatar;
14
+ }
@@ -0,0 +1,127 @@
1
+ /* eslint-disable react/no-danger */
2
+ import { useState } from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import Box from '@mui/material/Box';
5
+ import Dialog from '@arcblock/ux/lib/Dialog';
6
+ import Spinner from '@mui/material/CircularProgress';
7
+ import { ChromePicker } from 'react-color';
8
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
9
+ import Button from '@arcblock/ux/lib/Button';
10
+ import createPassportSvg from '@abtnode/auth/lib/util/create-passport-svg';
11
+ import { getDisplayName } from '@blocklet/meta/lib/util';
12
+ import { getPassportColorFromDid } from '@arcblock/nft-display';
13
+ import { BLOCKLET_CONFIGURABLE_KEY } from '@blocklet/constant';
14
+ import Toast from '@arcblock/ux/lib/Toast';
15
+ import { useNodeContext } from '../../contexts/node';
16
+ import { useBlockletContext } from '../../contexts/blocklet';
17
+ import { BlockletAdminRoles } from '../../util';
18
+ import { withPermission } from '../../permission';
19
+ import { jsx as _jsx } from "react/jsx-runtime";
20
+ import { jsxs as _jsxs } from "react/jsx-runtime";
21
+ import { Fragment as _Fragment } from "react/jsx-runtime";
22
+ function PassportColor({
23
+ onCancel,
24
+ onSuccess
25
+ }) {
26
+ const {
27
+ api
28
+ } = useNodeContext();
29
+ const {
30
+ blocklet
31
+ } = useBlockletContext();
32
+ const {
33
+ t
34
+ } = useLocaleContext();
35
+ const [loading, setLoading] = useState(false);
36
+ const curColor = (blocklet.environments.find(x => x.key === 'BLOCKLET_PASSPORT_COLOR') || {}).value || 'auto';
37
+ const defaultColor = curColor === 'auto' ? getPassportColorFromDid(blocklet.appDid) : curColor;
38
+ const [color, setColor] = useState(defaultColor);
39
+ const onSubmit = async () => {
40
+ const params = [{
41
+ key: BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_PASSPORT_COLOR,
42
+ value: color
43
+ }];
44
+ try {
45
+ setLoading(true);
46
+ await api.configBlocklet({
47
+ input: {
48
+ did: blocklet.meta.did,
49
+ configs: params
50
+ }
51
+ });
52
+ onSuccess();
53
+ } catch (err) {
54
+ Toast.error(err.message);
55
+ } finally {
56
+ setLoading(false);
57
+ }
58
+ };
59
+ return /*#__PURE__*/_jsx(Dialog, {
60
+ title: t('team.passport.color'),
61
+ onClose: onCancel,
62
+ open: true,
63
+ fullWidth: true,
64
+ actions: /*#__PURE__*/_jsxs(_Fragment, {
65
+ children: [/*#__PURE__*/_jsx(Button, {
66
+ onClick: onCancel,
67
+ color: "inherit",
68
+ children: t('common.cancel')
69
+ }), /*#__PURE__*/_jsxs(Button, {
70
+ onClick: onSubmit,
71
+ color: "primary",
72
+ disabled: loading,
73
+ variant: "contained",
74
+ autoFocus: true,
75
+ "data-cy": "color-btn-confirm",
76
+ children: [loading && /*#__PURE__*/_jsx(Spinner, {
77
+ size: 16
78
+ }), t('common.save')]
79
+ })]
80
+ }),
81
+ children: /*#__PURE__*/_jsxs(Box, {
82
+ display: "flex",
83
+ justifyContent: "center",
84
+ alignItems: "center",
85
+ className: "dialog-content",
86
+ children: [/*#__PURE__*/_jsx(ChromePicker, {
87
+ color: color,
88
+ onChange: c => setColor(c.hex)
89
+ }), /*#__PURE__*/_jsx("div", {
90
+ style: {
91
+ width: 220,
92
+ marginLeft: 24
93
+ },
94
+ dangerouslySetInnerHTML: {
95
+ __html: createPassportSvg({
96
+ title: 'Owner',
97
+ issuer: getDisplayName(blocklet),
98
+ issuerDid: blocklet.appDid,
99
+ ownerName: 'Your Name',
100
+ ownerDid: blocklet.appDid,
101
+ preferredColor: color
102
+ })
103
+ }
104
+ })]
105
+ })
106
+ });
107
+ }
108
+ const PassportColorInDaemon = withPermission(PassportColor, 'mutate_team');
109
+ const PassportColorInService = withPermission(PassportColor, '', BlockletAdminRoles);
110
+ export default function PassportColorWithPermission(props) {
111
+ const {
112
+ inService
113
+ } = useNodeContext();
114
+ if (inService) {
115
+ return /*#__PURE__*/_jsx(PassportColorInService, {
116
+ ...props
117
+ });
118
+ }
119
+ return /*#__PURE__*/_jsx(PassportColorInDaemon, {
120
+ ...props
121
+ });
122
+ }
123
+ PassportColor.propTypes = {
124
+ onCancel: PropTypes.func.isRequired,
125
+ onSuccess: PropTypes.func.isRequired
126
+ };
127
+ PassportColor.defaultProps = {};
@@ -0,0 +1,312 @@
1
+ import { useState, useEffect } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import styled from '@emotion/styled';
4
+ import cloneDeep from 'lodash/cloneDeep';
5
+ import Dialog from '@arcblock/ux/lib/Dialog';
6
+ import Spinner from '@mui/material/CircularProgress';
7
+ import IconButton from '@mui/material/IconButton';
8
+ import FormControlLabel from '@mui/material/FormControlLabel';
9
+ import Checkbox from '@mui/material/Checkbox';
10
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
11
+ import Button from '@arcblock/ux/lib/Button';
12
+ import EditIcon from '@arcblock/icons/lib/EditIcon';
13
+ import DeleteIcon from '@arcblock/icons/lib/DeleteIcon';
14
+ import Toast from '@arcblock/ux/lib/Toast';
15
+ import { useNodeContext } from '../../contexts/node';
16
+ import { useTeamContext } from '../../contexts/team';
17
+ import { formatError, isProtectedRole, BlockletAdminRoles } from '../../util';
18
+ import { withPermission } from '../../permission';
19
+ import Confirm from '../../confirm';
20
+ import MutateRole from './mutate-role';
21
+ import { jsx as _jsx } from "react/jsx-runtime";
22
+ import { jsxs as _jsxs } from "react/jsx-runtime";
23
+ import { Fragment as _Fragment } from "react/jsx-runtime";
24
+ function PassportDetail({
25
+ onCancel,
26
+ onSuccess,
27
+ onDelete,
28
+ roleName,
29
+ hasPermission
30
+ }) {
31
+ const {
32
+ api
33
+ } = useNodeContext();
34
+ const {
35
+ roles,
36
+ permissions,
37
+ teamDid,
38
+ refresh: refreshTeam,
39
+ isNodeTeam
40
+ } = useTeamContext();
41
+ const {
42
+ t
43
+ } = useLocaleContext();
44
+ const [binds, setBinds] = useState([]);
45
+ const [updateForm, setUpdateForm] = useState(false);
46
+ const [delConfirm, setDelConfirm] = useState(null);
47
+ const [loading, setLoading] = useState(false);
48
+ const role = cloneDeep(roles.find(x => x.name === roleName));
49
+ const isProtected = isProtectedRole(roleName);
50
+ const deletePassport = async name => {
51
+ if (loading) return;
52
+ try {
53
+ setLoading(true);
54
+ await api.deleteRole({
55
+ input: {
56
+ teamDid,
57
+ name
58
+ }
59
+ });
60
+ onDelete();
61
+ } catch (err) {
62
+ Toast.error(err.message);
63
+ } finally {
64
+ setLoading(false);
65
+ setDelConfirm(null);
66
+ }
67
+ };
68
+ const getData = async (team, name) => {
69
+ const res = await api.getPermissionsByRole({
70
+ input: {
71
+ teamDid: team,
72
+ role: {
73
+ name
74
+ }
75
+ }
76
+ });
77
+ const permissionList = res.permissions || [];
78
+ const bindList = permissions.map(x => ({
79
+ ...x,
80
+ bind: permissionList.some(y => y.name === x.name)
81
+ }));
82
+ setBinds(bindList);
83
+ };
84
+ const onBind = async () => {
85
+ setLoading(true);
86
+ const grantNames = binds.filter(x => x.bind).map(x => x.name);
87
+ try {
88
+ await api.updatePermissionsForRole({
89
+ input: {
90
+ teamDid,
91
+ roleName: role.name,
92
+ grantNames
93
+ }
94
+ });
95
+ Toast.success(t('common.saveSuccess'));
96
+ onSuccess();
97
+ } catch (err) {
98
+ Toast.error(formatError(err));
99
+ } finally {
100
+ setLoading(false);
101
+ }
102
+ };
103
+ useEffect(() => {
104
+ if (teamDid && roleName) {
105
+ getData(teamDid, roleName);
106
+ }
107
+ }, [teamDid, roleName]); // eslint-disable-line
108
+
109
+ const readPermissionsOnly = isNodeTeam || !hasPermission;
110
+ let bindPermission = null;
111
+ if (isNodeTeam) {
112
+ bindPermission = /*#__PURE__*/_jsxs("div", {
113
+ className: "bind",
114
+ children: [/*#__PURE__*/_jsx("div", {
115
+ className: "title",
116
+ children: t('common.permission')
117
+ }), /*#__PURE__*/_jsx("div", {
118
+ className: "list",
119
+ children: binds
120
+ // if readonly, show obtained permissions only
121
+ .filter(x => readPermissionsOnly ? x.bind : true).map(x => /*#__PURE__*/_jsx("div", {
122
+ className: "item",
123
+ children: /*#__PURE__*/_jsx(FormControlLabel, {
124
+ control: /*#__PURE__*/_jsx(Checkbox, {
125
+ disabled: readPermissionsOnly,
126
+ checked: x.bind,
127
+ onChange: () => {
128
+ setBinds(state => state.map(y => {
129
+ if (y.name === x.name) {
130
+ y.bind = !y.bind;
131
+ }
132
+ return y;
133
+ }));
134
+ },
135
+ name: x.name
136
+ }),
137
+ label: x.description
138
+ })
139
+ }))
140
+ })]
141
+ });
142
+ }
143
+ return /*#__PURE__*/_jsxs(Dialog, {
144
+ title: t('common.passport'),
145
+ onClose: onCancel,
146
+ open: true,
147
+ fullWidth: true,
148
+ toolbar: hasPermission && !isProtected && /*#__PURE__*/_jsxs(_Fragment, {
149
+ children: [/*#__PURE__*/_jsx(IconButton, {
150
+ onClick: () => setUpdateForm(role),
151
+ "data-cy": `edit-passport-${role.name}`,
152
+ size: "large",
153
+ children: /*#__PURE__*/_jsx(EditIcon, {
154
+ fill: "#bfbfbf"
155
+ })
156
+ }), /*#__PURE__*/_jsx(IconButton, {
157
+ onClick: () => setDelConfirm({
158
+ title: t('team.passport.delete.title'),
159
+ description: t('team.passport.delete.description', {
160
+ name: role.title
161
+ }),
162
+ confirm: t('common.delConfirm'),
163
+ cancel: t('common.cancel'),
164
+ onConfirm: () => {
165
+ deletePassport(role.name);
166
+ },
167
+ onCancel: () => {
168
+ setLoading(false);
169
+ setDelConfirm(null);
170
+ }
171
+ }),
172
+ "data-cy": `delete-passport-${role.name}`,
173
+ size: "large",
174
+ children: /*#__PURE__*/_jsx(DeleteIcon, {
175
+ "data-cy": "close-passport-dialog",
176
+ fill: "#bfbfbf"
177
+ })
178
+ })]
179
+ }),
180
+ actions: isNodeTeam && !readPermissionsOnly && /*#__PURE__*/_jsxs(_Fragment, {
181
+ children: [/*#__PURE__*/_jsx(Button, {
182
+ onClick: onCancel,
183
+ color: "inherit",
184
+ children: t('common.cancel')
185
+ }), /*#__PURE__*/_jsxs(Button, {
186
+ onClick: onBind,
187
+ color: "primary",
188
+ disabled: loading || !role,
189
+ variant: "contained",
190
+ autoFocus: true,
191
+ "data-cy": "bind-permission-btn-confirm",
192
+ children: [loading && /*#__PURE__*/_jsx(Spinner, {
193
+ size: 16
194
+ }), t('common.save')]
195
+ })]
196
+ }),
197
+ children: [/*#__PURE__*/_jsxs(Div, {
198
+ children: [!role && /*#__PURE__*/_jsx(Center, {
199
+ children: /*#__PURE__*/_jsx(Spinner, {})
200
+ }), role && /*#__PURE__*/_jsxs("div", {
201
+ className: "dialog-content",
202
+ children: [/*#__PURE__*/_jsxs("div", {
203
+ className: "header",
204
+ children: [/*#__PURE__*/_jsx("div", {
205
+ className: "title",
206
+ children: role.title
207
+ }), /*#__PURE__*/_jsx("div", {
208
+ className: "description",
209
+ style: {
210
+ marginTop: isNodeTeam ? 16 : 48
211
+ },
212
+ children: role.description
213
+ })]
214
+ }), bindPermission]
215
+ })]
216
+ }), updateForm && /*#__PURE__*/_jsx(MutateRole, {
217
+ teamDid: teamDid,
218
+ onCancel: () => setUpdateForm(null),
219
+ onSuccess: () => {
220
+ setUpdateForm(null);
221
+ refreshTeam();
222
+ },
223
+ mode: "update",
224
+ roleName: updateForm.name,
225
+ item: updateForm
226
+ }), delConfirm && /*#__PURE__*/_jsx(Confirm, {
227
+ title: delConfirm.title,
228
+ description: delConfirm.description,
229
+ confirm: delConfirm.confirm,
230
+ cancel: delConfirm.cancel,
231
+ params: delConfirm.params,
232
+ onConfirm: delConfirm.onConfirm,
233
+ onCancel: delConfirm.onCancel
234
+ })]
235
+ });
236
+ }
237
+ const PassportDetailInDaemon = withPermission(PassportDetail, 'mutate_team');
238
+ const PassportDetailInService = withPermission(PassportDetail, '', BlockletAdminRoles);
239
+ export default function PassportDetailWithPermission(props) {
240
+ const {
241
+ inService
242
+ } = useNodeContext();
243
+ if (inService) {
244
+ return /*#__PURE__*/_jsx(PassportDetailInService, {
245
+ ...props
246
+ });
247
+ }
248
+ return /*#__PURE__*/_jsx(PassportDetailInDaemon, {
249
+ ...props
250
+ });
251
+ }
252
+ PassportDetail.propTypes = {
253
+ roleName: PropTypes.string.isRequired,
254
+ onCancel: PropTypes.func.isRequired,
255
+ onSuccess: PropTypes.func.isRequired,
256
+ onDelete: PropTypes.func.isRequired,
257
+ hasPermission: PropTypes.bool
258
+ };
259
+ PassportDetail.defaultProps = {
260
+ hasPermission: false
261
+ };
262
+ const Div = styled.div`
263
+ .header {
264
+ .title {
265
+ font-weight: 400;
266
+ font-size: 24px;
267
+ line-height: 28px;
268
+ color: #222222;
269
+ }
270
+
271
+ .description {
272
+ margin-top: 16px;
273
+ font-weight: 400;
274
+ font-size: 16px;
275
+ line-height: 19px;
276
+ color: #999999;
277
+ }
278
+ }
279
+
280
+ .bind {
281
+ margin-top: 24px;
282
+ .title {
283
+ font-weight: 400;
284
+ font-size: 16px;
285
+ line-height: 19px;
286
+ color: #666666;
287
+ margin-bottom: 24px;
288
+ }
289
+ .item {
290
+ margin-top: 24px;
291
+ }
292
+
293
+ .MuiFormControlLabel-label {
294
+ font-weight: 400;
295
+ font-size: 16px;
296
+ line-height: 19px;
297
+ color: #666;
298
+ }
299
+
300
+ .PrivateSwitchBase-root-45 {
301
+ padding: 0;
302
+ padding-right: 12px;
303
+ }
304
+ }
305
+ `;
306
+ const Center = styled.div`
307
+ flex: 1;
308
+ display: flex;
309
+ justify-content: center;
310
+ align-items: center;
311
+ height: 200px;
312
+ `;