import React, { useEffect, useState } from 'react'; import { useAnalyzeTopic, useCancelTopicAnalysis, useTopicAnalysis, } from 'lib/hooks/api/topics'; import useAppParams from 'lib/hooks/useAppParams'; import { RouteParamsClusterTopic } from 'lib/paths'; import * as Informers from 'components/common/Metrics'; import ProgressBar from 'components/common/ProgressBar/ProgressBar'; import { List, Label, } from 'components/common/PropertiesList/PropertiesList.styled'; import BytesFormatted from 'components/common/BytesFormatted/BytesFormatted'; import { useTimeFormat } from 'lib/hooks/useTimeFormat'; import { calculateTimer } from 'lib/dateTimeHelpers'; import { Action, ResourceType } from 'generated-sources'; import { ActionButton } from 'components/common/ActionComponent'; import * as S from './Statistics.styles'; import Total from './Indicators/Total'; import SizeStats from './Indicators/SizeStats'; import PartitionTable from './PartitionTable'; const Metrics: React.FC = () => { const formatTimestamp = useTimeFormat(); const params = useAppParams(); const [isAnalyzing, setIsAnalyzing] = useState(true); const analyzeTopic = useAnalyzeTopic(params); const cancelTopicAnalysis = useCancelTopicAnalysis(params); const { data } = useTopicAnalysis(params, isAnalyzing); useEffect(() => { if (data && !data.progress) { setIsAnalyzing(false); } }, [data]); if (!data) { return null; } if (data.progress) { return ( {Math.floor(data.progress.completenessPercent || 0)} % { await cancelTopicAnalysis.mutateAsync(); setIsAnalyzing(true); }} buttonType="primary" buttonSize="M" permission={{ resource: ResourceType.TOPIC, action: Action.MESSAGES_READ, value: params.topicName, }} > Stop Analysis {formatTimestamp(data.progress.startedAt, 'hh:mm:ss a')} {calculateTimer(data.progress.startedAt as number)} {data.progress.msgsScanned} ); } if (!data.result) { return null; } const totalStats = data.result.totalStats || {}; const partitionStats = data.result.partitionStats || []; return ( <> {formatTimestamp(data?.result?.finishedAt)} { await analyzeTopic.mutateAsync(); setIsAnalyzing(true); }} buttonType="primary" buttonSize="S" permission={{ resource: ResourceType.TOPIC, action: Action.MESSAGES_READ, value: params.topicName, }} > Restart Analysis {totalStats.keySize && ( )} {totalStats.valueSize && ( )} ); }; export default Metrics;