Skip to content

Commit 73de872

Browse files
YanpasJohnstonCode
authored andcommitted
feat: Added pretty descriptions to treeview (#759)
1 parent b2c448c commit 73de872

File tree

5 files changed

+49
-29
lines changed

5 files changed

+49
-29
lines changed

package-lock.json

Lines changed: 29 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"watch:css": "npm run build:css -- -w"
4848
},
4949
"dependencies": {
50+
"date-fns": "^2.8.1",
5051
"minimatch": "^3.0.4",
5152
"original-fs": "^1.0.0",
5253
"semver": "^6.0.0",

src/historyView/common.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createHash } from "crypto";
2+
import { formatDistanceToNow } from "date-fns";
23
import * as path from "path";
34
import {
45
commands,
@@ -219,12 +220,18 @@ export function getCommitIcon(
219220
return gravatar;
220221
}
221222

223+
export function getCommitDescription(commit: ISvnLogEntry): string {
224+
const relativeDate = formatDistanceToNow(Date.parse(commit.date), {
225+
addSuffix: true
226+
});
227+
return `r${commit.revision}, ${relativeDate} by ${commit.author}`;
228+
}
229+
222230
export function getCommitLabel(commit: ISvnLogEntry): string {
223-
let commitMsg = "<blank>";
224-
if (commit.msg) {
225-
commitMsg = commit.msg.split(/\r?\n/, 1)[0];
231+
if (!commit.msg) {
232+
return "<blank>";
226233
}
227-
return `${commitMsg} • r${commit.revision}`;
234+
return commit.msg.split(/\r?\n/, 1)[0];
228235
}
229236

230237
export function getCommitToolTip(commit: ISvnLogEntry): string {

src/historyView/itemLogProvider.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ import {
2929
LogTreeItemKind,
3030
openDiff,
3131
openFileRemote,
32-
transform
32+
transform,
33+
getCommitDescription
3334
} from "./common";
3435

3536
export class ItemLogProvider
@@ -156,6 +157,7 @@ export class ItemLogProvider
156157
if (element.kind === LogTreeItemKind.Commit) {
157158
const commit = element.data as ISvnLogEntry;
158159
ti = new TreeItem(getCommitLabel(commit), TreeItemCollapsibleState.None);
160+
ti.description = getCommitDescription(commit);
159161
ti.iconPath = getCommitIcon(commit.author);
160162
ti.tooltip = getCommitToolTip(commit);
161163
ti.contextValue = "diffable";
@@ -182,6 +184,7 @@ export class ItemLogProvider
182184
const fname = path.basename(this.currentItem.svnTarget.fsPath);
183185
const ti = new TreeItem(fname, TreeItemCollapsibleState.Expanded);
184186
ti.tooltip = path.dirname(this.currentItem.svnTarget.fsPath);
187+
ti.description = path.dirname(this.currentItem.svnTarget.fsPath);
185188
ti.iconPath = getIconObject("icon-history");
186189
const item = {
187190
kind: LogTreeItemKind.TItem,

src/historyView/repoLogProvider.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import {
3737
openDiff,
3838
openFileRemote,
3939
SvnPath,
40-
transform
40+
transform,
41+
getCommitDescription
4142
} from "./common";
4243

4344
function getActionIcon(action: string) {
@@ -377,6 +378,7 @@ export class RepoLogProvider
377378
getCommitLabel(commit),
378379
TreeItemCollapsibleState.Collapsed
379380
);
381+
ti.description = getCommitDescription(commit);
380382
ti.tooltip = getCommitToolTip(commit);
381383
ti.iconPath = getCommitIcon(commit.author);
382384
ti.contextValue = "commit";
@@ -385,6 +387,7 @@ export class RepoLogProvider
385387
const pathElem = element.data as ISvnLogEntryPath;
386388
const basename = path.basename(pathElem._);
387389
ti = new TreeItem(basename, TreeItemCollapsibleState.None);
390+
ti.description = path.dirname(pathElem._);
388391
const cached = this.getCached(element);
389392
const nm = cached.repo.getPathNormalizer();
390393
ti.tooltip = nm.parse(pathElem._).relativeFromBranch;

0 commit comments

Comments
 (0)