import React from 'react'; import {Card, DefinitionList, Divider, Flex, Text} from '@gravity-ui/uikit'; import {ResponseError} from '../../../components/Errors/ResponseError'; import {LinkWithIcon} from '../../../components/LinkWithIcon/LinkWithIcon'; import {Skeleton} from '../../../components/Skeleton/Skeleton'; import type {ClusterGroupsStats} from '../../../store/reducers/cluster/types'; import type {AdditionalClusterProps} from '../../../types/additionalProps'; import type {TBridgePile, TClusterInfo} from '../../../types/api/cluster'; import type {IResponseError} from '../../../types/api/error'; import {useClusterLinks} from '../../../utils/clusterLinks/useClusterLinks'; import {formatNumber} from '../../../utils/dataFormatters/dataFormatters'; import {BridgeInfoTable} from '../ClusterOverview/components/BridgeInfoTable'; import i18n from '../i18n'; import {StorageGroupStats} from './components/DiskGroupsStatsBars/DiskGroupsStats'; import {prepareClusterGroupsStats} from './components/DiskGroupsStatsBars/utils'; import {b} from './shared'; import './ClusterInfo.scss'; interface ClusterInfoProps { cluster?: TClusterInfo; clusterName?: string; loading?: boolean; error?: IResponseError | string; additionalClusterProps?: AdditionalClusterProps; groupStats?: ClusterGroupsStats; bridgePiles?: TBridgePile[]; } export const ClusterInfo = ({ cluster, clusterName, loading, error, additionalClusterProps = {}, groupStats, bridgePiles, }: ClusterInfoProps) => { const {info = [], links = []} = additionalClusterProps; const clusterLinks = useClusterLinks(links); const preparedGroupStats = React.useMemo( () => prepareClusterGroupsStats(groupStats ?? {}), [groupStats], ); const noDetails = (error && !cluster) || (!info.length && !clusterLinks.length); const renderDetailSection = () => { if (loading) { return ( ); } if (noDetails) { return null; } return ( {i18n('title_details')} {info.length > 0 && ( {info.map(({label, value}) => { return (
{value}
); })}
)} {clusterLinks.length > 0 && ( {clusterLinks.map(({title, url, icon, description}, index) => { const delimiter = index < clusterLinks.length - 1 ? ( ) : ( '' ); return ( {delimiter} ); })} )}
); }; const renderStorageGroupsSection = () => { if (loading || preparedGroupStats.disks.length === 0) { return null; } return ( ); }; const renderBridgePilesSection = () => { if (loading || !bridgePiles?.length) { return null; } return ( {i18n('title_bridge')}{' '} {formatNumber(bridgePiles.length)} ); }; return ( {error ? : null}
{renderDetailSection()} {renderStorageGroupsSection()} {renderBridgePilesSection()}
); }; interface InfoSectionProps { children: React.ReactNode; className?: string; dataQa?: string; } function InfoSection({children, className, dataQa}: InfoSectionProps) { return ( {children} ); }