utils.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import type {TickStyle} from 'sentry/components/checkInTimeline/types';
  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 {CheckInStatus} from './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. // Orders the status in terms of ascending precedence for showing to the user
  40. export const checkInStatusPrecedent: CheckInStatus[] = [
  41. CheckInStatus.UNKNOWN,
  42. CheckInStatus.ERROR,
  43. CheckInStatus.TIMEOUT,
  44. CheckInStatus.MISSED,
  45. CheckInStatus.OK,
  46. CheckInStatus.IN_PROGRESS,
  47. ];
  48. export const statusToText: Record<CheckInStatus, string> = {
  49. [CheckInStatus.OK]: t('Okay'),
  50. [CheckInStatus.ERROR]: t('Failed'),
  51. [CheckInStatus.IN_PROGRESS]: t('In Progress'),
  52. [CheckInStatus.MISSED]: t('Missed'),
  53. [CheckInStatus.TIMEOUT]: t('Timed Out'),
  54. [CheckInStatus.UNKNOWN]: t('Unknown'),
  55. };
  56. export const tickStyle: Record<CheckInStatus, TickStyle> = {
  57. [CheckInStatus.ERROR]: {
  58. labelColor: 'red400',
  59. tickColor: 'red300',
  60. },
  61. [CheckInStatus.TIMEOUT]: {
  62. labelColor: 'red400',
  63. tickColor: 'red300',
  64. hatchTick: 'red200',
  65. },
  66. [CheckInStatus.OK]: {
  67. labelColor: 'green400',
  68. tickColor: 'green300',
  69. },
  70. [CheckInStatus.MISSED]: {
  71. labelColor: 'yellow400',
  72. tickColor: 'yellow300',
  73. },
  74. [CheckInStatus.IN_PROGRESS]: {
  75. labelColor: 'disabled',
  76. tickColor: 'disabled',
  77. },
  78. [CheckInStatus.UNKNOWN]: {
  79. labelColor: 'gray400',
  80. tickColor: 'gray300',
  81. hatchTick: 'gray200',
  82. },
  83. };
  84. export const getScheduleIntervals = (n: number): Array<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. ];