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

Commit

Permalink
useDocumentGateway: Pin shell to correct cluster (#812) (#813)
Browse files Browse the repository at this point in the history
Commit b5d30b1 fixed some reconnect issues, but it also introduced a
locally scoped `cluster` variable. This made it seem like it's the cluster
to which the given gateway belongs, but it was actually the root cluster.

This commit renames the old `cluster` variable to `rootCluster`. It also
makes sure that `workspaceDocumentsService.openNewTerminal` receives
correct root & leaf cluster IDs.
  • Loading branch information
ravicious authored May 5, 2022
1 parent 3c79903 commit ed9aa5c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/teleterm/src/ui/DocumentGateway/useDocumentGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export default function useGateway(doc: types.DocumentGateway) {
const workspaceDocumentsService = useWorkspaceDocumentsService();
const gateway = ctx.clustersService.findGateway(doc.gatewayUri);
const connected = !!gateway;
const cluster = ctx.clustersService.findRootClusterByResource(doc.targetUri);
const rootCluster = ctx.clustersService.findRootClusterByResource(
doc.targetUri
);
const cluster = ctx.clustersService.findClusterByResource(doc.targetUri);

const [connectAttempt, createGateway, setConnectAttempt] = useAsync(
async () => {
Expand Down Expand Up @@ -55,20 +58,20 @@ export default function useGateway(doc: types.DocumentGateway) {
});

const reconnect = () => {
if (cluster?.connected) {
if (rootCluster?.connected) {
createGateway();
return;
}

if (cluster && !cluster.connected) {
if (rootCluster && !rootCluster.connected) {
ctx.commandLauncher.executeCommand('cluster-connect', {
clusterUri: cluster.uri,
clusterUri: rootCluster.uri,
onSuccess: createGateway,
});
return;
}

if (!cluster) {
if (!rootCluster) {
setConnectAttempt({
status: 'error',
statusText: `unable to resolve cluster for ${doc.targetUri}`,
Expand All @@ -94,10 +97,10 @@ export default function useGateway(doc: types.DocumentGateway) {
}, [disconnectAttempt.status]);

useEffect(() => {
if (cluster.connected) {
if (rootCluster.connected) {
createGateway();
}
}, [cluster.connected]);
}, [rootCluster.connected]);

return {
doc,
Expand Down

0 comments on commit ed9aa5c

Please sign in to comment.