/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { Spin, Tooltip } from '@douyinfe/semi-ui';
import { Grid3x3 } from 'lucide-react';
import { fmtInt, fmtTs, pct, qualityErrorText } from './qualityConstants';
import { QualityMetaNotice } from './QualityOverview';
/**
* 渠道 × 时间 上游故障率热力图(仅平台侧)。
* 色阶由 --semi-color-danger 按故障率混入,跟随主题;点击格子下钻到该渠道该时段。
*/
const QualityHeatmap = ({ quality, t }) => {
const { get, params, setFilters } = quality;
const [data, setData] = useState(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
const seq = useRef(0);
useEffect(() => {
const current = ++seq.current;
setLoading(true);
setError('');
get('/heatmap', { ...params, top: 20 })
.then((d) => current === seq.current && setData(d))
.catch((e) => {
if (current !== seq.current) return;
setData(null);
setError(e.code || 'query_failed');
})
.finally(() => current === seq.current && setLoading(false));
}, [get, params]);
const gran = data?.meta?.granularity || 3600;
const timeline = useMemo(() => {
const set = new Set();
(data?.rows || []).forEach((row) =>
(row.cells || []).forEach((c) => set.add(c.ts)),
);
return Array.from(set).sort((a, b) => a - b);
}, [data]);
const rows = data?.rows || [];
const names = data?.channel_names || {};
return (