MM-11725: Using the new server endpoint to autocomplete channels (#2100)

* MM-11725: Using the new server endpoint to autocomplete channels

* Fixing suggestions from the PR

* Updating mattermost-redux dependency

* Removing unnecesary Client4.getServerVersion usage
This commit is contained in:
Jesús Espino 2018-09-14 21:06:11 +02:00 committed by Harrison Healey
parent 5aac68e785
commit 280577dbc7
6 changed files with 23 additions and 10 deletions

View file

@ -6,6 +6,8 @@ import PropTypes from 'prop-types';
import {SectionList} from 'react-native';
import {RequestStatus} from 'mattermost-redux/constants';
import {isMinimumServerVersion} from 'mattermost-redux/utils/helpers';
import {debounce} from 'mattermost-redux/actions/helpers';
import {CHANNEL_MENTION_REGEX, CHANNEL_MENTION_SEARCH_REGEX} from 'app/constants/autocomplete';
import AutocompleteDivider from 'app/components/autocomplete/autocomplete_divider';
@ -17,6 +19,7 @@ export default class ChannelMention extends PureComponent {
static propTypes = {
actions: PropTypes.shape({
searchChannels: PropTypes.func.isRequired,
autocompleteChannelsForSearch: PropTypes.func.isRequired,
}).isRequired,
currentTeamId: PropTypes.string.isRequired,
cursorPosition: PropTypes.number.isRequired,
@ -34,6 +37,7 @@ export default class ChannelMention extends PureComponent {
requestStatus: PropTypes.string.isRequired,
theme: PropTypes.object.isRequired,
value: PropTypes.string,
serverVersion: PropTypes.string,
};
static defaultProps = {
@ -49,6 +53,15 @@ export default class ChannelMention extends PureComponent {
};
}
runSearch = debounce((currentTeamId, matchTerm) => {
if (!isMinimumServerVersion(this.props.serverVersion, 5, 4)) {
this.props.actions.searchChannels(currentTeamId, matchTerm);
return;
}
this.props.actions.autocompleteChannelsForSearch(currentTeamId, matchTerm);
}, 200);
componentWillReceiveProps(nextProps) {
const {isSearch, matchTerm, myChannels, otherChannels, privateChannels, publicChannels, requestStatus, myMembers, deletedPublicChannels} = nextProps;
@ -70,7 +83,7 @@ export default class ChannelMention extends PureComponent {
if (matchTerm !== this.props.matchTerm) {
// if the term changed and we haven't made the request do that first
const {currentTeamId} = this.props;
this.props.actions.searchChannels(currentTeamId, matchTerm);
this.runSearch(currentTeamId, matchTerm);
return;
}
@ -85,7 +98,7 @@ export default class ChannelMention extends PureComponent {
sections.push({
id: 'suggestion.search.public',
defaultMessage: 'Public Channels',
data: publicChannels.filter((cId) => !deletedPublicChannels.has(cId) || myMembers[cId]),
data: publicChannels.filter((cId) => myMembers[cId]),
key: 'publicChannels',
});
}

View file

@ -4,7 +4,7 @@
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {searchChannels} from 'mattermost-redux/actions/channels';
import {searchChannels, autocompleteChannelsForSearch} from 'mattermost-redux/actions/channels';
import {getMyChannelMemberships} from 'mattermost-redux/selectors/entities/channels';
import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';
@ -49,6 +49,7 @@ function mapStateToProps(state, ownProps) {
matchTerm,
requestStatus: state.requests.channels.getChannels.status,
theme: getTheme(state),
serverVersion: state.entities.general.serverVersion,
};
}
@ -56,6 +57,7 @@ function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
searchChannels,
autocompleteChannelsForSearch,
}, dispatch),
};
}

View file

@ -7,7 +7,6 @@ import {bindActionCreators} from 'redux';
import {getCustomEmojisByName} from 'mattermost-redux/selectors/entities/emojis';
import {autocompleteCustomEmojis} from 'mattermost-redux/actions/emojis';
import {Client4} from 'mattermost-redux/client';
import {addReactionToLatestPost} from 'app/actions/views/emoji';
import {getTheme} from 'mattermost-redux/selectors/entities/preferences';
@ -46,7 +45,7 @@ function mapStateToProps(state) {
fuse,
emojis,
theme: getTheme(state),
serverVersion: state.entities.general.serverVersion || Client4.getServerVersion(),
serverVersion: state.entities.general.serverVersion,
};
}

View file

@ -9,7 +9,6 @@ import {getTheme} from 'mattermost-redux/selectors/entities/preferences';
import {getCustomEmojisByName} from 'mattermost-redux/selectors/entities/emojis';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {getCustomEmojis, searchCustomEmojis} from 'mattermost-redux/actions/emojis';
import {Client4} from 'mattermost-redux/client';
import {incrementEmojiPickerPage} from 'app/actions/views/emoji';
import {getDimensions, isLandscape} from 'app/selectors/device';
@ -160,7 +159,7 @@ function mapStateToProps(state) {
theme: getTheme(state),
customEmojisEnabled: getConfig(state).EnableCustomEmoji === 'true',
customEmojiPage: state.views.emoji.emojiPickerCustomPage,
serverVersion: state.entities.general.serverVersion || Client4.getServerVersion(),
serverVersion: state.entities.general.serverVersion,
};
}

4
package-lock.json generated
View file

@ -10178,8 +10178,8 @@
}
},
"mattermost-redux": {
"version": "github:mattermost/mattermost-redux#f7a515c54b30fbb6aa0e8c374f3618eb7935c4c3",
"from": "github:mattermost/mattermost-redux#f7a515c54b30fbb6aa0e8c374f3618eb7935c4c3",
"version": "github:mattermost/mattermost-redux#c7aa1f1dc8dd67f9806b2cbb3a6103ff8a9c16fd",
"from": "github:mattermost/mattermost-redux#c7aa1f1dc8dd67f9806b2cbb3a6103ff8a9c16fd",
"requires": {
"deep-equal": "1.0.1",
"eslint-plugin-header": "1.2.0",

View file

@ -16,7 +16,7 @@
"intl": "1.2.5",
"jail-monkey": "1.0.0",
"jsc-android": "216113.0.3",
"mattermost-redux": "github:mattermost/mattermost-redux#f7a515c54b30fbb6aa0e8c374f3618eb7935c4c3",
"mattermost-redux": "github:mattermost/mattermost-redux#c7aa1f1dc8dd67f9806b2cbb3a6103ff8a9c16fd",
"mime-db": "1.33.0",
"moment-timezone": "0.5.21",
"prop-types": "15.6.1",