monitorCheckIns.tsx 2.1 KB

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