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

MM-22989 - Adding reply count to root posts in RHS (Search, Flags, Pinned) #5031

Merged
merged 3 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
MM-22989 - Adding reply count to root posts in RHS
  • Loading branch information
asaadmahmood committed Mar 10, 2020
commit a3901b6dbbce02bf553ea6c078c0000bc05372d3
23 changes: 21 additions & 2 deletions components/search_results_item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {createSelector} from 'reselect';

import {getChannel} from 'mattermost-redux/selectors/entities/channels';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {getUser} from 'mattermost-redux/selectors/entities/users';
import {makeGetCommentCountForPost} from 'mattermost-redux/selectors/entities/posts';
import {getMyPreferences} from 'mattermost-redux/selectors/entities/preferences';
import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams';
import {isPostFlagged} from 'mattermost-redux/utils/post_utils';
import {isPostEphemeral, isPostFlagged} from 'mattermost-redux/utils/post_utils';

import {
closeRightHandSide,
Expand All @@ -23,7 +25,23 @@ import {getDirectTeammate, getDisplayNameByUser} from 'utils/utils.jsx';

import SearchResultsItem from './search_results_item.jsx';

export function makeGetReplyCount() {
return createSelector(
(state) => state.entities.posts.posts,
(state, post) => state.entities.posts.postsInThread[post.root_id || post.id],
(allPosts, postIds) => {
if (!postIds) {
return 0;
}

// Count the number of non-ephemeral posts in the thread
return postIds.map((id) => allPosts[id]).filter((post) => post && !isPostEphemeral(post)).length;
}
);
}

asaadmahmood marked this conversation as resolved.
Show resolved Hide resolved
function mapStateToProps() {
const getReplyCount = makeGetReplyCount();
const createAriaLabelForPost = makeCreateAriaLabelForPost();
const getCommentCountForPost = makeGetCommentCountForPost();

Expand All @@ -48,7 +66,8 @@ function mapStateToProps() {
isFlagged: isPostFlagged(post.id, preferences),
isBot: user ? user.is_bot : false,
directTeammate,
displayName: getDisplayNameByUser(state, directTeammate)
displayName: getDisplayNameByUser(state, directTeammate),
replyCount: getReplyCount(state, post),
};
};
}
Expand Down
7 changes: 7 additions & 0 deletions components/search_results_item/search_results_item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ class SearchResultsItem extends React.PureComponent {
intl: intlShape.isRequired,
directTeammate: PropTypes.string.isRequired,
displayName: PropTypes.string.isRequired,

/**
* The number of replies in the same thread as this post
*/
replyCount: PropTypes.number,
};

static defaultProps = {
Expand Down Expand Up @@ -307,8 +312,10 @@ class SearchResultsItem extends React.PureComponent {
<CommentIcon
location={Locations.SEARCH}
handleCommentClick={this.handleFocusRHSClick}
commentCount={this.props.replyCount}
postId={post.id}
searchStyle={'search-item__comment'}
extraClass={'icon--visible'}
/>
<a
href='#'
Expand Down