import React from 'react'; import * as Metrics from 'components/common/Metrics'; import { Tag } from 'components/common/Tag/Tag.styled'; import Switch from 'components/common/Switch/Switch'; import { useClusters } from 'lib/hooks/api/clusters'; import { Cluster, ServerStatus } from 'generated-sources'; import { ColumnDef } from '@tanstack/react-table'; import Table, { SizeCell } from 'components/common/NewTable'; import * as S from './ClustersWidget.styled'; import ClusterName from './ClusterName'; const ClustersWidget: React.FC = () => { const { data } = useClusters(); const [showOfflineOnly, setShowOfflineOnly] = React.useState(false); const config = React.useMemo(() => { const clusters = data || []; const offlineClusters = clusters.filter( ({ status }) => status === ServerStatus.OFFLINE ); return { list: showOfflineOnly ? offlineClusters : clusters, online: clusters.length - offlineClusters.length, offline: offlineClusters.length, }; }, [data, showOfflineOnly]); const columns = React.useMemo[]>( () => [ { header: 'Cluster name', accessorKey: 'name', cell: ClusterName }, { header: 'Version', accessorKey: 'version' }, { header: 'Brokers count', accessorKey: 'brokerCount' }, { header: 'Partitions', accessorKey: 'onlinePartitionCount' }, { header: 'Topics', accessorKey: 'topicCount' }, { header: 'Production', accessorKey: 'bytesInPerSec', cell: SizeCell }, { header: 'Consumption', accessorKey: 'bytesOutPerSec', cell: SizeCell }, ], [] ); const handleSwitch = () => setShowOfflineOnly(!showOfflineOnly); return ( <> Online}> {config.online}{' '} clusters Offline}> {config.offline}{' '} clusters ); }; export default ClustersWidget;