Skip to content

Commit e9ab8ae

Browse files
committed
Adds open in graph action
1 parent 6768341 commit e9ab8ae

File tree

4 files changed

+59
-4
lines changed

4 files changed

+59
-4
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import { ifDefined } from 'lit/directives/if-defined.js';
66
import { when } from 'lit/directives/when.js';
77
import type { GitTrackingState } from '../../../../../git/models/branch';
88
import { createWebviewCommandLink } from '../../../../../system/webview';
9-
import type { GetOverviewBranch, State } from '../../../../home/protocol';
9+
import type { GetOverviewBranch, OpenInGraphParams, State } from '../../../../home/protocol';
1010
import { stateContext } from '../../../home/context';
11+
import { ipcContext } from '../../../shared/context';
12+
import type { HostIpc } from '../../../shared/ipc';
1113
import { branchCardStyles, createCommandLink, headingLoaderStyles } from './branch-section';
1214
import type { Overview, OverviewState } from './overviewState';
1315
import { overviewStateContext } from './overviewState';
@@ -51,6 +53,9 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
5153
@consume({ context: overviewStateContext })
5254
private _overviewState!: OverviewState;
5355

56+
@consume({ context: ipcContext })
57+
private _ipc!: HostIpc;
58+
5459
override connectedCallback() {
5560
super.connectedCallback();
5661

@@ -103,13 +108,15 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
103108
>
104109
<span slot="heading-actions"
105110
><gl-button
106-
hidden
107111
aria-busy="${ifDefined(isFetching)}"
108112
?disabled=${isFetching}
109113
class="section-heading-action"
110114
appearance="toolbar"
111115
tooltip="Open in Commit Graph"
112-
@click=${(_e: MouseEvent) => {}}
116+
href=${createCommandLink('gitlens.home.openInGraph', {
117+
type: 'repo',
118+
repoPath: this._overviewState.state!.repository.path,
119+
} satisfies OpenInGraphParams)}
113120
><code-icon icon="gl-graph"></code-icon
114121
></gl-button>
115122
${when(

src/webviews/apps/plus/home/components/branch-section.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { customElement, property } from 'lit/decorators.js';
33
import { when } from 'lit/directives/when.js';
44
import type { Commands } from '../../../../../constants.commands';
55
import type { GitTrackingState } from '../../../../../git/models/branch';
6-
import type { GetOverviewBranch } from '../../../../home/protocol';
6+
import type { GetOverviewBranch, OpenInGraphParams } from '../../../../home/protocol';
77
import { srOnlyStyles } from '../../../shared/components/styles/lit/a11y.css';
88
import '../../../shared/components/code-icon';
99
import '../../../shared/components/avatar/avatar';
@@ -370,6 +370,16 @@ export class GlBranchCard extends LitElement {
370370
href=${this.createCommandLink('gitlens.home.fetch')}
371371
></action-item>`,
372372
);
373+
actions.push(
374+
html`<action-item
375+
label="Open in Commit Graph"
376+
icon="gl-graph"
377+
href=${createCommandLink('gitlens.home.openInGraph', {
378+
...this.branchRefs,
379+
type: 'branch',
380+
} satisfies OpenInGraphParams)}
381+
></action-item>`,
382+
);
373383

374384
if (!actions.length) {
375385
return nothing;

src/webviews/home/homeWebview.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { getOpenedWorktreesByBranch, groupWorktreesByBranch } from '../../git/mo
2424
import type { Subscription } from '../../plus/gk/account/subscription';
2525
import type { SubscriptionChangeEvent } from '../../plus/gk/account/subscriptionService';
2626
import { getLaunchpadSummary } from '../../plus/launchpad/utils';
27+
import type { ShowInCommitGraphCommandArgs } from '../../plus/webviews/graph/protocol';
2728
import { showRepositoryPicker } from '../../quickpicks/repositoryPicker';
2829
import type { Deferrable } from '../../system/function';
2930
import { debounce } from '../../system/function';
@@ -42,6 +43,7 @@ import type {
4243
GetOverviewBranch,
4344
GetOverviewBranches,
4445
GetOverviewResponse,
46+
OpenInGraphParams,
4547
OverviewFilters,
4648
OverviewRecentThreshold,
4749
OverviewStaleThreshold,
@@ -64,6 +66,7 @@ import {
6466
GetLaunchpadSummary,
6567
GetOverview,
6668
GetOverviewFilterState,
69+
OpenInGraphCommand,
6770
SetOverviewFilter,
6871
TogglePreviewEnabledCommand,
6972
} from './protocol';
@@ -268,6 +271,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
268271
registerCommand('gitlens.home.openWorktree', this.worktreeOpen, this),
269272
registerCommand('gitlens.home.switchToBranch', this.switchToBranch, this),
270273
registerCommand('gitlens.home.fetch', this.fetch, this),
274+
registerCommand('gitlens.home.openInGraph', this.openInGraph, this),
271275
];
272276
}
273277

@@ -303,6 +307,9 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
303307
case TogglePreviewEnabledCommand.is(e):
304308
this.onTogglePreviewEnabled();
305309
break;
310+
case OpenInGraphCommand.is(e):
311+
this.openInGraph(e.params);
312+
break;
306313
}
307314
}
308315

@@ -339,6 +346,31 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
339346
this.notifyDidChangeRepositories(true);
340347
}
341348

349+
private openInGraph(params: OpenInGraphParams) {
350+
if (params?.type === 'branch') {
351+
const repo = this._repositoryBranches.get(params.repoPath);
352+
if (repo == null) return;
353+
354+
const branch = repo.branches.find(b => b.id === params.branchId);
355+
if (branch == null) return;
356+
357+
const ref = getReferenceFromBranch(branch);
358+
if (ref == null) return;
359+
void executeCommand<ShowInCommitGraphCommandArgs>(Commands.ShowInCommitGraph, { ref: ref });
360+
return;
361+
}
362+
363+
let repo: Repository | undefined;
364+
if (params == null) {
365+
repo = this.getSelectedRepository();
366+
} else {
367+
const repoBranches = this._repositoryBranches.get(params.repoPath);
368+
repo = repoBranches?.repo;
369+
}
370+
if (repo == null) return;
371+
void executeCommand(Commands.ShowGraph, repo);
372+
}
373+
342374
private onTogglePreviewEnabled(isEnabled?: boolean) {
343375
if (isEnabled === undefined) {
344376
isEnabled = !this.getPreviewEnabled();

src/webviews/home/protocol.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ export const DismissWalkthroughSection = new IpcCommand<void>(scope, 'walkthroug
141141

142142
export const SetOverviewFilter = new IpcCommand<OverviewFilters>(scope, 'overview/filter/set');
143143

144+
export type OpenInGraphParams =
145+
| { type: 'repo'; repoPath: string }
146+
| { type: 'branch'; repoPath: string; branchId: string }
147+
| undefined;
148+
export const OpenInGraphCommand = new IpcCommand<OpenInGraphParams>(scope, 'openInGraph');
149+
144150
// NOTIFICATIONS
145151

146152
export interface DidCompleteDiscoveringRepositoriesParams {

0 commit comments

Comments
 (0)