import React from 'react'; import { chunk } from 'lodash'; import { v4 } from 'uuid'; import * as Metrics from 'components/common/Metrics'; import { Cluster } from 'generated-sources'; import { Tag } from 'components/common/Tag/Tag.styled'; import { Table } from 'components/common/table/Table/Table.styled'; import TableHeaderCell from 'components/common/table/TableHeaderCell/TableHeaderCell'; import BytesFormatted from 'components/common/BytesFormatted/BytesFormatted'; import { NavLink } from 'react-router-dom'; import { clusterTopicsPath } from 'lib/paths'; import Switch from 'components/common/Switch/Switch'; import * as S from './ClustersWidget.styled'; interface Props { clusters: Cluster[]; onlineClusters: Cluster[]; offlineClusters: Cluster[]; } interface ChunkItem { id: string; data: Cluster[]; } const ClustersWidget: React.FC = ({ clusters, onlineClusters, offlineClusters, }) => { const [showOfflineOnly, setShowOfflineOnly] = React.useState(false); const clusterList: ChunkItem[] = React.useMemo(() => { let list = clusters; if (showOfflineOnly) { list = offlineClusters; } return chunk(list, 2).map((data) => ({ id: v4(), data, })); }, [clusters, offlineClusters, showOfflineOnly]); const handleSwitch = () => setShowOfflineOnly(!showOfflineOnly); return ( <> Online}> {onlineClusters.length}{' '} clusters Offline}> {offlineClusters.length}{' '} clusters {clusterList.map((chunkItem) => ( {chunkItem.data.map((cluster) => ( ))}
{cluster.readOnly && readonly}{' '} {cluster.name} {cluster.version} {cluster.brokerCount} {cluster.onlinePartitionCount} {cluster.topicCount}
))} ); }; export default ClustersWidget;