diff --git a/src/containers/Cluster/ClusterInfo/ClusterInfo.tsx b/src/containers/Cluster/ClusterInfo/ClusterInfo.tsx index d640abfd25..b2fd6be2e8 100644 --- a/src/containers/Cluster/ClusterInfo/ClusterInfo.tsx +++ b/src/containers/Cluster/ClusterInfo/ClusterInfo.tsx @@ -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'; @@ -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) { diff --git a/src/containers/Cluster/ClusterInfo/utils.tsx b/src/containers/Cluster/ClusterInfo/utils.tsx index d0718142ef..d72fb0e48d 100644 --- a/src/containers/Cluster/ClusterInfo/utils.tsx +++ b/src/containers/Cluster/ClusterInfo/utils.tsx @@ -6,6 +6,7 @@ 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'; @@ -13,10 +14,12 @@ 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 = { Green: 5, Blue: 4, @@ -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]); +} diff --git a/src/containers/Cluster/i18n/en.json b/src/containers/Cluster/i18n/en.json index 8ad4b9446f..391b5b1f49 100644 --- a/src/containers/Cluster/i18n/en.json +++ b/src/containers/Cluster/i18n/en.json @@ -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", diff --git a/src/types/api/meta.ts b/src/types/api/meta.ts index c530448757..0ea2b709be 100644 --- a/src/types/api/meta.ts +++ b/src/types/api/meta.ts @@ -35,6 +35,8 @@ export interface MetaBaseClusterInfo { mvp_token?: string; name?: string; solomon?: string; + cores?: string; + logging?: string; status?: string; scale?: number; environment?: string;