@@ -6,17 +6,20 @@ import type {InfoViewerItem} from '../../../components/InfoViewer/InfoViewer';
6
6
import { LinkWithIcon } from '../../../components/LinkWithIcon/LinkWithIcon' ;
7
7
import { ProgressViewer } from '../../../components/ProgressViewer/ProgressViewer' ;
8
8
import { Tags } from '../../../components/Tags' ;
9
+ import { useClusterBaseInfo } from '../../../store/reducers/cluster/cluster' ;
9
10
import type { ClusterLink } from '../../../types/additionalProps' ;
10
11
import { isClusterInfoV2 } from '../../../types/api/cluster' ;
11
12
import type { TClusterInfo } from '../../../types/api/cluster' ;
12
13
import type { EFlag } from '../../../types/api/enums' ;
13
14
import type { TTabletStateInfo } from '../../../types/api/tablet' ;
14
15
import { EType } from '../../../types/api/tablet' ;
15
16
import { formatNumber } from '../../../utils/dataFormatters/dataFormatters' ;
17
+ import { parseJson } from '../../../utils/utils' ;
16
18
import i18n from '../i18n' ;
17
19
18
20
import { NodesState } from './components/NodesState/NodesState' ;
19
21
import { b } from './shared' ;
22
+
20
23
const COLORS_PRIORITY : Record < EFlag , number > = {
21
24
Green : 5 ,
22
25
Blue : 4 ,
@@ -103,3 +106,50 @@ export const getInfo = (
103
106
104
107
return info ;
105
108
} ;
109
+
110
+ /**
111
+ * parses stringified json in format {url: "href"}
112
+ */
113
+ function prepareClusterLink ( rawLink ?: string ) {
114
+ try {
115
+ const linkObject = parseJson ( rawLink ) as unknown ;
116
+
117
+ if (
118
+ linkObject &&
119
+ typeof linkObject === 'object' &&
120
+ 'url' in linkObject &&
121
+ typeof linkObject . url === 'string'
122
+ ) {
123
+ return linkObject . url ;
124
+ }
125
+ } catch { }
126
+
127
+ return undefined ;
128
+ }
129
+
130
+ export function useClusterLinks ( ) {
131
+ const { cores, logging} = useClusterBaseInfo ( ) ;
132
+
133
+ return React . useMemo ( ( ) => {
134
+ const result : ClusterLink [ ] = [ ] ;
135
+
136
+ const coresLink = prepareClusterLink ( cores ) ;
137
+ const loggingLink = prepareClusterLink ( logging ) ;
138
+
139
+ if ( coresLink ) {
140
+ result . push ( {
141
+ title : i18n ( 'link_cores' ) ,
142
+ url : coresLink ,
143
+ } ) ;
144
+ }
145
+
146
+ if ( loggingLink ) {
147
+ result . push ( {
148
+ title : i18n ( 'link_logging' ) ,
149
+ url : loggingLink ,
150
+ } ) ;
151
+ }
152
+
153
+ return result ;
154
+ } , [ cores , logging ] ) ;
155
+ }
0 commit comments