-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chart alerts: Add UI to Chart Builder
- Loading branch information
1 parent
e904ec3
commit 89ea338
Showing
5 changed files
with
193 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@hyperdx/app': patch | ||
--- | ||
|
||
Chart alerts: Add UI to chart builder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import * as React from 'react'; | ||
import { Form } from 'react-bootstrap'; | ||
import type { Alert } from './types'; | ||
import produce from 'immer'; | ||
|
||
import { | ||
ALERT_INTERVAL_OPTIONS, | ||
ALERT_CHANNEL_OPTIONS, | ||
SlackChannelForm, | ||
} from './Alert'; | ||
|
||
type ChartAlertFormProps = { | ||
alert: Alert; | ||
setAlert: (alert?: Alert) => void; | ||
}; | ||
|
||
export default function EditChartFormAlerts({ | ||
alert, | ||
setAlert, | ||
}: ChartAlertFormProps) { | ||
return ( | ||
<> | ||
<div className="d-flex align-items-center gap-3"> | ||
Alert when the value | ||
<Form.Select | ||
id="type" | ||
size="sm" | ||
style={{ | ||
width: 140, | ||
}} | ||
value={alert?.type} | ||
onChange={e => { | ||
setAlert( | ||
produce(alert, draft => { | ||
draft.type = e.target.value as 'presence' | 'absence'; | ||
}), | ||
); | ||
}} | ||
> | ||
<option key="presence" value="presence"> | ||
exceeds | ||
</option> | ||
<option key="absence" value="absence"> | ||
falls below | ||
</option> | ||
</Form.Select> | ||
<Form.Control | ||
style={{ width: 70 }} | ||
type="number" | ||
required | ||
id="threshold" | ||
size="sm" | ||
defaultValue={1} | ||
value={alert?.threshold} | ||
onChange={e => { | ||
setAlert( | ||
produce(alert, draft => { | ||
draft.threshold = parseFloat(e.target.value); | ||
}), | ||
); | ||
}} | ||
/> | ||
over | ||
<Form.Select | ||
id="interval" | ||
size="sm" | ||
style={{ | ||
width: 140, | ||
}} | ||
value={alert?.interval} | ||
onChange={e => { | ||
setAlert( | ||
produce(alert, draft => { | ||
draft.interval = e.target | ||
.value as keyof typeof ALERT_INTERVAL_OPTIONS; | ||
}), | ||
); | ||
}} | ||
> | ||
{Object.entries(ALERT_INTERVAL_OPTIONS).map(([value, text]) => ( | ||
<option key={value} value={value}> | ||
{text} | ||
</option> | ||
))} | ||
</Form.Select> | ||
window via | ||
<Form.Select | ||
id="channel" | ||
size="sm" | ||
style={{ width: 200 }} | ||
value={alert?.channel?.type} | ||
onChange={e => { | ||
setAlert( | ||
produce(alert, draft => { | ||
draft.channel = { | ||
type: e.target.value as keyof typeof ALERT_CHANNEL_OPTIONS, | ||
}; | ||
}), | ||
); | ||
}} | ||
> | ||
{Object.entries(ALERT_CHANNEL_OPTIONS).map(([value, text]) => ( | ||
<option key={value} value={value}> | ||
{text} | ||
</option> | ||
))} | ||
</Form.Select> | ||
</div> | ||
<div className="mt-3"> | ||
{alert?.channel?.type === 'webhook' && ( | ||
<SlackChannelForm | ||
webhookSelectProps={{ | ||
value: alert?.channel?.webhookId, | ||
onChange: e => { | ||
setAlert( | ||
produce(alert, draft => { | ||
draft.channel = { | ||
type: 'webhook', | ||
webhookId: e.target.value, | ||
}; | ||
}), | ||
); | ||
}, | ||
}} | ||
/> | ||
)} | ||
</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters