Skip to content

Commit

Permalink
Adds stash following to commit details view
Browse files Browse the repository at this point in the history
  • Loading branch information
d13 committed Aug 18, 2022
1 parent d0ac7b1 commit fe1ad9e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 57 deletions.
49 changes: 13 additions & 36 deletions src/webviews/apps/commitDetails/commitDetails.scss
Expand Up @@ -128,48 +128,25 @@ ul {
}
}

.pull-request,
.issue {
display: grid;
.commit-stashed {
display: flex;
gap: 0.25rem 0.5rem;
justify-content: start;
align-items: center;

&__icon {
grid-column: 1;
grid-row: 1 / 3;
color: var(--vscode-gitlens-mergedPullRequestIconColor);
}
&__title {
grid-column: 2;
grid-row: 1;
margin: 0;
font-size: 1.5rem;
}
&__date {
grid-column: 2;
grid-row: 2;
margin: 0;
font-size: 1.2rem;
}
}

.commit-author {
display: grid;
gap: 0.25rem 0.5rem;
justify-content: start;

&__avatar {
grid-column: 1;
grid-row: 1 / 3;
&__media {
width: 3.6rem;
height: 3.6rem;
display: flex;
justify-content: center;
align-items: center;
}
&__name {
grid-column: 2;
grid-row: 1;
font-size: 1.5rem;
&__media &__icon {
width: 2.8rem;
height: 2.8rem;
font-size: 2.8rem;
}
&__date {
grid-column: 2;
grid-row: 2;
font-size: 1.2rem;
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/webviews/apps/commitDetails/commitDetails.ts
Expand Up @@ -330,11 +330,12 @@ export class CommitDetailsApp extends App<Serialized<State>> {
}

if (state.selected.files?.length) {
const stashAttr = state.selected.isStash ? 'stash ' : '';
$el.innerHTML = state.selected.files
.map(
(file: Record<string, any>) => `
<li class="change-list__item">
<file-change-item class="commit-details__file" status="${file.status}" path="${file.path}" repo-path="${file.repoPath}" icon="${file.icon.dark}"></file-change-item>
<file-change-item class="commit-details__file" ${stashAttr}status="${file.status}" path="${file.path}" repo-path="${file.repoPath}" icon="${file.icon.dark}"></file-change-item>
</li>
`,
)
Expand All @@ -351,7 +352,15 @@ export class CommitDetailsApp extends App<Serialized<State>> {
return;
}

if (state.selected.author != null) {
if (state.selected?.isStash === true) {
$el.innerHTML = `
<div class="commit-stashed">
<span class="commit-stashed__media"><code-icon class="commit-stashed__icon" icon="inbox"></code-icon></span>
<span class="commit-stashed__date">stashed <formatted-date date=${state.selected.author.date} dateFormat="${state.dateFormat}"></formatted-date></span>
</div>
`;
$el.setAttribute('aria-hidden', 'false');
} else if (state.selected?.author != null) {
$el.innerHTML = `
<commit-identity
name="${state.selected.author.name}"
Expand Down
Expand Up @@ -46,7 +46,7 @@ export class CommitIdentity extends LitElement {
date = '';

@property()
avatar = 'https://www.gravatar.com/avatar/?s=16&d=robohash';
avatar = 'https://www.gravatar.com/avatar/?s=64&d=robohash';

@property()
dateFormat = 'MMMM Do, YYYY h:mma';
Expand Down
40 changes: 23 additions & 17 deletions src/webviews/apps/shared/components/commit/file-change-item.ts
@@ -1,4 +1,4 @@
import { css, html, LitElement } from 'lit';
import { css, html, LitElement, nothing } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import type { FileShowOptions } from '../../../../commitDetails/protocol';
import '../codicon';
Expand Down Expand Up @@ -156,6 +156,9 @@ export class FileChangeItem extends LitElement {
@property()
icon = '';

@property({ type: Boolean, reflect: true })
stash = false;

private renderIcon() {
if (this.icon !== '') {
return html`<img class="change-list__status-icon" src="${this.icon}" />`;
Expand All @@ -181,7 +184,8 @@ export class FileChangeItem extends LitElement {

return html`
<a id="item" class="change-list__link" @click=${this.onComparePrevious} href="#">
<span class="change-list__status" aria-label="${statusName}">${this.renderIcon()}</span
<span class="change-list__status" title="${statusName}" aria-label="${statusName}"
>${this.renderIcon()}</span
><span class="change-list__filename">${fileName}</span>
<small class="change-list__path">${filePath}</small>
</a>
Expand All @@ -200,21 +204,23 @@ export class FileChangeItem extends LitElement {
title="Open Changes with Working File"
aria-label="Open Changes with Working File"
><code-icon icon="git-compare"></code-icon></a
><a
class="change-list__action"
@click=${this.onOpenFileOnRemote}
href="#"
title="Open on remote"
aria-label="Open on remote"
><code-icon icon="globe"></code-icon></a
><a
class="change-list__action"
@click=${this.onMoreActions}
href="#"
title="Show more actions"
aria-label="Show more actions"
><code-icon icon="ellipsis"></code-icon
></a>
>${!this.stash
? html`<a
class="change-list__action"
@click=${this.onOpenFileOnRemote}
href="#"
title="Open on remote"
aria-label="Open on remote"
><code-icon icon="globe"></code-icon></a
><a
class="change-list__action"
@click=${this.onMoreActions}
href="#"
title="Show more actions"
aria-label="Show more actions"
><code-icon icon="ellipsis"></code-icon
></a>`
: nothing}
</nav>
`;
}
Expand Down
13 changes: 12 additions & 1 deletion src/webviews/commitDetails/commitDetailsWebviewView.ts
Expand Up @@ -21,6 +21,8 @@ import type { LinesChangeEvent } from '../../trackers/lineTracker';
import { CommitFileNode } from '../../views/nodes/commitFileNode';
import { CommitNode } from '../../views/nodes/commitNode';
import { FileRevisionAsCommitNode } from '../../views/nodes/fileRevisionAsCommitNode';
import { StashFileNode } from '../../views/nodes/stashFileNode';
import { StashNode } from '../../views/nodes/stashNode';
import type { ViewNode } from '../../views/nodes/viewNode';
import type { IpcMessage } from '../protocol';
import { onIpc } from '../protocol';
Expand Down Expand Up @@ -134,12 +136,13 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<

if (this._pinned || !this.visible) return;

const { lineTracker, commitsView, graphWebview } = this.container;
const { lineTracker, commitsView, graphWebview, stashesView } = this.container;
this._visibilityDisposable = Disposable.from(
lineTracker.subscribe(this, lineTracker.onDidChangeActiveLines(this.onActiveLinesChanged, this)),
commitsView.onDidChangeVisibility(this.onCommitsViewVisibilityChanged, this),
commitsView.onDidChangeSelection(this.onCommitsViewSelectionChanged, this),
graphWebview.onDidChangeSelection(this.onGraphWebviewSelectionChanged, this),
stashesView.onDidChangeSelection(this.onStashesViewSelectionChanged, this),
);

const commit = this.getBestCommit();
Expand Down Expand Up @@ -223,6 +226,13 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<
}
}

private onStashesViewSelectionChanged(e: TreeViewSelectionChangeEvent<ViewNode>) {
const node = e.selection?.[0];
if (node != null && (node instanceof StashNode || node instanceof StashFileNode)) {
this.updateCommit(node.commit);
}
}

private onGraphWebviewSelectionChanged(e: GraphSelectionChangeEvent) {
this.updateCommit(e.selection[0]);
}
Expand Down Expand Up @@ -527,6 +537,7 @@ export class CommitDetailsWebviewView extends WebviewViewBase<State, Serialized<
return {
sha: commit.sha,
shortSha: commit.shortSha,
isStash: commit.refType === 'stash',
// summary: commit.summary,
message: formattedMessage ?? encodeMarkup(commit.message ?? commit.summary),
author: { ...commit.author, avatar: authorAvatar.toString(true) },
Expand Down
1 change: 1 addition & 0 deletions src/webviews/commitDetails/protocol.ts
Expand Up @@ -15,6 +15,7 @@ export type CommitSummary = {
message: string;
author: GitCommitIdentityShape & { avatar: string | undefined };
// committer: GitCommitIdentityShape & { avatar: string | undefined };
isStash: boolean;
};

export type CommitDetails = CommitSummary & {
Expand Down

0 comments on commit fe1ad9e

Please sign in to comment.