Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/containers/Cluster/ClusterInfo/ClusterInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {IResponseError} from '../../../types/api/error';
import type {VersionToColorMap} from '../../../types/versions';

import {b} from './shared';
import {getInfo} from './utils';
import {getInfo, useClusterLinks} from './utils';

import './ClusterInfo.scss';

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

const clusterInfo = getInfo(cluster ?? {}, info, links);
const clusterLinks = useClusterLinks();

const clusterInfo = getInfo(cluster ?? {}, info, [...links, ...clusterLinks]);

const getContent = () => {
if (loading) {
Expand Down
50 changes: 50 additions & 0 deletions src/containers/Cluster/ClusterInfo/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import type {InfoViewerItem} from '../../../components/InfoViewer/InfoViewer';
import {LinkWithIcon} from '../../../components/LinkWithIcon/LinkWithIcon';
import {ProgressViewer} from '../../../components/ProgressViewer/ProgressViewer';
import {Tags} from '../../../components/Tags';
import {useClusterBaseInfo} from '../../../store/reducers/cluster/cluster';
import type {ClusterLink} from '../../../types/additionalProps';
import {isClusterInfoV2} from '../../../types/api/cluster';
import type {TClusterInfo} from '../../../types/api/cluster';
import type {EFlag} from '../../../types/api/enums';
import type {TTabletStateInfo} from '../../../types/api/tablet';
import {EType} from '../../../types/api/tablet';
import {formatNumber} from '../../../utils/dataFormatters/dataFormatters';
import {parseJson} from '../../../utils/utils';
import i18n from '../i18n';

import {NodesState} from './components/NodesState/NodesState';
import {b} from './shared';

const COLORS_PRIORITY: Record<EFlag, number> = {
Green: 5,
Blue: 4,
Expand Down Expand Up @@ -103,3 +106,50 @@ export const getInfo = (

return info;
};

/**
* parses stringified json in format {url: "href"}
*/
function prepareClusterLink(rawLink?: string) {
try {
const linkObject = parseJson(rawLink) as unknown;

if (
linkObject &&
typeof linkObject === 'object' &&
'url' in linkObject &&
typeof linkObject.url === 'string'
) {
return linkObject.url;
}
} catch {}

return undefined;
}

export function useClusterLinks() {
const {cores, logging} = useClusterBaseInfo();

return React.useMemo(() => {
const result: ClusterLink[] = [];

const coresLink = prepareClusterLink(cores);
const loggingLink = prepareClusterLink(logging);

if (coresLink) {
result.push({
title: i18n('link_cores'),
url: coresLink,
});
}

if (loggingLink) {
result.push({
title: i18n('link_logging'),
url: loggingLink,
});
}

return result;
}, [cores, logging]);
}
2 changes: 2 additions & 0 deletions src/containers/Cluster/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"storage-size": "Storage size",
"storage-groups": "Storage groups, {{diskType}}",
"links": "Links",
"link_cores": "Cores",
"link_logging": "Logging",
"context_cores": "cores",
"title_cpu": "CPU",
"title_storage": "Storage",
Expand Down
2 changes: 2 additions & 0 deletions src/types/api/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export interface MetaBaseClusterInfo {
mvp_token?: string;
name?: string;
solomon?: string;
cores?: string;
logging?: string;
status?: string;
scale?: number;
environment?: string;
Expand Down
Loading