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
23 changes: 8 additions & 15 deletions static/app/views/alerts/rules/crons/details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {TimezoneProvider, useTimezone} from 'sentry/components/timezoneProvider'
import {t} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
import {setApiQueryData, useApiQuery, useQueryClient} from 'sentry/utils/queryClient';
import {useApiQuery, useQueryClient} from 'sentry/utils/queryClient';
import useApi from 'sentry/utils/useApi';
import useOrganization from 'sentry/utils/useOrganization';
import {DetailsSidebar} from 'sentry/views/insights/crons/components/detailsSidebar';
Expand Down Expand Up @@ -73,26 +73,19 @@ function MonitorDetails({params, location}: Props) {
monitorSlug: params.monitorSlug,
});

function onUpdate(data: Monitor) {
const updatedMonitor = {
...data,
// TODO(davidenwang): This is a bit of a hack, due to the PUT request
// which pauses/unpauses a monitor not returning monitor environments
// we should reuse the environments retrieved from the initial request
environments: monitor?.environments,
};
setApiQueryData(queryClient, queryKey, updatedMonitor);
function onUpdate() {
// Invalidate the query to refetch the monitor with updated environment data.
// The PUT request doesn't return environments, so we need to refetch to get
// the latest environment muting status and other environment data.
queryClient.invalidateQueries({queryKey});
}

const handleUpdate = async (data: Partial<Monitor>) => {
if (monitor === undefined) {
return;
}
const resp = await updateMonitor(api, organization.slug, monitor, data);

if (resp !== null) {
onUpdate(resp);
}
await updateMonitor(api, organization.slug, monitor, data);
onUpdate();
};

const userTimezone = useTimezone();
Expand Down
21 changes: 5 additions & 16 deletions static/app/views/insights/crons/components/detailsTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ export function DetailsTimeline({monitor, onStatsLoaded, onEnvironmentUpdated}:
organization,
monitor.project.slug,
monitor.slug,
{...location.query}
{
environment: location.query.environment,
}
);

const {data: monitorStats} = useMonitorStats({
Expand Down Expand Up @@ -110,21 +112,8 @@ export function DetailsTimeline({monitor, onStatsLoaded, onEnvironmentUpdated}:
return;
}

setApiQueryData<Monitor>(queryClient, monitorDetailsQueryKey, oldMonitorDetails => {
return oldMonitorDetails
? {
...oldMonitorDetails,
environments: oldMonitorDetails.environments.map(monitorEnv =>
monitorEnv.name === env
? {
...monitorEnv,
isMuted,
}
: monitorEnv
),
}
: undefined;
});
// Invalidate the query to refetch the monitor with updated environment data
queryClient.invalidateQueries({queryKey: monitorDetailsQueryKey});

onEnvironmentUpdated?.();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ export function OverviewRow({
...(onToggleMuteEnvironment
? [
(env: string, isMuted: boolean) => ({
label:
isMuted && !monitor.isMuted
Copy link
Member Author

Choose a reason for hiding this comment

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

This is also needed to correctly set the title

? t('Unmute Environment')
: t('Mute Environment'),
label: isMuted ? t('Unmute Environment') : t('Mute Environment'),
key: 'mute',
details: monitor.isMuted ? t('Monitor is muted') : undefined,
disabled: monitor.isMuted,
Expand Down
Loading