Skip to content

Commit 1cbec0e

Browse files
fix query data copy against other query on quickly switching b/w queries in query library
1 parent e7c415e commit 1cbec0e

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

client/packages/lowcoder/src/pages/queryLibrary/QueryLibraryEditor.tsx

+26-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { registryDataSourcePlugin } from "constants/queryConstants";
4747
import { messageInstance } from "lowcoder-design/src/components/GlobalInstances";
4848
import { Helmet } from "react-helmet";
4949
import {fetchQLPaginationByOrg} from "@lowcoder-ee/util/pagination/axios";
50+
import { isEmpty } from "lodash";
5051

5152
const Wrapper = styled.div`
5253
display: flex;
@@ -393,16 +394,38 @@ function useSaveQueryLibrary(
393394
const dispatch = useDispatch();
394395
const [prevComp, setPrevComp] = useState<Comp>();
395396
const [prevJsonStr, setPrevJsonStr] = useState<string>();
397+
const [prevQueryId, setPrevQueryId] = useState<string>();
398+
const queryId = query?.id;
396399

397400
useEffect(() => {
398-
if (!comp || comp === prevComp || !query || !comp?.children.query.children.id.getView()) {
401+
if (!comp || comp === prevComp) {
399402
return;
400403
}
404+
401405
const curJson = comp.toJsonValue();
402406
const curJsonStr = JSON.stringify(curJson);
407+
408+
if (isEmpty(curJson?.query?.comp)) {
409+
return;
410+
}
411+
if (!Boolean(prevQueryId) && Boolean(queryId)) {
412+
setPrevComp(comp);
413+
setPrevJsonStr(curJsonStr);
414+
return setPrevQueryId(queryId);
415+
}
416+
if (prevQueryId !== queryId) {
417+
setPrevComp(comp);
418+
setPrevJsonStr(curJsonStr);
419+
return setPrevQueryId(queryId);
420+
}
421+
if (!Boolean(prevJsonStr) && Boolean(curJsonStr)) {
422+
setPrevComp(comp)
423+
return setPrevJsonStr(curJsonStr);
424+
}
403425
if (prevJsonStr === curJsonStr) {
404426
return;
405427
}
428+
406429
// the first time is a normal change, the latter is the manual update
407430
if (prevComp) {
408431
query.name = comp.children.query.children.name.getView();
@@ -411,5 +434,6 @@ function useSaveQueryLibrary(
411434
}
412435
setPrevComp(comp);
413436
setPrevJsonStr(curJsonStr);
414-
}, [comp, query, prevComp, prevJsonStr, dispatch]);
437+
setPrevQueryId(queryId);
438+
}, [comp, queryId, dispatch]);
415439
}

0 commit comments

Comments
 (0)