Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert files related to redux from js to ts #462

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
61fa7eb
[MM-222] Convert reducer and action types file to typescript and remo…
raghavaggarwal2308 Feb 16, 2024
90db1a0
[MM-222] Converted select file to typescript and fixes some css warnings
raghavaggarwal2308 Feb 16, 2024
f7b3d14
[MM-222] Convert actions file to typescript
raghavaggarwal2308 Feb 16, 2024
9588241
[MM-222] Updated reducer, used reducer type for store and added more …
ayusht2810 Mar 26, 2024
58fb984
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
ayusht2810 Mar 26, 2024
c765edd
[MM-222] Resolved conflicts from master
ayusht2810 Mar 26, 2024
950a339
[MM-222] Migrate a component to TS and minor review fixes
ayusht2810 Mar 28, 2024
7eaf225
[MM-222] Fix flaky test
ayusht2810 Mar 28, 2024
70f6986
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
raghavaggarwal2308 Jun 25, 2024
ee206bc
[MM-520] Review fixes
raghavaggarwal2308 Jun 25, 2024
98b9f75
[MM-520] Fix ts error in index file
raghavaggarwal2308 Jun 25, 2024
e501324
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
raghavaggarwal2308 Jul 3, 2024
a696754
[MM-542] Review fixes
raghavaggarwal2308 Jul 3, 2024
c8c2c38
MM-222: converted client file to TS
Kshitij-Katiyar Jul 8, 2024
ec3d6a0
[MM-222]: Added type to the client promises
Kshitij-Katiyar Jul 9, 2024
ce22b9a
[MM-222]: Added more types to the client.ts file
Kshitij-Katiyar Jul 9, 2024
e75b2c6
[MM-222]: updated function return type and added few types to client.ts
Kshitij-Katiyar Jul 10, 2024
7ac4b3b
[MM-222]: fixed linting issue
Kshitij-Katiyar Jul 10, 2024
35554b2
[MM-222]: resolved conflicts
Kshitij-Katiyar Jul 10, 2024
d1ebe67
[MM-222]: removed null type from client.ts API response
Kshitij-Katiyar Jul 10, 2024
64b28bc
[MM-222]: Added some additional types
Kshitij-Katiyar Jul 15, 2024
64b4385
Added lint types
Kshitij-Katiyar Jul 15, 2024
f7b2bf2
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
raghavaggarwal2308 Jul 31, 2024
ff8d95d
[MM-656] Add types for redux funcs related to create issue and attach…
raghavaggarwal2308 Aug 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
92 changes: 34 additions & 58 deletions webapp/src/actions/index.js → webapp/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import {getCurrentChannelId, getCurrentUserId} from 'mattermost-redux/selectors/

import {PostTypes} from 'mattermost-redux/action_types';

import {AnyAction, Dispatch} from 'redux';

import Client from '../client';
import ActionTypes from '../action_types';
import manifest from '../manifest';
import {APIError, ConnectedData, GitlabUsersData, LHSData, ShowRhsPluginActionData, SubscriptionData} from 'src/types';
import {Item} from 'src/types/gitlab_items';
import {GlobalState, pluginStateKey} from 'src/types/store';

export function getConnected(reminder = false) {
return async (dispatch) => {
let data;
return async (dispatch: Dispatch<AnyAction>) => {
let data: ConnectedData;
try {
data = await Client.getConnected(reminder);
} catch (error) {
Expand All @@ -24,8 +29,8 @@ export function getConnected(reminder = false) {
};
}

function checkAndHandleNotConnected(data) {
return async (dispatch) => {
function checkAndHandleNotConnected(data: APIError) {
return async (dispatch: Dispatch<AnyAction>) => {
if (data && data.id === 'not_connected') {
dispatch({
type: ActionTypes.RECEIVED_CONNECTED,
Expand All @@ -34,24 +39,24 @@ function checkAndHandleNotConnected(data) {
gitlab_username: '',
gitlab_client_id: '',
settings: {},
},
} as ConnectedData,
});
return false;
}
return true;
};
}

export function getReviewDetails(prList) {
return async (dispatch, getState) => {
let data;
export function getReviewDetails(prList: Item[]) {
return async (dispatch: Dispatch<AnyAction>) => {
let data: Item | APIError;
try {
data = await Client.getPrsDetails(prList);
} catch (error) {
return {error};
}

const connected = await checkAndHandleNotConnected(data)(dispatch, getState);
const connected = await checkAndHandleNotConnected(data as APIError)(dispatch);
if (!connected) {
return {error: data};
}
Expand All @@ -65,16 +70,16 @@ export function getReviewDetails(prList) {
};
}

export function getYourPrDetails(prList) {
return async (dispatch, getState) => {
let data;
export function getYourPrDetails(prList: Item[]) {
return async (dispatch: Dispatch<AnyAction>) => {
let data: Item | APIError;
try {
data = await Client.getPrsDetails(prList);
} catch (error) {
return {error};
}

const connected = await checkAndHandleNotConnected(data)(dispatch, getState);
const connected = await checkAndHandleNotConnected(data as APIError)(dispatch);
if (!connected) {
return {error: data};
}
Expand All @@ -88,45 +93,16 @@ export function getYourPrDetails(prList) {
};
}

export function getMentions() {
return async (dispatch, getState) => {
let data;
try {
data = await Client.getMentions();
} catch (error) {
return {error};
}

const connected = await checkAndHandleNotConnected(data)(
dispatch,
getState,
);
if (!connected) {
return {error: data};
}

dispatch({
type: ActionTypes.RECEIVED_MENTIONS,
data,
});

return {data};
};
}

export function getLHSData() {
return async (dispatch, getState) => {
let data;
return async (dispatch: Dispatch<AnyAction>) => {
let data: LHSData | APIError;
try {
data = await Client.getLHSData();
} catch (error) {
return {error};
}

const connected = await checkAndHandleNotConnected(data)(
dispatch,
getState,
);
const connected = await checkAndHandleNotConnected(data as APIError)(dispatch);
if (!connected) {
return {error: data};
}
Expand All @@ -144,14 +120,14 @@ export function getLHSData() {
* Stores "showRHSPlugin" action returned by
* "registerRightHandSidebarComponent" in plugin initialization.
*/
export function setShowRHSAction(showRHSPluginAction) {
export function setShowRHSAction(showRHSPluginAction: ShowRhsPluginActionData) {
return {
type: ActionTypes.RECEIVED_SHOW_RHS_ACTION,
showRHSPluginAction,
};
}

export function updateRHSState(rhsState) {
export function updateRHSState(rhsState: string) {
return {
type: ActionTypes.UPDATE_RHS_STATE,
state: rhsState,
Expand All @@ -160,13 +136,13 @@ export function updateRHSState(rhsState) {

const GITLAB_USER_GET_TIMEOUT_MILLISECONDS = 1000 * 60 * 60; // 1 hour

export function getGitlabUser(userID) {
return async (dispatch, getState) => {
export function getGitlabUser(userID: string) {
return async (dispatch: Dispatch<AnyAction>, getState: () => GlobalState) => {
if (!userID) {
return {};
}

const user = getState()[`plugins-${manifest.id}`].gitlabUsers[userID];
const user = getState()[`plugins-${manifest.id}` as pluginStateKey].gitlabUsers[userID];
if (
user &&
user.last_try &&
Expand All @@ -179,11 +155,11 @@ export function getGitlabUser(userID) {
return {data: user};
}

let data;
let data: GitlabUsersData;
try {
data = await Client.getGitlabUser(userID);
} catch (error) {
if (error.status === 404) {
} catch (error: unknown) {
if ((error as APIError).status === 404) {
dispatch({
type: ActionTypes.RECEIVED_GITLAB_USER,
userID,
ayusht2810 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -203,13 +179,13 @@ export function getGitlabUser(userID) {
};
}

export function getChannelSubscriptions(channelId) {
return async (dispatch) => {
export function getChannelSubscriptions(channelId: string) {
return async (dispatch: Dispatch<AnyAction>) => {
if (!channelId) {
return {};
}

let subscriptions;
let subscriptions: SubscriptionData;
try {
subscriptions = await Client.getChannelSubscriptions(channelId);
} catch (error) {
Expand All @@ -228,8 +204,8 @@ export function getChannelSubscriptions(channelId) {
};
}

export function sendEphemeralPost(message) {
return (dispatch, getState) => {
export function sendEphemeralPost(message: string) {
return (dispatch: Dispatch<AnyAction>, getState: () => GlobalState) => {
const timestamp = Date.now();
const state = getState();

Expand Down
4 changes: 0 additions & 4 deletions webapp/src/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export default class Client {
return this.doGet(`${this.url}/lhs-data`);
}

getMentions = async () => {
Kshitij-Katiyar marked this conversation as resolved.
Show resolved Hide resolved
return this.doGet(`${this.url}/mentions`);
};

getGitlabUser = async (userID) => {
return this.doPost(`${this.url}/user`, {user_id: userID});
};
Expand Down
10 changes: 5 additions & 5 deletions webapp/src/components/rhs_sidebar/rhs_sidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@
.gitlab-rhs-Description {
font-size: 12px;
font-weight: 400;
letterSpacing: 0;
letter-spacing: 0;
}

.gitlab-rhs-Username {
font-size: 11px;
font-weight: 600;
letterSpacing: 0.02em;
letter-spacing: 0.02em;
}

.gitlab-rhs-GitLabURL {
Expand Down Expand Up @@ -129,12 +129,12 @@
}

.gitlab-rhs-SubscriptionHeader {
font-family: 'Open Sans';
font-family: 'Open Sans' !important;
font-size: 12px;
font-weight: 600;
line-height: 16px;
letterSpacing: 0.02em;
textTransform: uppercase;
letter-spacing: 0.02em;
ayusht2810 marked this conversation as resolved.
Show resolved Hide resolved
text-transform: uppercase;
margin: 0 0 4px 0;
color: rgba(var(--center-channel-color-rgb), 0.72);
}
Expand Down
Loading
Loading