@@ -17,6 +17,15 @@ import { AuthoritiesSearchContext } from '../../context';
17
17
const useAutoOpenDetailView = ( authorities , onOpenDetailView , isLoading = false , urlAuthorityId = '' ) => {
18
18
const { navigationSegmentValue } = useContext ( AuthoritiesSearchContext ) ;
19
19
const prevOpenedSingleAuthority = useRef ( null ) ;
20
+ const isBlockOnMount = useRef ( false ) ;
21
+
22
+ useEffect ( ( ) => {
23
+ // block auto-opening on page reload and redirection from quick marc.
24
+ if ( urlAuthorityId ) {
25
+ isBlockOnMount . current = true ;
26
+ }
27
+ // eslint-disable-next-line react-hooks/exhaustive-deps
28
+ } , [ ] ) ;
20
29
21
30
useEffect ( ( ) => {
22
31
// do nothing during loading, to be able to correctly compare the previously opened record with the current one.
@@ -32,14 +41,10 @@ const useAutoOpenDetailView = (authorities, onOpenDetailView, isLoading = false,
32
41
if ( navigationSegmentValue === navigationSegments . browse ) {
33
42
isDetailViewNeedsToBeOpen = authority ?. isAnchor && authority ?. isExactMatch ;
34
43
} else {
35
- // Check the record id so that when the third pane has a single record open and the user creates a record
36
- // on a different route and then is redirected back to the third pane, then the third pane should contain
37
- // the newly created record instead of the previously opened one.
38
- if ( urlAuthorityId ) {
39
- // A single record can be opened in two ways: when reloading the page with opened single record and when all
40
- // the conditions for auto-opening a single record are met. So let's save the record for both cases. This will
41
- // be used to compare the previously opened record with the current one.
44
+ if ( isBlockOnMount . current ) {
45
+ // record should be stored to avoid auto-opening after closing the third pane.
42
46
prevOpenedSingleAuthority . current = authority ;
47
+ isBlockOnMount . current = false ;
43
48
return ;
44
49
}
45
50
@@ -53,7 +58,7 @@ const useAutoOpenDetailView = (authorities, onOpenDetailView, isLoading = false,
53
58
prevOpenedSingleAuthority . current = authority ;
54
59
onOpenDetailView ( authority ) ;
55
60
}
56
- } , [ authorities , navigationSegmentValue , onOpenDetailView , urlAuthorityId , isLoading ] ) ;
61
+ } , [ authorities , navigationSegmentValue , onOpenDetailView , isLoading ] ) ;
57
62
} ;
58
63
59
64
export default useAutoOpenDetailView ;
0 commit comments