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 @@ -39,7 +39,6 @@ import {
} 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';

type DetectorListTableProps = {
allResultsVisible: boolean;
Expand Down Expand Up @@ -144,7 +143,11 @@ function DetectorListTable({
const timelineWidth = useDebouncedValue(containerWidth, 1000);
const timeWindowConfig = useTimeWindowConfig({timelineWidth});

const {additionalColumns = [], renderVisualization} = useMonitorViewContext();
const {
additionalColumns = [],
renderVisualization,
renderTimelineOverlay,
} = useMonitorViewContext();
const hasVisualization = defined(renderVisualization);

return (
Expand Down Expand Up @@ -247,7 +250,7 @@ function DetectorListTable({
allowZoom
showCursor
cursorOffsets={{right: 40}}
additionalUi={<CronServiceIncidents timeWindowConfig={timeWindowConfig} />}
additionalUi={renderTimelineOverlay?.({timeWindowConfig})}
Copy link
Member

Choose a reason for hiding this comment

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

This change makes sense! Certainly better than it being hardcoded with CronServiceIncidents

timeWindowConfig={timeWindowConfig}
cursorOverlayAnchor="top"
cursorOverlayAnchorOffset={10}
Expand Down
53 changes: 52 additions & 1 deletion static/app/views/detectors/list/cron.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fetchMock from 'jest-fetch-mock';
import {CronDetectorFixture} from 'sentry-fixture/detectors';
import {OrganizationFixture} from 'sentry-fixture/organization';
import {PageFiltersFixture} from 'sentry-fixture/pageFilters';
import {ServiceIncidentFixture} from 'sentry-fixture/serviceIncident';
import {UserFixture} from 'sentry-fixture/user';

import {
Expand All @@ -12,7 +14,9 @@ import {
type RouterConfig,
} from 'sentry-test/reactTestingLibrary';

import ConfigStore from 'sentry/stores/configStore';
import PageFiltersStore from 'sentry/stores/pageFiltersStore';
import {StatusPageComponent} from 'sentry/types/system';
import CronDetectorsList from 'sentry/views/detectors/list/cron';

describe('CronDetectorsList', () => {
Expand All @@ -26,7 +30,15 @@ describe('CronDetectorsList', () => {
},
};

afterEach(() => {
fetchMock.resetMocks();
});

beforeEach(() => {
ConfigStore.set('statuspage', {
id: 'sentry',
api_host: 'status.sentry.io',
});
MockApiClient.clearMockResponses();
MockApiClient.addMockResponse({
url: '/organizations/org-slug/users/1/',
Expand Down Expand Up @@ -84,7 +96,7 @@ describe('CronDetectorsList', () => {
expect(screen.getByRole('button', {name: 'Manual Setup'})).toBeInTheDocument();
});

it('loads cron monitors, renders timeline, and updates on time selection', async () => {
it('loads cron monitors, renders timeline, displays service incidents, and updates on time selection', async () => {
// Detectors list returns a single cron monitor
MockApiClient.addMockResponse({
url: '/organizations/org-slug/detectors/',
Expand Down Expand Up @@ -114,6 +126,40 @@ describe('CronDetectorsList', () => {
},
});

const incident = ServiceIncidentFixture({
id: 'incident-1',
name: 'Incident',
status: 'monitoring',
created_at: new Date(nowSec * 1000 - 3600 * 1000).toISOString(),
started_at: new Date(nowSec * 1000 - 3600 * 1000).toISOString(),
updated_at: new Date(nowSec * 1000).toISOString(),
shortlink: 'http://example.com',
components: [
{
id: StatusPageComponent.US_CRON_MONITORING,
name: 'Crons',
created_at: '',
description: '',
group: false,
group_id: '',
only_show_if_degraded: false,
page_id: '',
position: 1,
showcase: false,
start_date: '',
status: 'major_outage',
updated_at: '',
},
],
incident_updates: [],
});

fetchMock.mockResponse(req =>
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Will investigate further but it seems the existing mocks for service incidents are not using MockApiClient, but fetchMock instead https://github.com/getsentry/sentry/blob/37a6465f1f80a07258a97d493dc726f67123d7c6/static/app/views/nav/primary/serviceIncidents.spec.tsx

Copy link
Member

Choose a reason for hiding this comment

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

Oh, sorry, it does look like this component is doing something unique! Carry on, looks like this is the best way to mock it

req.url.includes('status.sentry.io/api/v2/incidents.json')
? Promise.resolve(JSON.stringify({incidents: [incident]}))
: Promise.reject({status: 404})
);

const {router} = render(<CronDetectorsList />, {organization, initialRouterConfig});

// Page header/title and detector row
Expand All @@ -132,6 +178,11 @@ describe('CronDetectorsList', () => {
// Environment name
expect(within(row).getByText('production')).toBeInTheDocument();

// Should render service incidents overlay
expect(
await screen.findByTestId('cron-service-incident-indicator')
).toBeInTheDocument();

// Timeline visualization should render ticks once stats load
expect(await screen.findAllByTestId('monitor-checkin-tick')).not.toHaveLength(0);
expect(monitorStatsRequest).toHaveBeenCalled();
Expand Down
4 changes: 4 additions & 0 deletions static/app/views/detectors/list/cron.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
import {makeMonitorBasePathname} from 'sentry/views/detectors/pathnames';
import MonitorEnvironmentLabel from 'sentry/views/insights/crons/components/overviewTimeline/monitorEnvironmentLabel';
import {GlobalMonitorProcessingErrors} from 'sentry/views/insights/crons/components/processingErrors/globalMonitorProcessingErrors';
import {CronServiceIncidents} from 'sentry/views/insights/crons/components/serviceIncidents';
import {
platformGuides,
type SupportedPlatform,
Expand Down Expand Up @@ -216,6 +217,9 @@ export default function CronDetectorsList() {
const contextValue = useMemo<MonitorViewContextValue>(() => {
return {
additionalColumns: ADDITIONAL_COLUMNS,
renderTimelineOverlay: ({timeWindowConfig}) => (
<CronServiceIncidents timeWindowConfig={timeWindowConfig} />
),
renderVisualization: ({detector}) => {
if (!detector) {
return (
Expand Down
4 changes: 4 additions & 0 deletions static/app/views/detectors/monitorViewContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {createContext, useContext} from 'react';

import type {TimeWindowConfig} from 'sentry/components/checkInTimeline/types';
import type {Detector} from 'sentry/types/workflowEngine/detectors';

export interface MonitorListAdditionalColumn {
Expand All @@ -21,6 +22,9 @@ export interface MonitorViewContextValue {
* These appear to the right of the default columns and to the left of the visualization.
*/
additionalColumns?: MonitorListAdditionalColumn[];
renderTimelineOverlay?: (props: {
timeWindowConfig: TimeWindowConfig;
}) => React.ReactNode;
renderVisualization?: (params: RenderVisualizationParams) => React.ReactNode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ function CronServiceIncidents({timeWindowConfig}: CronServiceIncidentsProps) {
</Fragment>
}
>
<IncidentIndicator css={position}>
<IncidentIndicator
css={position}
data-test-id="cron-service-incident-indicator"
>
<StyledIconExclamation />
</IncidentIndicator>
</IncidentHovercard>
Expand Down
Loading