1- import React , { useCallback , useEffect } from 'react' ;
1+ import { useCallback , useEffect , useMemo } from 'react' ;
22import { useDispatch } from 'react-redux' ;
33import { useLocation } from 'react-router' ;
44import block from 'bem-cn-lite' ;
55import qs from 'qs' ;
66
7- import { Link } from '@gravity-ui/uikit' ;
7+ import { Link , Progress } from '@gravity-ui/uikit' ;
88
99import EntityStatus from '../../components/EntityStatus/EntityStatus' ;
1010import ProgressViewer from '../../components/ProgressViewer/ProgressViewer' ;
@@ -15,14 +15,19 @@ import {Icon} from '../../components/Icon';
1515import { Loader } from '../../components/Loader' ;
1616import { ResponseError } from '../../components/Errors/ResponseError' ;
1717
18+ import type { AdditionalVersionsProps } from '../../types/additionalProps' ;
1819import { hideTooltip , showTooltip } from '../../store/reducers/tooltip' ;
1920import { getClusterInfo } from '../../store/reducers/cluster/cluster' ;
21+ import { getClusterNodes } from '../../store/reducers/clusterNodes/clusterNodes' ;
2022import { backend , customBackend } from '../../store' ;
2123import { setHeader } from '../../store/reducers/header' ;
2224import { formatStorageValues } from '../../utils' ;
2325import { useAutofetcher , useTypedSelector } from '../../utils/hooks' ;
26+ import { parseVersionsToVersionToColorMap , parseNodesToVersionsValues } from '../../utils/versions' ;
2427import routes , { CLUSTER_PAGES , createHref } from '../../routes' ;
2528
29+ import { Versions } from '../Versions/Versions' ;
30+
2631import { compareTablets } from './utils' ;
2732
2833import './ClusterInfo.scss' ;
@@ -32,9 +37,14 @@ const b = block('cluster-info');
3237interface ClusterInfoProps {
3338 clusterTitle ?: string ;
3439 additionalClusterInfo ?: InfoViewerItem [ ] ;
40+ additionalVersionsProps ?: AdditionalVersionsProps ;
3541}
3642
37- export const ClusterInfo = ( { clusterTitle, additionalClusterInfo = [ ] } : ClusterInfoProps ) => {
43+ export const ClusterInfo = ( {
44+ clusterTitle,
45+ additionalClusterInfo = [ ] ,
46+ additionalVersionsProps,
47+ } : ClusterInfoProps ) => {
3848 const dispatch = useDispatch ( ) ;
3949 const location = useLocation ( ) ;
4050
@@ -44,6 +54,12 @@ export const ClusterInfo = ({clusterTitle, additionalClusterInfo = []}: ClusterI
4454 const { clusterName} = queryParams ;
4555
4656 const { data : cluster , loading, wasLoaded, error} = useTypedSelector ( ( state ) => state . cluster ) ;
57+ const {
58+ nodes,
59+ loading : nodesLoading ,
60+ wasLoaded : nodesWasLoaded ,
61+ error : nodesError ,
62+ } = useTypedSelector ( ( state ) => state . clusterNodes ) ;
4763 const singleClusterMode = useTypedSelector ( ( state ) => state . singleClusterMode ) ;
4864
4965 useEffect ( ( ) => {
@@ -59,10 +75,22 @@ export const ClusterInfo = ({clusterTitle, additionalClusterInfo = []}: ClusterI
5975
6076 const fetchData = useCallback ( ( ) => {
6177 dispatch ( getClusterInfo ( clusterName ? String ( clusterName ) : undefined ) ) ;
78+ dispatch ( getClusterNodes ( ) ) ;
6279 } , [ dispatch , clusterName ] ) ;
6380
6481 useAutofetcher ( fetchData , [ fetchData ] , true ) ;
6582
83+ const versionToColor = useMemo ( ( ) => {
84+ if ( additionalVersionsProps ?. getVersionToColorMap ) {
85+ return additionalVersionsProps ?. getVersionToColorMap ( ) ;
86+ }
87+ return parseVersionsToVersionToColorMap ( cluster ?. Versions ) ;
88+ } , [ additionalVersionsProps , cluster ] ) ;
89+
90+ const versionsValues = useMemo ( ( ) => {
91+ return parseNodesToVersionsValues ( nodes , versionToColor ) ;
92+ } , [ nodes , versionToColor ] ) ;
93+
6694 const onShowTooltip = ( ...args : Parameters < typeof showTooltip > ) => {
6795 dispatch ( showTooltip ( ...args ) ) ;
6896 } ;
@@ -128,39 +156,52 @@ export const ClusterInfo = ({clusterTitle, additionalClusterInfo = []}: ClusterI
128156 return info ;
129157 } ;
130158
131- if ( loading && ! wasLoaded ) {
159+ if ( ( loading && ! wasLoaded ) || ( nodesLoading && ! nodesWasLoaded ) ) {
132160 return < Loader size = "l" /> ;
133161 }
134162
135- if ( error ) {
136- return < ResponseError error = { error } /> ;
163+ if ( error || nodesError ) {
164+ return < ResponseError error = { error || nodesError } /> ;
137165 }
138- return (
139- < React . Fragment >
140- < div className = { b ( 'common' ) } >
141- < div className = { b ( 'url' ) } >
142- < EntityStatus
143- size = "m"
144- status = { cluster ?. Overall }
145- name = { clusterTitle ?? cluster ?. Name ?? 'Unknown cluster' }
146- />
147- </ div >
148-
149- { cluster ?. DataCenters && < Tags tags = { cluster ?. DataCenters } /> }
150166
151- < div className = { b ( 'system-tablets' ) } >
152- { cluster ?. SystemTablets &&
153- cluster . SystemTablets . sort ( compareTablets ) . map ( ( tablet , tabletIndex ) => (
154- < Tablet
155- onMouseEnter = { onShowTooltip }
156- onMouseLeave = { onHideTooltip }
157- key = { tabletIndex }
158- tablet = { tablet }
167+ return (
168+ < div className = { b ( ) } >
169+ < div className = { b ( 'header' ) } >
170+ < div className = "info" >
171+ < div className = { b ( 'common' ) } >
172+ < div className = { b ( 'url' ) } >
173+ < EntityStatus
174+ size = "m"
175+ status = { cluster ?. Overall }
176+ name = { clusterTitle ?? cluster ?. Name ?? 'Unknown cluster' }
159177 />
160- ) ) }
178+ </ div >
179+
180+ { cluster ?. DataCenters && < Tags tags = { cluster ?. DataCenters } /> }
181+
182+ < div className = { b ( 'system-tablets' ) } >
183+ { cluster ?. SystemTablets &&
184+ cluster . SystemTablets . sort ( compareTablets ) . map (
185+ ( tablet , tabletIndex ) => (
186+ < Tablet
187+ onMouseEnter = { onShowTooltip }
188+ onMouseLeave = { onHideTooltip }
189+ key = { tabletIndex }
190+ tablet = { tablet }
191+ />
192+ ) ,
193+ ) }
194+ </ div >
195+ </ div >
196+ < InfoViewer dots = { true } info = { getInfo ( ) } />
197+ </ div >
198+ < div className = { b ( 'version-progress' ) } >
199+ < h3 className = { b ( 'progress-label' ) } > Versions</ h3 >
200+ < Progress value = { 100 } stack = { versionsValues } />
161201 </ div >
162202 </ div >
163- < InfoViewer dots = { true } info = { getInfo ( ) } />
164- </ React . Fragment >
203+
204+ < Versions nodes = { nodes } versionToColor = { versionToColor } />
205+ </ div >
165206 ) ;
166207} ;
0 commit comments