-
Notifications
You must be signed in to change notification settings - Fork 462
Expand file tree
/
Copy pathAlertPreviewChart.tsx
More file actions
68 lines (62 loc) · 1.78 KB
/
Copy pathAlertPreviewChart.tsx
File metadata and controls
68 lines (62 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import React from 'react';
import {
AlertInterval,
SearchCondition,
SearchConditionLanguage,
} from '@hyperdx/common-utils/dist/types';
import { Paper } from '@mantine/core';
import { DBTimeChart } from '@/components/DBTimeChart';
import { useSource } from '@/source';
import { intervalToDateRange, intervalToGranularity } from '@/utils/alerts';
import { getAlertReferenceLines } from './Alerts';
export type AlertPreviewChartProps = {
sourceId?: string | null;
where?: SearchCondition | null;
whereLanguage?: SearchConditionLanguage | null;
interval: AlertInterval;
groupBy?: string;
thresholdType: 'above' | 'below';
threshold: number;
};
export const AlertPreviewChart = ({
sourceId,
where,
whereLanguage,
interval,
groupBy,
threshold,
thresholdType,
}: AlertPreviewChartProps) => {
const { data: source } = useSource({ id: sourceId });
if (!sourceId || !source) {
return null;
}
return (
<Paper w="100%" h={200}>
<DBTimeChart
sourceId={sourceId}
showDisplaySwitcher={false}
referenceLines={getAlertReferenceLines({ threshold, thresholdType })}
config={{
where: where || '',
whereLanguage: whereLanguage || undefined,
dateRange: intervalToDateRange(interval),
granularity: intervalToGranularity(interval),
implicitColumnExpression: source.implicitColumnExpression,
groupBy,
select: [
{
aggFn: 'count' as const,
aggCondition: '',
aggConditionLanguage: 'sql',
valueExpression: '',
},
],
timestampValueExpression: source.timestampValueExpression,
from: source.from,
connection: source.connection,
}}
/>
</Paper>
);
};