Browse Source

ref(ts): Convert `actionCreators/group` (#20638)

Co-authored-by: Priscila Oliveira <priscilawebdev@gmail.com>
Billy Vong 4 years ago
parent
commit
474dfb63af

+ 31 - 7
src/sentry/static/sentry/app/actionCreators/group.jsx → src/sentry/static/sentry/app/actionCreators/group.tsx

@@ -5,8 +5,18 @@ import {buildUserId, buildTeamId} from 'app/utils';
 import {uniqueId} from 'app/utils/guid';
 import GroupActions from 'app/actions/groupActions';
 import GroupStore from 'app/stores/groupStore';
-
-export function assignToUser(params) {
+import {Member, User, Group, Actor, Note} from 'app/types';
+
+type AssignToUserParams = {
+  /**
+   * Issue id
+   */
+  id: string;
+  user: User;
+  member?: Member;
+};
+
+export function assignToUser(params: AssignToUserParams) {
   const api = new Client();
 
   const endpoint = `/issues/${params.id}/`;
@@ -38,7 +48,7 @@ export function assignToUser(params) {
   return request;
 }
 
-export function clearAssignment(groupId) {
+export function clearAssignment(groupId: string) {
   const api = new Client();
 
   const endpoint = `/issues/${groupId}/`;
@@ -68,7 +78,15 @@ export function clearAssignment(groupId) {
   return request;
 }
 
-export function assignToActor({id, actor}) {
+type AssignToActorParams = {
+  /**
+   * Issue id
+   */
+  id: string;
+  actor: Pick<Actor, 'id' | 'type'>;
+};
+
+export function assignToActor({id, actor}: AssignToActorParams) {
   const api = new Client();
 
   const endpoint = `/issues/${id}/`;
@@ -107,7 +125,7 @@ export function assignToActor({id, actor}) {
     });
 }
 
-export function deleteNote(api, group, id, oldText) {
+export function deleteNote(api: Client, group: Group, id: string, oldText: string) {
   const index = GroupStore.removeActivity(group.id, id);
   if (index === -1) {
     // I dunno, the id wasn't found in the GroupStore
@@ -125,7 +143,7 @@ export function deleteNote(api, group, id, oldText) {
   return promise;
 }
 
-export function createNote(api, group, note) {
+export function createNote(api: Client, group: Group, note: Note) {
   const promise = api.requestPromise(`/issues/${group.id}/comments/`, {
     method: 'POST',
     data: note,
@@ -136,7 +154,13 @@ export function createNote(api, group, note) {
   return promise;
 }
 
-export function updateNote(api, group, note, id, oldText) {
+export function updateNote(
+  api: Client,
+  group: Group,
+  note: Note,
+  id: string,
+  oldText: string
+) {
   GroupStore.updateActivity(group.id, id, {text: note.text});
 
   const promise = api.requestPromise(`/issues/${group.id}/comments/${id}/`, {

+ 5 - 2
src/sentry/static/sentry/app/components/group/suggestedOwners/suggestedOwners.tsx

@@ -156,11 +156,14 @@ class SuggestedOwners extends React.Component<Props, State> {
     const {event} = this.props;
 
     if (actor.type === 'user') {
-      assignToUser({id: event.groupID, user: actor});
+      // TODO(ts): `event` here may not be 100% correct
+      // in this case groupID should always exist on event
+      // since this is only used in Issue Details
+      assignToUser({id: event.groupID as string, user: actor});
     }
 
     if (actor.type === 'team') {
-      assignToActor({id: event.groupID, actor});
+      assignToActor({id: event.groupID as string, actor});
     }
   };
 

+ 15 - 0
src/sentry/static/sentry/app/types/index.tsx

@@ -1408,3 +1408,18 @@ export type Frame = {
   mapUrl?: string;
   instructionAddr?: string;
 };
+
+/**
+ * Note used in Group Activity and Alerts for users to comment
+ */
+export type Note = {
+  /**
+   * Note contents (markdown allowed)
+   */
+  text: string;
+
+  /**
+   * Array of [id, display string] tuples used for @-mentions
+   */
+  mentions: [string, string][];
+};