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

Commit

Permalink
Take localClusterUri into account in QuickInput (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
gzdunek authored Mar 18, 2022
1 parent c70bac7 commit 0155eb3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
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]
);
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 [];
}
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

0 comments on commit 0155eb3

Please sign in to comment.