import React, { useMemo } from 'react'; import { MetricViewChartContent } from './MetricViewChartContent'; import { MetricViewChartHeader } from './MetricViewChartHeader'; import { useMetricIndividual, useUpdateMetric } from '@/api/buster_rest/metrics'; import { useMemoizedFn } from '@/hooks'; import { inputHasText } from '@/lib/text'; import { MetricChartEvaluation } from './MetricChartEvaluation'; import { ChartType } from '@/api/asset_interfaces/metric/charts/enum'; import { AnimatePresence, motion } from 'framer-motion'; import { cn } from '@/lib/classMerge'; export const MetricViewChart: React.FC<{ metricId: string }> = React.memo(({ metricId }) => { const { mutateAsync: updateMetric } = useUpdateMetric(); const { metric, metricData, metricDataError, isFetchedMetricData } = useMetricIndividual({ metricId }); const { title, description, time_frame, evaluation_score, evaluation_summary } = metric; const isTable = metric.chart_config.selectedChartType === ChartType.Table; const loadingData = !isFetchedMetricData; const errorData = !!metricDataError; const showEvaluation = !!evaluation_score && !!evaluation_summary; const onSetTitle = useMemoizedFn((title: string) => { if (inputHasText(title)) { updateMetric({ id: metricId, title }); } }); return (