Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
MM-28833 Remove computed details from getChannel selector (#6794)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmhealey committed Oct 28, 2020
1 parent c8372b9 commit 7d3af58
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 30 deletions.
4 changes: 2 additions & 2 deletions actions/notification_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import semver from 'semver';
import {logError} from 'mattermost-redux/actions/errors';
import {getProfilesByIds} from 'mattermost-redux/actions/users';
import {getChannel, getCurrentChannel, getMyChannelMember} from 'mattermost-redux/selectors/entities/channels';
import {getCurrentChannel, getMyChannelMember, makeGetChannel} from 'mattermost-redux/selectors/entities/channels';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {getTeammateNameDisplaySetting} from 'mattermost-redux/selectors/entities/preferences';
import {getCurrentUserId, getCurrentUser, getStatusForUserId, getUser} from 'mattermost-redux/selectors/entities/users';
Expand Down Expand Up @@ -48,7 +48,7 @@ export function sendDesktopNotification(post, msgProps) {
}
const teamId = msgProps.team_id;

let channel = getChannel(state, post.channel_id);
let channel = makeGetChannel()(state, post.channel_id);
const user = getCurrentUser(state);
const userStatus = getStatusForUserId(state, user.id);
const member = getMyChannelMember(state, post.channel_id);
Expand Down
1 change: 0 additions & 1 deletion components/post_view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ function makeMapStateToProps() {
return {
lastViewedAt,
channelLoading,
channel,
};
};
}
Expand Down
2 changes: 1 addition & 1 deletion components/rhs_root_post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function mapStateToProps(state, ownProps) {
const enableEmojiPicker = config.EnableEmojiPicker === 'true';
const enablePostUsernameOverride = config.EnablePostUsernameOverride === 'true';
const teamId = ownProps.teamId || getCurrentTeamId(state);
const channel = getChannel(state, ownProps.post.channel_id) || {};
const channel = getChannel(state, ownProps.post.channel_id);
const emojiMap = getEmojiMap(state);
const shortcutReactToLastPostEmittedFrom = getShortcutReactToLastPostEmittedFrom(state);

Expand Down
6 changes: 2 additions & 4 deletions components/rhs_thread/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import {connect} from 'react-redux';
import {bindActionCreators, Dispatch} from 'redux';
import {getChannel} from 'mattermost-redux/selectors/entities/channels';
import {makeGetPostsForThread} from 'mattermost-redux/selectors/entities/posts';
import {get, getBool} from 'mattermost-redux/selectors/entities/preferences';
import {removePost, getPostThread} from 'mattermost-redux/actions/posts';
Expand All @@ -13,7 +12,7 @@ import {UserProfile} from 'mattermost-redux/src/types/users';

import {Preferences} from 'utils/constants';
import {getDirectTeammate} from 'utils/utils.jsx';
import {getSelectedPost} from 'selectors/rhs';
import {getSelectedChannel, getSelectedPost} from 'selectors/rhs';
import {getSocketStatus} from 'selectors/views/websocket';
import {selectPostCard} from 'actions/views/rhs';
import {GlobalState} from 'types/store';
Expand All @@ -27,11 +26,10 @@ function makeMapStateToProps() {
const selected = getSelectedPost(state);
const socketStatus = getSocketStatus(state);

let channel = null;
const channel = getSelectedChannel(state);
let posts: Post[] = [];
if (selected) {
posts = getPostsForThread(state, {rootId: selected.id});
channel = getChannel(state, selected.channel_id);
}

const previewCollapsed = get(state, Preferences.CATEGORY_DISPLAY_SETTINGS, Preferences.COLLAPSE_DISPLAY, Preferences.COLLAPSE_DISPLAY_DEFAULT);
Expand Down
15 changes: 3 additions & 12 deletions components/sidebar_right/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users';
import {
getChannel,
getCurrentChannel,
} from 'mattermost-redux/selectors/entities/channels';
import {getCurrentChannel} from 'mattermost-redux/selectors/entities/channels';

import {setRhsExpanded, showPinnedPosts, openRHSSearch, closeRightHandSide, openAtPrevious, updateSearchTerms} from 'actions/views/rhs';
import {
getIsRhsExpanded,
getIsRhsOpen,
getRhsState,
getSelectedChannel,
getSelectedPostId,
getSelectedPostCardId,
getSelectedChannelId,
getPreviousRhsState,
} from 'selectors/rhs';
import {RHSStates} from 'utils/constants';
Expand All @@ -26,12 +23,6 @@ import SidebarRight from './sidebar_right.jsx';
function mapStateToProps(state) {
const rhsState = getRhsState(state);
const channel = getCurrentChannel(state);
const channelId = getSelectedChannelId(state);

let rhsChannel = null;
if (channelId) {
rhsChannel = getChannel(state, channelId);
}

const selectedPostId = getSelectedPostId(state);
const selectedPostCardId = getSelectedPostCardId(state);
Expand All @@ -49,7 +40,7 @@ function mapStateToProps(state) {
isFlaggedPosts: rhsState === RHSStates.FLAG,
isPinnedPosts: rhsState === RHSStates.PIN,
isPluginView: rhsState === RHSStates.PLUGIN,
rhsChannel,
rhsChannel: getSelectedChannel(state),
selectedPostId,
selectedPostCardId,
};
Expand Down
18 changes: 10 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"localforage-observable": "2.0.1",
"mark.js": "8.11.1",
"marked": "github:mattermost/marked#87769262aa02e1784570f61f4f962050e07cc335",
"mattermost-redux": "github:mattermost/mattermost-redux#fdf8fa87579f6457d55f8999301fe52068ac67d6",
"mattermost-redux": "github:mattermost/mattermost-redux#aba4df6b300ad4aaf8e0adb734ff549bf236d110",
"moment-timezone": "0.5.31",
"p-queue": "6.6.1",
"pdfjs-dist": "2.1.266",
Expand Down
14 changes: 13 additions & 1 deletion selectors/rhs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// See LICENSE.txt for license information.

import {createSelector} from 'reselect';
import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users';

import {makeGetChannel} from 'mattermost-redux/selectors/entities/channels';
import {Post, PostType} from 'mattermost-redux/types/posts';
import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users';
import {Channel} from 'mattermost-redux/types/channels';
import {$ID} from 'mattermost-redux/types/utilities';

Expand Down Expand Up @@ -33,6 +35,16 @@ export function getSelectedChannelId(state: GlobalState) {
return state.views.rhs.selectedChannelId;
}

export const getSelectedChannel = (() => {
const getChannel = makeGetChannel();

return (state: GlobalState) => {
const channelId = getSelectedChannelId(state);

return getChannel(state, {id: channelId});
};
})();

export function getPluggableId(state: GlobalState) {
return state.views.rhs.pluggableId;
}
Expand Down

0 comments on commit 7d3af58

Please sign in to comment.