Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added pretty descriptions to treeview #759

Merged
merged 1 commit into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 29 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"watch:css": "npm run build:css -- -w"
},
"dependencies": {
"date-fns": "^2.8.1",
"minimatch": "^3.0.4",
"original-fs": "^1.0.0",
"semver": "^6.0.0",
Expand Down
15 changes: 11 additions & 4 deletions src/historyView/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createHash } from "crypto";
import { formatDistanceToNow } from "date-fns";
import * as path from "path";
import {
commands,
Expand Down Expand Up @@ -219,12 +220,18 @@ export function getCommitIcon(
return gravatar;
}

export function getCommitDescription(commit: ISvnLogEntry): string {
const relativeDate = formatDistanceToNow(Date.parse(commit.date), {
addSuffix: true
});
return `r${commit.revision}, ${relativeDate} by ${commit.author}`;
}

export function getCommitLabel(commit: ISvnLogEntry): string {
let commitMsg = "<blank>";
if (commit.msg) {
commitMsg = commit.msg.split(/\r?\n/, 1)[0];
if (!commit.msg) {
return "<blank>";
}
return `${commitMsg} • r${commit.revision}`;
return commit.msg.split(/\r?\n/, 1)[0];
}

export function getCommitToolTip(commit: ISvnLogEntry): string {
Expand Down
5 changes: 4 additions & 1 deletion src/historyView/itemLogProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import {
LogTreeItemKind,
openDiff,
openFileRemote,
transform
transform,
getCommitDescription
} from "./common";

export class ItemLogProvider
Expand Down Expand Up @@ -156,6 +157,7 @@ export class ItemLogProvider
if (element.kind === LogTreeItemKind.Commit) {
const commit = element.data as ISvnLogEntry;
ti = new TreeItem(getCommitLabel(commit), TreeItemCollapsibleState.None);
ti.description = getCommitDescription(commit);
ti.iconPath = getCommitIcon(commit.author);
ti.tooltip = getCommitToolTip(commit);
ti.contextValue = "diffable";
Expand All @@ -182,6 +184,7 @@ export class ItemLogProvider
const fname = path.basename(this.currentItem.svnTarget.fsPath);
const ti = new TreeItem(fname, TreeItemCollapsibleState.Expanded);
ti.tooltip = path.dirname(this.currentItem.svnTarget.fsPath);
ti.description = path.dirname(this.currentItem.svnTarget.fsPath);
ti.iconPath = getIconObject("icon-history");
const item = {
kind: LogTreeItemKind.TItem,
Expand Down
5 changes: 4 additions & 1 deletion src/historyView/repoLogProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ import {
openDiff,
openFileRemote,
SvnPath,
transform
transform,
getCommitDescription
} from "./common";

function getActionIcon(action: string) {
Expand Down Expand Up @@ -377,6 +378,7 @@ export class RepoLogProvider
getCommitLabel(commit),
TreeItemCollapsibleState.Collapsed
);
ti.description = getCommitDescription(commit);
ti.tooltip = getCommitToolTip(commit);
ti.iconPath = getCommitIcon(commit.author);
ti.contextValue = "commit";
Expand All @@ -385,6 +387,7 @@ export class RepoLogProvider
const pathElem = element.data as ISvnLogEntryPath;
const basename = path.basename(pathElem._);
ti = new TreeItem(basename, TreeItemCollapsibleState.None);
ti.description = path.dirname(pathElem._);
const cached = this.getCached(element);
const nm = cached.repo.getPathNormalizer();
ti.tooltip = nm.parse(pathElem._).relativeFromBranch;
Expand Down