Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Assist] Fix random user selection #26183

Merged
merged 1 commit into from
May 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion web/packages/teleport/src/Assist/contexts/messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,22 @@ export const remoteCommandToMessage = async (
errorMsg = 'no users found';
}

// If the login has been selected, use it.
let avLogin = execCmd.selectedLogin;
if (!avLogin) {
// If the login has not been selected, use the first one.
avLogin = availableLogins ? availableLogins[0] : '';
} else {
// If the login has been selected, check if it is available.
// Updated query could have changed the available logins.
if (!availableLogins.includes(avLogin)) {
avLogin = availableLogins ? availableLogins[0] : '';
}
Comment on lines +142 to +147
Copy link
Contributor

Choose a reason for hiding this comment

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

elseif?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TS complains as it expects else block (potentially not all cases are covered with if and else if).

}

return {
...execCmd,
selectedLogin: availableLogins ? availableLogins[0] : '',
selectedLogin: avLogin,
availableLogins: availableLogins,
errorMsg: errorMsg,
};
Expand Down