utils.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import {t, tn} from 'sentry/locale';
  2. import type {Organization, SelectValue} from 'sentry/types';
  3. import type {ColorOrAlias} from 'sentry/utils/theme';
  4. import {CheckInStatus} from 'sentry/views/monitors/types';
  5. export function makeMonitorListQueryKey(
  6. organization: Organization,
  7. params: Record<string, any>
  8. ) {
  9. const {query, project, environment, cursor, sort, asc} = params;
  10. return [
  11. `/organizations/${organization.slug}/monitors/`,
  12. {
  13. query: {
  14. cursor,
  15. query,
  16. project,
  17. environment,
  18. includeNew: true,
  19. per_page: 20,
  20. sort,
  21. asc,
  22. },
  23. },
  24. ] as const;
  25. }
  26. export function makeMonitorDetailsQueryKey(
  27. organization: Organization,
  28. projectId: string,
  29. monitorSlug: string,
  30. query?: Record<string, any>
  31. ) {
  32. return [
  33. `/projects/${organization.slug}/${projectId}/monitors/${monitorSlug}/`,
  34. {query},
  35. ] as const;
  36. }
  37. export const statusToText: Record<CheckInStatus, string> = {
  38. [CheckInStatus.OK]: t('Okay'),
  39. [CheckInStatus.ERROR]: t('Failed'),
  40. [CheckInStatus.IN_PROGRESS]: t('In Progress'),
  41. [CheckInStatus.MISSED]: t('Missed'),
  42. [CheckInStatus.TIMEOUT]: t('Timed Out'),
  43. };
  44. interface TickStyle {
  45. /**
  46. * The color of the tooltip label
  47. */
  48. labelColor: ColorOrAlias;
  49. /**
  50. * The color of the tick
  51. */
  52. tickColor: ColorOrAlias;
  53. /**
  54. * Use a cross hatch fill for the tick instead of a solid color. The tick
  55. * color will be used as the border color
  56. */
  57. hatchTick?: ColorOrAlias;
  58. }
  59. export const tickStyle: Record<CheckInStatus, TickStyle> = {
  60. [CheckInStatus.ERROR]: {
  61. labelColor: 'red400',
  62. tickColor: 'red300',
  63. },
  64. [CheckInStatus.TIMEOUT]: {
  65. labelColor: 'red400',
  66. tickColor: 'red300',
  67. hatchTick: 'red200',
  68. },
  69. [CheckInStatus.OK]: {
  70. labelColor: 'green400',
  71. tickColor: 'green300',
  72. },
  73. [CheckInStatus.MISSED]: {
  74. labelColor: 'yellow400',
  75. tickColor: 'yellow300',
  76. },
  77. [CheckInStatus.IN_PROGRESS]: {
  78. labelColor: 'disabled',
  79. tickColor: 'disabled',
  80. },
  81. };
  82. export const getScheduleIntervals = (n: number): SelectValue<string>[] => [
  83. {value: 'minute', label: tn('minute', 'minutes', n)},
  84. {value: 'hour', label: tn('hour', 'hours', n)},
  85. {value: 'day', label: tn('day', 'days', n)},
  86. {value: 'week', label: tn('week', 'weeks', n)},
  87. {value: 'month', label: tn('month', 'months', n)},
  88. {value: 'year', label: tn('year', 'years', n)},
  89. ];