import {browserHistory} from 'react-router'; import styled from '@emotion/styled'; import {Breadcrumbs} from 'sentry/components/breadcrumbs'; import IdBadge from 'sentry/components/idBadge'; import * as Layout from 'sentry/components/layouts/thirds'; import LoadingError from 'sentry/components/loadingError'; import LoadingIndicator from 'sentry/components/loadingIndicator'; import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle'; import {t} from 'sentry/locale'; import {space} from 'sentry/styles/space'; import {setApiQueryData, useApiQuery, useQueryClient} from 'sentry/utils/queryClient'; import useOrganization from 'sentry/utils/useOrganization'; import usePageFilters from 'sentry/utils/usePageFilters'; import {useParams} from 'sentry/utils/useParams'; import {normalizeUrl} from 'sentry/utils/withDomainRequired'; import {makeMonitorDetailsQueryKey} from 'sentry/views/monitors/utils'; import MonitorForm from './components/monitorForm'; import type {Monitor} from './types'; export default function EditMonitor() { const {monitorSlug, projectId} = useParams<{monitorSlug: string; projectId: string}>(); const {selection} = usePageFilters(); const organization = useOrganization(); const queryClient = useQueryClient(); const queryKey = makeMonitorDetailsQueryKey(organization, projectId, monitorSlug, { expand: ['alertRule'], }); const { isLoading, isError, data: monitor, refetch, } = useApiQuery(queryKey, { cacheTime: 0, staleTime: 0, }); function onSubmitSuccess(data: Monitor) { setApiQueryData(queryClient, queryKey, data); browserHistory.push( normalizeUrl({ pathname: `/organizations/${organization.slug}/crons/${data.project.slug}/${data.slug}/`, query: { environment: selection.environments, project: selection.projects, }, }) ); } function getTitle() { if (monitor) { return `${monitor.name} - Crons - ${organization.slug}`; } return `Crons - ${organization.slug}`; } if (isLoading) { return ; } if (isError) { return ; } return ( {monitor.name} ), to: normalizeUrl( `/organizations/${organization.slug}/crons/${monitor.project.slug}/${monitor.slug}/` ), }, { label: t('Edit'), }, ]} /> {t('Edit Monitor')} ); } const MonitorBreadcrumb = styled('div')` display: flex; gap: ${space(1)}; align-items: center; `;