This repository was archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Fall back to leaf cluster id when restoring leaf cluster terminal document #920
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,6 @@ import { IPtyProcess } from 'teleterm/sharedProcess/ptyHost'; | |
| import { useAsync } from 'shared/hooks/useAsync'; | ||
| import { useWorkspaceDocumentsService } from 'teleterm/ui/Documents'; | ||
| import { routing } from 'teleterm/ui/uri'; | ||
| import { getClusterName } from 'teleterm/ui/utils'; | ||
| import { PtyCommand, PtyProcessCreationStatus } from 'teleterm/services/pty'; | ||
|
|
||
| export default function useDocumentTerminal(doc: Doc) { | ||
|
|
@@ -40,6 +39,15 @@ export default function useDocumentTerminal(doc: Doc) { | |
| }; | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| if (state.status === 'error') { | ||
| ctx.notificationsService.notifyError({ | ||
| title: 'Could not open a terminal', | ||
| description: state.statusText, | ||
| }); | ||
| } | ||
| }, [state.status]); | ||
|
|
||
| return state; | ||
| } | ||
|
|
||
|
|
@@ -48,10 +56,28 @@ async function initState( | |
| docsService: DocumentsService, | ||
| doc: Doc | ||
| ) { | ||
| const getClusterActualName = () => { | ||
| const cluster = ctx.clustersService.findCluster(clusterUri); | ||
| if (cluster) { | ||
| return cluster.actualName; | ||
| } | ||
|
|
||
| /* | ||
| When restoring the documents, we do not always have the leaf clusters already fetched. | ||
| In that case we can fall back to `clusterId` from a leaf cluster URI | ||
| (for a leaf cluster `clusterId` === `actualName`) | ||
| */ | ||
| const parsed = routing.parseClusterUri(clusterUri); | ||
|
|
||
| if (!parsed?.params?.leafClusterId) { | ||
| throw new Error('Incorrect cluster URI'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error message could provide more information though. :D Maybe something that at this point a leaf cluster URI was expected but the URI doesn't seem to include a leaf cluster ID?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, thanks |
||
| } | ||
| return parsed.params.leafClusterId; | ||
| }; | ||
|
|
||
| const clusterUri = routing.getClusterUri(doc); | ||
| const rootCluster = ctx.clustersService.findRootClusterByResource(clusterUri); | ||
| const cluster = ctx.clustersService.findCluster(clusterUri); | ||
| const cmd = createCmd(doc, rootCluster.proxyHost, cluster.actualName); | ||
| const cmd = createCmd(doc, rootCluster.proxyHost, getClusterActualName()); | ||
| const ptyProcess = await createPtyProcess(ctx, cmd); | ||
| if (!ptyProcess) { | ||
| return; | ||
|
|
@@ -67,7 +93,7 @@ async function initState( | |
| const cwd = await ptyProcess.getCwd(); | ||
| docsService.update(doc.uri, { | ||
| cwd, | ||
| title: `${cwd} · ${getClusterName(cluster)}`, | ||
| title: `${cwd} · ${getClusterActualName()}`, | ||
| }); | ||
| }; | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good comment, thanks.