-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(uptime): Support enable / disable on the frontend (#84025)
Allows monitors to be enabled / disabled from the details page
- Loading branch information
1 parent
8fe530e
commit e881b51
Showing
7 changed files
with
169 additions
and
4 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,44 @@ | ||
import * as Sentry from '@sentry/react'; | ||
|
||
import { | ||
addErrorMessage, | ||
addLoadingMessage, | ||
clearIndicators, | ||
} from 'sentry/actionCreators/indicator'; | ||
import type {Client} from 'sentry/api'; | ||
import {t} from 'sentry/locale'; | ||
import type RequestError from 'sentry/utils/requestError/requestError'; | ||
import type {UptimeRule} from 'sentry/views/alerts/rules/uptime/types'; | ||
|
||
export async function updateUptimeRule( | ||
api: Client, | ||
orgId: string, | ||
uptimeMonitor: UptimeRule, | ||
data: Partial<UptimeRule> | ||
): Promise<UptimeRule | null> { | ||
addLoadingMessage(); | ||
|
||
try { | ||
const resp = await api.requestPromise( | ||
`/projects/${orgId}/${uptimeMonitor.projectSlug}/uptime/${uptimeMonitor.id}/`, | ||
{method: 'PUT', data} | ||
); | ||
clearIndicators(); | ||
return resp; | ||
} catch (err) { | ||
const respError: RequestError = err; | ||
const updateKeys = Object.keys(data); | ||
|
||
// If we are updating a single value in the monitor we can read the | ||
// validation error for that key, otherwise fallback to the default error | ||
const validationError = | ||
updateKeys.length === 1 | ||
? (respError.responseJSON?.[updateKeys[0]!] as any)?.[0] | ||
: undefined; | ||
|
||
Sentry.captureException(err); | ||
addErrorMessage(validationError ?? t('Unable to update uptime monitor.')); | ||
} | ||
|
||
return null; | ||
} |
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
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
42 changes: 42 additions & 0 deletions
42
static/app/views/alerts/rules/uptime/statusToggleButton.tsx
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,42 @@ | ||
import type {BaseButtonProps} from 'sentry/components/button'; | ||
import {Button} from 'sentry/components/button'; | ||
import {IconPause, IconPlay} from 'sentry/icons'; | ||
import {t} from 'sentry/locale'; | ||
import type {ObjectStatus} from 'sentry/types/core'; | ||
|
||
import type {UptimeRule} from './types'; | ||
|
||
interface StatusToggleButtonProps extends Omit<BaseButtonProps, 'onClick'> { | ||
onToggleStatus: (status: ObjectStatus) => Promise<void>; | ||
uptimeRule: UptimeRule; | ||
} | ||
|
||
export function StatusToggleButton({ | ||
uptimeRule, | ||
onToggleStatus, | ||
...props | ||
}: StatusToggleButtonProps) { | ||
const {status} = uptimeRule; | ||
const isDisabled = status === 'disabled'; | ||
|
||
const Icon = isDisabled ? IconPlay : IconPause; | ||
|
||
const label = isDisabled | ||
? t('Enable this uptime rule') | ||
: t('Disable this uptime rule and stop performing checks'); | ||
|
||
return ( | ||
<Button | ||
icon={<Icon />} | ||
aria-label={label} | ||
title={label} | ||
onClick={async () => { | ||
await onToggleStatus(isDisabled ? 'active' : 'disabled'); | ||
// TODO(epurkhiser): We'll need a hook here to trigger subscription | ||
// refesh in getsentry when toggling uptime monitors since it will | ||
// consume quota. | ||
}} | ||
{...props} | ||
/> | ||
); | ||
} |
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