diff --git a/src/system/webview.ts b/src/system/webview.ts index 6d63c0705ae30..7687fc69ea2ec 100644 --- a/src/system/webview.ts +++ b/src/system/webview.ts @@ -1,12 +1,13 @@ import type { WebviewIds, WebviewViewIds } from '../constants.views'; -export function createWebviewCommandLink( +export function createWebviewCommandLink( command: `${WebviewIds | WebviewViewIds}.${string}`, webviewId: WebviewIds | WebviewViewIds, webviewInstanceId: string | undefined, + args?: T, ): string { return `command:${command}?${encodeURIComponent( - JSON.stringify({ webview: webviewId, webviewInstance: webviewInstanceId } satisfies WebviewContext), + JSON.stringify({ webview: webviewId, webviewInstance: webviewInstanceId, ...args } satisfies WebviewContext), )}`; } diff --git a/src/webviews/apps/plus/home/components/active-work.ts b/src/webviews/apps/plus/home/components/active-work.ts index 957ed24174e31..e1d35d082c520 100644 --- a/src/webviews/apps/plus/home/components/active-work.ts +++ b/src/webviews/apps/plus/home/components/active-work.ts @@ -4,6 +4,7 @@ import { css, html, LitElement, nothing } from 'lit'; import { customElement, state } from 'lit/decorators.js'; import { when } from 'lit/directives/when.js'; import type { GitTrackingState } from '../../../../../git/models/branch'; +import { createWebviewCommandLink } from '../../../../../system/webview'; import type { GetOverviewBranch, State } from '../../../../home/protocol'; import { stateContext } from '../../../home/context'; import { branchCardStyles, sectionHeadingStyles } from './branch-section'; @@ -83,11 +84,11 @@ export class GlActiveWork extends SignalWatcher(LitElement) { private renderComplete(overview: Overview) { const activeBranches = overview?.repository?.branches?.active; - if (activeBranches == null) return html`None`; + if (!activeBranches) return html`None`; return html`

- ${overview!.repository.name} + ${overview.repository.name} ${when( this._homeState.repositories.openCount > 1, () => @@ -116,13 +117,13 @@ export class GlActiveWork extends SignalWatcher(LitElement) { ${name}

${when(state, () => this.renderBranchStateActions(state, upstream))} - ${when(pr, () => { + ${when(pr, pr => { return html`

- + - ${pr!.title} - #${pr!.id} + ${pr.title} + #${pr.id}

`; })} ${when(workingTreeState, () => this.renderStatus(workingTreeState, state))} @@ -134,7 +135,10 @@ export class GlActiveWork extends SignalWatcher(LitElement) { if (upstream?.missing !== false) { return html`
- Publish Branch @@ -148,7 +152,11 @@ export class GlActiveWork extends SignalWatcher(LitElement) { const forcePushTooltip = upstream?.name ? `Force Push to ${upstream.name}` : 'Force Push'; return html`
- Pull - @@ -166,7 +180,11 @@ export class GlActiveWork extends SignalWatcher(LitElement) { const tooltip = upstream?.name ? `Pull from ${upstream.name}` : 'Pull'; return html`
- Pull - Push

${this.renderIcon(this.branch)} ${when( pr, - () => - html`${pr!.title} - #${pr!.id}`, + pr => + html`${pr.title} #${pr.id}`, () => html`${name}`, )}

diff --git a/src/webviews/home/homeWebview.ts b/src/webviews/home/homeWebview.ts index c35a617b3edba..725a7f6244e30 100644 --- a/src/webviews/home/homeWebview.ts +++ b/src/webviews/home/homeWebview.ts @@ -5,6 +5,7 @@ import { GlyphChars } from '../../constants'; import type { ContextKeys } from '../../constants.context'; import type { HomeTelemetryContext } from '../../constants.telemetry'; import type { Container } from '../../container'; +import { executeGitCommand } from '../../git/actions'; import type { BranchContributorOverview } from '../../git/gitProvider'; import type { GitBranch } from '../../git/models/branch'; import { sortBranches } from '../../git/models/branch'; @@ -146,7 +147,7 @@ export class HomeWebviewProvider implements WebviewProvider { + private async shouldNotifyRepositoryChange(): Promise { if (this._etag === this.container.git.etag) { return false; } @@ -181,7 +182,7 @@ export class HomeWebviewProvider implements WebviewProvider { + void this.push(args.force); + }, + this, + ), + registerCommand(`${this.host.id}.publishBranch`, this.push, this), registerCommand(`${this.host.id}.refresh`, () => this.host.refresh(true), this), registerCommand( `${this.host.id}.account.resync`, @@ -426,6 +458,7 @@ export class HomeWebviewProvider implements WebviewProvider = new Map(); - private async getBranchesAndWorktrees(repo: Repository, force = false) { + private _invalidateRepositoryBranches = true; + private readonly _repositoryBranches: Map = new Map(); + private async getBranchesAndWorktrees(repo: Repository, force = this._invalidateRepositoryBranches) { if (force || !this._repositoryBranches.has(repo.path)) { - const [branchesResult, worktreesResult] = await Promise.allSettled([ - repo.git.getBranches({ filter: b => !b.remote }), - repo.git.getWorktrees(), + const worktrees = (await repo.git.getWorktrees()) ?? []; + const worktreesByBranch = groupWorktreesByBranch(worktrees); + const [branchesResult] = await Promise.allSettled([ + repo.git.getBranches({ + filter: b => !b.remote, + sort: { current: true, openedWorktreesByBranch: getOpenedWorktreesByBranch(worktreesByBranch) }, + }), ]); const branches = getSettledValue(branchesResult)?.values ?? []; - const worktrees = getSettledValue(worktreesResult) ?? []; + this._invalidateRepositoryBranches = false; this._repositoryBranches.set(repo.path, { branches: branches, worktrees: worktrees }); } @@ -542,16 +580,11 @@ async function getOverviewBranches( container: Container, options: OverviewFilters, ): Promise { + console.log('try to getOverviewBranches'); if (branches.length === 0) return undefined; const worktreesByBranch = groupWorktreesByBranch(worktrees); - sortBranches(branches, { - current: true, - orderBy: 'date:desc', - openedWorktreesByBranch: getOpenedWorktreesByBranch(worktreesByBranch), - }); - const overviewBranches: GetOverviewBranches = { active: [], recent: [], @@ -571,7 +604,7 @@ async function getOverviewBranches( const timestamp = branch.date?.getTime(); if (branch.current || wt?.opened) { - prPromises.set(branch.id, branch.getAssociatedPullRequest()); + prPromises.set(branch.id, branch.getAssociatedPullRequest({ avatarSize: 16 })); if (wt != null) { statusPromises.set(branch.id, wt.getStatus()); } @@ -678,15 +711,15 @@ async function getOverviewBranches( const prs = new Map( getSettledValue(prResults) ?.filter(r => r.status === 'fulfilled') - .map(r => [ - r.value[0], - r.value[1] - ? { - id: r.value[1].id, - title: r.value[1].title, - state: r.value[1].state, - url: r.value[1].url, - } + .map(({ value: [prId, pr] }) => [ + prId, + pr + ? ({ + id: pr.id, + title: pr.title, + state: pr.state, + url: pr.url, + } satisfies GetOverviewBranch['pr']) : undefined, ]), );