Skip to content

Commit f8acb2b

Browse files
feat(ClusterInfo): add cores and logging links (#1731)
1 parent 9cdab88 commit f8acb2b

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

src/containers/Cluster/ClusterInfo/ClusterInfo.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {IResponseError} from '../../../types/api/error';
77
import type {VersionToColorMap} from '../../../types/versions';
88

99
import {b} from './shared';
10-
import {getInfo} from './utils';
10+
import {getInfo, useClusterLinks} from './utils';
1111

1212
import './ClusterInfo.scss';
1313

@@ -27,7 +27,9 @@ export const ClusterInfo = ({
2727
}: ClusterInfoProps) => {
2828
const {info = [], links = []} = additionalClusterProps;
2929

30-
const clusterInfo = getInfo(cluster ?? {}, info, links);
30+
const clusterLinks = useClusterLinks();
31+
32+
const clusterInfo = getInfo(cluster ?? {}, info, [...links, ...clusterLinks]);
3133

3234
const getContent = () => {
3335
if (loading) {

src/containers/Cluster/ClusterInfo/utils.tsx

+50
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ import type {InfoViewerItem} from '../../../components/InfoViewer/InfoViewer';
66
import {LinkWithIcon} from '../../../components/LinkWithIcon/LinkWithIcon';
77
import {ProgressViewer} from '../../../components/ProgressViewer/ProgressViewer';
88
import {Tags} from '../../../components/Tags';
9+
import {useClusterBaseInfo} from '../../../store/reducers/cluster/cluster';
910
import type {ClusterLink} from '../../../types/additionalProps';
1011
import {isClusterInfoV2} from '../../../types/api/cluster';
1112
import type {TClusterInfo} from '../../../types/api/cluster';
1213
import type {EFlag} from '../../../types/api/enums';
1314
import type {TTabletStateInfo} from '../../../types/api/tablet';
1415
import {EType} from '../../../types/api/tablet';
1516
import {formatNumber} from '../../../utils/dataFormatters/dataFormatters';
17+
import {parseJson} from '../../../utils/utils';
1618
import i18n from '../i18n';
1719

1820
import {NodesState} from './components/NodesState/NodesState';
1921
import {b} from './shared';
22+
2023
const COLORS_PRIORITY: Record<EFlag, number> = {
2124
Green: 5,
2225
Blue: 4,
@@ -103,3 +106,50 @@ export const getInfo = (
103106

104107
return info;
105108
};
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+
}

src/containers/Cluster/i18n/en.json

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
"storage-size": "Storage size",
1010
"storage-groups": "Storage groups, {{diskType}}",
1111
"links": "Links",
12+
"link_cores": "Cores",
13+
"link_logging": "Logging",
1214
"context_cores": "cores",
1315
"title_cpu": "CPU",
1416
"title_storage": "Storage",

src/types/api/meta.ts

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export interface MetaBaseClusterInfo {
3535
mvp_token?: string;
3636
name?: string;
3737
solomon?: string;
38+
cores?: string;
39+
logging?: string;
3840
status?: string;
3941
scale?: number;
4042
environment?: string;

0 commit comments

Comments
 (0)