Skip to content

Commit 9bb9c4a

Browse files
committed
Implements actions-list component
1 parent f8ca506 commit 9bb9c4a

File tree

11 files changed

+617
-108
lines changed

11 files changed

+617
-108
lines changed

contributions.json

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2875,6 +2875,114 @@
28752875
]
28762876
}
28772877
},
2878+
"gitlens.home.openPullRequestChanges": {
2879+
"label": "Open Pull Request Changes",
2880+
"icon": "$(request-changes)",
2881+
"menus": {
2882+
"webview/context": [
2883+
{
2884+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openPullRequestChanges\\b)/",
2885+
"group": "10_gitlens_action@1"
2886+
}
2887+
]
2888+
}
2889+
},
2890+
"gitlens.home.openPullRequestOnRemote": {
2891+
"label": "Open Pull Request on Remote",
2892+
"icon": "$(globe)",
2893+
"menus": {
2894+
"webview/context": [
2895+
{
2896+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openPullRequestOnRemote\\b)/",
2897+
"group": "20_gitlens_action@1"
2898+
}
2899+
]
2900+
}
2901+
},
2902+
"gitlens.home.createPullRequest": {
2903+
"label": "Create Pull Request...",
2904+
"icon": "$(git-pull-request-create)",
2905+
"menus": {
2906+
"webview/context": [
2907+
{
2908+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.createPullRequest\\b)/",
2909+
"group": "30_gitlens_action@1"
2910+
}
2911+
]
2912+
}
2913+
},
2914+
"gitlens.home.openWorktree": {
2915+
"label": "Open Worktree",
2916+
"icon": "$(browser)",
2917+
"menus": {
2918+
"webview/context": [
2919+
{
2920+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openWorktree\\b)/",
2921+
"group": "40_gitlens_action@1"
2922+
}
2923+
]
2924+
}
2925+
},
2926+
"gitlens.home.openWorktreeInNewWindow": {
2927+
"label": "Open Worktree in New Window",
2928+
"icon": "$(empty-window)",
2929+
"menus": {
2930+
"webview/context": [
2931+
{
2932+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openWorktreeInNewWindow\\b)/",
2933+
"group": "40_gitlens_action@1"
2934+
}
2935+
]
2936+
}
2937+
},
2938+
"gitlens.home.fetch": {
2939+
"label": "Fetch",
2940+
"icon": "$(gl-repo-fetch)",
2941+
"menus": {
2942+
"webview/context": [
2943+
{
2944+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.fetch\\b)/",
2945+
"group": "60_gitlens_action@1"
2946+
}
2947+
]
2948+
}
2949+
},
2950+
"gitlens.home.switchToBranch": {
2951+
"label": "Switch to Branch...",
2952+
"icon": "$(gl-switch)",
2953+
"menus": {
2954+
"webview/context": [
2955+
{
2956+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.switchToBranch\\b)/",
2957+
"group": "50_gitlens_action@1"
2958+
}
2959+
]
2960+
}
2961+
},
2962+
"gitlens.home.pull": {
2963+
"label": "Pull",
2964+
"icon": "$(gl-repo-pull)",
2965+
"menus": {
2966+
"webview/context": [
2967+
{
2968+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.pull\\b)/",
2969+
"group": "60_gitlens_action@1"
2970+
}
2971+
]
2972+
}
2973+
},
2974+
"gitlens.home.openInGraph": {
2975+
"label": "Open in Commit Graph",
2976+
"icon": "$(gl-graph)",
2977+
"menus": {
2978+
"webview/context": [
2979+
{
2980+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openInGraph\\b)/",
2981+
"group": "80_gitlens_action@1"
2982+
}
2983+
]
2984+
}
2985+
},
28782986
"gitlens.inviteToLiveShare": {
28792987
"label": "Invite to Live Share",
28802988
"icon": "$(live-share)",

package.json

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6830,6 +6830,51 @@
68306830
"icon": "$(discard)",
68316831
"enablement": "!operationInProgress"
68326832
},
6833+
{
6834+
"command": "gitlens.home.openPullRequestChanges",
6835+
"title": "Open Pull Request Changes",
6836+
"icon": "$(request-changes)"
6837+
},
6838+
{
6839+
"command": "gitlens.home.openPullRequestOnRemote",
6840+
"title": "Open Pull Request on Remote",
6841+
"icon": "$(globe)"
6842+
},
6843+
{
6844+
"command": "gitlens.home.createPullRequest",
6845+
"title": "Create Pull Request...",
6846+
"icon": "$(git-pull-request-create)"
6847+
},
6848+
{
6849+
"command": "gitlens.home.openWorktree",
6850+
"title": "Open Worktree",
6851+
"icon": "$(browser)"
6852+
},
6853+
{
6854+
"command": "gitlens.home.openWorktreeInNewWindow",
6855+
"title": "Open Worktree in New Window",
6856+
"icon": "$(empty-window)"
6857+
},
6858+
{
6859+
"command": "gitlens.home.fetch",
6860+
"title": "Fetch",
6861+
"icon": "$(gl-repo-fetch)"
6862+
},
6863+
{
6864+
"command": "gitlens.home.switchToBranch",
6865+
"title": "Switch to Branch...",
6866+
"icon": "$(gl-switch)"
6867+
},
6868+
{
6869+
"command": "gitlens.home.pull",
6870+
"title": "Pull",
6871+
"icon": "$(gl-repo-pull)"
6872+
},
6873+
{
6874+
"command": "gitlens.home.openInGraph",
6875+
"title": "Open in Commit Graph",
6876+
"icon": "$(gl-graph)"
6877+
},
68336878
{
68346879
"command": "gitlens.inviteToLiveShare",
68356880
"title": "Invite to Live Share",
@@ -10679,6 +10724,42 @@
1067910724
"command": "gitlens.graph.undoCommit",
1068010725
"when": "false"
1068110726
},
10727+
{
10728+
"command": "gitlens.home.createPullRequest",
10729+
"when": "false"
10730+
},
10731+
{
10732+
"command": "gitlens.home.fetch",
10733+
"when": "false"
10734+
},
10735+
{
10736+
"command": "gitlens.home.openInGraph",
10737+
"when": "false"
10738+
},
10739+
{
10740+
"command": "gitlens.home.openPullRequestChanges",
10741+
"when": "false"
10742+
},
10743+
{
10744+
"command": "gitlens.home.openPullRequestOnRemote",
10745+
"when": "false"
10746+
},
10747+
{
10748+
"command": "gitlens.home.openWorktree",
10749+
"when": "false"
10750+
},
10751+
{
10752+
"command": "gitlens.home.openWorktreeInNewWindow",
10753+
"when": "false"
10754+
},
10755+
{
10756+
"command": "gitlens.home.pull",
10757+
"when": "false"
10758+
},
10759+
{
10760+
"command": "gitlens.home.switchToBranch",
10761+
"when": "false"
10762+
},
1068210763
{
1068310764
"command": "gitlens.inviteToLiveShare",
1068410765
"when": "false"
@@ -18354,6 +18435,51 @@
1835418435
"when": "webviewItem =~ /gitlens:graph:(columns|settings)\\b/",
1835518436
"group": "3_columns@2"
1835618437
},
18438+
{
18439+
"command": "gitlens.home.openPullRequestChanges",
18440+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openPullRequestChanges\\b)/",
18441+
"group": "10_gitlens_action@1"
18442+
},
18443+
{
18444+
"command": "gitlens.home.openPullRequestOnRemote",
18445+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openPullRequestOnRemote\\b)/",
18446+
"group": "20_gitlens_action@1"
18447+
},
18448+
{
18449+
"command": "gitlens.home.createPullRequest",
18450+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.createPullRequest\\b)/",
18451+
"group": "30_gitlens_action@1"
18452+
},
18453+
{
18454+
"command": "gitlens.home.openWorktree",
18455+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openWorktree\\b)/",
18456+
"group": "40_gitlens_action@1"
18457+
},
18458+
{
18459+
"command": "gitlens.home.openWorktreeInNewWindow",
18460+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openWorktreeInNewWindow\\b)/",
18461+
"group": "40_gitlens_action@1"
18462+
},
18463+
{
18464+
"command": "gitlens.home.switchToBranch",
18465+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.switchToBranch\\b)/",
18466+
"group": "50_gitlens_action@1"
18467+
},
18468+
{
18469+
"command": "gitlens.home.fetch",
18470+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.fetch\\b)/",
18471+
"group": "60_gitlens_action@1"
18472+
},
18473+
{
18474+
"command": "gitlens.home.pull",
18475+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.pull\\b)/",
18476+
"group": "60_gitlens_action@1"
18477+
},
18478+
{
18479+
"command": "gitlens.home.openInGraph",
18480+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openInGraph\\b)/",
18481+
"group": "80_gitlens_action@1"
18482+
},
1835718483
{
1835818484
"command": "gitlens.graph.openPullRequestChanges",
1835918485
"when": "webviewItem =~ /gitlens:pullrequest\\b(?=.*?\\b\\+refs\\b)/ && config.multiDiffEditor.experimental.enabled",

src/constants.commands.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,10 @@ type HomeWebviewCommands = `home.${
681681
| 'openPullRequestOnRemote'
682682
| 'createPullRequest'
683683
| 'openWorktree'
684+
| 'openWorktreeInNewWindow'
684685
| 'switchToBranch'
685686
| 'fetch'
687+
| 'pull'
686688
| 'openInGraph'
687689
| 'createBranch'
688690
| 'startWork'}`;

src/webviews/apps/home/home.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<body
2020
class="preload"
2121
data-placement="#{placement}"
22-
data-vscode-context='{ "webview": "#{webviewId}", "webviewInstance": "#{webviewInstanceId}" }'
22+
data-vscode-context='{ "preventDefaultContextMenuItems": true, "webview": "#{webviewId}", "webviewInstance": "#{webviewInstanceId}" }'
2323
>
2424
<gl-home-app name="HomeView" placement="#{placement}" state="#{state}"></gl-home-app>
2525
</body>

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

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import { when } from 'lit/directives/when.js';
77
import type { GitTrackingState } from '../../../../../git/models/branch';
88
import { createCommandLink } from '../../../../../system/commands';
99
import { createWebviewCommandLink } from '../../../../../system/webview';
10-
import type { GetOverviewBranch, OpenInGraphParams, State } from '../../../../home/protocol';
10+
import type { BranchRef, GetOverviewBranch, OpenInGraphParams, State } from '../../../../home/protocol';
1111
import { stateContext } from '../../../home/context';
12+
import type { ActionList } from '../../../shared/components/actions/action-list';
1213
import { ipcContext } from '../../../shared/context';
1314
import type { HostIpc } from '../../../shared/ipc';
1415
import { linkStyles } from '../../shared/components/vscode.css';
@@ -229,42 +230,68 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
229230
</div>
230231
`;
231232
}
233+
private prevAttr = JSON.parse(document.body.getAttribute('data-vscode-context') ?? '{}');
234+
private applyContext(context: object) {
235+
const prevContext = JSON.parse(document.body.getAttribute('data-vscode-context') ?? '{}');
236+
document.body.setAttribute(
237+
'data-vscode-context',
238+
JSON.stringify({
239+
...prevContext,
240+
...context,
241+
}),
242+
);
243+
setTimeout(() => {
244+
document.body.setAttribute('data-vscode-context', JSON.stringify(prevContext));
245+
});
246+
}
247+
248+
private handleBranchContext(branchRefs: BranchRef, e: typeof ActionList.OpenContextMenuEvent) {
249+
let context = 'gitlens:home';
250+
e.detail.items.forEach(x => {
251+
if (x.href) {
252+
context += `+${x.href}`;
253+
}
254+
});
255+
// clear context immediatelly after the contextmenu is opened to avoid randomly clicked contextmenu being filled
256+
this.applyContext({ webviewItem: context, ...branchRefs, type: 'branch' });
257+
}
232258

233259
private renderActions(branch: GetOverviewBranch, repo: string) {
234260
const branchRefs = {
235261
repoPath: repo,
236262
branchId: branch.id,
237263
};
238-
const actions = [];
264+
const actions: (typeof ActionList.ItemProps)[] = [];
239265
if (branch.pr) {
240266
actions.push(
241-
html`<action-item
242-
label="Open Pull Request Changes"
243-
icon="request-changes"
244-
href=${createCommandLink('gitlens.home.openPullRequestChanges', branchRefs)}
245-
></action-item>`,
246-
);
247-
actions.push(
248-
html`<action-item
249-
label="Open Pull Request on Remote"
250-
icon="globe"
251-
href=${createCommandLink('gitlens.home.openPullRequestOnRemote', branchRefs)}
252-
></action-item>`,
267+
{
268+
label: 'Open Pull Request Changes',
269+
icon: 'request-changes',
270+
href: createCommandLink('gitlens.home.openPullRequestChanges', branchRefs),
271+
},
272+
{
273+
label: 'Open Pull Request on Remote',
274+
icon: 'globe',
275+
href: createCommandLink('gitlens.home.openPullRequestOnRemote', branchRefs),
276+
},
253277
);
254278
} else if (branch.upstream?.missing === false) {
255-
actions.push(
256-
html`<action-item
257-
label="Create Pull Request..."
258-
icon="git-pull-request-create"
259-
href=${createCommandLink('gitlens.home.createPullRequest', branchRefs)}
260-
></action-item>`,
261-
);
279+
actions.push({
280+
label: 'Create Pull Request...',
281+
icon: 'git-pull-request-create',
282+
href: createCommandLink('gitlens.home.createPullRequest', branchRefs),
283+
});
262284
}
263285

264286
if (!actions.length) {
265287
return nothing;
266288
}
267-
return html`<action-nav class="branch-item__actions">${actions}</action-nav>`;
289+
return html`<action-list
290+
@open-actions-menu=${this.handleBranchContext.bind(this, branchRefs)}
291+
limit=${3}
292+
.items=${actions}
293+
class="branch-item__actions"
294+
></action-list>`;
268295
}
269296

270297
private renderBranchStateActions(

0 commit comments

Comments
 (0)