diff --git a/src/pages/MetricDetail/index.tsx b/src/pages/MetricDetail/index.tsx index 71b8ea07..3d68ffae 100644 --- a/src/pages/MetricDetail/index.tsx +++ b/src/pages/MetricDetail/index.tsx @@ -15,7 +15,7 @@ import { SUPPORT_METRICS } from '@/utils/promQL'; import { Chart } from '@antv/g2'; import { configDetailChart, updateDetailChart } from '@/utils/chart/chart'; import { shouldCheckCluster } from '@/utils'; -import { Popover } from 'antd'; +import { Popover, Spin } from 'antd'; import Icon from '@/components/Icon'; import BaseLineEditModal from '@/components/BaseLineEditModal'; @@ -64,6 +64,8 @@ const mapState = (state: IRootState) => ({ serviceInstanceList: state.service.instanceList, metricsFilterValues: state.machine.metricsFilterValues, serviceMetricsFilterValues: state.service.metricsFilterValues, + serviceLoading: state.loading.models.service, + machineLoading: state.loading.models.machine, }); const mapDispatch: any = (dispatch: IDispatch) => ({ @@ -84,12 +86,15 @@ function MetricDetail(props: Props) { const { cluster, type, metricsFilterValues, serviceMetricsFilterValues, updateMetricsFiltervalues, updateServiceMetricsFiltervalues, instances, serviceInstanceList, - asyncFetchMachineMetricsData, aliasConfig, serviceMetric, asyncFetchServiceMetricsData, asyncGetSpaces } = props; + asyncFetchMachineMetricsData, aliasConfig, serviceMetric, asyncFetchServiceMetricsData, asyncGetSpaces, + serviceLoading, machineLoading } = props; const { metricName, metricType } = useParams(); const [dataSource, setDataSource] = useState([]); + const [showLoading, setShowLoading] = useState(false); + const curMetricsFilterValues = useMemo(() => isServiceMetric(metricType) ? serviceMetricsFilterValues : metricsFilterValues, [type, metricsFilterValues, serviceMetricsFilterValues]); const metricOption = useMemo(() => { @@ -113,6 +118,14 @@ function MetricDetail(props: Props) { return metricItem }, [metricName, metricType, serviceMetric]) + useEffect(() => { + if (isServiceMetric(metricType)) { + setShowLoading(serviceLoading && curMetricsFilterValues.frequency === 0) + } else { + setShowLoading(machineLoading && curMetricsFilterValues.frequency === 0) + } + }, [metricType, serviceLoading, machineLoading, curMetricsFilterValues.frequency]); + const metricChartRef = useRef(); const metricChart: any = useMemo(() => { @@ -131,7 +144,7 @@ function MetricDetail(props: Props) { metricChartRef.current = res; return res }, [metricOption]); - + useEffect(() => { if (!isServiceMetric(metricType)) return; const [start, end] = calcTimeRange(curMetricsFilterValues.timeRange); @@ -150,7 +163,7 @@ function MetricDetail(props: Props) { }) } }, [curMetricsFilterValues.timeRange, cluster, metricType]) - + useEffect(() => { if (pollingTimer) { clearTimeout(pollingTimer); @@ -265,6 +278,12 @@ function MetricDetail(props: Props) { }; const handleRefresh = () => { + if (isServiceMetric(metricType)) { + setShowLoading(!!serviceLoading); + } else { + setShowLoading(!!machineLoading); + } + getData(); } const renderChart = (chartInstance: Chart) => { @@ -295,61 +314,63 @@ function MetricDetail(props: Props) { }; return ( -
-
- { - isServiceMetric(metricType) ? ( - - ) : ( - - ) - } -
-
-
-
- {metricChart.metric?.metric} - {intl.get(`metric_description.${metricChart.metric?.metric}`)}
- } - > - - -
-
- metricChart.chartRef = ref} - renderChart={renderChart} - /> -
-
-
- - {intl.get('common.baseLine')} + +
+
+ { + isServiceMetric(metricType) ? ( + + ) : ( + + ) + } +
+
+
+
+ {metricChart.metric?.metric} + {intl.get(`metric_description.${metricChart.metric?.metric}`)}
+ } + > + + +
+
+ metricChart.chartRef = ref} + renderChart={renderChart} + /> +
+
+
+ + {intl.get('common.baseLine')} +
-
+ ) }