alerts.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import type {SchemaFormConfig} from 'sentry/views/settings/organizationIntegrations/sentryAppExternalForm';
  2. import type {IssueConfigField} from './integrations';
  3. type IssueAlertRuleFormField =
  4. | {
  5. type: 'choice';
  6. choices?: [string, string][];
  7. initial?: string;
  8. placeholder?: string;
  9. }
  10. | {
  11. type: 'string';
  12. initial?: string;
  13. placeholder?: string;
  14. }
  15. | {
  16. type: 'number';
  17. initial?: string;
  18. placeholder?: number | string;
  19. };
  20. /**
  21. * These templates that tell the UI how to render the action or condition
  22. * and what fields it needs
  23. */
  24. export interface IssueAlertRuleActionTemplate {
  25. enabled: boolean;
  26. id: string;
  27. label: string;
  28. actionType?: 'ticket' | 'sentryapp';
  29. formFields?:
  30. | {
  31. [key: string]: IssueAlertRuleFormField;
  32. }
  33. | SchemaFormConfig;
  34. link?: string;
  35. prompt?: string;
  36. sentryAppInstallationUuid?: string;
  37. ticketType?: string;
  38. }
  39. export type IssueAlertRuleConditionTemplate = IssueAlertRuleActionTemplate;
  40. /**
  41. * These are the action or condition data that the user is editing or has saved.
  42. */
  43. export interface IssueAlertRuleAction
  44. extends Omit<IssueAlertRuleActionTemplate, 'formFields' | 'enabled'> {
  45. // These are the same values as the keys in `formFields` for a template
  46. [key: string]: any;
  47. dynamic_form_fields?: IssueConfigField[];
  48. }
  49. export type IssueAlertRuleCondition = Omit<
  50. IssueAlertRuleConditionTemplate,
  51. 'formFields' | 'enabled'
  52. > & {
  53. dynamic_form_fields?: IssueConfigField[];
  54. } & {
  55. // These are the same values as the keys in `formFields` for a template
  56. [key: string]: number | string;
  57. };
  58. export interface UnsavedIssueAlertRule {
  59. /** When an issue matches [actionMatch] of the following */
  60. actionMatch: 'all' | 'any' | 'none';
  61. actions: IssueAlertRuleAction[];
  62. conditions: IssueAlertRuleCondition[];
  63. /** If that issue has [filterMatch] of these properties */
  64. filterMatch: 'all' | 'any' | 'none';
  65. filters: IssueAlertRuleCondition[];
  66. frequency: number;
  67. name: string;
  68. environment?: null | string;
  69. owner?: string | null;
  70. }
  71. // Issue-based alert rule
  72. export interface IssueAlertRule extends UnsavedIssueAlertRule {
  73. createdBy: {email: string; id: number; name: string} | null;
  74. dateCreated: string;
  75. id: string;
  76. projects: string[];
  77. snooze: boolean;
  78. status: 'active' | 'disabled';
  79. /**
  80. * Date alert is set to be disabled unless action is taken
  81. */
  82. disableDate?: string;
  83. disableReason?: 'noisy';
  84. errors?: {detail: string}[];
  85. lastTriggered?: string;
  86. /**
  87. * Set to true to opt out of the rule being automatically disabled
  88. * see also - status=disabled, disableDate, disableReason
  89. * TODO(scttcper): This is only used in the edit request and we should
  90. * move it to its own interface
  91. */
  92. optOutEdit?: boolean;
  93. snoozeCreatedBy?: string;
  94. snoozeForEveryone?: boolean;
  95. }
  96. // Project's alert rule stats
  97. export type ProjectAlertRuleStats = {
  98. count: number;
  99. date: string;
  100. };
  101. export enum MailActionTargetType {
  102. ISSUE_OWNERS = 'IssueOwners',
  103. TEAM = 'Team',
  104. MEMBER = 'Member',
  105. RELEASE_MEMBERS = 'ReleaseMembers',
  106. }
  107. export enum AssigneeTargetType {
  108. UNASSIGNED = 'Unassigned',
  109. TEAM = 'Team',
  110. MEMBER = 'Member',
  111. }
  112. export type NoteType = {
  113. mentions: string[];
  114. text: string;
  115. };
  116. /**
  117. * Used when determining what types of actions a rule has. The default action is "sentry.mail.actions.NotifyEmailAction"
  118. * while other actions can be integration (Slack, PagerDuty, etc) actions. We need to know this to determine what kind of muting
  119. * the alert should have.
  120. */
  121. export enum RuleActionsCategories {
  122. ALL_DEFAULT = 'all_default',
  123. SOME_DEFAULT = 'some_default',
  124. NO_DEFAULT = 'no_default',
  125. }