monitorCheckIns.tsx 1.9 KB

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