Skip to content

Conversation

@mas-who
Copy link
Contributor

@mas-who mas-who commented Nov 12, 2024

Summary

This PR is aimed resolve the issue raised in #15755 . The approach is to add the ~ character as an suffix when the /join command is selected via mouse or keyboard (Enter or Tab). By doing this, it would automatically display the auto-complete options for the /join command when selected.

QA steps:
  1. Start typing a command prefixed by / so that the /join command is displayed in the auto-complete suggestions.
  2. Select the /join command in the suggestion list by clicking it, or pressing the Tab / Enter key.
  3. Selecting the /join command using anyone of the interactions mentioned in 2 should result in /join ~ displayed in the message input, and the suggestion list for channel options should be displayed automatically.

Ticket Link

Fixes #15755
https://mattermost.atlassian.net/browse/MM-26655

Screenshots

before after
Screencast from 12-11-2024 13:26:28.webm Screencast from 12-11-2024 13:26:51.webm

Release Note

- Improvement in the UI for auto displaying channel suggestion list when the `/join` command suggestion is selected.

@mm-cloud-bot
Copy link

@mas-who: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

I understand the commands that are listed here

@mattermost-build
Copy link
Contributor

Hello @mas-who,

Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here.

handleCompleteWord(term: string, pretext: string, callback: (s: string) => void) {
callback(term + ' ');
let newValue = term + ' ';
if (term === '/join') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be worthwhile to convert this logic into something more generic, and also cater for other commands that have the same behaviour? e.g. /mute

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could try to set a dictionary with command and the symbol to follow, then find the term in the dictionary and use the symbol to create the new value. Perhaps you can start with join and mute and see how it works. But feel free to open a new PR for that. This one is ok as it is, given that is solves what was initially requested.

@hanzei hanzei added 2: Dev Review Requires review by a developer 3: QA Review Requires review by a QA tester. May occur at the same time as Dev Review labels Nov 13, 2024
@unified-ci-app
Copy link
Contributor

Not triggering E2E tests: this PR has 9 commit status(es) or check-runs that are not passing. Ensure all statuses aside from the E2E testing ones are green, before triggering E2E tests.

@hanzei hanzei requested review from a team and pvev and removed request for a team November 13, 2024 06:15
@mm-cloud-bot mm-cloud-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed labels Nov 13, 2024
Copy link
Contributor

@pvev pvev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution @mas-who , this is great work 🎉

handleCompleteWord(term: string, pretext: string, callback: (s: string) => void) {
callback(term + ' ');
let newValue = term + ' ';
if (term === '/join') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could try to set a dictionary with command and the symbol to follow, then find the term in the dictionary and use the symbol to create the new value. Perhaps you can start with join and mute and see how it works. But feel free to open a new PR for that. This one is ok as it is, given that is solves what was initially requested.

@pvev pvev requested a review from devinbinnie November 20, 2024 23:05
@mas-who
Copy link
Contributor Author

mas-who commented Nov 21, 2024

I think you could try to set a dictionary with command and the symbol to follow, then find the term in the dictionary and use the symbol to create the new value. Perhaps you can start with join and mute and see how it works. But feel free to open a new PR for that. This one is ok as it is, given that is solves what was initially requested.

@pvev noted, I think let's get this PR merged and I will open a new issue referencing this one to generalise the approach?

@devinbinnie devinbinnie requested review from hmhealey and removed request for devinbinnie November 21, 2024 14:36
@devinbinnie
Copy link
Member

Passing this over to @hmhealey as he understands the inner workings of the Suggestion component better

@hmhealey hmhealey changed the title [MM-15755] Show auto-complete channel options when /join command suggestion is selected [MM-26655] Show auto-complete channel options when /join command suggestion is selected Nov 21, 2024
Copy link
Member

@hmhealey hmhealey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @mas-who!

I like the idea of trying to add this when completing the word, but it seems like this won't work because handleCompleteWord is triggered after the text in the textbox is updated. I'm actually surprised that the changes to handleCompleteWord make the autocomplete appear even though there's no ~ in the textbox.

Instead, I think it'd be better to change this in CommandProvider.handleWebapp. When it calls Client4.getCommandAutocompleteSuggestionsList to make the array of results from the server, I think that's where we should look for the result that corresponds to the /join command and add a ~ to it. That way, it'll keep the special handling for /join inside the CommandProvider without needing special handling for it in SuggestionBox. Ideally, we'll keep all of that logic in the provider itself.

How does that sound?

const suffix = text.substring(caret);
let suffix = text.substring(caret);
if (term.endsWith('join')) {
suffix = '~';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to use the suffix for this because that contains all the pre-existing text after the keyboard caret. For example, if the user goes back to add an emoji earlier in this text

this : is some text
     ^ the caret is after this colon

then the suffix will be is some text

window.requestAnimationFrame(() => {
if (textbox.value === newValue) {
Utils.setCaretPosition(textbox, prefix.length + term.length + 1);
Utils.setCaretPosition(textbox, prefix.length + term.length + suffix.length + 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, this would make it so that, in cases where we keep the suffix, the cursor would move to the end of the textbox instead of after the autocompleted text

@mattermost-build
Copy link
Contributor

This PR has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2: Dev Review Requires review by a developer 3: QA Review Requires review by a QA tester. May occur at the same time as Dev Review Contributor Lifecycle/1:stale release-note Denotes a PR that will be considered when it comes time to generate release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add autocomplete data to /join

8 participants