From a170ad9c411987606950bf4e382a7b2f321ac985 Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Wed, 28 Nov 2018 13:13:51 -0500 Subject: [PATCH 1/4] MM-13209: fix textbox to bind channel from props This avoids relying on a global notion of the current channel, which only applies to the centre and not the RHS. --- actions/views/channel.js | 7 +++---- components/textbox/index.js | 21 +++++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/actions/views/channel.js b/actions/views/channel.js index a2c1955ba94d..849dbc5680c5 100644 --- a/actions/views/channel.js +++ b/actions/views/channel.js @@ -2,7 +2,7 @@ // See LICENSE.txt for license information. import {leaveChannel as leaveChannelRedux, joinChannel, unfavoriteChannel} from 'mattermost-redux/actions/channels'; -import {getChannel, getChannelByName, getCurrentChannelId} from 'mattermost-redux/selectors/entities/channels'; +import {getChannel, getChannelByName} from 'mattermost-redux/selectors/entities/channels'; import {getCurrentRelativeTeamUrl, getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUserId, getUserByUsername} from 'mattermost-redux/selectors/entities/users'; import {getMyPreferences} from 'mattermost-redux/selectors/entities/preferences'; @@ -102,13 +102,12 @@ export function leaveChannel(channelId) { }; } -export function autocompleteUsersInChannel(prefix) { +export function autocompleteUsersInChannel(prefix, channelId) { return async (dispatch, getState) => { const state = getState(); const currentTeamId = getCurrentTeamId(state); - const currentChannelId = getCurrentChannelId(state); - return dispatch(autocompleteUsers(prefix, currentTeamId, currentChannelId)); + return dispatch(autocompleteUsers(prefix, currentTeamId, channelId)); }; } diff --git a/components/textbox/index.js b/components/textbox/index.js index f152c055e2a0..d777e9f8d331 100644 --- a/components/textbox/index.js +++ b/components/textbox/index.js @@ -4,21 +4,26 @@ import {bindActionCreators} from 'redux'; import {connect} from 'react-redux'; -import {getCurrentUserId, getProfilesInCurrentChannel, getProfilesNotInCurrentChannel} from 'mattermost-redux/selectors/entities/users'; +import {getCurrentUserId, makeGetProfilesInChannel, makeGetProfilesNotInChannel} from 'mattermost-redux/selectors/entities/users'; import {autocompleteUsersInChannel} from 'actions/views/channel'; import Textbox from './textbox.jsx'; -const mapStateToProps = (state) => ({ - currentUserId: getCurrentUserId(state), - profilesInChannel: getProfilesInCurrentChannel(state), - profilesNotInChannel: getProfilesNotInCurrentChannel(state), -}); +const mapStateToProps = () => { + const getProfilesInChannel = makeGetProfilesInChannel(); + const getProfilesNotInChannel = makeGetProfilesNotInChannel(); + + return (state, ownProps) => ({ + currentUserId: getCurrentUserId(state), + profilesInChannel: getProfilesInChannel(state, ownProps.channelId, true), + profilesNotInChannel: getProfilesNotInChannel(state, ownProps.channelId, true), + }); +}; -const mapDispatchToProps = (dispatch) => ({ +const mapDispatchToProps = (dispatch, ownProps) => ({ actions: bindActionCreators({ - autocompleteUsersInChannel, + autocompleteUsersInChannel: (prefix) => autocompleteUsersInChannel(prefix, ownProps.channelId), }, dispatch), }); From 1b49ad2bedb02c9225fed3ede8bacfebb197107a Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Thu, 29 Nov 2018 12:52:07 -0500 Subject: [PATCH 2/4] update mattermost-redux --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index ee65cc52ab4c..e7d0381ba575 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11581,8 +11581,8 @@ "dev": true }, "mattermost-redux": { - "version": "github:mattermost/mattermost-redux#f64d813e66d5f8f65cd9d92d87a7e94f0fa6c9f0", - "from": "github:mattermost/mattermost-redux#f64d813e66d5f8f65cd9d92d87a7e94f0fa6c9f0", + "version": "github:mattermost/mattermost-redux#652e79cc4ccbcb40ea4d4433e15b02f2ee338bf6", + "from": "github:mattermost/mattermost-redux#652e79cc4ccbcb40ea4d4433e15b02f2ee338bf6", "requires": { "deep-equal": "1.0.1", "eslint-plugin-header": "1.2.0", diff --git a/package.json b/package.json index b572d4399f95..3a76a44ce721 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "localforage": "1.7.2", "localforage-observable": "1.4.0", "marked": "github:mattermost/marked#ed33baecd7d7fa97d479ba22dde9d226b083d67d", - "mattermost-redux": "github:mattermost/mattermost-redux#f64d813e66d5f8f65cd9d92d87a7e94f0fa6c9f0", + "mattermost-redux": "github:mattermost/mattermost-redux#652e79cc4ccbcb40ea4d4433e15b02f2ee338bf6", "moment-timezone": "0.5.21", "pdfjs-dist": "2.0.489", "perfect-scrollbar": "0.8.1", From 7022502a8fbe244f53a33c38578c1e5256fc6d7f Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Thu, 29 Nov 2018 14:40:26 -0500 Subject: [PATCH 3/4] code review feedback --- components/__snapshots__/textbox.test.jsx.snap | 6 +++--- components/textbox/index.js | 8 ++++---- components/textbox/textbox.jsx | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/components/__snapshots__/textbox.test.jsx.snap b/components/__snapshots__/textbox.test.jsx.snap index 757e633e2c98..8e9f299e3f9e 100644 --- a/components/__snapshots__/textbox.test.jsx.snap +++ b/components/__snapshots__/textbox.test.jsx.snap @@ -24,7 +24,7 @@ exports[`components/TextBox should match snapshot with required props 1`] = ` providers={ Array [ AtMentionProvider { - "autocompleteUsersInChannel": [MockFunction], + "autocompleteUsersInChannel": [Function], "currentUserId": "currentUserId", "data": null, "disableDispatches": false, @@ -174,7 +174,7 @@ exports[`components/TextBox should throw error when new property is too long 1`] providers={ Array [ AtMentionProvider { - "autocompleteUsersInChannel": [MockFunction], + "autocompleteUsersInChannel": [Function], "currentUserId": "currentUserId", "data": null, "disableDispatches": false, @@ -324,7 +324,7 @@ exports[`components/TextBox should throw error when value is too long 1`] = ` providers={ Array [ AtMentionProvider { - "autocompleteUsersInChannel": [MockFunction], + "autocompleteUsersInChannel": [Function], "currentUserId": "currentUserId", "data": null, "disableDispatches": false, diff --git a/components/textbox/index.js b/components/textbox/index.js index d777e9f8d331..f3199909c61d 100644 --- a/components/textbox/index.js +++ b/components/textbox/index.js @@ -10,7 +10,7 @@ import {autocompleteUsersInChannel} from 'actions/views/channel'; import Textbox from './textbox.jsx'; -const mapStateToProps = () => { +const makeMapStateToProps = () => { const getProfilesInChannel = makeGetProfilesInChannel(); const getProfilesNotInChannel = makeGetProfilesNotInChannel(); @@ -21,10 +21,10 @@ const mapStateToProps = () => { }); }; -const mapDispatchToProps = (dispatch, ownProps) => ({ +const mapDispatchToProps = (dispatch) => ({ actions: bindActionCreators({ - autocompleteUsersInChannel: (prefix) => autocompleteUsersInChannel(prefix, ownProps.channelId), + autocompleteUsersInChannel, }, dispatch), }); -export default connect(mapStateToProps, mapDispatchToProps, null, {withRef: true})(Textbox); +export default connect(makeMapStateToProps, mapDispatchToProps, null, {withRef: true})(Textbox); diff --git a/components/textbox/textbox.jsx b/components/textbox/textbox.jsx index 7fa2d5fcaa03..1558a459530c 100644 --- a/components/textbox/textbox.jsx +++ b/components/textbox/textbox.jsx @@ -62,7 +62,7 @@ export default class Textbox extends React.Component { currentUserId: this.props.currentUserId, profilesInChannel: this.props.profilesInChannel, profilesNotInChannel: this.props.profilesNotInChannel, - autocompleteUsersInChannel: this.props.actions.autocompleteUsersInChannel, + autocompleteUsersInChannel: (prefix) => this.props.actions.autocompleteUsersInChannel(prefix, props.channelId), }), new ChannelMentionProvider(), new EmoticonProvider(), @@ -178,7 +178,7 @@ export default class Textbox extends React.Component { currentUserId: nextProps.currentUserId, profilesInChannel: nextProps.profilesInChannel, profilesNotInChannel: nextProps.profilesNotInChannel, - autocompleteUsersInChannel: nextProps.actions.autocompleteUsersInChannel, + autocompleteUsersInChannel: (prefix) => nextProps.actions.autocompleteUsersInChannel(prefix, nextProps.channelId), }); } } From c06b50affb56a91d5a4487a3bca6c4a93f52bdfe Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Mon, 3 Dec 2018 09:25:42 -0500 Subject: [PATCH 4/4] update mattermost-redux --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 019a06f9329a..fc046988c4cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11581,8 +11581,8 @@ "dev": true }, "mattermost-redux": { - "version": "github:mattermost/mattermost-redux#212101f413f0c8288f4250a74b60a8c8c58418f7", - "from": "github:mattermost/mattermost-redux#212101f413f0c8288f4250a74b60a8c8c58418f7", + "version": "github:mattermost/mattermost-redux#632cda350e295aa0d7af07905c879b5014ca9456", + "from": "github:mattermost/mattermost-redux#632cda350e295aa0d7af07905c879b5014ca9456", "requires": { "deep-equal": "1.0.1", "eslint-plugin-header": "1.2.0", diff --git a/package.json b/package.json index 3c7858709100..171f1f332d2e 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "localforage": "1.7.2", "localforage-observable": "1.4.0", "marked": "github:mattermost/marked#ed33baecd7d7fa97d479ba22dde9d226b083d67d", - "mattermost-redux": "github:mattermost/mattermost-redux#212101f413f0c8288f4250a74b60a8c8c58418f7", + "mattermost-redux": "github:mattermost/mattermost-redux#632cda350e295aa0d7af07905c879b5014ca9456", "moment-timezone": "0.5.21", "pdfjs-dist": "2.0.489", "perfect-scrollbar": "0.8.1",