utils.tsx 2.4 KB

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