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

Take localClusterUri into account in QuickInput #679

Merged
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
5 changes: 3 additions & 2 deletions packages/teleterm/src/ui/QuickInput/useQuickInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export default function useQuickInput() {
const {
quickInputService,
workspacesService,
clustersService,
commandLauncher,
} = useAppContext();
workspacesService.useState();
Expand All @@ -36,7 +35,9 @@ export default function useQuickInput() {
const [activeSuggestion, setActiveSuggestion] = React.useState(0);
const autocompleteResult = React.useMemo(
() => quickInputService.getAutocompleteResult(inputValue),
[inputValue]
// `localClusterUri` has been added to refresh suggestions from
// `QuickSshLoginPicker` and `QuickServerPicker` when it changes
[inputValue, workspacesService.getActiveWorkspace()?.localClusterUri]
Copy link
Member

Choose a reason for hiding this comment

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

Let's just add a comment here explaining why it's in the dependency list to make sure we're highlighting a potential code smell.

);
const hasSuggestions =
autocompleteResult.kind === 'autocomplete.partial-match';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ test('getAutocompleteResult returns correct result for an SSH host suggestion ri
CommandLauncherMock,
onlyTshSshCommand
);
jest
.spyOn(WorkspacesServiceMock.prototype, 'getActiveWorkspace')
.mockImplementation(() => ({
localClusterUri: 'test_uri',
documents: [],
location: '',
}));
jest
.spyOn(ClustersServiceMock.prototype, 'searchServers')
.mockImplementation(() => {
Expand Down Expand Up @@ -351,6 +358,13 @@ test('getAutocompleteResult returns correct result for a partial match on an SSH
},
];
});
jest
.spyOn(WorkspacesServiceMock.prototype, 'getActiveWorkspace')
.mockImplementation(() => ({
localClusterUri: 'test_uri',
documents: [],
location: '',
}));
const quickInputService = new QuickInputService(
new CommandLauncherMock(undefined),
new ClustersServiceMock(undefined),
Expand Down
18 changes: 12 additions & 6 deletions packages/teleterm/src/ui/services/quickInput/quickPickers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,13 @@ export class QuickSshLoginPicker implements QuickInputPicker {
) {}

private filterSshLogins(input: string): SuggestionSshLogin[] {
// TODO(ravicious): Use local cluster URI.
// TODO(ravicious): Handle the `--cluster` tsh ssh flag.
const rootClusterUri = this.workspacesService.getRootClusterUri();
const cluster = this.clustersService.findCluster(rootClusterUri);
const localClusterUri =
this.workspacesService.getActiveWorkspace()?.localClusterUri;
if (!localClusterUri) {
return [];
Copy link
Member

Choose a reason for hiding this comment

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

Good catch, I thought of this scenario once but then it escaped my head.

}
const cluster = this.clustersService.findCluster(localClusterUri);
const allLogins = cluster?.loggedInUser?.sshLoginsList || [];
let matchingLogins: typeof allLogins;

Expand Down Expand Up @@ -302,10 +305,13 @@ export class QuickServerPicker implements QuickInputPicker {
) {}

private filterServers(input: string): SuggestionServer[] {
// TODO(ravicious): Use local cluster URI.
// TODO(ravicious): Handle the `--cluster` tsh ssh flag.
const rootClusterUri = this.workspacesService.getRootClusterUri();
const servers = this.clustersService.searchServers(rootClusterUri, {
const localClusterUri =
this.workspacesService.getActiveWorkspace()?.localClusterUri;
if (!localClusterUri) {
return [];
}
const servers = this.clustersService.searchServers(localClusterUri, {
search: input,
});

Expand Down