import React from 'react'; import styled from '@emotion/styled'; import {Button} from 'sentry/components/button'; import {SectionHeading} from 'sentry/components/charts/styles'; import DateTime from 'sentry/components/dateTime'; import Duration from 'sentry/components/duration'; import LoadingError from 'sentry/components/loadingError'; import LoadingIndicator from 'sentry/components/loadingIndicator'; import Pagination from 'sentry/components/pagination'; import {PanelTable} from 'sentry/components/panels'; import StatusIndicator from 'sentry/components/statusIndicator'; import Text from 'sentry/components/text'; import {IconDownload} from 'sentry/icons'; import {t, tct} from 'sentry/locale'; import {defined} from 'sentry/utils'; import {useApiQuery} from 'sentry/utils/queryClient'; import {useLocation} from 'sentry/utils/useLocation'; import { CheckIn, CheckInStatus, Monitor, MonitorEnvironment, } from 'sentry/views/monitors/types'; type Props = { monitor: Monitor; monitorEnvs: MonitorEnvironment[]; orgId: string; }; const checkStatusToIndicatorStatus: Record< CheckInStatus, 'success' | 'error' | 'muted' | 'warning' > = { [CheckInStatus.OK]: 'success', [CheckInStatus.ERROR]: 'error', [CheckInStatus.IN_PROGRESS]: 'muted', [CheckInStatus.MISSED]: 'warning', [CheckInStatus.TIMEOUT]: 'error', }; const statusToText: Record = { [CheckInStatus.OK]: t('Okay'), [CheckInStatus.ERROR]: t('Failed'), [CheckInStatus.IN_PROGRESS]: t('In Progress'), [CheckInStatus.MISSED]: t('Missed'), [CheckInStatus.TIMEOUT]: t('Timed Out'), }; function MonitorCheckIns({monitor, monitorEnvs, orgId}: Props) { const location = useLocation(); const queryKey = [ `/organizations/${orgId}/monitors/${monitor.slug}/checkins/`, { query: { per_page: '10', environment: monitorEnvs.map(e => e.name), ...location.query, }, }, ] as const; const { data: checkInList, getResponseHeader, isLoading, isError, } = useApiQuery(queryKey, {staleTime: 0}); if (isLoading) { return ; } if (isError) { return ; } const generateDownloadUrl = (checkin: CheckIn) => `/api/0/organizations/${orgId}/monitors/${monitor.slug}/checkins/${checkin.id}/attachment/`; const emptyCell = {'\u2014'}; return ( {t('Recent Check-Ins')} {checkInList.map(checkIn => ( {statusToText[checkIn.status]} {checkIn.status !== CheckInStatus.MISSED ? ( ) : ( emptyCell )} {defined(checkIn.duration) ? ( ) : ( emptyCell )} {checkIn.attachmentId ? ( ) : ( emptyCell )} ))} ); } export default MonitorCheckIns; const Status = styled('div')` display: flex; align-items: center; `; const Timestamp = styled(DateTime)` color: ${p => p.theme.subText}; `;