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 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 {space} from 'sentry/styles/space'; import {defined} from 'sentry/utils'; import useApiRequests from 'sentry/utils/useApiRequests'; import { CheckIn, CheckInStatus, Monitor, MonitorEnvironment, } from 'sentry/views/monitors/types'; type Props = { monitor: Monitor; monitorEnv: MonitorEnvironment; orgId: string; }; type State = { checkInList: CheckIn[]; }; const checkStatusToIndicatorStatus: Record = { [CheckInStatus.OK]: 'success', [CheckInStatus.ERROR]: 'error', [CheckInStatus.IN_PROGRESS]: 'muted', [CheckInStatus.MISSED]: 'warning', [CheckInStatus.TIMEOUT]: 'error', }; const statusToText = { [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, monitorEnv, orgId}: Props) { const {data, hasError, renderComponent} = useApiRequests({ endpoints: [ [ 'checkInList', `/organizations/${orgId}/monitors/${monitor.slug}/checkins/`, {query: {per_page: '10', environment: monitorEnv.name}}, {paginate: true}, ], ], }); const generateDownloadUrl = (checkin: CheckIn) => `/api/0/organizations/${orgId}/monitors/${monitor.slug}/checkins/${checkin.id}/attachment/`; const emptyCell = {'\u2014'}; const renderedComponent = renderComponent( {t('Recent Check-Ins')} {data.checkInList?.map(checkIn => ( {statusToText[checkIn.status]} {checkIn.status !== CheckInStatus.MISSED ? ( ) : ( emptyCell )} {defined(checkIn.duration) ? ( ) : ( emptyCell )} {checkIn.attachmentId ? ( ) : ( emptyCell )} ))} ); return hasError ? {renderedComponent} : renderedComponent; } export default MonitorCheckIns; const Status = styled('div')` display: flex; align-items: center; `; const Timestamp = styled(DateTime)` color: ${p => p.theme.subText}; `; const ErrorWrapper = styled('div')` margin: ${space(3)} ${space(3)} 0; `;