Files
upstream-mirror 30810eecd7
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:21:02 +05:00

120 lines
2.9 KiB
TypeScript

import { useStableCallback } from '@rocket.chat/fuselage-hooks';
import { useToastMessageDispatch, useEndpoint } from '@rocket.chat/ui-contexts';
import type * as chartjs from 'chart.js';
import { useEffect, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { secondsToHHMMSS } from '../../../../lib/utils/secondsToHHMMSS';
import { drawLineChart } from '../chartHandler';
import Chart from '../realTimeMonitoring/charts/Chart';
const getChartTooltips = (chartName: string) => {
switch (chartName) {
case 'Avg_chat_duration':
case 'Avg_first_response_time':
case 'Best_first_response_time':
case 'Avg_response_time':
case 'Avg_reaction_time':
return {
callbacks: {
title([ctx]: [chartjs.TooltipItem<'line'>]) {
const { dataset } = ctx;
return dataset.label;
},
label(ctx: chartjs.TooltipItem<'line'>) {
const { dataset, dataIndex } = ctx;
const item = dataset.data[dataIndex];
return secondsToHHMMSS(typeof item === 'number' ? item : 0);
},
},
};
default:
return {};
}
};
const InterchangeableChart = ({
departmentId,
dateRange,
chartName,
...props
}: {
departmentId: string;
dateRange: { start: string; end: string };
chartName: string;
flexShrink: number;
height: string;
width: string;
alignSelf: string;
}) => {
const { t } = useTranslation();
const dispatchToastMessage = useToastMessageDispatch();
const canvas = useRef<HTMLCanvasElement | null>(null);
const context = useRef<chartjs.Chart<'line', number[], string>>(undefined);
const { start, end } = dateRange;
const loadData = useEndpoint('GET', '/v1/livechat/analytics/dashboards/charts-data');
const draw = useStableCallback(
async (params: {
daterange: {
from: string;
to: string;
};
chartOptions: {
name: string;
};
departmentId?: string;
}) => {
try {
const tooltipCallbacks = getChartTooltips(chartName);
if (!params?.daterange?.from || !params?.daterange?.to) {
return;
}
const result = await loadData({
chartName,
start,
end,
...(departmentId && { departmentId }),
});
if (!result?.dataLabels || !result?.dataPoints) {
throw new Error('Error! fetching chart data.');
}
(context.current || typeof context.current === 'undefined') &&
canvas.current &&
(context.current = await drawLineChart(
canvas.current,
context.current,
[result.chartLabel],
result.dataLabels,
[result.dataPoints],
{
tooltipCallbacks,
},
));
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
},
);
useEffect(() => {
draw({
daterange: {
from: start,
to: end,
},
chartOptions: { name: chartName },
...(departmentId && { departmentId }),
});
}, [chartName, departmentId, draw, end, start, t, loadData]);
return <Chart canvasRef={canvas} {...props} />;
};
export default InterchangeableChart;