utils.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import {css, type Theme} from '@emotion/react';
  2. import {t, tn} from 'sentry/locale';
  3. import type {Organization, SelectValue} from 'sentry/types';
  4. import type {ColorOrAlias} from 'sentry/utils/theme';
  5. import {CheckInStatus} from 'sentry/views/monitors/types';
  6. export function makeMonitorListQueryKey(
  7. organization: Organization,
  8. params: Record<string, any>
  9. ) {
  10. const {query, project, environment, owner, cursor, sort, asc} = params;
  11. return [
  12. `/organizations/${organization.slug}/monitors/`,
  13. {
  14. query: {
  15. cursor,
  16. query,
  17. project,
  18. environment,
  19. owner,
  20. includeNew: true,
  21. per_page: 20,
  22. sort,
  23. asc,
  24. },
  25. },
  26. ] as const;
  27. }
  28. export function makeMonitorDetailsQueryKey(
  29. organization: Organization,
  30. projectId: string,
  31. monitorSlug: string,
  32. query?: Record<string, any>
  33. ) {
  34. return [
  35. `/projects/${organization.slug}/${projectId}/monitors/${monitorSlug}/`,
  36. {query},
  37. ] as const;
  38. }
  39. export const statusToText: Record<CheckInStatus, string> = {
  40. [CheckInStatus.OK]: t('Okay'),
  41. [CheckInStatus.ERROR]: t('Failed'),
  42. [CheckInStatus.IN_PROGRESS]: t('In Progress'),
  43. [CheckInStatus.MISSED]: t('Missed'),
  44. [CheckInStatus.TIMEOUT]: t('Timed Out'),
  45. };
  46. interface TickStyle {
  47. /**
  48. * The color of the tooltip label
  49. */
  50. labelColor: ColorOrAlias;
  51. /**
  52. * The color of the tick
  53. */
  54. tickColor: ColorOrAlias;
  55. /**
  56. * Use a cross hatch fill for the tick instead of a solid color. The tick
  57. * color will be used as the border color
  58. */
  59. hatchTick?: ColorOrAlias;
  60. }
  61. export const tickStyle: Record<CheckInStatus, TickStyle> = {
  62. [CheckInStatus.ERROR]: {
  63. labelColor: 'red400',
  64. tickColor: 'red300',
  65. },
  66. [CheckInStatus.TIMEOUT]: {
  67. labelColor: 'red400',
  68. tickColor: 'red300',
  69. hatchTick: 'red200',
  70. },
  71. [CheckInStatus.OK]: {
  72. labelColor: 'green400',
  73. tickColor: 'green300',
  74. },
  75. [CheckInStatus.MISSED]: {
  76. labelColor: 'yellow400',
  77. tickColor: 'yellow300',
  78. },
  79. [CheckInStatus.IN_PROGRESS]: {
  80. labelColor: 'disabled',
  81. tickColor: 'disabled',
  82. },
  83. };
  84. export const getScheduleIntervals = (n: number): SelectValue<string>[] => [
  85. {value: 'minute', label: tn('minute', 'minutes', n)},
  86. {value: 'hour', label: tn('hour', 'hours', n)},
  87. {value: 'day', label: tn('day', 'days', n)},
  88. {value: 'week', label: tn('week', 'weeks', n)},
  89. {value: 'month', label: tn('month', 'months', n)},
  90. {value: 'year', label: tn('year', 'years', n)},
  91. ];
  92. export function getTickStyle(status: CheckInStatus, theme: Theme) {
  93. const style = tickStyle[status];
  94. if (style.hatchTick === undefined) {
  95. return css`
  96. background: ${theme[style.tickColor]};
  97. `;
  98. }
  99. return css`
  100. border: 1px solid ${theme[style.tickColor]};
  101. background-size: 3px 3px;
  102. opacity: 0.5;
  103. background-image: linear-gradient(
  104. -45deg,
  105. ${theme[style.hatchTick]} 25%,
  106. transparent 25%,
  107. transparent 50%,
  108. ${theme[style.hatchTick]} 50%,
  109. ${theme[style.hatchTick]} 75%,
  110. transparent 75%,
  111. transparent
  112. ),
  113. linear-gradient(
  114. 45deg,
  115. ${theme[style.hatchTick]} 25%,
  116. transparent 25%,
  117. transparent 50%,
  118. ${theme[style.hatchTick]} 50%,
  119. ${theme[style.hatchTick]} 75%,
  120. transparent 75%,
  121. transparent
  122. );
  123. `;
  124. }