1
1
import block from 'bem-cn-lite' ;
2
- import { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
2
+ import { useCallback , useEffect , useMemo , useState } from 'react' ;
3
3
import { useDispatch } from 'react-redux' ;
4
4
import { escapeRegExp } from 'lodash/fp' ;
5
5
@@ -53,8 +53,6 @@ export const Partitions = ({path, type, nodes, consumers}: PartitionsProps) => {
53
53
54
54
const dispatch = useDispatch ( ) ;
55
55
56
- const isFirstRenderRef = useRef ( true ) ;
57
-
58
56
const [ generalSearchValue , setGeneralSearchValue ] = useState ( '' ) ;
59
57
const [ partitionIdSearchValue , setPartitionIdSearchValue ] = useState ( '' ) ;
60
58
@@ -74,14 +72,6 @@ export const Partitions = ({path, type, nodes, consumers}: PartitionsProps) => {
74
72
useEffect ( ( ) => {
75
73
// Manual path control to ensure it updates with other values so no request with wrong params will be sent
76
74
setComponentCurrentPath ( path ) ;
77
-
78
- // Do not reset selected consumer on first effect call
79
- // To enable navigating to specific consumer
80
- if ( isFirstRenderRef . current ) {
81
- isFirstRenderRef . current = false ;
82
- } else {
83
- dispatch ( setSelectedConsumer ( undefined ) ) ;
84
- }
85
75
} , [ dispatch , path ] ) ;
86
76
87
77
const fetchConsumerData = useCallback (
@@ -90,11 +80,11 @@ export const Partitions = ({path, type, nodes, consumers}: PartitionsProps) => {
90
80
dispatch ( setDataWasNotLoaded ( ) ) ;
91
81
}
92
82
93
- if ( selectedConsumer ) {
83
+ if ( selectedConsumer && consumers && consumers . includes ( selectedConsumer ) ) {
94
84
dispatch ( getConsumer ( componentCurrentPath , selectedConsumer ) ) ;
95
85
}
96
86
} ,
97
- [ dispatch , selectedConsumer , componentCurrentPath ] ,
87
+ [ dispatch , selectedConsumer , componentCurrentPath , consumers ] ,
98
88
) ;
99
89
100
90
useAutofetcher ( fetchConsumerData , [ fetchConsumerData ] , autorefresh ) ;
@@ -111,10 +101,13 @@ export const Partitions = ({path, type, nodes, consumers}: PartitionsProps) => {
111
101
) ;
112
102
113
103
useEffect ( ( ) => {
114
- if ( consumersToSelect && consumersToSelect . length && ! selectedConsumer ) {
104
+ const shouldUpdateSelectedConsumer =
105
+ ! selectedConsumer || ( consumers && ! consumers . includes ( selectedConsumer ) ) ;
106
+
107
+ if ( consumersToSelect && consumersToSelect . length && shouldUpdateSelectedConsumer ) {
115
108
dispatch ( setSelectedConsumer ( consumersToSelect [ 0 ] . value ) ) ;
116
109
}
117
- } , [ dispatch , consumersToSelect , selectedConsumer ] ) ;
110
+ } , [ dispatch , consumersToSelect , selectedConsumer , consumers ] ) ;
118
111
119
112
const selectedColumns : string [ ] = useMemo (
120
113
( ) =>
0 commit comments