Browse Source

feat(perf-issues): Add 'issueSupports' helper (#38518)

Co-authored-by: George Gritsouk <989898+gggritso@users.noreply.github.com>
Evan Purkhiser 2 years ago
parent
commit
d667f8361c
2 changed files with 52 additions and 0 deletions
  1. 23 0
      static/app/types/group.tsx
  2. 29 0
      static/app/utils/groupCapabilities.tsx

+ 23 - 0
static/app/types/group.tsx

@@ -52,6 +52,29 @@ export enum IssueType {
   PERFORMANCE_N_PLUS_ONE = 'performance_n_plus_one',
 }
 
+/**
+ * Defines what capabilities a category of issue has. Not all categories of
+ * issues work the same.
+ */
+export type IssueCategoryCapabilities = {
+  /**
+   * Can the issue be deleted
+   */
+  delete: boolean;
+  /**
+   * Can the issue be deleted and discarded
+   */
+  deleteAndDiscard: boolean;
+  /**
+   * Can the issue be ignored
+   */
+  ignore: boolean;
+  /**
+   * Can the issue be merged
+   */
+  merge: boolean;
+};
+
 // endpoint: /api/0/issues/:issueId/attachments/?limit=50
 export type IssueAttachment = {
   dateCreated: string;

+ 29 - 0
static/app/utils/groupCapabilities.tsx

@@ -0,0 +1,29 @@
+import {IssueCategory, IssueCategoryCapabilities} from 'sentry/types/group';
+
+/**
+ * Defines what capabilities each category of issue supports
+ */
+const ISSUE_CATEGORY_CAPABILITIES: Record<IssueCategory, IssueCategoryCapabilities> = {
+  [IssueCategory.ERROR]: {
+    delete: true,
+    deleteAndDiscard: true,
+    ignore: true,
+    merge: true,
+  },
+  [IssueCategory.PERFORMANCE]: {
+    delete: false,
+    deleteAndDiscard: false,
+    ignore: false,
+    merge: false,
+  },
+};
+
+/**
+ * Checks if an issue supports a specific capability.
+ */
+export function issueSupports(
+  issueCategory: IssueCategory,
+  capability: keyof IssueCategoryCapabilities
+) {
+  return ISSUE_CATEGORY_CAPABILITIES[issueCategory][capability] ?? false;
+}