Browse Source

Updates pull request actions in the focus view

- disables "switch to branch" when on the current branch
- disables "open worktree" when already in it
main
Keith Daulton 1 year ago
parent
commit
b5f0b43802
4 changed files with 56 additions and 7 deletions
  1. +34
    -2
      src/plus/webviews/focus/focusWebview.ts
  2. +2
    -0
      src/plus/webviews/focus/protocol.ts
  3. +17
    -4
      src/webviews/apps/plus/focus/components/pull-request-row.ts
  4. +3
    -1
      src/webviews/apps/plus/focus/focus.ts

+ 34
- 2
src/plus/webviews/focus/focusWebview.ts View File

@ -19,6 +19,7 @@ import { createReference } from '../../../git/models/reference';
import type { GitRemote } from '../../../git/models/remote'; import type { GitRemote } from '../../../git/models/remote';
import type { Repository, RepositoryChangeEvent } from '../../../git/models/repository'; import type { Repository, RepositoryChangeEvent } from '../../../git/models/repository';
import { RepositoryChange, RepositoryChangeComparisonMode } from '../../../git/models/repository'; import { RepositoryChange, RepositoryChangeComparisonMode } from '../../../git/models/repository';
import type { GitWorktree } from '../../../git/models/worktree';
import { parseGitRemoteUrl } from '../../../git/parsers/remoteParser'; import { parseGitRemoteUrl } from '../../../git/parsers/remoteParser';
import type { RichRemoteProvider } from '../../../git/remotes/richRemoteProvider'; import type { RichRemoteProvider } from '../../../git/remotes/richRemoteProvider';
import type { Subscription } from '../../../subscription'; import type { Subscription } from '../../../subscription';
@ -45,6 +46,8 @@ interface RepoWithRichRemote {
interface SearchedPullRequestWithRemote extends SearchedPullRequest { interface SearchedPullRequestWithRemote extends SearchedPullRequest {
repoAndRemote: RepoWithRichRemote; repoAndRemote: RepoWithRichRemote;
isCurrentBranch?: boolean;
isCurrentWorktree?: boolean;
} }
export class FocusWebviewProvider implements WebviewProvider<State> { export class FocusWebviewProvider implements WebviewProvider<State> {
@ -267,6 +270,8 @@ export class FocusWebviewProvider implements WebviewProvider {
const serializedPrs = prs.map(pr => ({ const serializedPrs = prs.map(pr => ({
pullRequest: serializePullRequest(pr.pullRequest), pullRequest: serializePullRequest(pr.pullRequest),
reasons: pr.reasons, reasons: pr.reasons,
isCurrentBranch: pr.isCurrentBranch ?? false,
iscurrentWorktree: pr.isCurrentWorktree ?? false,
})); }));
const issues = await this.getMyIssues(connectedRepos); const issues = await this.getMyIssues(connectedRepos);
@ -333,15 +338,42 @@ export class FocusWebviewProvider implements WebviewProvider {
} }
} }
private async getWorktreeForPullRequest(
searchedPullRequest: SearchedPullRequestWithRemote,
): Promise<GitWorktree | undefined> {
const worktree = await this.container.git.getWorktree(
searchedPullRequest.repoAndRemote.remote.repoPath,
w => w.branch === searchedPullRequest.pullRequest.refs!.head.branch,
);
return worktree;
}
private async getMyPullRequests(richRepos: RepoWithRichRemote[]): Promise<SearchedPullRequestWithRemote[]> { private async getMyPullRequests(richRepos: RepoWithRichRemote[]): Promise<SearchedPullRequestWithRemote[]> {
const allPrs = [];
const allPrs: SearchedPullRequestWithRemote[] = [];
for (const richRepo of richRepos) { for (const richRepo of richRepos) {
const { remote } = richRepo; const { remote } = richRepo;
const prs = await this.container.git.getMyPullRequests(remote); const prs = await this.container.git.getMyPullRequests(remote);
if (prs == null) { if (prs == null) {
continue; continue;
} }
allPrs.push(...prs.filter(pr => pr.reasons.length > 0).map(pr => ({ ...pr, repoAndRemote: richRepo })));
for (const pr of prs) {
if (pr.reasons.length === 0) {
continue;
}
const entry: SearchedPullRequestWithRemote = {
...pr,
repoAndRemote: richRepo,
isCurrentWorktree: false,
isCurrentBranch: false,
};
const worktree = await this.getWorktreeForPullRequest(entry);
entry.isCurrentWorktree = worktree?.opened === true;
const branch = await richRepo.repo.getBranch();
entry.isCurrentBranch = branch?.name === entry.pullRequest.refs!.head.branch;
allPrs.push(entry);
}
} }
function getScore(pr: SearchedPullRequest) { function getScore(pr: SearchedPullRequest) {

+ 2
- 0
src/plus/webviews/focus/protocol.ts View File

@ -22,6 +22,8 @@ export interface IssueResult extends SearchResultBase {
export interface PullRequestResult extends SearchResultBase { export interface PullRequestResult extends SearchResultBase {
pullRequest: PullRequestShape; pullRequest: PullRequestShape;
isCurrentBranch: boolean;
iscurrentWorktree: boolean;
} }
export interface RepoWithRichProvider { export interface RepoWithRichProvider {

+ 17
- 4
src/webviews/apps/plus/focus/components/pull-request-row.ts View File

@ -102,14 +102,16 @@ const template = html`
<table-cell class="vcenter actions"> <table-cell class="vcenter actions">
<a <a
href="#" href="#"
title="Open Worktree..."
aria-label="Open Worktree..."
tabindex="${x => (x.iscurrentWorktree ? -1 : null)}"
title="${x => (x.iscurrentWorktree ? 'On this Workree' : 'Open Worktree...')}"
aria-label="${x => (x.iscurrentWorktree ? 'On this Workree' : 'Open Worktree...')}"
@click="${(x, c) => x.onOpenWorktreeClick(c.event)}" @click="${(x, c) => x.onOpenWorktreeClick(c.event)}"
><code-icon icon="gl-worktrees-view"></code-icon></a ><code-icon icon="gl-worktrees-view"></code-icon></a
><a ><a
href="#" href="#"
title="Switch to Branch..."
aria-label="Switch to Branch..."
tabindex="${x => (x.isCurrentBranch ? -1 : null)}"
title="${x => (x.isCurrentBranch ? 'On this Branch' : 'Switch to Branch...')}"
aria-label="${x => (x.isCurrentBranch ? 'On this Branch' : 'Switch to Branch...')}"
@click="${(x, c) => x.onSwitchBranchClick(c.event)}" @click="${(x, c) => x.onSwitchBranchClick(c.event)}"
><code-icon icon="gl-switch"></code-icon ><code-icon icon="gl-switch"></code-icon
></a> ></a>
@ -208,6 +210,11 @@ const styles = css`
.actions a:active { .actions a:active {
background-color: var(--vscode-toolbar-activeBackground); background-color: var(--vscode-toolbar-activeBackground);
} }
.actions a[tabindex='-1'] {
opacity: 0.5;
cursor: default;
pointer-events: none;
}
.actions a code-icon { .actions a code-icon {
font-size: 1.6rem; font-size: 1.6rem;
@ -275,6 +282,12 @@ export class PullRequestRow extends FASTElement {
@observable @observable
public checks?: boolean; public checks?: boolean;
@observable
public isCurrentBranch = false;
@observable
public iscurrentWorktree = false;
@volatile @volatile
get lastUpdatedDate() { get lastUpdatedDate() {
return new Date(this.pullRequest!.date); return new Date(this.pullRequest!.date);

+ 3
- 1
src/webviews/apps/plus/focus/focus.ts View File

@ -154,11 +154,13 @@ export class FocusApp extends App {
} else { } else {
noneEl.setAttribute('hidden', 'true'); noneEl.setAttribute('hidden', 'true');
loadingEl.setAttribute('hidden', 'true'); loadingEl.setAttribute('hidden', 'true');
this.state.pullRequests.forEach(({ pullRequest, reasons }) => {
this.state.pullRequests.forEach(({ pullRequest, reasons, isCurrentBranch, iscurrentWorktree }) => {
if (this._prFilter == null || this._prFilter === '' || reasons.includes(this._prFilter)) { if (this._prFilter == null || this._prFilter === '' || reasons.includes(this._prFilter)) {
const rowEl = document.createElement('pull-request-row') as PullRequestRow; const rowEl = document.createElement('pull-request-row') as PullRequestRow;
rowEl.pullRequest = pullRequest; rowEl.pullRequest = pullRequest;
rowEl.reasons = reasons; rowEl.reasons = reasons;
rowEl.isCurrentBranch = isCurrentBranch;
rowEl.iscurrentWorktree = iscurrentWorktree;
tableEl.append(rowEl); tableEl.append(rowEl);
} }

Loading…
Cancel
Save