monitorCheckIns.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import styled from '@emotion/styled';
  2. import AsyncComponent from 'sentry/components/asyncComponent';
  3. import Duration from 'sentry/components/duration';
  4. import {PanelBody, PanelItem} from 'sentry/components/panels';
  5. import TimeSince from 'sentry/components/timeSince';
  6. import space from 'sentry/styles/space';
  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. } & AsyncComponent['props'];
  18. type State = {
  19. checkInList: CheckIn[];
  20. } & AsyncComponent['state'];
  21. export default class MonitorCheckIns extends AsyncComponent<Props, State> {
  22. getEndpoints(): ReturnType<AsyncComponent['getEndpoints']> {
  23. const {monitor} = this.props;
  24. return [
  25. ['checkInList', `/monitors/${monitor.id}/checkins/`, {query: {per_page: 10}}],
  26. ];
  27. }
  28. renderError() {
  29. return <ErrorWrapper>{super.renderError()}</ErrorWrapper>;
  30. }
  31. renderBody() {
  32. return (
  33. <PanelBody>
  34. {this.state.checkInList.map(checkIn => (
  35. <PanelItem key={checkIn.id}>
  36. <CheckInIconWrapper>
  37. <CheckInIcon status={checkIn.status} size={16} />
  38. </CheckInIconWrapper>
  39. <TimeSinceWrapper>
  40. <TimeSince date={checkIn.dateCreated} />
  41. </TimeSinceWrapper>
  42. <DurationWrapper>
  43. {checkIn.duration && <Duration seconds={checkIn.duration / 100} />}
  44. </DurationWrapper>
  45. </PanelItem>
  46. ))}
  47. </PanelBody>
  48. );
  49. }
  50. }
  51. const DivMargin = styled('div')`
  52. margin-right: ${space(2)};
  53. `;
  54. const CheckInIconWrapper = styled(DivMargin)`
  55. display: flex;
  56. align-items: center;
  57. `;
  58. const TimeSinceWrapper = styled(DivMargin)`
  59. font-variant-numeric: tabular-nums;
  60. `;
  61. const DurationWrapper = styled('div')`
  62. font-variant-numeric: tabular-nums;
  63. `;
  64. const ErrorWrapper = styled('div')`
  65. margin: ${space(3)} ${space(3)} 0;
  66. `;