44 FieldErrors ,
55 UseFormClearErrors ,
66 UseFormSetValue ,
7- useWatch ,
87} from 'react-hook-form' ;
9- import { NativeSelect , NumberInput } from 'react-hook-form-mantine' ;
108import { TableConnection } from '@hyperdx/common-utils/dist/core/metadata' ;
119import { isBuilderChartConfig } from '@hyperdx/common-utils/dist/guards' ;
1210import {
@@ -15,20 +13,9 @@ import {
1513 SourceKind ,
1614 TSource ,
1715} from '@hyperdx/common-utils/dist/types' ;
18- import {
19- Button ,
20- Divider ,
21- Flex ,
22- Group ,
23- Paper ,
24- Stack ,
25- Switch ,
26- Text ,
27- } from '@mantine/core' ;
16+ import { Box , Button , Divider , Flex , Group , Switch , Text } from '@mantine/core' ;
2817import { IconBell , IconCirclePlus } from '@tabler/icons-react' ;
2918
30- import { AlertChannelForm } from '@/components/Alerts' ;
31- import { AlertScheduleFields } from '@/components/AlertScheduleFields' ;
3219import {
3320 ChartEditorFormState ,
3421 SavedChartConfigWithSelectArray ,
@@ -39,16 +26,10 @@ import SourceSchemaPreview from '@/components/SourceSchemaPreview';
3926import { SourceSelectControlled } from '@/components/SourceSelect' ;
4027import { SQLInlineEditorControlled } from '@/components/SQLEditor/SQLInlineEditor' ;
4128import { IS_LOCAL_MODE } from '@/config' ;
42- import { optionsToSelectData } from '@/utils' ;
43- import {
44- ALERT_CHANNEL_OPTIONS ,
45- DEFAULT_TILE_ALERT ,
46- intervalToMinutes ,
47- TILE_ALERT_INTERVAL_OPTIONS ,
48- TILE_ALERT_THRESHOLD_TYPE_OPTIONS ,
49- } from '@/utils/alerts' ;
29+ import { DEFAULT_TILE_ALERT } from '@/utils/alerts' ;
5030
5131import { ChartSeriesEditor } from './ChartSeriesEditor' ;
32+ import { TileAlertEditor } from './TileAlertEditor' ;
5233
5334type ChartEditorControlsProps = {
5435 control : Control < ChartEditorFormState > ;
@@ -103,18 +84,6 @@ export function ChartEditorControls({
10384 onSubmit,
10485 openDisplaySettings,
10586} : ChartEditorControlsProps ) {
106- const alertChannelType = useWatch ( { control, name : 'alert.channel.type' } ) ;
107- const alertScheduleOffsetMinutes = useWatch ( {
108- control,
109- name : 'alert.scheduleOffsetMinutes' ,
110- } ) ;
111- const maxAlertScheduleOffsetMinutes = alert ?. interval
112- ? Math . max ( intervalToMinutes ( alert . interval ) - 1 , 0 )
113- : 0 ;
114- const alertIntervalLabel = alert ?. interval
115- ? TILE_ALERT_INTERVAL_OPTIONS [ alert . interval ]
116- : undefined ;
117-
11887 return (
11988 < >
12089 < Flex mb = "md" align = "center" justify = "space-between" >
@@ -274,20 +243,19 @@ export function ChartEditorControls({
274243 />
275244 ) }
276245 { ( displayType === DisplayType . Line ||
246+ displayType === DisplayType . StackedBar ||
277247 displayType === DisplayType . Number ) &&
278248 dashboardId &&
249+ ! alert &&
279250 ! IS_LOCAL_MODE && (
280251 < Button
281252 variant = "subtle"
282253 data-testid = "alert-button"
283254 size = "sm"
284- color = { alert ? 'red' : 'gray' }
285- onClick = { ( ) =>
286- setValue ( 'alert' , alert ? undefined : DEFAULT_TILE_ALERT )
287- }
255+ onClick = { ( ) => setValue ( 'alert' , DEFAULT_TILE_ALERT ) }
288256 >
289257 < IconBell size = { 14 } className = "me-2" />
290- { ! alert ? ' Add Alert' : 'Remove Alert' }
258+ Add Alert
291259 </ Button >
292260 ) }
293261 </ Group >
@@ -334,76 +302,14 @@ export function ChartEditorControls({
334302 </ Flex >
335303 ) }
336304 { alert && ! isRawSqlInput && (
337- < Paper my = "sm" >
338- < Stack gap = "xs" data-testid = "alert-details" >
339- < Paper px = "md" py = "sm" radius = "xs" >
340- < Text size = "xxs" opacity = { 0.5 } mb = { 4 } >
341- Trigger
342- </ Text >
343- < Group gap = "xs" >
344- < Text size = "sm" opacity = { 0.7 } >
345- Alert when the value
346- </ Text >
347- < NativeSelect
348- data = { optionsToSelectData ( TILE_ALERT_THRESHOLD_TYPE_OPTIONS ) }
349- size = "xs"
350- name = { `alert.thresholdType` }
351- control = { control }
352- />
353- < NumberInput
354- size = "xs"
355- w = { 80 }
356- control = { control }
357- name = { `alert.threshold` }
358- />
359- over
360- < NativeSelect
361- data = { optionsToSelectData ( TILE_ALERT_INTERVAL_OPTIONS ) }
362- size = "xs"
363- name = { `alert.interval` }
364- control = { control }
365- />
366- < Text size = "sm" opacity = { 0.7 } >
367- window via
368- </ Text >
369- < NativeSelect
370- data = { optionsToSelectData ( ALERT_CHANNEL_OPTIONS ) }
371- size = "xs"
372- name = { `alert.channel.type` }
373- control = { control }
374- />
375- </ Group >
376- { alert ?. createdBy && (
377- < Text size = "xs" opacity = { 0.6 } mt = "xs" >
378- Created by { alert . createdBy . name || alert . createdBy . email }
379- </ Text >
380- ) }
381- < AlertScheduleFields
382- control = { control }
383- setValue = { setValue }
384- scheduleOffsetName = "alert.scheduleOffsetMinutes"
385- scheduleStartAtName = "alert.scheduleStartAt"
386- scheduleOffsetMinutes = { alertScheduleOffsetMinutes }
387- maxScheduleOffsetMinutes = { maxAlertScheduleOffsetMinutes }
388- offsetWindowLabel = {
389- alertIntervalLabel
390- ? `from each ${ alertIntervalLabel } window`
391- : 'from each alert window'
392- }
393- />
394- </ Paper >
395- < Paper px = "md" py = "sm" radius = "xs" >
396- < Text size = "xxs" opacity = { 0.5 } mb = { 4 } >
397- Send to
398- </ Text >
399- < AlertChannelForm
400- control = { control }
401- type = { alertChannelType }
402- namePrefix = "alert."
403- />
404- </ Paper >
405- </ Stack >
406- </ Paper >
305+ < Box mt = "sm" >
306+ < TileAlertEditor
307+ control = { control }
308+ setValue = { setValue }
309+ alert = { alert }
310+ onRemove = { ( ) => setValue ( 'alert' , undefined ) }
311+ />
312+ </ Box >
407313 ) }
408314 </ >
409315 ) ;
0 commit comments