@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.
- package/es/actions.js +97 -0
- package/es/analytics/card.js +92 -0
- package/es/analytics/chart.js +96 -0
- package/es/analytics/cpu.js +36 -0
- package/es/analytics/disk.js +111 -0
- package/es/analytics/memory.js +72 -0
- package/es/analytics/runtime.js +173 -0
- package/es/analytics/traffic.js +259 -0
- package/es/blocklet/access/config-access.js +307 -0
- package/es/blocklet/access/index.js +216 -0
- package/es/blocklet/actions.js +474 -0
- package/es/blocklet/add-cert.js +177 -0
- package/es/blocklet/agreement-app.js +21 -0
- package/es/blocklet/agreement.js +127 -0
- package/es/blocklet/app-avatar.js +57 -0
- package/es/blocklet/audit-logs.js +259 -0
- package/es/blocklet/blocklet-source.js +48 -0
- package/es/blocklet/bundle-avatar.js +64 -0
- package/es/blocklet/component/add.js +1308 -0
- package/es/blocklet/component/configuration.js +122 -0
- package/es/blocklet/component/delete.js +134 -0
- package/es/blocklet/component/environment.js +370 -0
- package/es/blocklet/component/index.js +975 -0
- package/es/blocklet/component/line.js +20 -0
- package/es/blocklet/component/navigation/locale-tabs.js +225 -0
- package/es/blocklet/component/navigation/navigation-actions.js +112 -0
- package/es/blocklet/component/navigation/navigation-dialog.js +607 -0
- package/es/blocklet/component/navigation/navigation-preview.js +101 -0
- package/es/blocklet/component/navigation/simple-select.js +124 -0
- package/es/blocklet/component/select-store.js +155 -0
- package/es/blocklet/component/setting.js +109 -0
- package/es/blocklet/component/sortable-tree.js +126 -0
- package/es/blocklet/component/space-connector.js +199 -0
- package/es/blocklet/component/space-selector.js +178 -0
- package/es/blocklet/component/start.js +101 -0
- package/es/blocklet/component/store-blocklet-list.js +200 -0
- package/es/blocklet/component/switch-control.js +57 -0
- package/es/blocklet/config-navigation.js +331 -0
- package/es/blocklet/configuration.js +603 -0
- package/es/blocklet/disk-info.js +75 -0
- package/es/blocklet/icons.js +18 -0
- package/es/blocklet/install-from-url.js +337 -0
- package/es/blocklet/log.js +90 -0
- package/es/blocklet/migration.js +149 -0
- package/es/blocklet/mode.js +19 -0
- package/es/blocklet/notification/email.js +257 -0
- package/es/blocklet/notification/index.js +49 -0
- package/es/blocklet/oauth/auth0.js +145 -0
- package/es/blocklet/oauth/common-settings.js +133 -0
- package/es/blocklet/oauth/federated-detail-dialog.js +175 -0
- package/es/blocklet/oauth/federated-invite-dialog.js +83 -0
- package/es/blocklet/oauth/federated-join-dialog.js +111 -0
- package/es/blocklet/oauth/federated-site-list.js +338 -0
- package/es/blocklet/oauth/federated.js +81 -0
- package/es/blocklet/oauth/index.js +69 -0
- package/es/blocklet/overview.js +293 -0
- package/es/blocklet/page-group.js +19 -0
- package/es/blocklet/preferences/app-sk.js +142 -0
- package/es/blocklet/preferences/index.js +305 -0
- package/es/blocklet/purchase/common.js +95 -0
- package/es/blocklet/purchase/component-purchase.js +237 -0
- package/es/blocklet/purchase/index.js +4 -0
- package/es/blocklet/router/action/add-domain-alias.js +167 -0
- package/es/blocklet/router/action/add-rule.js +211 -0
- package/es/blocklet/router/action/config-routing-rule.js +232 -0
- package/es/blocklet/router/action/delete-domain-alias.js +99 -0
- package/es/blocklet/router/action/delete-rule.js +108 -0
- package/es/blocklet/router/action/update-rule.js +209 -0
- package/es/blocklet/router/domain-actions.js +64 -0
- package/es/blocklet/router/domain-status.js +88 -0
- package/es/blocklet/router/rule-actions.js +66 -0
- package/es/blocklet/router/rule-list.js +190 -0
- package/es/blocklet/router/util.js +131 -0
- package/es/blocklet/runtime-info.js +68 -0
- package/es/blocklet/status.js +91 -0
- package/es/blocklet/storage/action.js +134 -0
- package/es/blocklet/storage/backups.js +241 -0
- package/es/blocklet/storage/connect-to.js +373 -0
- package/es/blocklet/storage/connected.js +198 -0
- package/es/blocklet/storage/delete.js +113 -0
- package/es/blocklet/storage/disconnect.js +243 -0
- package/es/blocklet/storage/index.js +19 -0
- package/es/blocklet/storage/item.js +558 -0
- package/es/blocklet/storage/preview-nft.js +286 -0
- package/es/blocklet/transfer-owner.js +198 -0
- package/es/blocklet/types.js +18 -0
- package/es/blocklet/util.js +145 -0
- package/es/blocklet/version.js +141 -0
- package/es/card-selector.js +134 -0
- package/es/certificate.js +105 -0
- package/es/chain.js +13 -0
- package/es/click-to-copy.js +22 -0
- package/es/confirm.js +149 -0
- package/es/contexts/audit-log.js +152 -0
- package/es/contexts/blocklet.js +10 -0
- package/es/contexts/deleting-blocklets.js +70 -0
- package/es/contexts/node.js +17 -0
- package/es/contexts/session.js +8 -0
- package/es/contexts/team.js +10 -0
- package/es/delete-confirm.js +121 -0
- package/es/did-address.js +46 -0
- package/es/dot.js +14 -0
- package/es/exchange-passport.js +102 -0
- package/es/form/form-select-input.js +184 -0
- package/es/form/form-text-input.js +178 -0
- package/es/form/form-wrapper.js +88 -0
- package/es/form/input-triggers.js +98 -0
- package/es/form/required.js +8 -0
- package/es/hooks/blocklet.js +229 -0
- package/es/hooks/confirm.js +90 -0
- package/es/hooks/mobile-width.js +11 -0
- package/es/hooks/url-evaluation.js +155 -0
- package/es/hooks/use-app-logo.js +16 -0
- package/es/hooks/use-backup-progress.js +31 -0
- package/es/hooks/use-blocklet-info-for-connect-did-spaces.js +50 -0
- package/es/hooks/use-bundle-logo.js +27 -0
- package/es/hooks/use-navigation.js +347 -0
- package/es/hooks/use-passport-id.js +14 -0
- package/es/hooks/use-subscription.js +22 -0
- package/es/icons/empty-space-nft.svg +59 -0
- package/es/icons/empty-spaces-nft.svg +58 -0
- package/es/icons/long-arrow.svg +5 -0
- package/es/icons/space-connected.svg +3 -0
- package/es/icons/space-disconnect.svg +3 -0
- package/es/index.js +3 -0
- package/es/invitation/invitation-app.js +58 -0
- package/es/invitation/invitation-login.js +68 -0
- package/es/invitation/invitation-passport.js +144 -0
- package/es/invitation/invitation-receive.js +138 -0
- package/es/invitation/invitation-success.js +93 -0
- package/es/invitation/invitation-user.js +90 -0
- package/es/invitation/invitation.js +90 -0
- package/es/issue-passport.js +142 -0
- package/es/launch-blocklet/content-layout.js +58 -0
- package/es/launch-blocklet/page-header.js +43 -0
- package/es/layout/addon.js +114 -0
- package/es/layout/feedback.js +55 -0
- package/es/locales/en.js +1534 -0
- package/es/locales/index.js +9 -0
- package/es/locales/zh.js +1537 -0
- package/es/logs/clock.js +11 -0
- package/es/logs/download.js +132 -0
- package/es/logs/log-terminal.js +253 -0
- package/es/lost-passport.js +452 -0
- package/es/nav-logo.js +219 -0
- package/es/passport-tag.js +43 -0
- package/es/permission.js +57 -0
- package/es/relative-time.js +53 -0
- package/es/result-message.js +11 -0
- package/es/schema-form/color-input.js +98 -0
- package/es/schema-form/common-prop-types.js +13 -0
- package/es/schema-form/index.js +215 -0
- package/es/schema-form/passport-input.js +54 -0
- package/es/schema-form/text-input.js +57 -0
- package/es/store/add.js +179 -0
- package/es/store/delete.js +96 -0
- package/es/store/item.js +76 -0
- package/es/subscription.js +144 -0
- package/es/table-icons.js +34 -0
- package/es/table.js +52 -0
- package/es/tag.js +21 -0
- package/es/team/members/actions.js +89 -0
- package/es/team/members/index.js +636 -0
- package/es/team/members/invitations.js +188 -0
- package/es/team/members/invite-member.js +208 -0
- package/es/team/members/issue-passport.js +152 -0
- package/es/team/members/member.js +408 -0
- package/es/team/members/passport-issuances.js +155 -0
- package/es/team/members/passports.js +364 -0
- package/es/team/members/toggle-user-approval.js +122 -0
- package/es/team/members/transfer-node.js +256 -0
- package/es/team/members/util.js +14 -0
- package/es/team/passports/color.js +126 -0
- package/es/team/passports/detail.js +312 -0
- package/es/team/passports/index.js +282 -0
- package/es/team/passports/mutate-role.js +198 -0
- package/es/team/passports/trusted-factories.js +221 -0
- package/es/team/passports/trusted-factory.js +343 -0
- package/es/team/passports/trusted-issuer.js +296 -0
- package/es/team/passports/trusted-issuers.js +226 -0
- package/es/team/search-input.js +46 -0
- package/es/team/styles/dialog.js +72 -0
- package/es/team/styles/list-header.js +31 -0
- package/es/util/api.js +6 -0
- package/es/util/constants.js +2 -0
- package/es/util/index.js +598 -0
- package/es/util/mode.js +4 -0
- package/es/util/space-gateway.js +51 -0
- package/es/util/spaces.js +151 -0
- package/es/who-can-access/config.js +38 -0
- package/es/wrap-locale.js +15 -0
- package/lib/blocklet/component/space-connector.js +1 -1
- package/lib/blocklet/component/space-selector.js +1 -1
- package/lib/blocklet/storage/backups.js +1 -1
- package/lib/blocklet/storage/connect-to.js +1 -1
- package/lib/blocklet/storage/connected.js +1 -1
- package/lib/blocklet/storage/disconnect.js +1 -1
- package/lib/blocklet/storage/index.js +1 -1
- package/lib/blocklet/storage/item.js +1 -1
- package/lib/invitation/invitation-receive.js +1 -1
- package/lib/team/passports/trusted-factory.js +1 -1
- package/package.json +81 -18
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import styled from '@emotion/styled';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import IconButton from '@mui/material/IconButton';
|
|
5
|
+
import Box from '@mui/material/Box';
|
|
6
|
+
import EditIcon from '@mui/icons-material/Edit';
|
|
7
|
+
import { getDisplayName } from '@blocklet/meta/lib/util';
|
|
8
|
+
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
9
|
+
import Dialog from '@arcblock/ux/lib/Dialog';
|
|
10
|
+
import Tabs from '@arcblock/ux/lib/Tabs';
|
|
11
|
+
import { isInstalling } from '../../util';
|
|
12
|
+
import ComponentEnvironment from './environment';
|
|
13
|
+
import ComponentSetting from './setting';
|
|
14
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
+
export default function ComponentConfiguration({
|
|
17
|
+
blocklet,
|
|
18
|
+
ancestors,
|
|
19
|
+
children
|
|
20
|
+
}) {
|
|
21
|
+
const [showDialog, setShowDialog] = useState('');
|
|
22
|
+
const {
|
|
23
|
+
t
|
|
24
|
+
} = useLocaleContext();
|
|
25
|
+
const isComponent = !!ancestors.length;
|
|
26
|
+
const [tab, setTab] = useState('settings');
|
|
27
|
+
const name = isComponent ? getDisplayName(blocklet, true) : t('blocklet.component.container');
|
|
28
|
+
if (isInstalling(blocklet.status)) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
if (blocklet.status === 'unknown' && isInstalling(blocklet.status)) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const onClose = () => {
|
|
35
|
+
setShowDialog(false);
|
|
36
|
+
};
|
|
37
|
+
const onOpen = e => {
|
|
38
|
+
e.stopPropagation();
|
|
39
|
+
// eslint-disable-next-line no-unused-expressions
|
|
40
|
+
setShowDialog(true);
|
|
41
|
+
};
|
|
42
|
+
const tabConfigs = {
|
|
43
|
+
settings: {
|
|
44
|
+
label: t('blocklet.component.setting'),
|
|
45
|
+
value: 'settings',
|
|
46
|
+
component: /*#__PURE__*/_jsx(ComponentSetting, {
|
|
47
|
+
blocklet: blocklet,
|
|
48
|
+
ancestors: ancestors
|
|
49
|
+
})
|
|
50
|
+
},
|
|
51
|
+
environments: {
|
|
52
|
+
label: t('common.environment'),
|
|
53
|
+
value: 'environments',
|
|
54
|
+
component: /*#__PURE__*/_jsx(ComponentEnvironment, {
|
|
55
|
+
blocklet: blocklet,
|
|
56
|
+
ancestors: ancestors
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const tabs = Object.values(tabConfigs).map(({
|
|
61
|
+
label,
|
|
62
|
+
value
|
|
63
|
+
}) => ({
|
|
64
|
+
label,
|
|
65
|
+
value
|
|
66
|
+
}));
|
|
67
|
+
const onTabChange = newTab => {
|
|
68
|
+
setTab(newTab);
|
|
69
|
+
};
|
|
70
|
+
const tabConfig = tabConfigs[tab] || tabConfigs.settings;
|
|
71
|
+
return [typeof children === 'function' ? children({
|
|
72
|
+
open: onOpen
|
|
73
|
+
}) : /*#__PURE__*/_jsx(IconButton, {
|
|
74
|
+
onClick: onOpen,
|
|
75
|
+
"data-cy": "action-config-component",
|
|
76
|
+
children: /*#__PURE__*/_jsx(EditIcon, {})
|
|
77
|
+
}), showDialog && /*#__PURE__*/_jsx(StyledDialog, {
|
|
78
|
+
open: true,
|
|
79
|
+
fullWidth: true,
|
|
80
|
+
maxWidth: "md",
|
|
81
|
+
title: name,
|
|
82
|
+
onClose: onClose,
|
|
83
|
+
PaperProps: {
|
|
84
|
+
style: {
|
|
85
|
+
minHeight: 'auto'
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
children: isComponent ? /*#__PURE__*/_jsxs(Box, {
|
|
89
|
+
mt: 1,
|
|
90
|
+
children: [/*#__PURE__*/_jsx(Tabs, {
|
|
91
|
+
tabs: tabs,
|
|
92
|
+
current: tab,
|
|
93
|
+
onChange: onTabChange,
|
|
94
|
+
scrollButtons: "auto"
|
|
95
|
+
}), tabConfig.component]
|
|
96
|
+
}) : /*#__PURE__*/_jsx(ComponentEnvironment, {
|
|
97
|
+
blocklet: blocklet,
|
|
98
|
+
ancestors: ancestors
|
|
99
|
+
})
|
|
100
|
+
})];
|
|
101
|
+
}
|
|
102
|
+
ComponentConfiguration.propTypes = {
|
|
103
|
+
blocklet: PropTypes.object.isRequired,
|
|
104
|
+
ancestors: PropTypes.array,
|
|
105
|
+
children: PropTypes.any
|
|
106
|
+
};
|
|
107
|
+
ComponentConfiguration.defaultProps = {
|
|
108
|
+
ancestors: [],
|
|
109
|
+
children: null
|
|
110
|
+
};
|
|
111
|
+
const StyledDialog = styled(Dialog)`
|
|
112
|
+
.MuiDialogContent-root {
|
|
113
|
+
padding-top: 0;
|
|
114
|
+
margin-top: -32px;
|
|
115
|
+
}
|
|
116
|
+
.MuiToolbar-root {
|
|
117
|
+
padding-right: 12px;
|
|
118
|
+
}
|
|
119
|
+
.ux-dialog_right {
|
|
120
|
+
padding-right: 20px;
|
|
121
|
+
}
|
|
122
|
+
`;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { useState, useContext, useEffect } from 'react';
|
|
2
|
+
import styled from '@emotion/styled';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import DeleteIcon from '@mui/icons-material/Delete';
|
|
5
|
+
import { LocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
6
|
+
import IconButton from '@mui/material/IconButton';
|
|
7
|
+
import Tooltip from '@mui/material/Tooltip';
|
|
8
|
+
import Typography from '@mui/material/Typography';
|
|
9
|
+
import Radio from '@mui/material/Radio';
|
|
10
|
+
import RadioGroup from '@mui/material/RadioGroup';
|
|
11
|
+
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
12
|
+
import Confirm from '../../confirm';
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
16
|
+
export default function DeleteComponent({
|
|
17
|
+
component,
|
|
18
|
+
remove,
|
|
19
|
+
disabled,
|
|
20
|
+
tip,
|
|
21
|
+
showConfirm,
|
|
22
|
+
hideBtn,
|
|
23
|
+
onCancel
|
|
24
|
+
}) {
|
|
25
|
+
const {
|
|
26
|
+
t
|
|
27
|
+
} = useContext(LocaleContext);
|
|
28
|
+
const [loading, setLoading] = useState(false);
|
|
29
|
+
const [deleteSetting, setDeleteSetting] = useState(null);
|
|
30
|
+
const deleteComponent = async param => {
|
|
31
|
+
setLoading(true);
|
|
32
|
+
await remove(param.component, param.removeType);
|
|
33
|
+
setLoading(false);
|
|
34
|
+
setDeleteSetting(null);
|
|
35
|
+
};
|
|
36
|
+
const componentDisabled = disabled || loading;
|
|
37
|
+
const doShowConfirm = () => {
|
|
38
|
+
setDeleteSetting({
|
|
39
|
+
title: `${t('common.delete')} ${component.meta.title || component.meta.name}`,
|
|
40
|
+
// eslint-disable-next-line react/no-unstable-nested-components
|
|
41
|
+
description: (params, setParams) => /*#__PURE__*/_jsxs(Typography, {
|
|
42
|
+
component: "div",
|
|
43
|
+
children: [/*#__PURE__*/_jsx(Typography, {
|
|
44
|
+
gutterBottom: true,
|
|
45
|
+
children: t('blocklet.action.removeComponentDescription')
|
|
46
|
+
}), /*#__PURE__*/_jsxs(RadioGroup, {
|
|
47
|
+
name: "removeType",
|
|
48
|
+
value: params.removeType,
|
|
49
|
+
onChange: e => setParams({
|
|
50
|
+
...params,
|
|
51
|
+
removeType: e.target.value
|
|
52
|
+
}),
|
|
53
|
+
children: [/*#__PURE__*/_jsx(FormControlLabel, {
|
|
54
|
+
value: "keepData",
|
|
55
|
+
control: /*#__PURE__*/_jsx(Radio, {}),
|
|
56
|
+
label: t('blocklet.action.removeComponentKeepData')
|
|
57
|
+
}), /*#__PURE__*/_jsx(FormControlLabel, {
|
|
58
|
+
value: "complete",
|
|
59
|
+
control: /*#__PURE__*/_jsx(Radio, {}),
|
|
60
|
+
label: t('blocklet.action.removeComponentComplete')
|
|
61
|
+
})]
|
|
62
|
+
})]
|
|
63
|
+
}),
|
|
64
|
+
confirm: t('common.confirm'),
|
|
65
|
+
cancel: t('common.cancel'),
|
|
66
|
+
params: {
|
|
67
|
+
component,
|
|
68
|
+
removeType: 'keepData'
|
|
69
|
+
},
|
|
70
|
+
onConfirm: deleteComponent,
|
|
71
|
+
onCancel: () => {
|
|
72
|
+
setDeleteSetting(null);
|
|
73
|
+
onCancel();
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (showConfirm) {
|
|
79
|
+
doShowConfirm();
|
|
80
|
+
} else {
|
|
81
|
+
setLoading(false);
|
|
82
|
+
setDeleteSetting(null);
|
|
83
|
+
}
|
|
84
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
85
|
+
}, [showConfirm]);
|
|
86
|
+
const btn = /*#__PURE__*/_jsx(StyledButton, {
|
|
87
|
+
size: "small",
|
|
88
|
+
disabled: componentDisabled,
|
|
89
|
+
onClick: () => doShowConfirm,
|
|
90
|
+
"data-cy": "delete-component-btn",
|
|
91
|
+
children: /*#__PURE__*/_jsx(DeleteIcon, {
|
|
92
|
+
disabled: componentDisabled
|
|
93
|
+
})
|
|
94
|
+
});
|
|
95
|
+
const btnWithToolTip = /*#__PURE__*/_jsx(Tooltip, {
|
|
96
|
+
title: tip || t('common.delete'),
|
|
97
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
98
|
+
children: btn
|
|
99
|
+
})
|
|
100
|
+
});
|
|
101
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
102
|
+
children: [!hideBtn && btnWithToolTip, deleteSetting && /*#__PURE__*/_jsx(Confirm, {
|
|
103
|
+
title: deleteSetting.title,
|
|
104
|
+
description: deleteSetting.description,
|
|
105
|
+
confirm: deleteSetting.confirm,
|
|
106
|
+
cancel: deleteSetting.cancel,
|
|
107
|
+
params: deleteSetting.params,
|
|
108
|
+
onConfirm: deleteSetting.onConfirm,
|
|
109
|
+
onCancel: deleteSetting.onCancel
|
|
110
|
+
})]
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
DeleteComponent.propTypes = {
|
|
114
|
+
component: PropTypes.object.isRequired,
|
|
115
|
+
remove: PropTypes.func,
|
|
116
|
+
onCancel: PropTypes.func,
|
|
117
|
+
disabled: PropTypes.bool,
|
|
118
|
+
showConfirm: PropTypes.bool,
|
|
119
|
+
hideBtn: PropTypes.bool,
|
|
120
|
+
tip: PropTypes.string
|
|
121
|
+
};
|
|
122
|
+
DeleteComponent.defaultProps = {
|
|
123
|
+
remove: async () => {},
|
|
124
|
+
disabled: false,
|
|
125
|
+
showConfirm: false,
|
|
126
|
+
hideBtn: false,
|
|
127
|
+
onCancel: () => {},
|
|
128
|
+
tip: ''
|
|
129
|
+
};
|
|
130
|
+
const StyledButton = styled(IconButton)`
|
|
131
|
+
&.Mui-disabled {
|
|
132
|
+
opacity: 0.5;
|
|
133
|
+
}
|
|
134
|
+
`;
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/* eslint-disable react/no-unstable-nested-components */
|
|
2
|
+
/* eslint-disable react/prop-types */
|
|
3
|
+
import { useContext } from 'react';
|
|
4
|
+
import styled from '@emotion/styled';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import MaterialTable from '@material-table/core';
|
|
7
|
+
import TextField from '@mui/material/TextField';
|
|
8
|
+
import Alert from '@mui/material/Alert';
|
|
9
|
+
import { BLOCKLET_CONFIGURABLE_KEY, CHAIN_PROP_MAP } from '@blocklet/constant';
|
|
10
|
+
import { getComponentMissingConfigs, getSharedConfigObj } from '@blocklet/meta/lib/util';
|
|
11
|
+
import { LocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
12
|
+
import Toast from '@arcblock/ux/lib/Toast';
|
|
13
|
+
import ClickToCopy from '../../click-to-copy';
|
|
14
|
+
import { useNodeContext } from '../../contexts/node';
|
|
15
|
+
import tableIcons from '../../table-icons';
|
|
16
|
+
import TableStyle from '../../table';
|
|
17
|
+
import Permission from '../../permission';
|
|
18
|
+
import { formatError, isInstalling, isValidClusterSize, isBlockletDev, BlockletAdminRoles } from '../../util';
|
|
19
|
+
import blockletIcons from '../icons';
|
|
20
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
21
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
|
+
const getDescription = (data, t) => {
|
|
23
|
+
let {
|
|
24
|
+
description
|
|
25
|
+
} = data;
|
|
26
|
+
if (Object.values(CHAIN_PROP_MAP).includes(data.key)) {
|
|
27
|
+
if (description) {
|
|
28
|
+
description = `${description} (${t('blocklet.config.sharedToAllComponents')})`;
|
|
29
|
+
} else {
|
|
30
|
+
description = t('blocklet.config.sharedToAllComponents');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return description && /*#__PURE__*/_jsx("div", {
|
|
34
|
+
style: {
|
|
35
|
+
marginLeft: 12
|
|
36
|
+
},
|
|
37
|
+
children: description
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
export default function ComponentEnvironment({
|
|
41
|
+
blocklet,
|
|
42
|
+
ancestors
|
|
43
|
+
}) {
|
|
44
|
+
const node = useNodeContext();
|
|
45
|
+
const {
|
|
46
|
+
inService
|
|
47
|
+
} = node;
|
|
48
|
+
const {
|
|
49
|
+
t
|
|
50
|
+
} = useContext(LocaleContext);
|
|
51
|
+
const dids = [...ancestors.map(x => x.meta.did), blocklet.meta.did];
|
|
52
|
+
const onConfigChanged = () => Toast.success(t('blocklet.config.changedTip'));
|
|
53
|
+
const isConfigEditable = x => x.custom;
|
|
54
|
+
if (isInstalling(blocklet.status)) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
if (blocklet.status === 'unknown' && isInstalling(blocklet.status)) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const onAddConfig = async data => {
|
|
61
|
+
if (!data.key.trim() || !data.value.trim()) {
|
|
62
|
+
Toast.error(t('blocklet.config.environment.keyValueRequired'));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (data.key.startsWith('BLOCKLET_') || data.key.startsWith('COMPONENT_')) {
|
|
66
|
+
Toast.error(t('blocklet.config.environment.invalidKey'));
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
data.custom = true;
|
|
70
|
+
const result = await node.api.configBlocklet({
|
|
71
|
+
input: {
|
|
72
|
+
did: dids,
|
|
73
|
+
configs: [data]
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
if (result.code === 'ok') {
|
|
77
|
+
onConfigChanged(result.blocklet);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const onEditConfig = async (newData, oldData) => {
|
|
81
|
+
// only required field can't be empty
|
|
82
|
+
if (newData.required && (!newData.key.trim() || !newData.value.trim())) {
|
|
83
|
+
Toast.error(t('blocklet.config.environment.keyValueRequired'));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (newData.key.startsWith('BLOCKLET_') && !BLOCKLET_CONFIGURABLE_KEY[newData.key]) {
|
|
87
|
+
Toast.error(t('blocklet.config.environment.invalidKey'));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (newData.key === BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_CLUSTER_SIZE) {
|
|
91
|
+
const errMessage = isValidClusterSize(newData);
|
|
92
|
+
if (errMessage) {
|
|
93
|
+
Toast.error(errMessage);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const configs = [newData];
|
|
98
|
+
if (newData.key !== oldData.key) {
|
|
99
|
+
if (!newData.custom) {
|
|
100
|
+
Toast.error('Only key of custom env can be changed');
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
configs.push({
|
|
104
|
+
key: oldData.key,
|
|
105
|
+
custom: true
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
const result = await node.api.configBlocklet({
|
|
110
|
+
input: {
|
|
111
|
+
did: dids,
|
|
112
|
+
configs
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
if (result.code === 'ok') {
|
|
116
|
+
onConfigChanged(result.blocklet);
|
|
117
|
+
}
|
|
118
|
+
} catch (err) {
|
|
119
|
+
Toast.error(formatError(err));
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const onDeleteConfig = async data => {
|
|
123
|
+
if (data.required) {
|
|
124
|
+
Toast.error(t('blocklet.config.environment.deleteForbidden'));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (!data.custom) {
|
|
128
|
+
Toast.error('Only key of custom env can be changed');
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const result = await node.api.configBlocklet({
|
|
132
|
+
input: {
|
|
133
|
+
did: dids,
|
|
134
|
+
configs: [{
|
|
135
|
+
key: data.key,
|
|
136
|
+
custom: true
|
|
137
|
+
}]
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
if (result.code === 'ok') {
|
|
141
|
+
onConfigChanged(result.blocklet);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// configs
|
|
146
|
+
const componentConfigs = (blocklet.configs || []).filter(x => !BLOCKLET_CONFIGURABLE_KEY[x.key]);
|
|
147
|
+
const sharedConfigObj = getSharedConfigObj(blocklet, ancestors);
|
|
148
|
+
const missingRequiredConfigs = getComponentMissingConfigs(blocklet, ancestors);
|
|
149
|
+
const configs = componentConfigs.map(x => ({
|
|
150
|
+
...x,
|
|
151
|
+
value: Object.values(CHAIN_PROP_MAP).includes(x.key) && Object.keys(sharedConfigObj).includes(x.key) ? sharedConfigObj[x.key] : sharedConfigObj[x.key] || x.value
|
|
152
|
+
}));
|
|
153
|
+
const hasBWAConfig = configs.some(x => x.key && x.key.startsWith('BWA_'));
|
|
154
|
+
const action = {
|
|
155
|
+
onRowAdd: onAddConfig,
|
|
156
|
+
onRowUpdate: onEditConfig,
|
|
157
|
+
onRowDelete: onDeleteConfig,
|
|
158
|
+
// environment declare in blocklet.yml can't be deleted, only custom env can be deleted
|
|
159
|
+
isDeletable: isConfigEditable
|
|
160
|
+
};
|
|
161
|
+
const onColumns = () => [{
|
|
162
|
+
title: t('common.key'),
|
|
163
|
+
field: 'key',
|
|
164
|
+
initialEditValue: 'Key',
|
|
165
|
+
width: '30%',
|
|
166
|
+
render: d => /*#__PURE__*/_jsx(ClickToCopy, {
|
|
167
|
+
value: d.value,
|
|
168
|
+
style: {
|
|
169
|
+
color: d.required && !d.value ? '#ff4436' : '#222222',
|
|
170
|
+
fontWeight: d.required ? 'bold' : 'normal'
|
|
171
|
+
},
|
|
172
|
+
children: d.key
|
|
173
|
+
}),
|
|
174
|
+
editComponent: props => {
|
|
175
|
+
const {
|
|
176
|
+
value,
|
|
177
|
+
rowData,
|
|
178
|
+
onChange
|
|
179
|
+
} = props;
|
|
180
|
+
return /*#__PURE__*/_jsx(EditDiv, {
|
|
181
|
+
children: /*#__PURE__*/_jsx(TextField, {
|
|
182
|
+
fullWidth: true,
|
|
183
|
+
size: "small",
|
|
184
|
+
disabled: isConfigEditable(rowData) === false,
|
|
185
|
+
value: value,
|
|
186
|
+
onChange: e => onChange(e.target.value),
|
|
187
|
+
variant: "outlined",
|
|
188
|
+
label: "Key",
|
|
189
|
+
placeholder: t('blocklet.config.environment.key'),
|
|
190
|
+
margin: "dense",
|
|
191
|
+
autoFocus: true
|
|
192
|
+
})
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}, {
|
|
196
|
+
title: t('common.value'),
|
|
197
|
+
field: 'value',
|
|
198
|
+
initialEditValue: 'Value',
|
|
199
|
+
width: 'calc((100% - (96px + 30%)) / 1)',
|
|
200
|
+
render: d => {
|
|
201
|
+
if (!d.value) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
if (d.secure) {
|
|
205
|
+
return '******';
|
|
206
|
+
}
|
|
207
|
+
return /*#__PURE__*/_jsx(ClickToCopy, {
|
|
208
|
+
unstyled: true,
|
|
209
|
+
value: d.value,
|
|
210
|
+
style: {
|
|
211
|
+
wordBreak: 'break-all'
|
|
212
|
+
},
|
|
213
|
+
children: d.value
|
|
214
|
+
});
|
|
215
|
+
},
|
|
216
|
+
// eslint-disable-next-line no-shadow
|
|
217
|
+
editComponent: props => {
|
|
218
|
+
const {
|
|
219
|
+
value,
|
|
220
|
+
rowData,
|
|
221
|
+
onChange
|
|
222
|
+
} = props;
|
|
223
|
+
return /*#__PURE__*/_jsxs(EditDiv, {
|
|
224
|
+
children: [/*#__PURE__*/_jsx(TextField, {
|
|
225
|
+
fullWidth: true,
|
|
226
|
+
size: "small",
|
|
227
|
+
value: value === '__encrypted__' ? '' : value,
|
|
228
|
+
onChange: e => onChange(e.target.value),
|
|
229
|
+
variant: "outlined",
|
|
230
|
+
label: t('common.value'),
|
|
231
|
+
placeholder: t('blocklet.config.environment.value'),
|
|
232
|
+
margin: "dense",
|
|
233
|
+
autoFocus: true
|
|
234
|
+
}), getDescription(rowData, t)]
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}];
|
|
238
|
+
return /*#__PURE__*/_jsxs(Div, {
|
|
239
|
+
children: [!!missingRequiredConfigs.length && /*#__PURE__*/_jsx(Alert, {
|
|
240
|
+
severity: "error",
|
|
241
|
+
style: {
|
|
242
|
+
marginTop: 24
|
|
243
|
+
},
|
|
244
|
+
children: t('blocklet.config.missingRequired')
|
|
245
|
+
}), hasBWAConfig && /*#__PURE__*/_jsx(Alert, {
|
|
246
|
+
severity: "info",
|
|
247
|
+
children: t('blocklet.config.environment.tip')
|
|
248
|
+
}), /*#__PURE__*/_jsx(Permission, {
|
|
249
|
+
permission: inService ? '' : 'mutate_blocklets',
|
|
250
|
+
role: inService ? BlockletAdminRoles : [],
|
|
251
|
+
children: hasPermission => /*#__PURE__*/_jsx(TableStyle, {
|
|
252
|
+
className: isBlockletDev(blocklet) ? 'readonly-block config-table' : 'config-table',
|
|
253
|
+
"data-disabled-text": t('blocklet.config.disabledText'),
|
|
254
|
+
children: /*#__PURE__*/_jsx(MaterialTable, {
|
|
255
|
+
title: /*#__PURE__*/_jsx("h4", {
|
|
256
|
+
children: t('common.environment')
|
|
257
|
+
}),
|
|
258
|
+
columns: onColumns(),
|
|
259
|
+
icons: {
|
|
260
|
+
...blockletIcons,
|
|
261
|
+
...tableIcons
|
|
262
|
+
},
|
|
263
|
+
options: {
|
|
264
|
+
emptyRowsWhenPaging: false,
|
|
265
|
+
actionsColumnIndex: -1,
|
|
266
|
+
tableLayout: 'auto',
|
|
267
|
+
maxBodyHeight: '100%',
|
|
268
|
+
paging: false,
|
|
269
|
+
search: false
|
|
270
|
+
},
|
|
271
|
+
localization: {
|
|
272
|
+
header: {
|
|
273
|
+
actions: t('common.actions')
|
|
274
|
+
},
|
|
275
|
+
body: {
|
|
276
|
+
emptyDataSourceMessage: t('common.noData')
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
data: configs,
|
|
280
|
+
editable: hasPermission ? action : {}
|
|
281
|
+
})
|
|
282
|
+
})
|
|
283
|
+
})]
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
ComponentEnvironment.propTypes = {
|
|
287
|
+
blocklet: PropTypes.object.isRequired,
|
|
288
|
+
ancestors: PropTypes.array
|
|
289
|
+
};
|
|
290
|
+
ComponentEnvironment.defaultProps = {
|
|
291
|
+
ancestors: []
|
|
292
|
+
};
|
|
293
|
+
const Div = styled.div`
|
|
294
|
+
.readonly-block {
|
|
295
|
+
position: relative;
|
|
296
|
+
&::after {
|
|
297
|
+
content: attr(data-disabled-text);
|
|
298
|
+
position: absolute;
|
|
299
|
+
display: flex;
|
|
300
|
+
align-items: center;
|
|
301
|
+
justify-content: center;
|
|
302
|
+
top: 0;
|
|
303
|
+
bottom: 0;
|
|
304
|
+
left: 0;
|
|
305
|
+
right: 0;
|
|
306
|
+
background-color: rgba(230, 230, 230, 0.7);
|
|
307
|
+
font-size: 24px;
|
|
308
|
+
letter-spacing: 2px;
|
|
309
|
+
color: #e33371;
|
|
310
|
+
padding: 20px;
|
|
311
|
+
word-break: break-all;
|
|
312
|
+
word-wrap: break-word;
|
|
313
|
+
z-index: 10;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
.config-table {
|
|
317
|
+
margin-bottom: 24px;
|
|
318
|
+
position: relative;
|
|
319
|
+
.hide-control {
|
|
320
|
+
position: absolute;
|
|
321
|
+
top: 10px;
|
|
322
|
+
left: 200px;
|
|
323
|
+
@media (max-width: ${props => props.theme.breakpoints.values.sm}px) {
|
|
324
|
+
left: 160px;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
.MuiToolbar-root {
|
|
329
|
+
display: flex;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
.MuiTableRow-head {
|
|
333
|
+
display: none;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
&.hide-header {
|
|
337
|
+
.MuiToolbar-root {
|
|
338
|
+
display: none;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
.accordion {
|
|
344
|
+
margin-bottom: 16px;
|
|
345
|
+
&:last-of-type {
|
|
346
|
+
margin-bottom: 0;
|
|
347
|
+
}
|
|
348
|
+
padding: 8px 0 8px 0px;
|
|
349
|
+
&.MuiAccordion-root {
|
|
350
|
+
background: transparent;
|
|
351
|
+
box-shadow: none;
|
|
352
|
+
border: 1px solid #ddd;
|
|
353
|
+
border-radius: 4px;
|
|
354
|
+
&::before,
|
|
355
|
+
&::after {
|
|
356
|
+
height: 0;
|
|
357
|
+
}
|
|
358
|
+
.MuiAccordionSummary-root {
|
|
359
|
+
padding-left: 0;
|
|
360
|
+
}
|
|
361
|
+
.accordion-title {
|
|
362
|
+
font-weight: bold;
|
|
363
|
+
padding-left: 16px;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
`;
|
|
368
|
+
const EditDiv = styled.div`
|
|
369
|
+
height: 60px;
|
|
370
|
+
`;
|