14
14
* limitations under the License.
15
15
*/
16
16
17
- import { useEffect , useState } from 'react'
17
+ import { useMemo } from 'react'
18
18
import { NavLink } from 'react-router-dom'
19
19
20
20
import { ReactComponent as ErrorInfo } from '../../../Assets/Icon/ic-errorInfo.svg'
@@ -24,33 +24,21 @@ import { AppDetailsErrorType, ErrorBarType } from './types'
24
24
import { renderErrorHeaderMessage } from './utils'
25
25
26
26
const ErrorBar = ( { appDetails } : ErrorBarType ) => {
27
- const [ isImagePullBackOff , setIsImagePullBackOff ] = useState ( false )
28
-
29
- useEffect ( ( ) => {
30
- if ( appDetails . appType === AppType . DEVTRON_APP && appDetails . resourceTree ?. nodes ?. length ) {
31
- for ( let index = 0 ; index < appDetails . resourceTree . nodes . length ; index ++ ) {
32
- const node = appDetails . resourceTree . nodes [ index ]
33
- let _isImagePullBackOff = false
34
- if ( node . info ?. length ) {
35
- for ( let idx = 0 ; idx < node . info . length ; idx ++ ) {
36
- const info = node . info [ idx ]
37
- if (
38
- info . value &&
39
- ( info . value . toLowerCase ( ) === AppDetailsErrorType . ERRIMAGEPULL ||
40
- info . value . toLowerCase ( ) === AppDetailsErrorType . IMAGEPULLBACKOFF )
41
- ) {
42
- _isImagePullBackOff = true
43
- break
44
- }
45
- }
46
-
47
- if ( _isImagePullBackOff ) {
48
- setIsImagePullBackOff ( true )
49
- break
50
- }
51
- }
52
- }
27
+ const isImagePullBackOff = useMemo ( ( ) => {
28
+ if ( appDetails ?. appType === AppType . DEVTRON_APP && appDetails ?. resourceTree ?. nodes ?. length ) {
29
+ appDetails . resourceTree . nodes . some (
30
+ ( node ) =>
31
+ ! ! node . info ?. some ( ( info ) => {
32
+ const infoValueLowerCase = info ?. value ?. toLowerCase ( )
33
+ return (
34
+ infoValueLowerCase === AppDetailsErrorType . ERRIMAGEPULL ||
35
+ infoValueLowerCase === AppDetailsErrorType . IMAGEPULLBACKOFF
36
+ )
37
+ } ) ,
38
+ )
53
39
}
40
+
41
+ return false
54
42
} , [ appDetails ] )
55
43
56
44
if (
0 commit comments