bitflicker64 commented on code in PR #870:
URL:
https://github.com/apache/hugegraph-toolchain/pull/870#discussion_r4429088463
##########
hugegraph-hubble/hubble-fe/src/pages/Graph/EditLayer.js:
##########
@@ -530,140 +528,64 @@ const ViewLayer = ({visible, onCancel, graphspace,
graph}) => {
const CloneLayer = ({open, onCancel, refresh, graphspace, graph}) => {
const [form] = Form.useForm();
- const [graphspaceList, setGraphspaceList] = useState([]);
- const [detail, setDetail] = useState({});
const [loading, setLoading] = useState(false);
const {t} = useTranslation();
- const notEq = (str, msg) => ({
- validator(_, value) {
- if (value !== str) {
- return Promise.resolve();
- }
-
- return Promise.reject(new Error(msg));
- },
- });
-
- const handleClone = useCallback(() => {
- form.validateFields().then(res => {
- setLoading(true);
- api.manage.cloneGraph(graphspace, graph, {
- graphspace: res.graphspace,
- nickname: res.nickname,
- name: res.name,
- load_data: res.load_data,
- }).then(res => {
- setLoading(false);
- if (res.status === 200) {
- message.success(t('graph.clone.success'));
- onCancel();
- refresh();
- return;
- }
-
- message.error(res.message);
- });
- });
- }, [form, graphspace, graph, onCancel, refresh, t]);
-
useEffect(() => {
- if (!open) {
- return;
- }
-
+ if (!open) return;
+ form.resetFields();
+ let active = true;
api.manage.getGraph(graphspace, graph).then(res => {
- if (res.status === 200) {
- setDetail(res.data);
+ if (active && res.status === 200) {
form.setFieldsValue({
- name: res.data.name,
- nickname: t('graph.clone.nickname', {nickname:
res.data.nickname}),
+ nickname: t('graph.clone.nickname', {nickname:
res.data.nickname || graph}),
});
}
- });
-
- api.manage.getGraphSpaceList({page_size: -1}).then(res => {
- if (res.status === 200) {
- setGraphspaceList(res.data.records);
- return;
- }
- message.error(res.message);
- });
+ }).catch(() => {});
+ return () => { active = false; };
}, [open, graphspace, graph, form, t]);
+ const handleClone = async () => {
+ let values;
+ try {
+ values = await form.validateFields();
+ }
+ catch {
+ return;
+ }
+ setLoading(true);
+ try {
+ const res = await api.manage.cloneGraph(graphspace, graph, {
+ graphspace, name: values.name, nickname: values.nickname,
load_data: 0,
+ }, {suppressBusinessErrorToast: true});
+ if (res.status !== 200) throw new Error();
Review Comment:
Important: every failure shows `graph.clone.failed`, so a Server rejection
such as `The graph 'copy' has existed` tells the user that an unrelated
existing graph may be a partial clone to inspect. Show `res.message` when the
response carries one, and keep the partial-target warning for failures without
a Server reason.
##########
hugegraph-hubble/hubble-fe/src/pages/Graph/index.js:
##########
@@ -537,16 +536,11 @@ const Graph = () => {
},
{
key: 'clone',
- disabled: true,
- label: (
- <Tooltip title={cloneUnavailableHint}>
- <span
- aria-label={`${t('graph.menu.clone')}:
${cloneUnavailableHint}`}
- >
- {t('graph.menu.clone')}
- </span>
- </Tooltip>
- ),
+ disabled: !canManage || !graphCreateEnabled,
Review Comment:
Important: `graph_create_enabled` holds on every released Server, none of
which has `schema-clone`, so those users get an enabled `Clone Schema` action
that always fails where they saw a disabled action with
`graph.clone.unavailable` before. Gate the action on a `ServerCompatibility`
check for the endpoint, for example an API version bump in
apache/hugegraph#3439, and keep the disabled hint otherwise.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]