Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface DetectorsTableActionsProps {
allResultsVisible: boolean;
canEdit: boolean;
detectorLimitReached: boolean;
hasSystemCreatedDetectors: boolean;
pageSelected: boolean;
queryCount: string;
selected: Set<string>;
Expand All @@ -36,11 +37,14 @@ export function DetectorsTableActions({
showEnable,
showDisable,
canEdit,
hasSystemCreatedDetectors,
detectorLimitReached,
}: DetectorsTableActionsProps) {
const [allInQuerySelected, setAllInQuerySelected] = useState(false);
const anySelected = selected.size > 0;

const canDelete = canEdit && !hasSystemCreatedDetectors;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Delete enabled for query with system-created monitors

When using "Select all X monitors that match this search query", the canDelete check only considers system-created monitors on the current page. If the current page has only user-created monitors but other pages in the query results contain system-created monitors, the Delete button remains enabled. Clicking Delete would then attempt to delete all monitors matching the query, including system-created ones on other pages, bypassing the intended protection.

Fix in Cursor Fix in Web


const {selection} = usePageFilters();
const {query} = useLocationQuery({
fields: {
Expand Down Expand Up @@ -199,14 +203,18 @@ export function DetectorsTableActions({
</Tooltip>
)}
<Tooltip
title={t('You do not have permission to delete the selected monitors.')}
disabled={canEdit}
title={
hasSystemCreatedDetectors
? t('Monitors managed by Sentry cannot be deleted.')
: t('You do not have permission to delete the selected monitors.')
}
disabled={canDelete}
>
<Button
size="xs"
priority="danger"
onClick={handleDelete}
disabled={isDeleting || !canEdit}
disabled={isDeleting || !canDelete}
>
{t('Delete')}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
useMonitorViewContext,
type MonitorListAdditionalColumn,
} from 'sentry/views/detectors/monitorViewContext';
import {detectorTypeIsUserCreateable} from 'sentry/views/detectors/utils/detectorTypeConfig';
import {useCanEditDetectors} from 'sentry/views/detectors/utils/useCanEditDetector';
import {CronServiceIncidents} from 'sentry/views/insights/crons/components/serviceIncidents';

Expand Down Expand Up @@ -139,6 +140,9 @@ function DetectorListTable({

const selectedDetectors = detectors.filter(d => selected.has(d.id));
const canEditDetectors = useCanEditDetectors({detectors: selectedDetectors});
const hasSystemCreatedDetectors = selectedDetectors.some(
d => !detectorTypeIsUserCreateable(d.type)
);

const elementRef = useRef<HTMLDivElement>(null);
const {width: containerWidth} = useDimensions<HTMLDivElement>({elementRef});
Expand Down Expand Up @@ -212,6 +216,7 @@ function DetectorListTable({
showDisable={canDisable}
showEnable={canEnable}
canEdit={canEditDetectors}
hasSystemCreatedDetectors={hasSystemCreatedDetectors}
// TODO: Check if metric detector limit is reached
detectorLimitReached={false}
/>
Expand Down
20 changes: 20 additions & 0 deletions static/app/views/detectors/list/allMonitors.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,26 @@ describe('DetectorsList', () => {
});
});

it('can not delete system-created detectors', async () => {
MockApiClient.addMockResponse({
url: '/organizations/org-slug/detectors/',
body: [
ErrorDetectorFixture({
name: 'System Created Detector',
}),
],
});
render(<AllMonitors />, {organization});
await screen.findByText('System Created Detector');

const rows = screen.getAllByTestId('detector-list-row');
const firstRowCheckbox = within(rows[0]!).getByRole('checkbox');
await userEvent.click(firstRowCheckbox);

// Verify that delete button is disabled
expect(screen.getByRole('button', {name: 'Delete'})).toBeDisabled();
});

it('shows option to select all query results when page is selected', async () => {
const deleteRequest = MockApiClient.addMockResponse({
url: '/organizations/org-slug/detectors/',
Expand Down
Loading