MM-13209: use textbox channel from context (#2108)

* 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.

* update mattermost-redux

* code review feedback

* update mattermost-redux
parent 957f6bd5
......@@ -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));
};
}
......@@ -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,
......
......@@ -4,17 +4,22 @@
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 makeMapStateToProps = () => {
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) => ({
actions: bindActionCreators({
......@@ -22,4 +27,4 @@ const mapDispatchToProps = (dispatch) => ({
}, dispatch),
});
export default connect(mapStateToProps, mapDispatchToProps, null, {withRef: true})(Textbox);
export default connect(makeMapStateToProps, mapDispatchToProps, null, {withRef: true})(Textbox);
......@@ -63,7 +63,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(),
......@@ -180,7 +180,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),
});
}
}
......
......@@ -11581,8 +11581,8 @@
"dev": true
},
"mattermost-redux": {
"version": "github:mattermost/mattermost-redux#b730595c859e61ebc04806967f2df27c60f0050a",
"from": "github:mattermost/mattermost-redux#b730595c859e61ebc04806967f2df27c60f0050a",
"version": "github:mattermost/mattermost-redux#b593625b0a053a8d248e6aee0f26c735ba4a169b",
"from": "github:mattermost/mattermost-redux#b593625b0a053a8d248e6aee0f26c735ba4a169b",
"requires": {
"deep-equal": "1.0.1",
"eslint-plugin-header": "1.2.0",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment