imbajin commented on code in PR #870:
URL:
https://github.com/apache/hugegraph-toolchain/pull/870#discussion_r4428727487
##########
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();
+ message.success(t('graph.clone.success'));
+ onCancel();
+ refresh();
Review Comment:
[P2] Ignore clone completions from a previous dialog instance
The clone request can outlive this dialog: submit for graph A, cancel, and
open Clone for graph B before A responds. Graph/index.js keeps CloneLayer
mounted and passes an unconditional setCloneLayer(false) callback, so A's
successful response reaches onCancel() here and closes B's newly opened form,
losing its unsubmitted input. The active flag above protects only the nickname
lookup, not this mutation. Please bind the mutation's UI callbacks/loading
cleanup to the current open/scope generation (or prevent closing/reopening
while it is pending), and add a deferred-response regression for cancel →
reopen → old response. This does not cancel or roll back the already-submitted
server POST; it prevents its stale response from controlling the new dialog.
Evidence: exact-head static cross-review plus a bounded test of the extracted
unchanged handleClone callback with a deferred API result, not browser/React or
Server integration testing.
Sources:
https://github.com/apache/hugegraph-toolchain/blob/629bbafdf441e27496aa26bd9fa3c5f92d445032/hugegraph-hubble/hubble-fe/src/pages/Graph/EditLayer.js#L548-L576
and
https://github.com/apache/hugegraph-toolchain/blob/629bbafdf441e27496aa26bd9fa3c5f92d445032/hugegraph-hubble/hubble-fe/src/pages/Graph/index.js#L719-L720
--
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]