@@ -47,6 +47,7 @@ import { registryDataSourcePlugin } from "constants/queryConstants";
47
47
import { messageInstance } from "lowcoder-design/src/components/GlobalInstances" ;
48
48
import { Helmet } from "react-helmet" ;
49
49
import { fetchQLPaginationByOrg } from "@lowcoder-ee/util/pagination/axios" ;
50
+ import { isEmpty } from "lodash" ;
50
51
51
52
const Wrapper = styled . div `
52
53
display: flex;
@@ -393,16 +394,38 @@ function useSaveQueryLibrary(
393
394
const dispatch = useDispatch ( ) ;
394
395
const [ prevComp , setPrevComp ] = useState < Comp > ( ) ;
395
396
const [ prevJsonStr , setPrevJsonStr ] = useState < string > ( ) ;
397
+ const [ prevQueryId , setPrevQueryId ] = useState < string > ( ) ;
398
+ const queryId = query ?. id ;
396
399
397
400
useEffect ( ( ) => {
398
- if ( ! comp || comp === prevComp || ! query || ! comp ?. children . query . children . id . getView ( ) ) {
401
+ if ( ! comp || comp === prevComp ) {
399
402
return ;
400
403
}
404
+
401
405
const curJson = comp . toJsonValue ( ) ;
402
406
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
+ }
403
425
if ( prevJsonStr === curJsonStr ) {
404
426
return ;
405
427
}
428
+
406
429
// the first time is a normal change, the latter is the manual update
407
430
if ( prevComp ) {
408
431
query . name = comp . children . query . children . name . getView ( ) ;
@@ -411,5 +434,6 @@ function useSaveQueryLibrary(
411
434
}
412
435
setPrevComp ( comp ) ;
413
436
setPrevJsonStr ( curJsonStr ) ;
414
- } , [ comp , query , prevComp , prevJsonStr , dispatch ] ) ;
437
+ setPrevQueryId ( queryId ) ;
438
+ } , [ comp , queryId , dispatch ] ) ;
415
439
}
0 commit comments