diff --git a/packages/teleterm/src/ui/DocumentCluster/ClusterResources/Databases/useDatabases.ts b/packages/teleterm/src/ui/DocumentCluster/ClusterResources/Databases/useDatabases.ts index 8c8606cefd..13f44a397e 100644 --- a/packages/teleterm/src/ui/DocumentCluster/ClusterResources/Databases/useDatabases.ts +++ b/packages/teleterm/src/ui/DocumentCluster/ClusterResources/Databases/useDatabases.ts @@ -33,8 +33,8 @@ export function useDatabases() { const doc = documentsService.createGatewayDocument({ // Not passing the `gatewayUri` field here, as at this point the gateway doesn't exist yet. // `port` is not passed as well, we'll let the tsh daemon pick a random one. - title: db.name, targetUri: db.uri, + targetName: db.name, targetUser: dbUser, targetSubresourceName: dbName, }); diff --git a/packages/teleterm/src/ui/TabHost/useTabShortcuts.test.tsx b/packages/teleterm/src/ui/TabHost/useTabShortcuts.test.tsx index d82284323f..2e63adb66f 100644 --- a/packages/teleterm/src/ui/TabHost/useTabShortcuts.test.tsx +++ b/packages/teleterm/src/ui/TabHost/useTabShortcuts.test.tsx @@ -38,6 +38,7 @@ function getMockDocuments(): Document[] { title: 'Test 4', gatewayUri: '', targetUri: '', + targetName: 'foobar', targetUser: 'foo', }, { @@ -46,6 +47,7 @@ function getMockDocuments(): Document[] { title: 'Test 5', gatewayUri: '', targetUri: '', + targetName: 'foobar', targetUser: 'bar', }, { diff --git a/packages/teleterm/src/ui/TopBar/Connections/Connections.story.tsx b/packages/teleterm/src/ui/TopBar/Connections/Connections.story.tsx index d1a3e025e5..c0d234158b 100644 --- a/packages/teleterm/src/ui/TopBar/Connections/Connections.story.tsx +++ b/packages/teleterm/src/ui/TopBar/Connections/Connections.story.tsx @@ -24,6 +24,7 @@ export function ExpanderConnections() { connected: true, kind: 'connection.gateway', title: 'graves', + targetName: 'graves', id: '68b6a281', targetUri: 'brock', port: '22', diff --git a/packages/teleterm/src/ui/services/connectionTracker/trackedConnectionOperationsFactory.ts b/packages/teleterm/src/ui/services/connectionTracker/trackedConnectionOperationsFactory.ts index 1549d0f430..8a014700b3 100644 --- a/packages/teleterm/src/ui/services/connectionTracker/trackedConnectionOperationsFactory.ts +++ b/packages/teleterm/src/ui/services/connectionTracker/trackedConnectionOperationsFactory.ts @@ -94,6 +94,7 @@ export class TrackedConnectionOperationsFactory { if (!gwDoc) { gwDoc = documentsService.createGatewayDocument({ targetUri: connection.targetUri, + targetName: connection.targetName, targetUser: connection.targetUser, title: connection.title, gatewayUri: connection.gatewayUri, diff --git a/packages/teleterm/src/ui/services/connectionTracker/trackedConnectionUtils.ts b/packages/teleterm/src/ui/services/connectionTracker/trackedConnectionUtils.ts index 2bbdbf1d26..3c5f246a66 100644 --- a/packages/teleterm/src/ui/services/connectionTracker/trackedConnectionUtils.ts +++ b/packages/teleterm/src/ui/services/connectionTracker/trackedConnectionUtils.ts @@ -48,6 +48,7 @@ export function createGatewayConnection( port: document.port, targetUri: document.targetUri, targetUser: document.targetUser, + targetName: document.targetName, targetSubresourceName: document.targetSubresourceName, gatewayUri: document.gatewayUri, }; diff --git a/packages/teleterm/src/ui/services/connectionTracker/types.ts b/packages/teleterm/src/ui/services/connectionTracker/types.ts index 3f856d201e..0f2e2f5461 100644 --- a/packages/teleterm/src/ui/services/connectionTracker/types.ts +++ b/packages/teleterm/src/ui/services/connectionTracker/types.ts @@ -16,6 +16,7 @@ export interface TrackedGatewayConnection extends TrackedConnectionBase { title: string; id: string; targetUri: string; + targetName: string; targetUser?: string; port?: string; gatewayUri: string; diff --git a/packages/teleterm/src/ui/services/workspacesService/documentsService/documentsService.test.ts b/packages/teleterm/src/ui/services/workspacesService/documentsService/documentsService.test.ts index 3532a8d03e..514ea2ab80 100644 --- a/packages/teleterm/src/ui/services/workspacesService/documentsService/documentsService.test.ts +++ b/packages/teleterm/src/ui/services/workspacesService/documentsService/documentsService.test.ts @@ -58,6 +58,7 @@ describe('document should be added', () => { kind: 'doc.gateway', gatewayUri: '', targetUri: '', + targetName: '', targetUser: 'foo', }; @@ -129,6 +130,7 @@ test('only gateway documents should be returned', () => { title: 'gw', gatewayUri: '', targetUri: '', + targetName: '', targetUser: 'foo', }; diff --git a/packages/teleterm/src/ui/services/workspacesService/documentsService/documentsService.ts b/packages/teleterm/src/ui/services/workspacesService/documentsService/documentsService.ts index ddfbb05c9a..4636659381 100644 --- a/packages/teleterm/src/ui/services/workspacesService/documentsService/documentsService.ts +++ b/packages/teleterm/src/ui/services/workspacesService/documentsService/documentsService.ts @@ -88,14 +88,29 @@ export class DocumentsService { }; } + /** + * If title is not present in opts, createGatewayDocument will create one for the doc based on the + * passed parameters. + */ createGatewayDocument(opts: CreateGatewayDocumentOpts): DocumentGateway { - const { targetUri, title, targetUser, targetSubresourceName } = opts; + const { targetUri, targetUser, targetName, targetSubresourceName } = opts; const uri = routing.getDocUri({ docId: unique() }); + let title = opts.title; + + if (!title) { + title = `${targetUser}@${targetName}`; + + if (targetSubresourceName) { + title += `/${targetSubresourceName}`; + } + } + return { uri, kind: 'doc.gateway', targetUri, targetUser, + targetName, targetSubresourceName, title, }; diff --git a/packages/teleterm/src/ui/services/workspacesService/documentsService/types.ts b/packages/teleterm/src/ui/services/workspacesService/documentsService/types.ts index c6ba4999df..626b28c8d1 100644 --- a/packages/teleterm/src/ui/services/workspacesService/documentsService/types.ts +++ b/packages/teleterm/src/ui/services/workspacesService/documentsService/types.ts @@ -56,7 +56,7 @@ export interface DocumentGateway extends DocumentBase { gatewayUri?: string; targetUri: string; targetUser: string; - targetName?: string; + targetName: string; targetSubresourceName?: string; port?: string; } @@ -86,9 +86,10 @@ export type Document = export type CreateGatewayDocumentOpts = { gatewayUri?: string; targetUri: string; + targetName: string; targetUser: string; targetSubresourceName?: string; - title: string; + title?: string; port?: string; };