monitorCheckIns.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import styled from '@emotion/styled';
  2. import Duration from 'sentry/components/duration';
  3. import {PanelBody, PanelItem} from 'sentry/components/panels';
  4. import TimeSince from 'sentry/components/timeSince';
  5. import {Tooltip} from 'sentry/components/tooltip';
  6. import {tct} from 'sentry/locale';
  7. import space from 'sentry/styles/space';
  8. import {defined} from 'sentry/utils';
  9. import useApiRequests from 'sentry/utils/useApiRequests';
  10. import {CheckInStatus, Monitor} from 'sentry/views/monitors/types';
  11. import CheckInIcon from './checkInIcon';
  12. type CheckIn = {
  13. dateCreated: string;
  14. duration: number;
  15. id: string;
  16. status: CheckInStatus;
  17. };
  18. type Props = {
  19. monitor: Monitor;
  20. orgId: string;
  21. };
  22. type State = {
  23. checkInList: CheckIn[];
  24. };
  25. const MonitorCheckIns = ({monitor, orgId}: Props) => {
  26. const {data, hasError, renderComponent} = useApiRequests<State>({
  27. endpoints: [
  28. [
  29. 'checkInList',
  30. `/organizations/${orgId}/monitors/${monitor.id}/checkins/`,
  31. {query: {per_page: '10'}},
  32. ],
  33. ],
  34. });
  35. const renderedComponent = renderComponent(
  36. <PanelBody>
  37. {data.checkInList?.map(checkIn => (
  38. <PanelItem key={checkIn.id}>
  39. <CheckInIconWrapper>
  40. <Tooltip
  41. title={tct('Check In Status: [status]', {
  42. status: checkIn.status,
  43. })}
  44. >
  45. <CheckInIcon status={checkIn.status} size={16} />
  46. </Tooltip>
  47. </CheckInIconWrapper>
  48. <TimeSinceWrapper>
  49. <TimeSince date={checkIn.dateCreated} />
  50. </TimeSinceWrapper>
  51. <DurationWrapper>
  52. {defined(checkIn.duration) && <Duration seconds={checkIn.duration / 1000} />}
  53. </DurationWrapper>
  54. </PanelItem>
  55. ))}
  56. </PanelBody>
  57. );
  58. return hasError ? <ErrorWrapper>{renderedComponent}</ErrorWrapper> : renderedComponent;
  59. };
  60. export default MonitorCheckIns;
  61. const DivMargin = styled('div')`
  62. margin-right: ${space(2)};
  63. `;
  64. const CheckInIconWrapper = styled(DivMargin)`
  65. display: flex;
  66. align-items: center;
  67. `;
  68. const TimeSinceWrapper = styled(DivMargin)`
  69. font-variant-numeric: tabular-nums;
  70. `;
  71. const DurationWrapper = styled('div')`
  72. font-variant-numeric: tabular-nums;
  73. `;
  74. const ErrorWrapper = styled('div')`
  75. margin: ${space(3)} ${space(3)} 0;
  76. `;