-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathindex.ts
More file actions
98 lines (75 loc) · 3.36 KB
/
index.ts
File metadata and controls
98 lines (75 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright (c) 2019-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {createSelector} from 'reselect';
import {getPost} from 'mattermost-redux/selectors/entities/posts';
import manifest from '../manifest';
import {Item} from '../types/gitlab_items';
import {GlobalState, PluginState, pluginStateKey} from '../types/store';
import {SideBarData} from '../types';
export const getPluginServerRoute = (state: GlobalState) => {
const config = getConfig(state);
let basePath = '';
if (config && config.SiteURL) {
basePath = new URL(config.SiteURL).pathname;
if (basePath && basePath[basePath.length - 1] === '/') {
basePath = basePath.substr(0, basePath.length - 1);
}
}
return basePath + '/plugins/' + manifest.id;
};
function mapPrsToDetails(prs?: Item[], details?: Item[]): Item[] {
if (!prs || !prs.length) {
return [];
}
return prs.map((pr) => {
const foundDetails = details && details.find((prDetails) => pr.project_id === prDetails.project_id && pr.sha === prDetails.sha);
if (!foundDetails) {
return pr;
}
return {
...pr,
status: foundDetails.status,
num_approvers: foundDetails.num_approvers,
total_reviewers: pr.reviewers.length,
};
});
}
export const getPluginState = (state: GlobalState) => state[pluginStateKey];
export const getSidebarData = createSelector(
getPluginState,
(pluginState: PluginState): SideBarData => {
return {
username: pluginState.username,
reviewDetails: pluginState.reviewDetails ?? [],
reviews: mapPrsToDetails(pluginState.lhsData?.reviews, pluginState.reviewDetails || []),
yourAssignedPrs: mapPrsToDetails(pluginState.lhsData?.yourAssignedPrs, pluginState.yourPrDetails || []),
yourPrDetails: pluginState.yourPrDetails ?? [],
yourAssignedIssues: pluginState.lhsData?.yourAssignedIssues ?? [],
todos: pluginState.lhsData?.todos ?? [],
org: pluginState.organization,
gitlabURL: pluginState.gitlabURL,
rhsState: pluginState.rhsState ?? '',
};
},
);
export const isCreateIssueModalVisible = (state: GlobalState) => getPluginState(state).isCreateIssueModalVisible;
export const isAttachCommentToIssueModalVisible = (state: GlobalState) => getPluginState(state).isAttachCommentToIssueModalVisible;
export const getCreateIssueModalContents = (state: GlobalState) => {
const {postId, title, channelId} = getPluginState(state).createIssueModal;
const post = postId ? getPost(state, postId) : null;
return {
post,
title,
channelId,
};
};
export const getAttachCommentModalContents = (state: GlobalState) => {
const postId = getPluginState(state).postIdForAttachCommentToIssueModal;
const post = getPost(state, postId);
return post;
};
export const getYourProjects = (state: GlobalState) => getPluginState(state).yourProjects;
export const getConnected = (state: GlobalState) => getPluginState(state).connected;
export const getConnectedGitlabUrl = (state: GlobalState) => getPluginState(state).gitlabURL;
export const getSidebarExpanded = (state: any) => state.views.rhs.isSidebarExpanded;