Skip to content

feat(aci): set up monitor Disable action #96716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion static/app/components/workflowEngine/layout/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function Title({title, project}: {title: string; project?: AvatarProject}) {
function Actions({children}: RequiredChildren) {
return (
<HeaderActions>
<Flex>{children}</Flex>
<Flex gap="sm">{children}</Flex>
</HeaderActions>
);
}
Expand Down
3 changes: 2 additions & 1 deletion static/app/types/workflowEngine/detectors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ type BaseDetector = Readonly<{
createdBy: string | null;
dateCreated: string;
dateUpdated: string;
disabled: boolean;
enabled: boolean;
id: string;
lastTriggered: string;
name: string;
Expand Down Expand Up @@ -197,6 +197,7 @@ export interface BaseDetectorUpdatePayload {
projectId: Detector['projectId'];
type: Detector['type'];
workflowIds: string[];
enabled?: boolean;
}

export interface UptimeDetectorUpdatePayload extends BaseDetectorUpdatePayload {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export function EditAutomationActions({automation}: EditAutomationActionsProps)
enabled: newEnabled,
},
{
onSuccess: () => {
onSuccess: data => {
addSuccessMessage(
newEnabled ? t('Automation enabled') : t('Automation disabled')
data.enabled ? t('Automation enabled') : t('Automation disabled')
);
},
}
Expand All @@ -58,16 +58,15 @@ export function EditAutomationActions({automation}: EditAutomationActionsProps)
return (
<div>
<ButtonBar>
<Button priority="default" size="sm" onClick={toggleDisabled} busy={isUpdating}>
{automation.enabled ? t('Disable') : t('Enable')}
</Button>
<Button
priority="danger"
onClick={handleDelete}
disabled={isDeleting}
busy={isDeleting}
priority="default"
size="sm"
onClick={toggleDisabled}
disabled={isUpdating}
>
{automation.enabled ? t('Disable') : t('Enable')}
</Button>
<Button priority="danger" onClick={handleDelete} disabled={isDeleting} size="sm">
{t('Delete')}
</Button>
<Button type="submit" priority="primary" size="sm">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
import {useCallback} from 'react';

import {addSuccessMessage} from 'sentry/actionCreators/indicator';
import {openConfirmModal} from 'sentry/components/confirm';
import {Button} from 'sentry/components/core/button';
import {LinkButton} from 'sentry/components/core/button/linkButton';
import {Link} from 'sentry/components/core/link';
import {IconEdit} from 'sentry/icons';
import {t, tct} from 'sentry/locale';
import type {Detector} from 'sentry/types/workflowEngine/detectors';
import {useNavigate} from 'sentry/utils/useNavigate';
import useOrganization from 'sentry/utils/useOrganization';
import {makeMonitorDetailsPathname} from 'sentry/views/detectors/pathnames';
import {useUpdateDetector} from 'sentry/views/detectors/hooks';
import {useDeleteDetectorMutation} from 'sentry/views/detectors/hooks/useDeleteDetectorMutation';
import {
makeMonitorBasePathname,
makeMonitorDetailsPathname,
} from 'sentry/views/detectors/pathnames';
import {useCanEditDetector} from 'sentry/views/detectors/utils/useCanEditDetector';

export function DisableDetectorAction({detector}: {detector: Detector}) {
const {mutate: updateDetector, isPending: isUpdating} = useUpdateDetector();

const toggleDisabled = useCallback(() => {
const newEnabled = !detector.enabled;
updateDetector(
{
detectorId: detector.id,
enabled: newEnabled,
},
{
onSuccess: data => {
addSuccessMessage(data.enabled ? t('Monitor enabled') : t('Monitor disabled'));
},
}
);
}, [updateDetector, detector.enabled, detector.id]);

const canEdit = useCanEditDetector({
detectorType: detector.type,
projectId: detector.projectId,
Expand All @@ -18,12 +45,9 @@ export function DisableDetectorAction({detector}: {detector: Detector}) {
return null;
}

/**
* TODO: Implement disable detector
*/
return (
<Button size="sm" onClick={() => {}}>
{detector.disabled ? t('Enable') : t('Disable')}
<Button size="sm" onClick={toggleDisabled} disabled={isUpdating}>
{detector.enabled ? t('Disable') : t('Enable')}
</Button>
);
}
Expand Down Expand Up @@ -54,3 +78,37 @@ export function EditDetectorAction({detector}: {detector: Detector}) {
</LinkButton>
);
}

export function DeleteDetectorAction({detector}: {detector: Detector}) {
const organization = useOrganization();
const navigate = useNavigate();
const {mutateAsync: deleteDetector, isPending: isDeleting} =
useDeleteDetectorMutation();

const handleDelete = useCallback(() => {
openConfirmModal({
message: t('Are you sure you want to delete this monitor?'),
confirmText: t('Delete'),
priority: 'danger',
onConfirm: async () => {
await deleteDetector(detector.id);
navigate(makeMonitorBasePathname(organization.slug));
},
});
}, [deleteDetector, detector.id, navigate, organization.slug]);

const canEdit = useCanEditDetector({
detectorType: detector.type,
projectId: detector.projectId,
});

if (!canEdit) {
return null;
}

return (
<Button priority="danger" onClick={handleDelete} disabled={isDeleting} size="sm">
{t('Delete')}
</Button>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function DetectorListRow({detector}: DetectorListRowProps) {

return (
<DetectorSimpleTableRow
variant={detector.disabled ? 'faded' : 'default'}
variant={detector.enabled ? 'default' : 'faded'}
data-test-id="detector-list-row"
>
<SimpleTable.RowCell>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import {useMemo} from 'react';

import {Button} from 'sentry/components/core/button';
import type {Data} from 'sentry/components/forms/types';
import EditLayout from 'sentry/components/workflowEngine/layout/edit';
import {t} from 'sentry/locale';
import type {
BaseDetectorUpdatePayload,
Detector,
} from 'sentry/types/workflowEngine/detectors';
import {
DeleteDetectorAction,
DisableDetectorAction,
} from 'sentry/views/detectors/components/details/common/actions';
import {EditDetectorBreadcrumbs} from 'sentry/views/detectors/components/forms/common/breadcrumbs';
import {DetectorBaseFields} from 'sentry/views/detectors/components/forms/detectorBaseFields';
import {EditDetectorActions} from 'sentry/views/detectors/components/forms/editDetectorActions';
import {useEditDetectorFormSubmit} from 'sentry/views/detectors/hooks/useEditDetectorFormSubmit';

type EditDetectorLayoutProps<TDetector, TFormData, TUpdatePayload> = {
Expand Down Expand Up @@ -52,7 +57,11 @@ export function EditDetectorLayout<
</EditLayout.HeaderContent>

<EditLayout.Actions>
<EditDetectorActions detectorId={detector.id} />
<DisableDetectorAction detector={detector} />
<DeleteDetectorAction detector={detector} />
<Button type="submit" priority="primary" size="sm">
{t('Save')}
</Button>
</EditLayout.Actions>

<EditLayout.HeaderFields>
Expand Down
Loading
Loading