Sfoglia il codice sorgente

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 anno fa
parent
commit
b5f0b43802
4 ha cambiato i file con 56 aggiunte e 7 eliminazioni
  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 Vedi File

@ -19,6 +19,7 @@ import { createReference } from '../../../git/models/reference';
import type { GitRemote } from '../../../git/models/remote';
import type { Repository, RepositoryChangeEvent } 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 type { RichRemoteProvider } from '../../../git/remotes/richRemoteProvider';
import type { Subscription } from '../../../subscription';
@ -45,6 +46,8 @@ interface RepoWithRichRemote {
interface SearchedPullRequestWithRemote extends SearchedPullRequest {
repoAndRemote: RepoWithRichRemote;
isCurrentBranch?: boolean;
isCurrentWorktree?: boolean;
}
export class FocusWebviewProvider implements WebviewProvider<State> {
@ -267,6 +270,8 @@ export class FocusWebviewProvider implements WebviewProvider {
const serializedPrs = prs.map(pr => ({
pullRequest: serializePullRequest(pr.pullRequest),
reasons: pr.reasons,
isCurrentBranch: pr.isCurrentBranch ?? false,
iscurrentWorktree: pr.isCurrentWorktree ?? false,
}));
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[]> {
const allPrs = [];
const allPrs: SearchedPullRequestWithRemote[] = [];
for (const richRepo of richRepos) {
const { remote } = richRepo;
const prs = await this.container.git.getMyPullRequests(remote);
if (prs == null) {
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) {

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

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

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

@ -102,14 +102,16 @@ const template = html`
<table-cell class="vcenter actions">
<a
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)}"
><code-icon icon="gl-worktrees-view"></code-icon></a
><a
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)}"
><code-icon icon="gl-switch"></code-icon
></a>
@ -208,6 +210,11 @@ const styles = css`
.actions a:active {
background-color: var(--vscode-toolbar-activeBackground);
}
.actions a[tabindex='-1'] {
opacity: 0.5;
cursor: default;
pointer-events: none;
}
.actions a code-icon {
font-size: 1.6rem;
@ -275,6 +282,12 @@ export class PullRequestRow extends FASTElement {
@observable
public checks?: boolean;
@observable
public isCurrentBranch = false;
@observable
public iscurrentWorktree = false;
@volatile
get lastUpdatedDate() {
return new Date(this.pullRequest!.date);

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

@ -154,11 +154,13 @@ export class FocusApp extends App {
} else {
noneEl.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)) {
const rowEl = document.createElement('pull-request-row') as PullRequestRow;
rowEl.pullRequest = pullRequest;
rowEl.reasons = reasons;
rowEl.isCurrentBranch = isCurrentBranch;
rowEl.iscurrentWorktree = iscurrentWorktree;
tableEl.append(rowEl);
}

Caricamento…
Annulla
Salva