utils.tsx 3.5 KB

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