mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 08:02:15 +03:00
console: add tooltip to db latency badge
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9525 GitOrigin-RevId: e4bd2629946ccb24d609d2643e8032e5d8a1992c
This commit is contained in:
parent
45f2d8f52d
commit
81bb636069
@ -1,38 +1,72 @@
|
|||||||
|
import { useMemo } from 'react';
|
||||||
import { FaCheck, FaExclamationTriangle, FaMinusCircle } from 'react-icons/fa';
|
import { FaCheck, FaExclamationTriangle, FaMinusCircle } from 'react-icons/fa';
|
||||||
|
import ToolTip from '../../../../../../lib/components/Common/Tooltip/Tooltip';
|
||||||
|
import { Badge, BadgeColor } from '../../../../../new-components/Badge';
|
||||||
import { Latency } from '../../../types';
|
import { Latency } from '../../../types';
|
||||||
import { Badge } from '../../../../../new-components/Badge';
|
|
||||||
import React from 'react';
|
|
||||||
|
|
||||||
export const LatencyBadge = ({
|
type AvgLatency = Latency['avgLatency'];
|
||||||
latencies,
|
|
||||||
dataSourceName,
|
type GetBadgeProps = {
|
||||||
}: {
|
color: BadgeColor;
|
||||||
|
icon: React.ReactNode;
|
||||||
|
label: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type LatencyBadgeProps = {
|
||||||
latencies: Latency[];
|
latencies: Latency[];
|
||||||
dataSourceName: string;
|
dataSourceName: string;
|
||||||
}) => {
|
};
|
||||||
const currentDataSourceLatencyInfo = latencies.find(
|
|
||||||
latencyInfo => latencyInfo.dataSourceName === dataSourceName
|
const getMessage = (avgLatency: AvgLatency) =>
|
||||||
|
`Latency: ${Math.ceil(avgLatency)} ms`;
|
||||||
|
|
||||||
|
const getBadgeProps = (avgLatency: AvgLatency): GetBadgeProps => {
|
||||||
|
if (avgLatency < 100) {
|
||||||
|
return {
|
||||||
|
color: 'green',
|
||||||
|
icon: <FaCheck className="mr-xs" />,
|
||||||
|
label: 'Connection',
|
||||||
|
};
|
||||||
|
} else if (avgLatency < 200) {
|
||||||
|
return {
|
||||||
|
color: 'yellow',
|
||||||
|
icon: <FaMinusCircle className="mr-xs" />,
|
||||||
|
label: 'Acceptable',
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
color: 'red',
|
||||||
|
icon: <FaExclamationTriangle className="mr-xs" />,
|
||||||
|
label: 'Elevated Latency',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const LatencyBadge = ({
|
||||||
|
latencies = [],
|
||||||
|
dataSourceName,
|
||||||
|
}: LatencyBadgeProps) => {
|
||||||
|
const currentDataSourceLatencyInfo = useMemo(
|
||||||
|
() =>
|
||||||
|
latencies.find(
|
||||||
|
latencyInfo => latencyInfo.dataSourceName === dataSourceName
|
||||||
|
),
|
||||||
|
[latencies, dataSourceName]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!currentDataSourceLatencyInfo) return null;
|
if (!currentDataSourceLatencyInfo) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (currentDataSourceLatencyInfo.avgLatency < 100)
|
const { avgLatency } = currentDataSourceLatencyInfo || {};
|
||||||
return (
|
const message = getMessage(avgLatency);
|
||||||
<Badge color="green">
|
const badgeProps = getBadgeProps(avgLatency);
|
||||||
<FaCheck className="mr-xs" /> Connection
|
|
||||||
</Badge>
|
|
||||||
);
|
|
||||||
|
|
||||||
if (currentDataSourceLatencyInfo.avgLatency < 200)
|
|
||||||
return (
|
|
||||||
<Badge color="yellow">
|
|
||||||
<FaMinusCircle className="mr-xs" /> Acceptable
|
|
||||||
</Badge>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Badge color="red">
|
<ToolTip message={message} placement="top">
|
||||||
<FaExclamationTriangle className="mr-xs" /> Elevated Latency
|
<Badge color={badgeProps.color}>
|
||||||
</Badge>
|
{badgeProps.icon} {badgeProps.label}
|
||||||
|
</Badge>
|
||||||
|
</ToolTip>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user