Skip to content

Commit

Permalink
[MM-199]: Fixed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Kshitij-Katiyar committed Apr 2, 2024
1 parent ec1b6dc commit 7b58b12
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
8 changes: 5 additions & 3 deletions webapp/src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions';
import {DispatchFunc} from 'mattermost-redux/types/actions';

import {GlobalState} from '../types/store';
import {getPluginState} from '../selectors';

import {GetStateFunc} from '../types/store';

import Client from '../client';
import ActionTypes from '../action_types';
Expand Down Expand Up @@ -221,7 +223,7 @@ export function getGitHubUser(userID: string) {
return {};
}

const user = (getState() as GlobalState)['plugins-github'].githubUsers[userID];
const user = getPluginState(getState()).githubUsers[userID];
if (user && user.last_try && Date.now() - user.last_try < GITHUB_USER_GET_TIMEOUT_MILLISECONDS) {
return {};
}
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/sidebar_right/github_items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ const getStyle = makeStyleFromTheme((theme) => {
};
});

function getGithubLabels(labels: Label[]) {
function getGithubLabels(labels: GithubLabel[]) {
return labels.map((label) => {
return (
<Badge
Expand Down
14 changes: 8 additions & 6 deletions webapp/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {createSelector} from 'reselect';

import {GlobalState} from './types/store';

const getPluginState = (state: GlobalState) => state['plugins-github'] || {};
const emptyArray: GithubIssueData[] | UnreadsData[] = [];

export const getPluginState = (state: GlobalState) => state['plugins-github'] || {};

export const getServerRoute = (state: GlobalState) => {
const config = getConfig(state);
Expand Down Expand Up @@ -47,14 +49,14 @@ function mapPrsToDetails(prs: GithubIssueData[], details: PrsDetailsData[]) {

export const getSidebarData = createSelector(
getPluginState,
(pluginState) => {
(pluginState): SidebarData => {
const {username, sidebarContent, reviewDetails, yourPrDetails, organization, rhsState} = pluginState;
return {
username,
reviews: mapPrsToDetails(sidebarContent.reviews || [], reviewDetails),
yourPrs: mapPrsToDetails(sidebarContent.prs || [], yourPrDetails),
yourAssignments: sidebarContent.assignments || [],
unreads: sidebarContent.unreads || [],
reviews: mapPrsToDetails(sidebarContent.reviews || emptyArray, reviewDetails),
yourPrs: mapPrsToDetails(sidebarContent.prs || emptyArray, yourPrDetails),
yourAssignments: sidebarContent.assignments || emptyArray,
unreads: sidebarContent.unreads || emptyArray,
org: organization,
rhsState,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Label = {
type GithubLabel = {
id: number;
name: string;
color: CSS.Properties;
Expand Down Expand Up @@ -125,3 +125,13 @@ type APIError = {
message: string;
status_code: number;
}

type SidebarData = {
username: string;
reviews: GithubIssueData[];
yourPrs: GithubIssueData[];
yourAssignments: GithubIssueData[],
unreads: UnreadsData[]
org: organization,
rhsState?: string | null
}
28 changes: 7 additions & 21 deletions webapp/src/types/store.d.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
import {GlobalState as ReduxGlobalState} from 'mattermost-redux/types/store';

import reducers from '../reducers';

export type GetStateFunc = () => GlobalState

export type GlobalState = ReduxGlobalState & {
'plugins-github': {
connected: boolean,
enterpriseURL: string,
organization: string,
username: string,
userSettings: UserSettingsData,
configuration: ConfigurationData | Record<string, unknown>,
clientId: string,
reviewDetails: PrsDetailsData[],
sidebarContent: SidebarContentData,
yourRepos: YourReposData[],
yourPrDetails: PrsDetailsData[],
mentions: MentionsData[],
githubUsers: Record<string, GithubUsersData>,
rhsPluginAction: ShowRhsPluginActionData | null,
rhsState: string | null,
isCreateIssueModalVisible: boolean,
attachCommentToIssueModalVisible: boolean,
createIssueModal: CreateIssueModalData,
attachCommentToIssueModalForPostId: string,
}
'plugins-github': PluginState
};

export type PluginState = ReturnType<typeof reducers>

0 comments on commit 7b58b12

Please sign in to comment.