Skip to content

Commit 936e5c3

Browse files
ayusht2810Kshitij-Katiyarhanzei
authored
[MM-199] Convert files related to redux from js to ts (#743)
* [MM-199] Convert files related to redux from js to ts * [MM-199]: Fixed review comments * [MM-199] Update type file and import types explicitly --------- Co-authored-by: kshitij <[email protected]> Co-authored-by: Ben Schumacher <[email protected]>
1 parent da4c4df commit 936e5c3

File tree

9 files changed

+262
-138
lines changed

9 files changed

+262
-138
lines changed
File renamed without changes.

webapp/src/actions/index.js renamed to webapp/src/actions/index.ts

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
22
// See LICENSE.txt for license information.
33

4+
import {DispatchFunc} from 'mattermost-redux/types/actions';
5+
6+
import {getPluginState} from '../selectors';
7+
8+
import {GetStateFunc} from '../types/store';
9+
410
import Client from '../client';
511
import ActionTypes from '../action_types';
6-
7-
import manifest from '../manifest';
12+
import {APIError, PrsDetailsData, ShowRhsPluginActionData} from '../types/github_types';
813

914
export function getConnected(reminder = false) {
10-
return async (dispatch) => {
15+
return async (dispatch: DispatchFunc) => {
1116
let data;
1217
try {
1318
data = await Client.getConnected(reminder);
@@ -24,8 +29,8 @@ export function getConnected(reminder = false) {
2429
};
2530
}
2631

27-
function checkAndHandleNotConnected(data) {
28-
return async (dispatch) => {
32+
function checkAndHandleNotConnected(data: {id: string}) {
33+
return async (dispatch: DispatchFunc) => {
2934
if (data && data.id === 'not_connected') {
3035
dispatch({
3136
type: ActionTypes.RECEIVED_CONNECTED,
@@ -42,16 +47,16 @@ function checkAndHandleNotConnected(data) {
4247
};
4348
}
4449

45-
export function getReviewsDetails(prList) {
46-
return async (dispatch, getState) => {
50+
export function getReviewsDetails(prList: PrsDetailsData[]) {
51+
return async (dispatch: DispatchFunc) => {
4752
let data;
4853
try {
4954
data = await Client.getPrsDetails(prList);
5055
} catch (error) {
5156
return {error};
5257
}
5358

54-
const connected = await checkAndHandleNotConnected(data)(dispatch, getState);
59+
const connected = await checkAndHandleNotConnected(data)(dispatch);
5560
if (!connected) {
5661
return {error: data};
5762
}
@@ -66,15 +71,15 @@ export function getReviewsDetails(prList) {
6671
}
6772

6873
export function getRepos() {
69-
return async (dispatch, getState) => {
74+
return async (dispatch: DispatchFunc) => {
7075
let data;
7176
try {
7277
data = await Client.getRepositories();
7378
} catch (error) {
7479
return {error: data};
7580
}
7681

77-
const connected = await checkAndHandleNotConnected(data)(dispatch, getState);
82+
const connected = await checkAndHandleNotConnected(data)(dispatch);
7883
if (!connected) {
7984
return {error: data};
8085
}
@@ -89,15 +94,15 @@ export function getRepos() {
8994
}
9095

9196
export function getSidebarContent() {
92-
return async (dispatch, getState) => {
97+
return async (dispatch: DispatchFunc) => {
9398
let data;
9499
try {
95100
data = await Client.getSidebarContent();
96101
} catch (error) {
97102
return {error};
98103
}
99104

100-
const connected = await checkAndHandleNotConnected(data)(dispatch, getState);
105+
const connected = await checkAndHandleNotConnected(data)(dispatch);
101106
if (!connected) {
102107
return {error: data};
103108
}
@@ -111,16 +116,16 @@ export function getSidebarContent() {
111116
};
112117
}
113118

114-
export function getYourPrsDetails(prList) {
115-
return async (dispatch, getState) => {
119+
export function getYourPrsDetails(prList: PrsDetailsData[]) {
120+
return async (dispatch: DispatchFunc) => {
116121
let data;
117122
try {
118123
data = await Client.getPrsDetails(prList);
119124
} catch (error) {
120125
return {error};
121126
}
122127

123-
const connected = await checkAndHandleNotConnected(data)(dispatch, getState);
128+
const connected = await checkAndHandleNotConnected(data)(dispatch);
124129
if (!connected) {
125130
return {error: data};
126131
}
@@ -134,16 +139,16 @@ export function getYourPrsDetails(prList) {
134139
};
135140
}
136141

137-
export function getLabelOptions(repo) {
138-
return async (dispatch, getState) => {
142+
export function getLabelOptions(repo: string) {
143+
return async (dispatch: DispatchFunc) => {
139144
let data;
140145
try {
141146
data = await Client.getLabels(repo);
142147
} catch (error) {
143148
return {error};
144149
}
145150

146-
const connected = await checkAndHandleNotConnected(data)(dispatch, getState);
151+
const connected = await checkAndHandleNotConnected(data)(dispatch);
147152
if (!connected) {
148153
return {error: data};
149154
}
@@ -152,16 +157,16 @@ export function getLabelOptions(repo) {
152157
};
153158
}
154159

155-
export function getAssigneeOptions(repo) {
156-
return async (dispatch, getState) => {
160+
export function getAssigneeOptions(repo: string) {
161+
return async (dispatch: DispatchFunc) => {
157162
let data;
158163
try {
159164
data = await Client.getAssignees(repo);
160165
} catch (error) {
161166
return {error};
162167
}
163168

164-
const connected = await checkAndHandleNotConnected(data)(dispatch, getState);
169+
const connected = await checkAndHandleNotConnected(data)(dispatch);
165170
if (!connected) {
166171
return {error: data};
167172
}
@@ -170,16 +175,16 @@ export function getAssigneeOptions(repo) {
170175
};
171176
}
172177

173-
export function getMilestoneOptions(repo) {
174-
return async (dispatch, getState) => {
178+
export function getMilestoneOptions(repo: string) {
179+
return async (dispatch: DispatchFunc) => {
175180
let data;
176181
try {
177182
data = await Client.getMilestones(repo);
178183
} catch (error) {
179184
return {error};
180185
}
181186

182-
const connected = await checkAndHandleNotConnected(data)(dispatch, getState);
187+
const connected = await checkAndHandleNotConnected(data)(dispatch);
183188
if (!connected) {
184189
return {error: data};
185190
}
@@ -189,15 +194,15 @@ export function getMilestoneOptions(repo) {
189194
}
190195

191196
export function getMentions() {
192-
return async (dispatch, getState) => {
197+
return async (dispatch: DispatchFunc) => {
193198
let data;
194199
try {
195200
data = await Client.getMentions();
196201
} catch (error) {
197202
return {error};
198203
}
199204

200-
const connected = await checkAndHandleNotConnected(data)(dispatch, getState);
205+
const connected = await checkAndHandleNotConnected(data)(dispatch);
201206
if (!connected) {
202207
return {error: data};
203208
}
@@ -213,13 +218,13 @@ export function getMentions() {
213218

214219
const GITHUB_USER_GET_TIMEOUT_MILLISECONDS = 1000 * 60 * 60; // 1 hour
215220

216-
export function getGitHubUser(userID) {
217-
return async (dispatch, getState) => {
221+
export function getGitHubUser(userID: string) {
222+
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
218223
if (!userID) {
219224
return {};
220225
}
221226

222-
const user = getState()[`plugins-${manifest.id}`].githubUsers[userID];
227+
const user = getPluginState(getState()).githubUsers[userID];
223228
if (user && user.last_try && Date.now() - user.last_try < GITHUB_USER_GET_TIMEOUT_MILLISECONDS) {
224229
return {};
225230
}
@@ -231,8 +236,8 @@ export function getGitHubUser(userID) {
231236
let data;
232237
try {
233238
data = await Client.getGitHubUser(userID);
234-
} catch (error) {
235-
if (error.status === 404) {
239+
} catch (error: unknown) {
240+
if ((error as APIError).status_code === 404) {
236241
dispatch({
237242
type: ActionTypes.RECEIVED_GITHUB_USER,
238243
userID,
@@ -256,21 +261,21 @@ export function getGitHubUser(userID) {
256261
* Stores`showRHSPlugin` action returned by
257262
* registerRightHandSidebarComponent in plugin initialization.
258263
*/
259-
export function setShowRHSAction(showRHSPluginAction) {
264+
export function setShowRHSAction(showRHSPluginAction: ShowRhsPluginActionData) {
260265
return {
261266
type: ActionTypes.RECEIVED_SHOW_RHS_ACTION,
262267
showRHSPluginAction,
263268
};
264269
}
265270

266-
export function updateRhsState(rhsState) {
271+
export function updateRhsState(rhsState: string) {
267272
return {
268273
type: ActionTypes.UPDATE_RHS_STATE,
269274
state: rhsState,
270275
};
271276
}
272277

273-
export function openCreateIssueModal(postId) {
278+
export function openCreateIssueModal(postId: string) {
274279
return {
275280
type: ActionTypes.OPEN_CREATE_ISSUE_MODAL,
276281
data: {
@@ -279,7 +284,7 @@ export function openCreateIssueModal(postId) {
279284
};
280285
}
281286

282-
export function openCreateIssueModalWithoutPost(title, channelId) {
287+
export function openCreateIssueModalWithoutPost(title: string, channelId: string) {
283288
return {
284289
type: ActionTypes.OPEN_CREATE_ISSUE_MODAL_WITHOUT_POST,
285290
data: {
@@ -295,16 +300,16 @@ export function closeCreateIssueModal() {
295300
};
296301
}
297302

298-
export function createIssue(payload) {
299-
return async (dispatch) => {
303+
export function createIssue(payload: CreateIssuePayload) {
304+
return async (dispatch: DispatchFunc) => {
300305
let data;
301306
try {
302307
data = await Client.createIssue(payload);
303308
} catch (error) {
304309
return {error};
305310
}
306311

307-
const connected = await dispatch(checkAndHandleNotConnected(data));
312+
const connected = await checkAndHandleNotConnected(data);
308313
if (!connected) {
309314
return {error: data};
310315
}
@@ -313,7 +318,7 @@ export function createIssue(payload) {
313318
};
314319
}
315320

316-
export function openAttachCommentToIssueModal(postId) {
321+
export function openAttachCommentToIssueModal(postId: string) {
317322
return {
318323
type: ActionTypes.OPEN_ATTACH_COMMENT_TO_ISSUE_MODAL,
319324
data: {
@@ -328,16 +333,16 @@ export function closeAttachCommentToIssueModal() {
328333
};
329334
}
330335

331-
export function attachCommentToIssue(payload) {
332-
return async (dispatch) => {
336+
export function attachCommentToIssue(payload: AttachCommentToIssuePayload) {
337+
return async (dispatch: DispatchFunc) => {
333338
let data;
334339
try {
335340
data = await Client.attachCommentToIssue(payload);
336341
} catch (error) {
337342
return {error};
338343
}
339344

340-
const connected = await dispatch(checkAndHandleNotConnected(data));
345+
const connected = await checkAndHandleNotConnected(data);
341346
if (!connected) {
342347
return {error: data};
343348
}

0 commit comments

Comments
 (0)