Skip to content

Commit 737cc75

Browse files
authored
Improve overview titles (#8498)
* Improve overview titles * Fix tests
1 parent da7229b commit 737cc75

5 files changed

Lines changed: 40 additions & 16 deletions

File tree

Lines changed: 4 additions & 0 deletions
Loading

resources/icons/issue_webview.svg

Lines changed: 4 additions & 0 deletions
Loading

src/github/issueOverview.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class IssueOverviewPanel<TItem extends IssueModel = IssueModel> extends W
6464
if (panel) {
6565
panel._panel.reveal(activeColumn, true);
6666
} else {
67-
const title = `Issue #${identity.number.toString()}`;
67+
const title = `#${identity.number.toString()}`;
6868
panel = new IssueOverviewPanel(
6969
telemetry,
7070
extensionUri,
@@ -108,6 +108,21 @@ export class IssueOverviewPanel<TItem extends IssueModel = IssueModel> extends W
108108
return this._panels.get(panelKey(owner, repo, number));
109109
}
110110

111+
/**
112+
* Build a short panel title: `#<number> <truncated title>`.
113+
* The item title is truncated to approximately `maxLength` characters on a
114+
* word boundary and suffixed with "..." when it doesn't fit in full.
115+
*/
116+
protected buildPanelTitle(itemNumber: number, itemTitle: string, maxLength: number = 20): string {
117+
let truncated = itemTitle;
118+
if (itemTitle.length > maxLength) {
119+
const lastSpace = itemTitle.lastIndexOf(' ', maxLength);
120+
const cutOff = lastSpace > 0 ? lastSpace : maxLength;
121+
truncated = itemTitle.substring(0, cutOff) + '...';
122+
}
123+
return `#${itemNumber} ${truncated}`;
124+
}
125+
111126
protected setPanelTitle(title: string): void {
112127
try {
113128
this._panel.title = title;
@@ -125,10 +140,13 @@ export class IssueOverviewPanel<TItem extends IssueModel = IssueModel> extends W
125140
folderRepositoryManager: FolderRepositoryManager,
126141
private readonly type: string = IssueOverviewPanel.viewType,
127142
existingPanel?: vscode.WebviewPanel,
128-
iconSubpath?: {
143+
iconSubpath: {
129144
light: string,
130145
dark: string,
131-
}
146+
} = {
147+
light: 'resources/icons/issue_webview.svg',
148+
dark: 'resources/icons/dark/issue_webview.svg',
149+
}
132150
) {
133151
super();
134152
this._folderRepositoryManager = folderRepositoryManager;
@@ -144,12 +162,10 @@ export class IssueOverviewPanel<TItem extends IssueModel = IssueModel> extends W
144162
enableFindWidget: true
145163
}));
146164

147-
if (iconSubpath) {
148-
this._panel.iconPath = {
149-
dark: vscode.Uri.joinPath(_extensionUri, iconSubpath.dark),
150-
light: vscode.Uri.joinPath(_extensionUri, iconSubpath.light)
151-
};
152-
}
165+
this._panel.iconPath = {
166+
dark: vscode.Uri.joinPath(_extensionUri, iconSubpath.dark),
167+
light: vscode.Uri.joinPath(_extensionUri, iconSubpath.light)
168+
};
153169

154170
this._webview = this._panel.webview;
155171
super.initialize();
@@ -298,7 +314,7 @@ export class IssueOverviewPanel<TItem extends IssueModel = IssueModel> extends W
298314
}
299315

300316
this._item = issue as TItem;
301-
this.setPanelTitle(`Issue #${issueModel.number.toString()}`);
317+
this.setPanelTitle(this.buildPanelTitle(issueModel.number, issueModel.title));
302318

303319
Logger.debug('pr.initialize', IssueOverviewPanel.ID);
304320
this._postMessage({

src/github/pullRequestOverview.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
9191
if (panel) {
9292
panel._panel.reveal(activeColumn, preserveFocus);
9393
} else {
94-
const title = `Pull Request #${identity.number.toString()}`;
94+
const title = `#${identity.number.toString()}`;
9595
panel = new PullRequestOverviewPanel(
9696
telemetry,
9797
extensionUri,
@@ -364,7 +364,7 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
364364
this._repositoryDefaultBranch = defaultBranch!;
365365
this._teamsCount = orgTeamsCount;
366366
this._assignableUsers = assignableUsers;
367-
this.setPanelTitle(`Pull Request #${pullRequestModel.number.toString()}`);
367+
this.setPanelTitle(this.buildPanelTitle(pullRequestModel.number, pullRequestModel.title));
368368

369369
const isCurrentlyCheckedOut = pullRequestModel.equals(this._folderRepositoryManager.activePullRequest);
370370
const mergeMethodsAvailability = repositoryAccess!.mergeMethodsAvailability;

src/test/github/pullRequestOverview.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe('PullRequestOverview', function () {
8989
await PullRequestOverviewPanel.createOrShow(telemetry, EXTENSION_URI, pullRequestManager, identity, prModel);
9090

9191
assert(
92-
createWebviewPanel.calledWith(sinonMatch.string, 'Pull Request #1000', vscode.ViewColumn.One, {
92+
createWebviewPanel.calledWith(sinonMatch.string, '#1000', vscode.ViewColumn.One, {
9393
enableScripts: true,
9494
retainContextWhenHidden: true,
9595
localResourceRoots: [vscode.Uri.joinPath(EXTENSION_URI, 'dist')],
@@ -130,7 +130,7 @@ describe('PullRequestOverview', function () {
130130
const panel0 = PullRequestOverviewPanel.findPanel(identity0.owner, identity0.repo, identity0.number);
131131
assert.notStrictEqual(panel0, undefined);
132132
assert.strictEqual(createWebviewPanel.callCount, 1);
133-
assert.strictEqual(panel0!.getCurrentTitle(), 'Pull Request #1000');
133+
assert.strictEqual(panel0!.getCurrentTitle(), '#1000 New feature');
134134

135135
// Opening the same PR again should reuse the existing panel
136136
await PullRequestOverviewPanel.createOrShow(telemetry, EXTENSION_URI, pullRequestManager, identity0, prModel0);
@@ -185,8 +185,8 @@ describe('PullRequestOverview', function () {
185185
assert.notStrictEqual(panel1, undefined);
186186
assert.notStrictEqual(panel0, panel1);
187187
assert.strictEqual(createWebviewPanel.callCount, 2);
188-
assert.strictEqual(panel0!.getCurrentTitle(), 'Pull Request #1000');
189-
assert.strictEqual(panel1!.getCurrentTitle(), 'Pull Request #2000');
188+
assert.strictEqual(panel0!.getCurrentTitle(), '#1000 New feature');
189+
assert.strictEqual(panel1!.getCurrentTitle(), '#2000 New feature');
190190
});
191191
});
192192
});

0 commit comments

Comments
 (0)