Skip to content

Commit 0cd26d8

Browse files
committed
Adds branch switching to Home nav
1 parent fe19cfa commit 0cd26d8

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

src/webviews/apps/plus/home/components/active-work.ts

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import type {
1515
OpenInTimelineParams,
1616
State,
1717
} from '../../../../home/protocol';
18+
import { ExecuteCommand } from '../../../../protocol';
1819
import { stateContext } from '../../../home/context';
1920
import type { RepoButtonGroupClickEvent } from '../../../shared/components/repo-button-group';
21+
import { ipcContext } from '../../../shared/contexts/ipc';
2022
import { linkStyles, ruleStyles } from '../../shared/components/vscode.css';
2123
import { branchCardStyles, GlBranchCardBase } from './branch-card';
2224
import type { ActiveOverviewState } from './overviewState';
@@ -31,6 +33,7 @@ import '../../../shared/components/menu/menu-item';
3133
import '../../../shared/components/menu/menu-label';
3234
import '../../../shared/components/overlays/popover';
3335
import '../../../shared/components/pills/tracking';
36+
import '../../../shared/components/ref-button';
3437
import '../../../shared/components/repo-button-group';
3538
import '../../../shared/components/rich/issue-icon';
3639
import '../../../shared/components/rich/pr-icon';
@@ -104,6 +107,9 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
104107
@consume({ context: activeOverviewStateContext })
105108
private _activeOverviewState!: ActiveOverviewState;
106109

110+
@consume({ context: ipcContext })
111+
private _ipc!: typeof ipcContext.__context__;
112+
107113
@state()
108114
private repoCollapsed = true;
109115

@@ -119,6 +125,13 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
119125
}
120126
}
121127

128+
private onBranchSelectorClicked() {
129+
this._ipc.sendCommand(ExecuteCommand, {
130+
command: 'gitlens.home.switchToBranch',
131+
args: [{ repoPath: this._activeOverviewState.state?.active.repoPath }],
132+
});
133+
}
134+
122135
override render(): unknown {
123136
if (this._homeState.discovering) {
124137
return this.renderLoader();
@@ -176,7 +189,9 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
176189
></gl-breadcrumb-item
177190
>
178191
<gl-breadcrumb-item collapsibleState="none" icon="git-branch" class="heading-branch-breadcrumb"
179-
>${activeBranch.name}</gl-breadcrumb-item
192+
><gl-ref-button .ref=${activeBranch.reference} @click=${this.onBranchSelectorClicked}
193+
><span slot="tooltip">Switch to Another Branch... </span></gl-ref-button
194+
></gl-breadcrumb-item
180195
>
181196
</gl-breadcrumbs>
182197
<span class="section-heading-actions" slot="heading-actions">
@@ -546,18 +561,19 @@ export class GlActiveBranchCard extends GlBranchCardBase {
546561

547562
return html`<div class="branch-item__row" full>
548563
<span class="branch-item__missing" full>Current work item</span>
549-
<gl-tooltip hoist content="Associate an issue">
550-
<a
551-
href=${this.createCommandLink<AssociateIssueWithBranchCommandArgs>(
552-
'gitlens.associateIssueWithBranch',
553-
{
554-
branch: this.branch.reference,
555-
source: 'home',
556-
},
557-
)}
558-
><span class="branch-item__icon"> <issue-icon></issue-icon> </span
559-
></a>
560-
</gl-tooltip>
564+
<gl-button
565+
appearance="toolbar"
566+
href=${this.createCommandLink<AssociateIssueWithBranchCommandArgs>(
567+
'gitlens.associateIssueWithBranch',
568+
{
569+
branch: this.branch.reference,
570+
source: 'home',
571+
},
572+
)}
573+
tooltip="Associate Issue with Branch"
574+
aria-label="Associate Issue with Branch"
575+
><issue-icon></issue-icon>
576+
</gl-button>
561577
</div>`;
562578
}
563579
return super.renderIssuesItem();

src/webviews/home/homeWebview.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,12 +1502,10 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
15021502
openWorkspace(worktree.uri, location ? { location: location } : undefined);
15031503
}
15041504

1505-
@log<HomeWebviewProvider['switchToBranch']>({ args: { 0: r => r.branchId } })
1506-
private async switchToBranch(ref: BranchRef) {
1505+
@log<HomeWebviewProvider['switchToBranch']>({ args: { 0: r => r?.branchId } })
1506+
private async switchToBranch(ref: BranchRef | { repoPath: string; branchName?: never; branchId?: never }) {
15071507
const { repo, branch } = await this.getRepoInfoFromRef(ref);
1508-
if (branch == null) return;
1509-
1510-
void RepoActions.switchTo(repo, getReferenceFromBranch(branch));
1508+
void RepoActions.switchTo(repo, branch ? getReferenceFromBranch(branch) : undefined);
15111509
}
15121510

15131511
@log<HomeWebviewProvider['fetch']>({ args: { 0: r => r?.branchId } })
@@ -1560,10 +1558,11 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
15601558
}
15611559

15621560
private async getRepoInfoFromRef(
1563-
ref: BranchRef,
1561+
ref: BranchRef | { repoPath: string; branchName?: string },
15641562
): Promise<{ repo: Repository; branch: GitBranch | undefined } | { repo: undefined; branch: undefined }> {
15651563
const repo = this.container.git.getRepository(ref.repoPath);
15661564
if (repo == null) return { repo: undefined, branch: undefined };
1565+
if (!ref.branchName) return { repo: repo, branch: undefined };
15671566

15681567
const branch = await repo.git.branches.getBranch(ref.branchName);
15691568
return { repo: repo, branch: branch };

src/webviews/protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const WebviewFocusChangedCommand = new IpcCommand<WebviewFocusChangedPara
8282

8383
export interface ExecuteCommandParams {
8484
command: GlCommands;
85-
args?: [];
85+
args?: unknown[];
8686
}
8787
export const ExecuteCommand = new IpcCommand<ExecuteCommandParams>('core', 'command/execute');
8888

0 commit comments

Comments
 (0)