utils.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. };
  47. interface TickStyle {
  48. /**
  49. * The color of the tooltip label
  50. */
  51. labelColor: ColorOrAlias;
  52. /**
  53. * The color of the tick
  54. */
  55. tickColor: ColorOrAlias;
  56. /**
  57. * Use a cross hatch fill for the tick instead of a solid color. The tick
  58. * color will be used as the border color
  59. */
  60. hatchTick?: ColorOrAlias;
  61. }
  62. export const tickStyle: Record<CheckInStatus, TickStyle> = {
  63. [CheckInStatus.ERROR]: {
  64. labelColor: 'red400',
  65. tickColor: 'red300',
  66. },
  67. [CheckInStatus.TIMEOUT]: {
  68. labelColor: 'red400',
  69. tickColor: 'red300',
  70. hatchTick: 'red200',
  71. },
  72. [CheckInStatus.OK]: {
  73. labelColor: 'green400',
  74. tickColor: 'green300',
  75. },
  76. [CheckInStatus.MISSED]: {
  77. labelColor: 'yellow400',
  78. tickColor: 'yellow300',
  79. },
  80. [CheckInStatus.IN_PROGRESS]: {
  81. labelColor: 'disabled',
  82. tickColor: 'disabled',
  83. },
  84. };
  85. export const getScheduleIntervals = (n: number): SelectValue<string>[] => [
  86. {value: 'minute', label: tn('minute', 'minutes', n)},
  87. {value: 'hour', label: tn('hour', 'hours', n)},
  88. {value: 'day', label: tn('day', 'days', n)},
  89. {value: 'week', label: tn('week', 'weeks', n)},
  90. {value: 'month', label: tn('month', 'months', n)},
  91. {value: 'year', label: tn('year', 'years', n)},
  92. ];
  93. export function getTickStyle(status: CheckInStatus, theme: Theme) {
  94. const style = tickStyle[status];
  95. if (style.hatchTick === undefined) {
  96. return css`
  97. background: ${theme[style.tickColor]};
  98. `;
  99. }
  100. return css`
  101. border: 1px solid ${theme[style.tickColor]};
  102. background-size: 3px 3px;
  103. opacity: 0.5;
  104. background-image: linear-gradient(
  105. -45deg,
  106. ${theme[style.hatchTick]} 25%,
  107. transparent 25%,
  108. transparent 50%,
  109. ${theme[style.hatchTick]} 50%,
  110. ${theme[style.hatchTick]} 75%,
  111. transparent 75%,
  112. transparent
  113. ),
  114. linear-gradient(
  115. 45deg,
  116. ${theme[style.hatchTick]} 25%,
  117. transparent 25%,
  118. transparent 50%,
  119. ${theme[style.hatchTick]} 50%,
  120. ${theme[style.hatchTick]} 75%,
  121. transparent 75%,
  122. transparent
  123. );
  124. `;
  125. }