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

Commit

Permalink
Set better title for gateway tab
Browse files Browse the repository at this point in the history
  • Loading branch information
ravicious committed Apr 25, 2022
1 parent 4a39bee commit 6017f4d
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
2 changes: 2 additions & 0 deletions packages/teleterm/src/ui/TabHost/useTabShortcuts.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function getMockDocuments(): Document[] {
title: 'Test 4',
gatewayUri: '',
targetUri: '',
targetName: 'foobar',
targetUser: 'foo',
},
{
Expand All @@ -46,6 +47,7 @@ function getMockDocuments(): Document[] {
title: 'Test 5',
gatewayUri: '',
targetUri: '',
targetName: 'foobar',
targetUser: 'bar',
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function ExpanderConnections() {
connected: true,
kind: 'connection.gateway',
title: 'graves',
targetName: 'graves',
id: '68b6a281',
targetUri: 'brock',
port: '22',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface TrackedGatewayConnection extends TrackedConnectionBase {
title: string;
id: string;
targetUri: string;
targetName: string;
targetUser?: string;
port?: string;
gatewayUri: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('document should be added', () => {
kind: 'doc.gateway',
gatewayUri: '',
targetUri: '',
targetName: '',
targetUser: 'foo',
};

Expand Down Expand Up @@ -129,6 +130,7 @@ test('only gateway documents should be returned', () => {
title: 'gw',
gatewayUri: '',
targetUri: '',
targetName: '',
targetUser: 'foo',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface DocumentGateway extends DocumentBase {
gatewayUri?: string;
targetUri: string;
targetUser: string;
targetName?: string;
targetName: string;
targetSubresourceName?: string;
port?: string;
}
Expand Down Expand Up @@ -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;
};

Expand Down

0 comments on commit 6017f4d

Please sign in to comment.