diff --git a/webapp/channels/src/components/__snapshots__/textbox.test.tsx.snap b/webapp/channels/src/components/__snapshots__/textbox.test.tsx.snap index 5f2428aed3..e0d7aa8bc4 100644 --- a/webapp/channels/src/components/__snapshots__/textbox.test.tsx.snap +++ b/webapp/channels/src/components/__snapshots__/textbox.test.tsx.snap @@ -110,6 +110,7 @@ exports[`components/TextBox should match snapshot with additional, optional prop "priorityProfiles": undefined, "requestStarted": false, "searchAssociatedGroupsForReference": [Function], + "textboxId": "someid", "triggerCharacter": "@", "useChannelMentions": true, }, @@ -257,6 +258,7 @@ exports[`components/TextBox should match snapshot with required props 1`] = ` "priorityProfiles": undefined, "requestStarted": false, "searchAssociatedGroupsForReference": [Function], + "textboxId": "someid", "triggerCharacter": "@", "useChannelMentions": true, }, @@ -404,6 +406,7 @@ exports[`components/TextBox should throw error when new property is too long 1`] "priorityProfiles": undefined, "requestStarted": false, "searchAssociatedGroupsForReference": [Function], + "textboxId": "someid", "triggerCharacter": "@", "useChannelMentions": true, }, @@ -551,6 +554,7 @@ exports[`components/TextBox should throw error when value is too long 1`] = ` "priorityProfiles": undefined, "requestStarted": false, "searchAssociatedGroupsForReference": [Function], + "textboxId": "someid", "triggerCharacter": "@", "useChannelMentions": true, }, diff --git a/webapp/channels/src/components/suggestion/at_mention_provider/__snapshots__/at_mention_suggestion.test.tsx.snap b/webapp/channels/src/components/suggestion/at_mention_provider/__snapshots__/at_mention_suggestion.test.tsx.snap index 87c42cf986..bba7209ac8 100644 --- a/webapp/channels/src/components/suggestion/at_mention_provider/__snapshots__/at_mention_suggestion.test.tsx.snap +++ b/webapp/channels/src/components/suggestion/at_mention_provider/__snapshots__/at_mention_suggestion.test.tsx.snap @@ -9,6 +9,7 @@ exports[`at mention suggestion Should display nick name of non signed in user 1` "id": "userid2", "last_name": "b", "nickname": "c", + "textboxId": "post_textbox", "username": "user2", } } @@ -19,6 +20,7 @@ exports[`at mention suggestion Should display nick name of non signed in user 1` >
  • void; export type Props = { + textboxId?: string; currentUserId: string; channelId: string; autocompleteUsersInChannel: (prefix: string) => Promise; @@ -58,6 +59,7 @@ export type Props = { // users in the channel and users not in the channel. It mixes together results from the local // store with results fetched from the server. export default class AtMentionProvider extends Provider { + public textboxId?: string; public currentUserId: string; public channelId: string; public autocompleteUsersInChannel: (prefix: string) => Promise; @@ -75,8 +77,9 @@ export default class AtMentionProvider extends Provider { constructor(props: Props) { super(); - const {currentUserId, channelId, autocompleteUsersInChannel, useChannelMentions, autocompleteGroups, searchAssociatedGroupsForReference, priorityProfiles} = props; + const {currentUserId, channelId, autocompleteUsersInChannel, useChannelMentions, autocompleteGroups, searchAssociatedGroupsForReference, priorityProfiles, textboxId} = props; + this.textboxId = textboxId; this.currentUserId = currentUserId; this.channelId = channelId; this.autocompleteUsersInChannel = autocompleteUsersInChannel; @@ -93,7 +96,8 @@ export default class AtMentionProvider extends Provider { this.addLastViewAtToProfiles = makeAddLastViewAtToProfiles(); } - setProps({currentUserId, channelId, autocompleteUsersInChannel, useChannelMentions, autocompleteGroups, searchAssociatedGroupsForReference, priorityProfiles}: Props) { + setProps({currentUserId, channelId, autocompleteUsersInChannel, useChannelMentions, autocompleteGroups, searchAssociatedGroupsForReference, priorityProfiles, textboxId}: Props) { + this.textboxId = textboxId; this.currentUserId = currentUserId; this.channelId = channelId; this.autocompleteUsersInChannel = autocompleteUsersInChannel; @@ -362,19 +366,24 @@ export default class AtMentionProvider extends Provider { } else if (this.lastPrefixWithNoResults === this.latestPrefix) { this.lastPrefixWithNoResults = ''; } - const mentions = items.map((item) => { + const mentions: string[] = []; + + // Add the textboxId for each suggestions + const modifiedItems = items.map((item) => { if (item.username) { - return '@' + item.username; + mentions.push('@' + item.username); } else if (item.name) { - return '@' + item.name; + mentions.push('@' + item.name); + } else { + mentions.push(''); } - return ''; + return {...item, textboxId: this.textboxId}; }); resultCallback({ matchedPretext: `@${this.latestPrefix}`, terms: mentions, - items, + items: modifiedItems, component: AtMentionSuggestion, }); } diff --git a/webapp/channels/src/components/suggestion/at_mention_provider/at_mention_suggestion.test.tsx b/webapp/channels/src/components/suggestion/at_mention_provider/at_mention_suggestion.test.tsx index 96f1b7c2e0..7f4178535e 100644 --- a/webapp/channels/src/components/suggestion/at_mention_provider/at_mention_suggestion.test.tsx +++ b/webapp/channels/src/components/suggestion/at_mention_provider/at_mention_suggestion.test.tsx @@ -20,6 +20,7 @@ describe('at mention suggestion', () => { last_name: 'b', nickname: 'c', isCurrentUser: true, + textboxId: 'post_textbox', } as Item; const userid2 = { @@ -28,6 +29,7 @@ describe('at mention suggestion', () => { first_name: 'a', last_name: 'b', nickname: 'c', + textboxId: 'post_textbox', } as Item; const baseProps = { diff --git a/webapp/channels/src/components/suggestion/at_mention_provider/at_mention_suggestion.tsx b/webapp/channels/src/components/suggestion/at_mention_provider/at_mention_suggestion.tsx index a14b763bff..42656b729d 100644 --- a/webapp/channels/src/components/suggestion/at_mention_provider/at_mention_suggestion.tsx +++ b/webapp/channels/src/components/suggestion/at_mention_provider/at_mention_suggestion.tsx @@ -28,6 +28,7 @@ export interface Item extends UserProfile { name: string; isCurrentUser: boolean; type: string; + textboxId?: string; } interface Group extends Item { @@ -52,7 +53,10 @@ const AtMentionSuggestion = React.forwardRef ); icon = ( - +
  • ); } diff --git a/webapp/channels/src/components/suggestion/switch_channel_provider.tsx b/webapp/channels/src/components/suggestion/switch_channel_provider.tsx index 28475d4946..e5d8ee1711 100644 --- a/webapp/channels/src/components/suggestion/switch_channel_provider.tsx +++ b/webapp/channels/src/components/suggestion/switch_channel_provider.tsx @@ -330,8 +330,6 @@ function mapStateToPropsForSwitchChannelSuggestion(state: GlobalState, ownProps: collapsedThreads, team, isPartOfOnlyOneTeam, - - // id: 'quickSwitchInput', }; } diff --git a/webapp/channels/src/components/textbox/textbox.tsx b/webapp/channels/src/components/textbox/textbox.tsx index b3f3963a73..36acfc3db0 100644 --- a/webapp/channels/src/components/textbox/textbox.tsx +++ b/webapp/channels/src/components/textbox/textbox.tsx @@ -105,6 +105,7 @@ export default class Textbox extends React.PureComponent { this.suggestionProviders.push( new AtMentionProvider({ + textboxId: this.props.id, currentUserId: this.props.currentUserId, channelId: this.props.channelId, autocompleteUsersInChannel: (prefix: string) => this.props.actions.autocompleteUsersInChannel(prefix, this.props.channelId), @@ -146,6 +147,7 @@ export default class Textbox extends React.PureComponent { for (const provider of this.suggestionProviders) { if (provider instanceof AtMentionProvider) { provider.setProps({ + textboxId: this.props.id, currentUserId: this.props.currentUserId, channelId: this.props.channelId, autocompleteUsersInChannel: (prefix: string) => this.props.actions.autocompleteUsersInChannel(prefix, this.props.channelId),