11import React , { useEffect } from 'react' ;
2- import { useDispatch , useSelector } from 'react-redux' ;
2+ import { useDispatch } from 'react-redux' ;
33import cn from 'bem-cn-lite' ;
4- import { useHistory , useLocation } from 'react-router' ;
4+ import { useHistory } from 'react-router' ;
55import { Breadcrumbs , BreadcrumbsItem , Link } from '@gravity-ui/uikit' ;
66
77import Divider from '../../components/Divider/Divider' ;
88import { Icon } from '../../components/Icon' ;
99
10- import { clusterName as clusterNameLocation , backend , customBackend } from '../../store' ;
11- import { getClusterInfo } from '../../store/reducers/cluster/cluster' ;
10+ import { backend , customBackend } from '../../store' ;
1211import { getHostInfo } from '../../store/reducers/host' ;
1312import { HeaderItemType } from '../../store/reducers/header' ;
13+ import { useTypedSelector } from '../../utils/hooks' ;
1414
1515import './Header.scss' ;
1616
@@ -31,26 +31,19 @@ interface HeaderProps {
3131
3232function Header ( { clusterName} : HeaderProps ) {
3333 const dispatch = useDispatch ( ) ;
34- const { data : host } : { data : { ClusterName ?: string } } = useSelector ( ( state : any ) => state . host ) ;
34+
3535 const { singleClusterMode, header} : { singleClusterMode : boolean ; header : HeaderItemType [ ] } =
36- useSelector ( ( state : any ) => state ) ;
36+ useTypedSelector ( ( state ) => state ) ;
37+ const { data : host } = useTypedSelector ( ( state ) => state . host ) ;
3738
38- const location = useLocation ( ) ;
3939 const history = useHistory ( ) ;
4040
41- const { pathname} = location ;
42-
4341 useEffect ( ( ) => {
44- const isClustersPage = pathname . includes ( '/clusters' ) ;
45-
46- if ( ! isClustersPage && ! clusterName && ! singleClusterMode ) {
47- dispatch ( getClusterInfo ( clusterNameLocation ) ) ;
48- }
4942 dispatch ( getHostInfo ( ) ) ;
50- } , [ ] ) ;
43+ } , [ dispatch ] ) ;
5144
5245 const renderHeader = ( ) => {
53- const clusterNameFinal = singleClusterMode ? host . ClusterName : clusterName ;
46+ const clusterNameFinal = singleClusterMode ? host ? .ClusterName : clusterName ;
5447
5548 let link = backend + '/internal' ;
5649
0 commit comments