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

Cherry-pick to 6.4 of "Improving selectors of Textbox component (#9831)" #9840

Merged
merged 1 commit into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
44 changes: 12 additions & 32 deletions components/__snapshots__/textbox.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ exports[`components/TextBox should match snapshot with additional, optional prop
providers={
Array [
AtMentionProvider {
"addLastViewAtToProfiles": [Function],
"autocompleteGroups": Array [
Object {
"id": "gid1",
Expand All @@ -44,22 +45,16 @@ exports[`components/TextBox should match snapshot with additional, optional prop
},
],
"autocompleteUsersInChannel": [Function],
"channelId": "channelId",
"currentUserId": "currentUserId",
"data": null,
"disableDispatches": false,
"getProfilesInChannel": [Function],
"lastCompletedWord": "",
"lastPrefixWithNoResults": "",
"latestComplete": true,
"latestPrefix": "",
"priorityProfiles": undefined,
"profilesInChannel": Array [
Object {
"id": "id1",
},
Object {
"id": "id2",
},
],
"requestStarted": false,
"searchAssociatedGroupsForReference": [Function],
"triggerCharacter": "@",
Expand Down Expand Up @@ -143,6 +138,7 @@ exports[`components/TextBox should match snapshot with required props 1`] = `
providers={
Array [
AtMentionProvider {
"addLastViewAtToProfiles": [Function],
"autocompleteGroups": Array [
Object {
"id": "gid1",
Expand All @@ -152,22 +148,16 @@ exports[`components/TextBox should match snapshot with required props 1`] = `
},
],
"autocompleteUsersInChannel": [Function],
"channelId": "channelId",
"currentUserId": "currentUserId",
"data": null,
"disableDispatches": false,
"getProfilesInChannel": [Function],
"lastCompletedWord": "",
"lastPrefixWithNoResults": "",
"latestComplete": true,
"latestPrefix": "",
"priorityProfiles": undefined,
"profilesInChannel": Array [
Object {
"id": "id1",
},
Object {
"id": "id2",
},
],
"requestStarted": false,
"searchAssociatedGroupsForReference": [Function],
"triggerCharacter": "@",
Expand Down Expand Up @@ -236,6 +226,7 @@ exports[`components/TextBox should throw error when new property is too long 1`]
providers={
Array [
AtMentionProvider {
"addLastViewAtToProfiles": [Function],
"autocompleteGroups": Array [
Object {
"id": "gid1",
Expand All @@ -245,22 +236,16 @@ exports[`components/TextBox should throw error when new property is too long 1`]
},
],
"autocompleteUsersInChannel": [Function],
"channelId": "channelId",
"currentUserId": "currentUserId",
"data": null,
"disableDispatches": false,
"getProfilesInChannel": [Function],
"lastCompletedWord": "",
"lastPrefixWithNoResults": "",
"latestComplete": true,
"latestPrefix": "",
"priorityProfiles": undefined,
"profilesInChannel": Array [
Object {
"id": "id1",
},
Object {
"id": "id2",
},
],
"requestStarted": false,
"searchAssociatedGroupsForReference": [Function],
"triggerCharacter": "@",
Expand Down Expand Up @@ -329,6 +314,7 @@ exports[`components/TextBox should throw error when value is too long 1`] = `
providers={
Array [
AtMentionProvider {
"addLastViewAtToProfiles": [Function],
"autocompleteGroups": Array [
Object {
"id": "gid1",
Expand All @@ -338,22 +324,16 @@ exports[`components/TextBox should throw error when value is too long 1`] = `
},
],
"autocompleteUsersInChannel": [Function],
"channelId": "channelId",
"currentUserId": "currentUserId",
"data": null,
"disableDispatches": false,
"getProfilesInChannel": [Function],
"lastCompletedWord": "",
"lastPrefixWithNoResults": "",
"latestComplete": true,
"latestPrefix": "",
"priorityProfiles": undefined,
"profilesInChannel": Array [
Object {
"id": "id1",
},
Object {
"id": "id2",
},
],
"requestStarted": false,
"searchAssociatedGroupsForReference": [Function],
"triggerCharacter": "@",
Expand Down
22 changes: 19 additions & 3 deletions components/suggestion/at_mention_provider/at_mention_provider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
import XRegExp from 'xregexp';

import {getSuggestionsSplitBy, getSuggestionsSplitByMultiple} from 'mattermost-redux/utils/user_utils';
import {makeGetProfilesInChannel} from 'mattermost-redux/selectors/entities/users';
import {makeAddLastViewAtToProfiles} from 'mattermost-redux/selectors/entities/utils';

import store from 'stores/redux_store';
import {Constants} from 'utils/constants';

import Provider from '../provider.jsx';

import AtMentionSuggestion from './at_mention_suggestion.jsx';

const profilesInChannelOptions = {active: true};

// The AtMentionProvider provides matches for at mentions, including @here, @channel, @all,
// users in the channel and users not in the channel. It mixes together results from the local
// store with results fetch from the server.
Expand All @@ -24,13 +29,15 @@ export default class AtMentionProvider extends Provider {
this.lastCompletedWord = '';
this.lastPrefixWithNoResults = '';
this.triggerCharacter = '@';
this.getProfilesInChannel = makeGetProfilesInChannel();
this.addLastViewAtToProfiles = makeAddLastViewAtToProfiles();
}

// setProps gives the provider additional context for matching pretexts. Ideally this would
// just be something akin to a connected component with access to the store itself.
setProps({currentUserId, profilesInChannel, autocompleteUsersInChannel, useChannelMentions, autocompleteGroups, searchAssociatedGroupsForReference, priorityProfiles}) {
setProps({currentUserId, channelId, autocompleteUsersInChannel, useChannelMentions, autocompleteGroups, searchAssociatedGroupsForReference, priorityProfiles}) {
this.currentUserId = currentUserId;
this.profilesInChannel = profilesInChannel;
this.channelId = channelId;
this.autocompleteUsersInChannel = autocompleteUsersInChannel;
this.useChannelMentions = useChannelMentions;
this.autocompleteGroups = autocompleteGroups;
Expand Down Expand Up @@ -115,9 +122,18 @@ export default class AtMentionProvider extends Provider {
return groupSuggestions.some((suggestion) => suggestion.startsWith(prefixLower));
}

getProfilesWithLastViewAtInChannel() {
const state = store.getState();

const profilesInChannel = this.getProfilesInChannel(state, this.channelId, profilesInChannelOptions);
const profilesWithLastViewAtInChannel = this.addLastViewAtToProfiles(state, profilesInChannel);

return profilesWithLastViewAtInChannel;
}

// localMembers matches up to 25 local results from the store before the server has responded.
localMembers() {
const localMembers = this.profilesInChannel.
const localMembers = this.getProfilesWithLastViewAtInChannel().
filter((profile) => this.filterProfile(profile)).
map((profile) => this.createFromProfile(profile, Constants.MENTION_MEMBERS)).
splice(0, 25);
Expand Down
Loading