@abtnode/ux 1.16.14-beta-ab7f615e → 1.16.14-beta-cb53c14b

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 (202) 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 +1308 -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/setting.js +109 -0
  32. package/es/blocklet/component/sortable-tree.js +126 -0
  33. package/es/blocklet/component/space-connector.js +199 -0
  34. package/es/blocklet/component/space-selector.js +178 -0
  35. package/es/blocklet/component/start.js +101 -0
  36. package/es/blocklet/component/store-blocklet-list.js +200 -0
  37. package/es/blocklet/component/switch-control.js +57 -0
  38. package/es/blocklet/config-navigation.js +331 -0
  39. package/es/blocklet/configuration.js +603 -0
  40. package/es/blocklet/disk-info.js +75 -0
  41. package/es/blocklet/icons.js +18 -0
  42. package/es/blocklet/install-from-url.js +337 -0
  43. package/es/blocklet/log.js +90 -0
  44. package/es/blocklet/migration.js +149 -0
  45. package/es/blocklet/mode.js +19 -0
  46. package/es/blocklet/notification/email.js +257 -0
  47. package/es/blocklet/notification/index.js +49 -0
  48. package/es/blocklet/oauth/auth0.js +145 -0
  49. package/es/blocklet/oauth/common-settings.js +133 -0
  50. package/es/blocklet/oauth/federated-detail-dialog.js +175 -0
  51. package/es/blocklet/oauth/federated-invite-dialog.js +83 -0
  52. package/es/blocklet/oauth/federated-join-dialog.js +111 -0
  53. package/es/blocklet/oauth/federated-site-list.js +338 -0
  54. package/es/blocklet/oauth/federated.js +81 -0
  55. package/es/blocklet/oauth/index.js +69 -0
  56. package/es/blocklet/overview.js +293 -0
  57. package/es/blocklet/page-group.js +19 -0
  58. package/es/blocklet/preferences/app-sk.js +142 -0
  59. package/es/blocklet/preferences/index.js +305 -0
  60. package/es/blocklet/purchase/common.js +95 -0
  61. package/es/blocklet/purchase/component-purchase.js +237 -0
  62. package/es/blocklet/purchase/index.js +4 -0
  63. package/es/blocklet/router/action/add-domain-alias.js +167 -0
  64. package/es/blocklet/router/action/add-rule.js +211 -0
  65. package/es/blocklet/router/action/config-routing-rule.js +232 -0
  66. package/es/blocklet/router/action/delete-domain-alias.js +99 -0
  67. package/es/blocklet/router/action/delete-rule.js +108 -0
  68. package/es/blocklet/router/action/update-rule.js +209 -0
  69. package/es/blocklet/router/domain-actions.js +64 -0
  70. package/es/blocklet/router/domain-status.js +88 -0
  71. package/es/blocklet/router/rule-actions.js +66 -0
  72. package/es/blocklet/router/rule-list.js +190 -0
  73. package/es/blocklet/router/util.js +131 -0
  74. package/es/blocklet/runtime-info.js +68 -0
  75. package/es/blocklet/status.js +91 -0
  76. package/es/blocklet/storage/action.js +134 -0
  77. package/es/blocklet/storage/backups.js +241 -0
  78. package/es/blocklet/storage/connect-to.js +373 -0
  79. package/es/blocklet/storage/connected.js +198 -0
  80. package/es/blocklet/storage/delete.js +113 -0
  81. package/es/blocklet/storage/disconnect.js +243 -0
  82. package/es/blocklet/storage/index.js +19 -0
  83. package/es/blocklet/storage/item.js +558 -0
  84. package/es/blocklet/storage/preview-nft.js +286 -0
  85. package/es/blocklet/transfer-owner.js +198 -0
  86. package/es/blocklet/types.js +18 -0
  87. package/es/blocklet/util.js +145 -0
  88. package/es/blocklet/version.js +141 -0
  89. package/es/card-selector.js +134 -0
  90. package/es/certificate.js +105 -0
  91. package/es/chain.js +13 -0
  92. package/es/click-to-copy.js +22 -0
  93. package/es/confirm.js +149 -0
  94. package/es/contexts/audit-log.js +152 -0
  95. package/es/contexts/blocklet.js +10 -0
  96. package/es/contexts/deleting-blocklets.js +70 -0
  97. package/es/contexts/node.js +17 -0
  98. package/es/contexts/session.js +8 -0
  99. package/es/contexts/team.js +10 -0
  100. package/es/delete-confirm.js +121 -0
  101. package/es/did-address.js +46 -0
  102. package/es/dot.js +14 -0
  103. package/es/exchange-passport.js +102 -0
  104. package/es/form/form-select-input.js +184 -0
  105. package/es/form/form-text-input.js +178 -0
  106. package/es/form/form-wrapper.js +88 -0
  107. package/es/form/input-triggers.js +98 -0
  108. package/es/form/required.js +8 -0
  109. package/es/hooks/blocklet.js +229 -0
  110. package/es/hooks/confirm.js +90 -0
  111. package/es/hooks/mobile-width.js +11 -0
  112. package/es/hooks/url-evaluation.js +155 -0
  113. package/es/hooks/use-app-logo.js +16 -0
  114. package/es/hooks/use-backup-progress.js +31 -0
  115. package/es/hooks/use-blocklet-info-for-connect-did-spaces.js +50 -0
  116. package/es/hooks/use-bundle-logo.js +27 -0
  117. package/es/hooks/use-navigation.js +347 -0
  118. package/es/hooks/use-passport-id.js +14 -0
  119. package/es/hooks/use-subscription.js +22 -0
  120. package/es/icons/empty-space-nft.svg +59 -0
  121. package/es/icons/empty-spaces-nft.svg +58 -0
  122. package/es/icons/long-arrow.svg +5 -0
  123. package/es/icons/space-connected.svg +3 -0
  124. package/es/icons/space-disconnect.svg +3 -0
  125. package/es/index.js +3 -0
  126. package/es/invitation/invitation-app.js +58 -0
  127. package/es/invitation/invitation-login.js +68 -0
  128. package/es/invitation/invitation-passport.js +144 -0
  129. package/es/invitation/invitation-receive.js +138 -0
  130. package/es/invitation/invitation-success.js +93 -0
  131. package/es/invitation/invitation-user.js +90 -0
  132. package/es/invitation/invitation.js +90 -0
  133. package/es/issue-passport.js +142 -0
  134. package/es/launch-blocklet/content-layout.js +58 -0
  135. package/es/launch-blocklet/page-header.js +43 -0
  136. package/es/layout/addon.js +114 -0
  137. package/es/layout/feedback.js +55 -0
  138. package/es/locales/en.js +1534 -0
  139. package/es/locales/index.js +9 -0
  140. package/es/locales/zh.js +1537 -0
  141. package/es/logs/clock.js +11 -0
  142. package/es/logs/download.js +132 -0
  143. package/es/logs/log-terminal.js +253 -0
  144. package/es/lost-passport.js +452 -0
  145. package/es/nav-logo.js +219 -0
  146. package/es/passport-tag.js +43 -0
  147. package/es/permission.js +57 -0
  148. package/es/relative-time.js +53 -0
  149. package/es/result-message.js +11 -0
  150. package/es/schema-form/color-input.js +98 -0
  151. package/es/schema-form/common-prop-types.js +13 -0
  152. package/es/schema-form/index.js +215 -0
  153. package/es/schema-form/passport-input.js +54 -0
  154. package/es/schema-form/text-input.js +57 -0
  155. package/es/store/add.js +179 -0
  156. package/es/store/delete.js +96 -0
  157. package/es/store/item.js +76 -0
  158. package/es/subscription.js +144 -0
  159. package/es/table-icons.js +34 -0
  160. package/es/table.js +52 -0
  161. package/es/tag.js +21 -0
  162. package/es/team/members/actions.js +89 -0
  163. package/es/team/members/index.js +636 -0
  164. package/es/team/members/invitations.js +188 -0
  165. package/es/team/members/invite-member.js +208 -0
  166. package/es/team/members/issue-passport.js +152 -0
  167. package/es/team/members/member.js +408 -0
  168. package/es/team/members/passport-issuances.js +155 -0
  169. package/es/team/members/passports.js +364 -0
  170. package/es/team/members/toggle-user-approval.js +122 -0
  171. package/es/team/members/transfer-node.js +256 -0
  172. package/es/team/members/util.js +14 -0
  173. package/es/team/passports/color.js +126 -0
  174. package/es/team/passports/detail.js +312 -0
  175. package/es/team/passports/index.js +282 -0
  176. package/es/team/passports/mutate-role.js +198 -0
  177. package/es/team/passports/trusted-factories.js +221 -0
  178. package/es/team/passports/trusted-factory.js +343 -0
  179. package/es/team/passports/trusted-issuer.js +296 -0
  180. package/es/team/passports/trusted-issuers.js +226 -0
  181. package/es/team/search-input.js +46 -0
  182. package/es/team/styles/dialog.js +72 -0
  183. package/es/team/styles/list-header.js +31 -0
  184. package/es/util/api.js +6 -0
  185. package/es/util/constants.js +2 -0
  186. package/es/util/index.js +598 -0
  187. package/es/util/mode.js +4 -0
  188. package/es/util/space-gateway.js +51 -0
  189. package/es/util/spaces.js +151 -0
  190. package/es/who-can-access/config.js +38 -0
  191. package/es/wrap-locale.js +15 -0
  192. package/lib/blocklet/component/space-connector.js +1 -1
  193. package/lib/blocklet/component/space-selector.js +1 -1
  194. package/lib/blocklet/storage/backups.js +1 -1
  195. package/lib/blocklet/storage/connect-to.js +1 -1
  196. package/lib/blocklet/storage/connected.js +1 -1
  197. package/lib/blocklet/storage/disconnect.js +1 -1
  198. package/lib/blocklet/storage/index.js +1 -1
  199. package/lib/blocklet/storage/item.js +1 -1
  200. package/lib/invitation/invitation-receive.js +1 -1
  201. package/lib/team/passports/trusted-factory.js +1 -1
  202. package/package.json +81 -18
@@ -0,0 +1,975 @@
1
+ import React, { useState, useContext } from 'react';
2
+ import styled from '@emotion/styled';
3
+ import PropTypes from 'prop-types';
4
+ import Dialog from '@mui/material/Dialog';
5
+ import Box from '@mui/material/Box';
6
+ import DialogContent from '@mui/material/DialogContent';
7
+ import DialogTitle from '@mui/material/DialogTitle';
8
+ import DialogActions from '@mui/material/DialogActions';
9
+ import UpdateIcon from '@mui/icons-material/Update';
10
+ import IconButton from '@mui/material/IconButton';
11
+ import AddIcon from '@mui/icons-material/Add';
12
+ import Badge from '@mui/material/Badge';
13
+ import SettingsOutlinedIcon from '@mui/icons-material/SettingsOutlined';
14
+ import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined';
15
+ import LaunchIcon from '@mui/icons-material/Launch';
16
+ import Grid from '@mui/material/Grid';
17
+ import Tooltip from '@mui/material/Tooltip';
18
+ import ArrowForwardIcon from '@mui/icons-material/ArrowForward';
19
+ import Checkbox from '@mui/material/Checkbox';
20
+ import RestartIcon from '@mui/icons-material/Replay';
21
+ import ReloadIcon from '@mui/icons-material/Autorenew';
22
+ import DeleteIcon from '@mui/icons-material/Delete';
23
+ import FormControlLabel from '@mui/material/FormControlLabel';
24
+ import Switch from '@mui/material/Switch';
25
+ import { Icon } from '@iconify/react';
26
+ import { APP_STRUCT_VERSION } from '@abtnode/constant';
27
+ import Spinner from '@mui/material/CircularProgress';
28
+ import InfoRow from '@arcblock/ux/lib/InfoRow';
29
+ import { LocaleContext } from '@arcblock/ux/lib/Locale/context';
30
+ import Button from '@arcblock/ux/lib/Button';
31
+ import Empty from '@arcblock/ux/lib/Empty';
32
+ import { getComponentMissingConfigs, getDisplayName, forEachChildSync, isInProgress } from '@blocklet/meta/lib/util';
33
+ import normalizePathPrefix from '@abtnode/util/lib/normalize-path-prefix';
34
+ import Toast from '@arcblock/ux/lib/Toast';
35
+ import { useDeletingBlockletContext } from '../../contexts/deleting-blocklets';
36
+ import DidAddress from '../../did-address';
37
+ import Tag from '../../tag';
38
+ import BlockletSource from '../blocklet-source';
39
+ import BlockletStatus from '../status';
40
+ import BlockletVersion from '../version';
41
+ import Confirm from '../../confirm';
42
+ import { useNodeContext } from '../../contexts/node';
43
+ import { formatPerson, formatError, sleep, BlockletAdminRoles, formatToDatetime } from '../../util';
44
+ import Permission from '../../permission';
45
+ import BlockletBundleAvatar from '../bundle-avatar';
46
+ import BlockletMode from '../mode';
47
+ import ComponentConfiguration from './configuration';
48
+ import DeleteComponent from './delete';
49
+ import StartComponent from './start';
50
+ import Line from './line';
51
+ import AddComponent from './add';
52
+ import AddRule from '../router/action/add-rule';
53
+ import RuleList from '../router/rule-list';
54
+ import Actions from '../../actions';
55
+ import { jsx as _jsx } from "react/jsx-runtime";
56
+ import { jsxs as _jsxs } from "react/jsx-runtime";
57
+ const getEngineRows = (engine, t) => {
58
+ if (!engine) {
59
+ return [];
60
+ }
61
+ return [{
62
+ name: t('common.name'),
63
+ value: engine.displayName
64
+ }, {
65
+ name: t('common.description'),
66
+ value: engine.description
67
+ }, {
68
+ name: t('common.version'),
69
+ value: /*#__PURE__*/_jsx(Tag, {
70
+ children: engine.version
71
+ })
72
+ }];
73
+ };
74
+ const getSourceInfo = blocklet => {
75
+ const {
76
+ source,
77
+ deployedFrom,
78
+ bundleSource
79
+ } = blocklet;
80
+ if (source) {
81
+ return {
82
+ source,
83
+ deployedFrom
84
+ };
85
+ }
86
+ if (!bundleSource) {
87
+ return {
88
+ source: 'upload',
89
+ deployedFrom
90
+ };
91
+ }
92
+ if (bundleSource.url) {
93
+ return {
94
+ source: 'url',
95
+ deployedFrom: deployedFrom || Array.isArray(bundleSource.url) ? bundleSource.url[0] : bundleSource.url
96
+ };
97
+ }
98
+ if (bundleSource.store) {
99
+ return {
100
+ source: 'registry',
101
+ deployedFrom: deployedFrom || Array.isArray(bundleSource.store) ? bundleSource.store[0] : bundleSource.store
102
+ };
103
+ }
104
+ return {};
105
+ };
106
+ const getComponentName = (componentId, app) => {
107
+ const ids = componentId.split('/').slice(1);
108
+ let parent = app;
109
+ let index = 0;
110
+ const names = [];
111
+ while (parent && index < ids.length) {
112
+ // eslint-disable-next-line no-loop-func
113
+ const component = parent.children.find(x => x.meta.did === ids[index]);
114
+ parent = component;
115
+ index++;
116
+ if (component) {
117
+ names.push(component.meta.title);
118
+ }
119
+ }
120
+ return names.join(' / ');
121
+ };
122
+ function ComponentItem({
123
+ blocklet,
124
+ ancestors,
125
+ depth,
126
+ onRemove,
127
+ onStart,
128
+ onStop,
129
+ onRestart,
130
+ onReload,
131
+ getComponentUrl,
132
+ app
133
+ }) {
134
+ const {
135
+ t,
136
+ locale
137
+ } = useContext(LocaleContext);
138
+ const [componentInfo, setComponentInfo] = useState();
139
+ const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
140
+ const [loading, setLoading] = useState(false);
141
+ const [confirmSetting, setConfirmSetting] = useState(null);
142
+ const {
143
+ deletingBlocklets: deletingComponents
144
+ } = useDeletingBlockletContext();
145
+ let {
146
+ status
147
+ } = blocklet;
148
+ if (depth === 1 && deletingComponents.includes(blocklet.meta.did)) {
149
+ status = 'deleting';
150
+ }
151
+ const mountPoint = `/${blocklet.mountPoint || '/'}`.replace(/\/+/g, '/');
152
+ const href = getComponentUrl(mountPoint);
153
+ const renderRows = rows => rows.map(row => {
154
+ if (row.name === t('common.did') || row.name === t('blocklet.appId')) {
155
+ return /*#__PURE__*/_jsx(InfoRow, {
156
+ valueComponent: "div",
157
+ nameWidth: 120,
158
+ name: row.name,
159
+ nameFormatter: () => row.name,
160
+ children: row.value
161
+ }, row.name);
162
+ }
163
+ return /*#__PURE__*/_jsx(InfoRow, {
164
+ valueComponent: "div",
165
+ nameWidth: 120,
166
+ name: row.name,
167
+ children: row.value
168
+ }, row.name);
169
+ });
170
+ const sourceInfo = componentInfo ? getSourceInfo(componentInfo) : {};
171
+ const componentRows = componentInfo ? [{
172
+ name: t('common.name'),
173
+ value: getDisplayName(componentInfo, true)
174
+ }, {
175
+ name: t('common.version'),
176
+ value: /*#__PURE__*/_jsx(BlockletVersion, {
177
+ blocklet: componentInfo,
178
+ checkUpgrade: false
179
+ })
180
+ }, {
181
+ name: t('common.status'),
182
+ value: /*#__PURE__*/_jsx(BlockletStatus, {
183
+ status: status,
184
+ source: componentInfo.source
185
+ })
186
+ }, blocklet.status === 'running' ? {
187
+ name: t('blocklet.startedAt'),
188
+ value: formatToDatetime(blocklet.startedAt, locale)
189
+ } : null, blocklet.status !== 'running' ? {
190
+ name: t('blocklet.stoppedAt'),
191
+ value: formatToDatetime(blocklet.stoppedAt, locale)
192
+ } : null, {
193
+ name: t('common.mountPoint'),
194
+ value: mountPoint
195
+ }, {
196
+ name: t('common.group'),
197
+ value: /*#__PURE__*/_jsx(Tag, {
198
+ type: "success",
199
+ children: componentInfo.meta.group
200
+ })
201
+ }, {
202
+ name: t('blocklet.overview.source'),
203
+ value: /*#__PURE__*/_jsx(BlockletSource, {
204
+ sourceInfo: sourceInfo,
205
+ blocklet: blocklet
206
+ })
207
+ }, {
208
+ name: t('blocklet.overview.deployedFrom'),
209
+ value: sourceInfo.deployedFrom || '-'
210
+ }, {
211
+ name: t('common.did'),
212
+ value: /*#__PURE__*/_jsx(DidAddress, {
213
+ did: componentInfo.meta.did
214
+ })
215
+ }, {
216
+ name: t('common.author'),
217
+ value: formatPerson(componentInfo.meta.author)
218
+ }, {
219
+ name: t('common.engine'),
220
+ value: getEngineRows(componentInfo.engine, t).map(({
221
+ name,
222
+ value
223
+ }) => /*#__PURE__*/_jsx(InfoRow, {
224
+ style: {
225
+ marginBottom: 4
226
+ },
227
+ nameWidth: 120,
228
+ name: name,
229
+ children: value
230
+ }, name))
231
+ }, blocklet.dependents?.length ? {
232
+ name: t('common.dependents'),
233
+ value: /*#__PURE__*/_jsx(Box, {
234
+ children: blocklet.dependents.map(x => /*#__PURE__*/_jsx(Box, {
235
+ children: `${getComponentName(x.id, app)} ${x.required ? `(${t('common.required')})` : ''}`
236
+ }))
237
+ })
238
+ } : null].filter(Boolean) : [];
239
+ const appInProgress = isInProgress(app.status);
240
+ const componentInProgress = isInProgress(blocklet.status);
241
+ let deleteDisabledTip = '';
242
+ if (appInProgress || componentInProgress || depth === 1 && deletingComponents.includes(blocklet.meta.did)) {
243
+ deleteDisabledTip = t('blocklet.component.tip.stopBlocklet');
244
+ } else if (blocklet.dependents?.length) {
245
+ const requires = blocklet.dependents.filter(x => x.required);
246
+ if (requires.length) {
247
+ const names = requires.map(x => getComponentName(x.id, app));
248
+ deleteDisabledTip = t('blocklet.component.tip.requiredBy', {
249
+ name: names.join(', ')
250
+ });
251
+ }
252
+ }
253
+ return [/*#__PURE__*/_jsxs(StyledComponentRow, {
254
+ display: "flex",
255
+ py: 2,
256
+ className: "component-item",
257
+ justifyContent: "space-between",
258
+ alignItems: "center",
259
+ children: [/*#__PURE__*/_jsxs(Box, {
260
+ pl: 2,
261
+ width: {
262
+ xs: 300,
263
+ md: 400
264
+ },
265
+ display: "flex",
266
+ alignItems: "center",
267
+ children: [/*#__PURE__*/_jsx(BlockletBundleAvatar, {
268
+ blocklet: blocklet,
269
+ ancestors: ancestors
270
+ }), /*#__PURE__*/_jsxs(Box, {
271
+ ml: "16px",
272
+ children: [/*#__PURE__*/_jsx(Box, {
273
+ className: "component-name",
274
+ onClick: () => setComponentInfo(blocklet),
275
+ children: getDisplayName(blocklet, true)
276
+ }), /*#__PURE__*/_jsxs(Box, {
277
+ display: "flex",
278
+ alignItems: "center",
279
+ children: [/*#__PURE__*/_jsx(BlockletVersion, {
280
+ blocklet: blocklet,
281
+ checkUpgrade: false
282
+ }), /*#__PURE__*/_jsx(BlockletMode, {
283
+ style: {
284
+ marginLeft: 4
285
+ },
286
+ mode: blocklet.mode || ''
287
+ }), status !== 'unknown' && /*#__PURE__*/_jsx(BlockletStatus, {
288
+ style: {
289
+ marginLeft: 4
290
+ },
291
+ status: status,
292
+ source: blocklet.source
293
+ }), !!blocklet.dependents?.length && /*#__PURE__*/_jsx(Tooltip, {
294
+ title: [`${t('common.dependents')}: `, blocklet.dependents.map(x => /*#__PURE__*/_jsx(Box, {
295
+ pl: 1,
296
+ children: `${getComponentName(x.id, app)} ${x.required ? `(${t('common.required')})` : ''}`
297
+ }))],
298
+ children: /*#__PURE__*/_jsx(Box, {
299
+ display: "flex",
300
+ color: "primary.main",
301
+ ml: 1,
302
+ children: /*#__PURE__*/_jsx(Icon, {
303
+ icon: "octicon:package-dependents-16"
304
+ })
305
+ })
306
+ })]
307
+ })]
308
+ })]
309
+ }, blocklet), /*#__PURE__*/_jsx(Box, {
310
+ sx: {
311
+ display: {
312
+ xs: 'none',
313
+ md: 'flex'
314
+ }
315
+ },
316
+ alignItems: "center",
317
+ flexGrow: "1",
318
+ children: /*#__PURE__*/_jsx("a", {
319
+ target: "_blank",
320
+ href: href,
321
+ rel: "noopener noreferrer",
322
+ title: href,
323
+ children: /*#__PURE__*/_jsx(Box, {
324
+ maxWidth: 400,
325
+ sx: {
326
+ color: 'secondary.main',
327
+ fontSize: 18,
328
+ px: 2
329
+ },
330
+ overflow: "hidden",
331
+ whiteSpace: "nowrap",
332
+ textOverflow: "ellipsis",
333
+ children: normalizePathPrefix(mountPoint)
334
+ })
335
+ })
336
+ }, mountPoint), /*#__PURE__*/_jsxs(Box, {
337
+ display: "flex",
338
+ alignItems: "center",
339
+ children: [/*#__PURE__*/_jsx(Tooltip, {
340
+ title: t('common.visit'),
341
+ children: /*#__PURE__*/_jsx("a", {
342
+ target: "_blank",
343
+ href: href,
344
+ rel: "noopener noreferrer",
345
+ children: /*#__PURE__*/_jsx(IconButton, {
346
+ size: "small",
347
+ children: /*#__PURE__*/_jsx(LaunchIcon, {})
348
+ })
349
+ })
350
+ }), /*#__PURE__*/_jsx(ComponentConfiguration, {
351
+ blocklet: blocklet,
352
+ ancestors: ancestors,
353
+ children: ({
354
+ open
355
+ }) => /*#__PURE__*/_jsx(Tooltip, {
356
+ title: t('common.config'),
357
+ children: /*#__PURE__*/_jsx(StyledBadge, {
358
+ color: "error",
359
+ badgeContent: "",
360
+ variant: "dot",
361
+ invisible: !getComponentMissingConfigs(blocklet, ancestors).length,
362
+ children: /*#__PURE__*/_jsx(IconButton, {
363
+ onClick: open,
364
+ size: "small",
365
+ children: /*#__PURE__*/_jsx(SettingsOutlinedIcon, {})
366
+ })
367
+ })
368
+ }, "config")
369
+ }), /*#__PURE__*/_jsx(StartComponent, {
370
+ blocklet: app,
371
+ component: blocklet,
372
+ onStart: onStart,
373
+ onStop: onStop,
374
+ disabled: app.status !== 'starting' && isInProgress(app.status)
375
+ }), /*#__PURE__*/_jsx(Actions, {
376
+ "data-cy": "component-actions",
377
+ actions: [{
378
+ icon: /*#__PURE__*/_jsx(InfoOutlinedIcon, {}),
379
+ text: t('common.detail'),
380
+ onClick: () => {
381
+ setComponentInfo(blocklet);
382
+ }
383
+ }, {
384
+ icon: /*#__PURE__*/_jsx(RestartIcon, {}),
385
+ text: t('common.restart'),
386
+ onClick: () => {
387
+ setConfirmSetting({
388
+ title: `${t('common.restart')} ${blocklet.meta.title}`,
389
+ description: t('blocklet.action.restartDescription'),
390
+ confirm: t('blocklet.action.confirmRestart'),
391
+ cancel: t('common.cancel'),
392
+ onConfirm: async () => {
393
+ setLoading(true);
394
+ await onRestart(blocklet);
395
+ setLoading(false);
396
+ },
397
+ onCancel: () => setConfirmSetting(null)
398
+ });
399
+ },
400
+ disabled: appInProgress || componentInProgress || blocklet.status !== 'running'
401
+ }, {
402
+ icon: /*#__PURE__*/_jsx(ReloadIcon, {}),
403
+ text: t('common.reload'),
404
+ onClick: async () => {
405
+ setLoading(true);
406
+ await onReload(blocklet);
407
+ setLoading(false);
408
+ },
409
+ disabled: loading || appInProgress || componentInProgress || blocklet.status !== 'running'
410
+ }, {
411
+ icon: /*#__PURE__*/_jsx(DeleteIcon, {}),
412
+ text: t('common.delete'),
413
+ onClick: () => {
414
+ setShowDeleteConfirm(true);
415
+ },
416
+ disabled: appInProgress || componentInProgress || !!deleteDisabledTip,
417
+ tip: deleteDisabledTip
418
+ }]
419
+ })]
420
+ }, "actions")]
421
+ }, "group-not-gateway-box"), /*#__PURE__*/_jsx(Line, {
422
+ depth: 2
423
+ }), !!componentInfo && /*#__PURE__*/_jsx(Dialog, {
424
+ open: true,
425
+ fullWidth: true,
426
+ maxWidth: "md",
427
+ onClose: () => {
428
+ setComponentInfo(null);
429
+ },
430
+ children: /*#__PURE__*/_jsxs(Box, {
431
+ paddingY: 1.5,
432
+ children: [/*#__PURE__*/_jsx(DialogTitle, {
433
+ children: t('common.componentBasicInfo')
434
+ }), /*#__PURE__*/_jsx(DialogContent, {
435
+ children: renderRows(componentRows)
436
+ })]
437
+ }, "dialog-wrapper")
438
+ }, "base-info-dialog"), /*#__PURE__*/_jsx(DeleteComponent, {
439
+ blocklet: app,
440
+ component: blocklet,
441
+ remove: async (...param) => {
442
+ setLoading(true);
443
+ try {
444
+ await onRemove(...param);
445
+ } catch {
446
+ // ignore
447
+ }
448
+ setLoading(false);
449
+ setShowDeleteConfirm(false);
450
+ },
451
+ onCancel: () => setShowDeleteConfirm(false),
452
+ hideBtn: true,
453
+ showConfirm: showDeleteConfirm
454
+ }), confirmSetting && /*#__PURE__*/_jsx(Confirm, {
455
+ title: confirmSetting.title,
456
+ description: confirmSetting.description,
457
+ confirm: confirmSetting.confirm,
458
+ cancel: confirmSetting.cancel,
459
+ params: confirmSetting.params,
460
+ onConfirm: confirmSetting.onConfirm,
461
+ onCancel: confirmSetting.onCancel
462
+ })];
463
+ }
464
+ ComponentItem.propTypes = {
465
+ blocklet: PropTypes.object.isRequired,
466
+ ancestors: PropTypes.array,
467
+ depth: PropTypes.number,
468
+ onRemove: PropTypes.func,
469
+ onStart: PropTypes.func,
470
+ onStop: PropTypes.func,
471
+ onRestart: PropTypes.func,
472
+ onReload: PropTypes.func,
473
+ getComponentUrl: PropTypes.func,
474
+ app: PropTypes.object
475
+ };
476
+ ComponentItem.defaultProps = {
477
+ ancestors: [],
478
+ depth: 0,
479
+ onRemove: () => {},
480
+ onStart: () => {},
481
+ onStop: () => {},
482
+ onRestart: () => {},
483
+ onReload: () => {},
484
+ getComponentUrl: () => window.location.origin,
485
+ app: null
486
+ };
487
+ const StyledBadge = styled(Badge)`
488
+ .BaseBadge-badge {
489
+ top: ${props => props.top * 8 || 6}px;
490
+ right: ${props => props.right * 8 || 6}px;
491
+ }
492
+ `;
493
+ const StyledComponentRow = styled(Box)`
494
+ .component-name {
495
+ color: #222;
496
+ font-size: 16px;
497
+ cursor: pointer;
498
+ }
499
+ `;
500
+ export default function BlockletComponent({
501
+ blocklet,
502
+ onUpdate,
503
+ getComponentUrl,
504
+ ...rest
505
+ }) {
506
+ const {
507
+ t
508
+ } = useContext(LocaleContext);
509
+ const {
510
+ api,
511
+ inService,
512
+ info
513
+ } = useNodeContext();
514
+ const {
515
+ addDeletingDid,
516
+ removeDeletingDid,
517
+ matchDeletingDid
518
+ } = useDeletingBlockletContext();
519
+ const [loading, setLoading] = useState(false);
520
+ const [updateConfirm, setUpdateConfirm] = useState(null);
521
+ const [showSettings, setShowSettings] = useState(null);
522
+ const [showContainer, setShowContainer] = useState(false);
523
+ const needMigration = blocklet && blocklet.structVersion !== APP_STRUCT_VERSION;
524
+
525
+ // update dot is not used but maybe useful in the further
526
+ const [showUpdateDot, setShowUpdateDot] = useState(false);
527
+ const components = [...blocklet.children] || [];
528
+ if (blocklet.meta.group !== 'gateway') {
529
+ // add root blocklet to table list
530
+ components.unshift(blocklet);
531
+ }
532
+ matchDeletingDid(components.map(e => e.meta.did));
533
+ const checkForUpdates = async () => {
534
+ if (loading) {
535
+ return;
536
+ }
537
+ setLoading(true);
538
+ try {
539
+ // check child component version
540
+ const {
541
+ updateId,
542
+ updateList
543
+ } = (await api.checkComponentsForUpdates({
544
+ input: {
545
+ did: blocklet.meta.did
546
+ }
547
+ })).preUpdateInfo || {};
548
+ setLoading(false);
549
+ if (!updateId) {
550
+ Toast.info(t('blocklet.component.noUpdate'));
551
+ return;
552
+ }
553
+ const list = [];
554
+ forEachChildSync(blocklet, (b, {
555
+ id,
556
+ ancestors
557
+ }) => {
558
+ const updateItem = updateList.find(x => x.id === id);
559
+ if (updateItem) {
560
+ const name = ancestors.slice(1).concat(b).map(x => x.meta.title || x.meta.name).join(' / ');
561
+
562
+ // groupId 为一级组件的 id
563
+ const groupId = (ancestors[1] || b).meta.did;
564
+ list.push({
565
+ groupId,
566
+ name,
567
+ version: b.meta.version,
568
+ newVersion: updateItem.meta.version
569
+ });
570
+ }
571
+ });
572
+ const checks = {};
573
+ list.forEach(x => {
574
+ if (!checks[x.groupId]) {
575
+ checks[x.groupId] = true;
576
+ } else {
577
+ x.disabled = true;
578
+ }
579
+ });
580
+ setUpdateConfirm({
581
+ params: {
582
+ updateId
583
+ },
584
+ list,
585
+ checks,
586
+ hasChecks: true
587
+ });
588
+ } catch (err) {
589
+ setLoading(false);
590
+ Toast.error(formatError(err));
591
+ }
592
+ };
593
+ const onConfirmUpdate = async () => {
594
+ if (loading) {
595
+ return;
596
+ }
597
+ try {
598
+ setLoading(true);
599
+ const selectedComponents = Object.keys(updateConfirm.checks).filter(x => updateConfirm.checks[x]);
600
+ const input = {
601
+ updateId: updateConfirm.params.updateId,
602
+ rootDid: blocklet.meta.did,
603
+ selectedComponents
604
+ };
605
+ await api.upgradeComponents({
606
+ input
607
+ });
608
+ setLoading(false);
609
+ setUpdateConfirm(null);
610
+ setShowUpdateDot(null);
611
+ } catch (error) {
612
+ setLoading(false);
613
+ Toast.error(formatError(error));
614
+ }
615
+ };
616
+ const removeComponent = async (d, type) => {
617
+ addDeletingDid(d.meta.did);
618
+ try {
619
+ await api.deleteComponent({
620
+ input: {
621
+ did: d.meta.did,
622
+ keepData: type === 'keepData',
623
+ rootDid: blocklet.meta.did
624
+ }
625
+ });
626
+ await sleep(800);
627
+ } catch (err) {
628
+ Toast.error(formatError(err));
629
+ removeDeletingDid(d.meta.did);
630
+ }
631
+ };
632
+ const startComponent = async d => {
633
+ try {
634
+ await api.startBlocklet({
635
+ input: {
636
+ did: blocklet.meta.did,
637
+ componentDids: [d.meta.did]
638
+ }
639
+ });
640
+ await sleep(800);
641
+ } catch (err) {
642
+ Toast.error(formatError(err));
643
+ }
644
+ };
645
+ const stopComponent = async d => {
646
+ try {
647
+ await api.stopBlocklet({
648
+ input: {
649
+ did: blocklet.meta.did,
650
+ componentDids: [d.meta.did]
651
+ }
652
+ });
653
+ await sleep(800);
654
+ } catch (err) {
655
+ Toast.error(formatError(err));
656
+ }
657
+ };
658
+ const restartComponent = async d => {
659
+ try {
660
+ await api.restartBlocklet({
661
+ input: {
662
+ did: blocklet.meta.did,
663
+ componentDids: [d.meta.did]
664
+ }
665
+ });
666
+ await sleep(800);
667
+ } catch (err) {
668
+ Toast.error(formatError(err));
669
+ }
670
+ };
671
+ const reloadComponent = async d => {
672
+ try {
673
+ await api.reloadBlocklet({
674
+ input: {
675
+ did: blocklet.meta.did,
676
+ componentDids: [d.meta.did]
677
+ }
678
+ });
679
+ await sleep(800);
680
+ Toast.success(t('blocklet.reloadSuccess'));
681
+ } catch (err) {
682
+ Toast.error(formatError(err));
683
+ }
684
+ };
685
+ const onUpdateChecksChange = (e, groupId) => {
686
+ const {
687
+ checked: newValue
688
+ } = e.target;
689
+ setUpdateConfirm(x => {
690
+ const checks = Object.entries(x.checks).reduce((o, [key, oldValue]) => {
691
+ o[key] = groupId === key ? newValue : oldValue;
692
+ return o;
693
+ }, {});
694
+ const hasChecks = Object.values(checks).includes(true);
695
+ return {
696
+ ...x,
697
+ checks,
698
+ hasChecks
699
+ };
700
+ });
701
+ };
702
+ return /*#__PURE__*/_jsxs(Div, {
703
+ component: "div",
704
+ ...rest,
705
+ children: [/*#__PURE__*/_jsxs(Box, {
706
+ display: "flex",
707
+ justifyContent: "space-between",
708
+ alignItems: "center",
709
+ children: [/*#__PURE__*/_jsxs("div", {
710
+ className: "title",
711
+ children: [t('common.components'), !needMigration && /*#__PURE__*/_jsx(Permission, {
712
+ permission: inService ? '' : 'mutate_blocklets',
713
+ role: inService ? BlockletAdminRoles : [],
714
+ children: /*#__PURE__*/_jsx(StyledBadge, {
715
+ top: 1.2,
716
+ right: 0.4,
717
+ color: "error",
718
+ badgeContent: "",
719
+ variant: "dot",
720
+ invisible: !showUpdateDot,
721
+ children: /*#__PURE__*/_jsxs(Button, {
722
+ disabled: loading || isInProgress(blocklet.status),
723
+ color: "secondary",
724
+ onClick: () => {
725
+ checkForUpdates();
726
+ },
727
+ "data-cy": "check-for-updates",
728
+ children: [/*#__PURE__*/_jsx(Box, {
729
+ mr: 0.5,
730
+ display: "flex",
731
+ children: loading ? /*#__PURE__*/_jsx(Spinner, {
732
+ size: 16
733
+ }) : /*#__PURE__*/_jsx(UpdateIcon, {
734
+ style: {
735
+ fontSize: '1em'
736
+ }
737
+ })
738
+ }), t('blocklet.component.checkUpdateTitle')]
739
+ })
740
+ })
741
+ })]
742
+ }), /*#__PURE__*/_jsx(Permission, {
743
+ permission: inService ? '' : 'mutate_blocklets',
744
+ role: inService ? BlockletAdminRoles : [],
745
+ children: /*#__PURE__*/_jsxs(Box, {
746
+ display: "flex",
747
+ alignItems: "center",
748
+ children: [/*#__PURE__*/_jsx(AddRule, {
749
+ children: ({
750
+ open
751
+ }) => /*#__PURE__*/_jsxs(Button, {
752
+ disabled: loading || isInProgress(blocklet.status),
753
+ variant: "text",
754
+ color: "primary",
755
+ "data-cy": "add-rule",
756
+ onClick: open,
757
+ children: [/*#__PURE__*/_jsx(AddIcon, {
758
+ style: {
759
+ fontSize: '1.3em',
760
+ marginRight: 4
761
+ }
762
+ }), t('router.rule.add.title')]
763
+ })
764
+ }), !needMigration && /*#__PURE__*/_jsx(AddComponent, {
765
+ blocklet: blocklet,
766
+ serverVersion: info.version,
767
+ children: ({
768
+ open
769
+ }) => /*#__PURE__*/_jsxs(Button, {
770
+ disabled: loading || isInProgress(blocklet.status),
771
+ variant: "text",
772
+ color: "primary",
773
+ "data-cy": "add-component",
774
+ onClick: open,
775
+ children: [/*#__PURE__*/_jsx(AddIcon, {
776
+ style: {
777
+ fontSize: '1.3em',
778
+ marginRight: 4
779
+ }
780
+ }), t('blocklet.component.add')]
781
+ })
782
+ }), !needMigration && /*#__PURE__*/_jsx(ComponentConfiguration, {
783
+ blocklet: blocklet,
784
+ ancestors: [],
785
+ children: ({
786
+ open
787
+ }) => /*#__PURE__*/_jsx(Tooltip, {
788
+ title: `${t('blocklet.component.container')}${t('common.config')}`,
789
+ children: /*#__PURE__*/_jsx(IconButton, {
790
+ onClick: open,
791
+ size: "small",
792
+ color: "primary",
793
+ children: /*#__PURE__*/_jsx(SettingsOutlinedIcon, {
794
+ style: {
795
+ fontSize: 18
796
+ }
797
+ })
798
+ })
799
+ }, "config")
800
+ })]
801
+ })
802
+ })]
803
+ }), components && components.length ? /*#__PURE__*/_jsxs(Box, {
804
+ mt: 2,
805
+ ml: {
806
+ xs: '-12px',
807
+ md: '-24px'
808
+ },
809
+ children: [blocklet.meta.group !== 'gateway' && /*#__PURE__*/_jsx(ComponentItem, {
810
+ blocklet: blocklet,
811
+ app: blocklet,
812
+ onRemove: removeComponent,
813
+ onStart: startComponent,
814
+ onStop: stopComponent,
815
+ onReload: reloadComponent,
816
+ onRestart: restartComponent,
817
+ getComponentUrl: getComponentUrl
818
+ }, `0-${blocklet.meta.did}`), blocklet.children.map(component => /*#__PURE__*/_jsx(ComponentItem, {
819
+ depth: 1,
820
+ blocklet: component,
821
+ ancestors: [blocklet],
822
+ app: blocklet,
823
+ onRemove: removeComponent,
824
+ onStart: startComponent,
825
+ onStop: stopComponent,
826
+ onReload: reloadComponent,
827
+ onRestart: restartComponent,
828
+ getComponentUrl: getComponentUrl
829
+ }, `1-${component.meta.did}`))]
830
+ }, `top-blocklet-${blocklet.meta.did}`) : /*#__PURE__*/_jsx(Box, {
831
+ mt: 8,
832
+ children: /*#__PURE__*/_jsx(Empty, {
833
+ children: t('blocklet.component.noComponent')
834
+ })
835
+ }), !!blocklet.site.rules.length && /*#__PURE__*/_jsx(Box, {
836
+ mt: 0,
837
+ ml: {
838
+ xs: '-16px',
839
+ md: '-28px'
840
+ },
841
+ children: /*#__PURE__*/_jsx(RuleList, {})
842
+ }), !!updateConfirm && /*#__PURE__*/_jsx(Dialog, {
843
+ open: true,
844
+ fullWidth: true,
845
+ children: /*#__PURE__*/_jsxs(Box, {
846
+ paddingY: 1.5,
847
+ children: [/*#__PURE__*/_jsx(DialogTitle, {
848
+ children: t('blocklet.component.updateTitle')
849
+ }), /*#__PURE__*/_jsx(Box, {
850
+ component: DialogContent,
851
+ py: 4,
852
+ children: updateConfirm.list.map(x => /*#__PURE__*/_jsxs(Box, {
853
+ display: "flex",
854
+ alignItems: "center",
855
+ children: [/*#__PURE__*/_jsx(Checkbox, {
856
+ checked: updateConfirm.checks[x.groupId],
857
+ onChange: e => onUpdateChecksChange(e, x.groupId),
858
+ style: {
859
+ marginLeft: x.disabled ? 16 : 0
860
+ },
861
+ defaultChecked: true,
862
+ disabled: x.disabled
863
+ }), /*#__PURE__*/_jsxs(Box, {
864
+ flexGrow: 1,
865
+ mt: 3,
866
+ children: [/*#__PURE__*/_jsx(Box, {
867
+ item: true,
868
+ xs: 8,
869
+ children: x.name
870
+ }), x.version && /*#__PURE__*/_jsxs(Grid, {
871
+ fontSize: "h6.fontSize",
872
+ container: true,
873
+ spacing: 2,
874
+ alignItems: "center",
875
+ children: [/*#__PURE__*/_jsx(Grid, {
876
+ item: true,
877
+ xs: 3,
878
+ children: x.version
879
+ }), /*#__PURE__*/_jsx(Grid, {
880
+ item: true,
881
+ xs: 1,
882
+ children: /*#__PURE__*/_jsx(ArrowForwardIcon, {
883
+ style: {
884
+ fontSize: '0.9em'
885
+ }
886
+ })
887
+ }), /*#__PURE__*/_jsx(Grid, {
888
+ item: true,
889
+ xs: 3,
890
+ children: /*#__PURE__*/_jsx(Box, {
891
+ color: "secondary.main",
892
+ children: x.newVersion
893
+ })
894
+ })]
895
+ })]
896
+ }, `${x.name}-${x.newVersion}`)]
897
+ }))
898
+ }), /*#__PURE__*/_jsxs(DialogActions, {
899
+ style: {
900
+ padding: '8px 24px 24px'
901
+ },
902
+ children: [/*#__PURE__*/_jsx(Button, {
903
+ onClick: () => {
904
+ setUpdateConfirm(null);
905
+ },
906
+ children: t('common.cancel')
907
+ }), /*#__PURE__*/_jsxs(Button, {
908
+ onClick: e => {
909
+ e.stopPropagation();
910
+ onConfirmUpdate();
911
+ },
912
+ color: "primary",
913
+ disabled: loading || !updateConfirm.hasChecks,
914
+ variant: "contained",
915
+ autoFocus: true,
916
+ children: [loading && /*#__PURE__*/_jsx(Spinner, {
917
+ size: 16
918
+ }), t('common.update')]
919
+ })]
920
+ })]
921
+ })
922
+ }), !!showSettings && /*#__PURE__*/_jsx(Dialog, {
923
+ open: true,
924
+ fullWidth: true,
925
+ onClose: () => setShowSettings(false),
926
+ children: /*#__PURE__*/_jsxs(Box, {
927
+ paddingY: 1.5,
928
+ children: [/*#__PURE__*/_jsx(DialogTitle, {
929
+ children: t('common.configuration')
930
+ }), /*#__PURE__*/_jsx(DialogContent, {
931
+ children: /*#__PURE__*/_jsx(Box, {
932
+ py: 2,
933
+ children: /*#__PURE__*/_jsx(FormControlLabel, {
934
+ control: /*#__PURE__*/_jsx(Switch, {
935
+ checked: showContainer,
936
+ onChange: e => setShowContainer(!!e.target.checked)
937
+ }),
938
+ label: t('blocklet.component.showContainer')
939
+ })
940
+ })
941
+ })]
942
+ })
943
+ })]
944
+ });
945
+ }
946
+ BlockletComponent.propTypes = {
947
+ blocklet: PropTypes.object.isRequired,
948
+ onUpdate: PropTypes.func,
949
+ getComponentUrl: PropTypes.func
950
+ };
951
+ BlockletComponent.defaultProps = {
952
+ onUpdate: () => {},
953
+ getComponentUrl: () => window.location.origin
954
+ };
955
+ const Div = styled.div`
956
+ .title {
957
+ font-size: 1.2rem;
958
+ font-weight: bold;
959
+ margin-bottom: ${props => props.theme.spacing(1)};
960
+ }
961
+
962
+ @keyframes showDelay {
963
+ 0% {
964
+ opacity: 0;
965
+ }
966
+
967
+ 100% {
968
+ opacity: 1;
969
+ }
970
+ }
971
+
972
+ .component-item {
973
+ animation: showDelay 0.75s ease 1;
974
+ }
975
+ `;