1
1
import React from 'react' ;
2
2
3
- import { CircleCheckFill , CircleXmarkFill } from '@gravity-ui/icons ' ;
4
- import { DefinitionList , Flex , Icon , Label , Text } from '@gravity-ui/uikit' ;
3
+ import { DefinitionList , Flex , Label , Text } from '@gravity-ui/uikit ' ;
4
+ import type { LabelProps } from '@gravity-ui/uikit' ;
5
5
6
6
import type { TBridgePile } from '../../../../types/api/cluster' ;
7
+ import { BridgePileState } from '../../../../types/api/cluster' ;
7
8
import { cn } from '../../../../utils/cn' ;
8
9
import { EMPTY_DATA_PLACEHOLDER } from '../../../../utils/constants' ;
9
10
import { formatNumber } from '../../../../utils/dataFormatters/dataFormatters' ;
@@ -13,6 +14,27 @@ import './BridgeInfoTable.scss';
13
14
14
15
const b = cn ( 'bridge-info-table' ) ;
15
16
17
+ function getBridgePileStateTheme ( state ?: string ) : NonNullable < LabelProps [ 'theme' ] > {
18
+ if ( ! state ) {
19
+ return 'unknown' ;
20
+ }
21
+
22
+ switch ( state . toUpperCase ( ) ) {
23
+ case BridgePileState . PRIMARY :
24
+ case BridgePileState . PROMOTE :
25
+ case BridgePileState . SYNCHRONIZED :
26
+ return 'success' ; // Green - healthy states
27
+ case BridgePileState . NOT_SYNCHRONIZED :
28
+ return 'warning' ; // Yellow - needs attention
29
+ case BridgePileState . SUSPENDED :
30
+ case BridgePileState . DISCONNECTED :
31
+ return 'danger' ; // Red - critical states
32
+ case BridgePileState . UNSPECIFIED :
33
+ default :
34
+ return 'unknown' ; // Purple - unknown state
35
+ }
36
+ }
37
+
16
38
interface BridgeInfoTableProps {
17
39
piles : TBridgePile [ ] ;
18
40
}
@@ -22,57 +44,17 @@ interface BridgePileCardProps {
22
44
}
23
45
24
46
const BridgePileCard = React . memo ( function BridgePileCard ( { pile} : BridgePileCardProps ) {
25
- const renderPrimaryStatus = React . useCallback ( ( ) => {
26
- const isPrimary = pile . IsPrimary ;
27
- const icon = isPrimary ? CircleCheckFill : CircleXmarkFill ;
28
- const text = isPrimary ? i18n ( 'value_yes' ) : i18n ( 'value_no' ) ;
29
-
30
- return (
31
- < Flex gap = { 1 } alignItems = "center" >
32
- < Icon data = { icon } size = { 16 } className = { b ( 'status-icon' , { primary : isPrimary } ) } />
33
- < Text color = "secondary" > { text } </ Text >
34
- </ Flex >
35
- ) ;
36
- } , [ pile . IsPrimary ] ) ;
37
-
38
47
const renderStateStatus = React . useCallback ( ( ) => {
39
48
if ( ! pile . State ) {
40
49
return EMPTY_DATA_PLACEHOLDER ;
41
50
}
42
51
43
- const isSynchronized = pile . State . toUpperCase ( ) === 'SYNCHRONIZED' ;
44
- const theme = isSynchronized ? 'success' : 'info' ;
45
-
52
+ const theme = getBridgePileStateTheme ( pile . State ) ;
46
53
return < Label theme = { theme } > { pile . State } </ Label > ;
47
54
} , [ pile . State ] ) ;
48
55
49
- const renderBeingPromotedStatus = React . useCallback ( ( ) => {
50
- const isBeingPromoted = pile . IsBeingPromoted ;
51
- const icon = isBeingPromoted ? CircleCheckFill : CircleXmarkFill ;
52
- const text = isBeingPromoted ? i18n ( 'value_yes' ) : i18n ( 'value_no' ) ;
53
-
54
- return (
55
- < Flex gap = { 1 } alignItems = "center" >
56
- < Icon
57
- data = { icon }
58
- size = { 16 }
59
- className = { b ( 'status-icon' , { primary : isBeingPromoted } ) }
60
- />
61
- < Text color = "secondary" > { text } </ Text >
62
- </ Flex >
63
- ) ;
64
- } , [ pile . IsBeingPromoted ] ) ;
65
-
66
56
const info = React . useMemo (
67
57
( ) => [
68
- {
69
- name : i18n ( 'field_primary' ) ,
70
- content : renderPrimaryStatus ( ) ,
71
- } ,
72
- {
73
- name : i18n ( 'field_being-promoted' ) ,
74
- content : renderBeingPromotedStatus ( ) ,
75
- } ,
76
58
{
77
59
name : i18n ( 'field_state' ) ,
78
60
content : renderStateStatus ( ) ,
@@ -83,7 +65,7 @@ const BridgePileCard = React.memo(function BridgePileCard({pile}: BridgePileCard
83
65
pile . Nodes === undefined ? EMPTY_DATA_PLACEHOLDER : formatNumber ( pile . Nodes ) ,
84
66
} ,
85
67
] ,
86
- [ renderPrimaryStatus , renderBeingPromotedStatus , renderStateStatus , pile . Nodes ] ,
68
+ [ renderStateStatus , pile . Nodes ] ,
87
69
) ;
88
70
89
71
return (
0 commit comments