import React from 'react'; import {Checkbox, Loader} from '@gravity-ui/uikit'; import {Link} from 'react-router-dom'; import {ResponseError} from '../../../../components/Errors/ResponseError'; import {ProblemFilter} from '../../../../components/ProblemFilter/ProblemFilter'; import {getDefaultNodePath} from '../../../../routes'; import {useClusterWithProxy} from '../../../../store/reducers/cluster/cluster'; import {networkApi} from '../../../../store/reducers/network/network'; import type {TNetNodeInfo} from '../../../../types/api/netInfo'; import {cn} from '../../../../utils/cn'; import {useAutoRefreshInterval} from '../../../../utils/hooks'; import {useWithProblemsQueryParam} from '../../../../utils/hooks/useWithProblemsQueryParam'; import {NetworkPlaceholder} from './NetworkPlaceholder/NetworkPlaceholder'; import {NodeTooltipPopup} from './NodeTooltipPopup/NodeTooltipPopup'; import {Nodes} from './Nodes/Nodes'; import i18n from './i18n'; import {groupNodesByField} from './utils'; import './Network.scss'; const b = cn('network'); interface NetworkProps { database: string; databaseFullPath: string; } export function Network({database, databaseFullPath}: NetworkProps) { const useMetaProxy = useClusterWithProxy(); const [autoRefreshInterval] = useAutoRefreshInterval(); const {withProblems, handleWithProblemsChange} = useWithProblemsQueryParam(); const [clickedNode, setClickedNode] = React.useState(); const [showId, setShowId] = React.useState(false); const [showRacks, setShowRacks] = React.useState(false); const [nodeTooltip, setNodeTooltip] = React.useState<{ anchor: HTMLDivElement | null; data: { nodeId: number | string; connected?: number; capacity?: number; rack: string; } | null; }>({ anchor: null, data: null, }); const {currentData, isFetching, error} = networkApi.useGetNetworkInfoQuery( {database, databaseFullPath, useMetaProxy}, { pollingInterval: autoRefreshInterval, }, ); const loading = isFetching && currentData === undefined; const netWorkInfo = currentData; const nodes = React.useMemo( () => (netWorkInfo?.Tenants && netWorkInfo.Tenants[0].Nodes) ?? [], [netWorkInfo], ); const handleShowNodeTooltip = React.useCallback( ( anchor: HTMLDivElement, data: { nodeId: number | string; connected?: number; capacity?: number; rack: string; }, ) => { setNodeTooltip({anchor, data}); }, [], ); const handleHideNodeTooltip = React.useCallback(() => { setNodeTooltip({anchor: null, data: null}); }, []); const nodesGroupedByType = React.useMemo(() => groupNodesByField(nodes, 'NodeType'), [nodes]); const rightNodes = React.useMemo( () => (clickedNode ? groupNodesByField(clickedNode.Peers ?? [], 'NodeType') : {}), [clickedNode], ); if (loading) { return (
); } if (!error && nodes.length === 0) { return
{i18n('description_no-nodes-data')}
; } return (
{error ? : null} {nodes.length > 0 ? (
{ setShowId(!showId); }} checked={showId} > {i18n('field_id')}
{ setShowRacks(!showRacks); }} checked={showRacks} > {i18n('label_racks')}
{clickedNode ? (
{i18n('label_connectivity')}{' '} {clickedNode.NodeId} {' '} {i18n('label_to-other-nodes')}
) : ( )}
) : null}
); }