Skip to content

Commit

Permalink
Implements actions-list component
Browse files Browse the repository at this point in the history
  • Loading branch information
nzaytsev committed Dec 18, 2024
1 parent f8ca506 commit 9bb9c4a
Show file tree
Hide file tree
Showing 11 changed files with 617 additions and 108 deletions.
108 changes: 108 additions & 0 deletions contributions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2875,6 +2875,114 @@
]
}
},
"gitlens.home.openPullRequestChanges": {
"label": "Open Pull Request Changes",
"icon": "$(request-changes)",
"menus": {
"webview/context": [
{
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openPullRequestChanges\\b)/",
"group": "10_gitlens_action@1"
}
]
}
},
"gitlens.home.openPullRequestOnRemote": {
"label": "Open Pull Request on Remote",
"icon": "$(globe)",
"menus": {
"webview/context": [
{
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openPullRequestOnRemote\\b)/",
"group": "20_gitlens_action@1"
}
]
}
},
"gitlens.home.createPullRequest": {
"label": "Create Pull Request...",
"icon": "$(git-pull-request-create)",
"menus": {
"webview/context": [
{
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.createPullRequest\\b)/",
"group": "30_gitlens_action@1"
}
]
}
},
"gitlens.home.openWorktree": {
"label": "Open Worktree",
"icon": "$(browser)",
"menus": {
"webview/context": [
{
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openWorktree\\b)/",
"group": "40_gitlens_action@1"
}
]
}
},
"gitlens.home.openWorktreeInNewWindow": {
"label": "Open Worktree in New Window",
"icon": "$(empty-window)",
"menus": {
"webview/context": [
{
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openWorktreeInNewWindow\\b)/",
"group": "40_gitlens_action@1"
}
]
}
},
"gitlens.home.fetch": {
"label": "Fetch",
"icon": "$(gl-repo-fetch)",
"menus": {
"webview/context": [
{
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.fetch\\b)/",
"group": "60_gitlens_action@1"
}
]
}
},
"gitlens.home.switchToBranch": {
"label": "Switch to Branch...",
"icon": "$(gl-switch)",
"menus": {
"webview/context": [
{
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.switchToBranch\\b)/",
"group": "50_gitlens_action@1"
}
]
}
},
"gitlens.home.pull": {
"label": "Pull",
"icon": "$(gl-repo-pull)",
"menus": {
"webview/context": [
{
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.pull\\b)/",
"group": "60_gitlens_action@1"
}
]
}
},
"gitlens.home.openInGraph": {
"label": "Open in Commit Graph",
"icon": "$(gl-graph)",
"menus": {
"webview/context": [
{
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openInGraph\\b)/",
"group": "80_gitlens_action@1"
}
]
}
},
"gitlens.inviteToLiveShare": {
"label": "Invite to Live Share",
"icon": "$(live-share)",
Expand Down
126 changes: 126 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6830,6 +6830,51 @@
"icon": "$(discard)",
"enablement": "!operationInProgress"
},
{
"command": "gitlens.home.openPullRequestChanges",
"title": "Open Pull Request Changes",
"icon": "$(request-changes)"
},
{
"command": "gitlens.home.openPullRequestOnRemote",
"title": "Open Pull Request on Remote",
"icon": "$(globe)"
},
{
"command": "gitlens.home.createPullRequest",
"title": "Create Pull Request...",
"icon": "$(git-pull-request-create)"
},
{
"command": "gitlens.home.openWorktree",
"title": "Open Worktree",
"icon": "$(browser)"
},
{
"command": "gitlens.home.openWorktreeInNewWindow",
"title": "Open Worktree in New Window",
"icon": "$(empty-window)"
},
{
"command": "gitlens.home.fetch",
"title": "Fetch",
"icon": "$(gl-repo-fetch)"
},
{
"command": "gitlens.home.switchToBranch",
"title": "Switch to Branch...",
"icon": "$(gl-switch)"
},
{
"command": "gitlens.home.pull",
"title": "Pull",
"icon": "$(gl-repo-pull)"
},
{
"command": "gitlens.home.openInGraph",
"title": "Open in Commit Graph",
"icon": "$(gl-graph)"
},
{
"command": "gitlens.inviteToLiveShare",
"title": "Invite to Live Share",
Expand Down Expand Up @@ -10679,6 +10724,42 @@
"command": "gitlens.graph.undoCommit",
"when": "false"
},
{
"command": "gitlens.home.createPullRequest",
"when": "false"
},
{
"command": "gitlens.home.fetch",
"when": "false"
},
{
"command": "gitlens.home.openInGraph",
"when": "false"
},
{
"command": "gitlens.home.openPullRequestChanges",
"when": "false"
},
{
"command": "gitlens.home.openPullRequestOnRemote",
"when": "false"
},
{
"command": "gitlens.home.openWorktree",
"when": "false"
},
{
"command": "gitlens.home.openWorktreeInNewWindow",
"when": "false"
},
{
"command": "gitlens.home.pull",
"when": "false"
},
{
"command": "gitlens.home.switchToBranch",
"when": "false"
},
{
"command": "gitlens.inviteToLiveShare",
"when": "false"
Expand Down Expand Up @@ -18354,6 +18435,51 @@
"when": "webviewItem =~ /gitlens:graph:(columns|settings)\\b/",
"group": "3_columns@2"
},
{
"command": "gitlens.home.openPullRequestChanges",
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openPullRequestChanges\\b)/",
"group": "10_gitlens_action@1"
},
{
"command": "gitlens.home.openPullRequestOnRemote",
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openPullRequestOnRemote\\b)/",
"group": "20_gitlens_action@1"
},
{
"command": "gitlens.home.createPullRequest",
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.createPullRequest\\b)/",
"group": "30_gitlens_action@1"
},
{
"command": "gitlens.home.openWorktree",
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openWorktree\\b)/",
"group": "40_gitlens_action@1"
},
{
"command": "gitlens.home.openWorktreeInNewWindow",
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openWorktreeInNewWindow\\b)/",
"group": "40_gitlens_action@1"
},
{
"command": "gitlens.home.switchToBranch",
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.switchToBranch\\b)/",
"group": "50_gitlens_action@1"
},
{
"command": "gitlens.home.fetch",
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.fetch\\b)/",
"group": "60_gitlens_action@1"
},
{
"command": "gitlens.home.pull",
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.pull\\b)/",
"group": "60_gitlens_action@1"
},
{
"command": "gitlens.home.openInGraph",
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openInGraph\\b)/",
"group": "80_gitlens_action@1"
},
{
"command": "gitlens.graph.openPullRequestChanges",
"when": "webviewItem =~ /gitlens:pullrequest\\b(?=.*?\\b\\+refs\\b)/ && config.multiDiffEditor.experimental.enabled",
Expand Down
2 changes: 2 additions & 0 deletions src/constants.commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,10 @@ type HomeWebviewCommands = `home.${
| 'openPullRequestOnRemote'
| 'createPullRequest'
| 'openWorktree'
| 'openWorktreeInNewWindow'
| 'switchToBranch'
| 'fetch'
| 'pull'
| 'openInGraph'
| 'createBranch'
| 'startWork'}`;
Expand Down
2 changes: 1 addition & 1 deletion src/webviews/apps/home/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<body
class="preload"
data-placement="#{placement}"
data-vscode-context='{ "webview": "#{webviewId}", "webviewInstance": "#{webviewInstanceId}" }'
data-vscode-context='{ "preventDefaultContextMenuItems": true, "webview": "#{webviewId}", "webviewInstance": "#{webviewInstanceId}" }'
>
<gl-home-app name="HomeView" placement="#{placement}" state="#{state}"></gl-home-app>
</body>
Expand Down
71 changes: 49 additions & 22 deletions src/webviews/apps/plus/home/components/active-work.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { when } from 'lit/directives/when.js';
import type { GitTrackingState } from '../../../../../git/models/branch';
import { createCommandLink } from '../../../../../system/commands';
import { createWebviewCommandLink } from '../../../../../system/webview';
import type { GetOverviewBranch, OpenInGraphParams, State } from '../../../../home/protocol';
import type { BranchRef, GetOverviewBranch, OpenInGraphParams, State } from '../../../../home/protocol';
import { stateContext } from '../../../home/context';
import type { ActionList } from '../../../shared/components/actions/action-list';
import { ipcContext } from '../../../shared/context';
import type { HostIpc } from '../../../shared/ipc';
import { linkStyles } from '../../shared/components/vscode.css';
Expand Down Expand Up @@ -229,42 +230,68 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
</div>
`;
}
private prevAttr = JSON.parse(document.body.getAttribute('data-vscode-context') ?? '{}');
private applyContext(context: object) {
const prevContext = JSON.parse(document.body.getAttribute('data-vscode-context') ?? '{}');
document.body.setAttribute(
'data-vscode-context',
JSON.stringify({
...prevContext,
...context,
}),
);
setTimeout(() => {
document.body.setAttribute('data-vscode-context', JSON.stringify(prevContext));
});
}

private handleBranchContext(branchRefs: BranchRef, e: typeof ActionList.OpenContextMenuEvent) {
let context = 'gitlens:home';
e.detail.items.forEach(x => {
if (x.href) {
context += `+${x.href}`;
}
});
// clear context immediatelly after the contextmenu is opened to avoid randomly clicked contextmenu being filled
this.applyContext({ webviewItem: context, ...branchRefs, type: 'branch' });
}

private renderActions(branch: GetOverviewBranch, repo: string) {
const branchRefs = {
repoPath: repo,
branchId: branch.id,
};
const actions = [];
const actions: (typeof ActionList.ItemProps)[] = [];
if (branch.pr) {
actions.push(
html`<action-item
label="Open Pull Request Changes"
icon="request-changes"
href=${createCommandLink('gitlens.home.openPullRequestChanges', branchRefs)}
></action-item>`,
);
actions.push(
html`<action-item
label="Open Pull Request on Remote"
icon="globe"
href=${createCommandLink('gitlens.home.openPullRequestOnRemote', branchRefs)}
></action-item>`,
{
label: 'Open Pull Request Changes',
icon: 'request-changes',
href: createCommandLink('gitlens.home.openPullRequestChanges', branchRefs),
},
{
label: 'Open Pull Request on Remote',
icon: 'globe',
href: createCommandLink('gitlens.home.openPullRequestOnRemote', branchRefs),
},
);
} else if (branch.upstream?.missing === false) {
actions.push(
html`<action-item
label="Create Pull Request..."
icon="git-pull-request-create"
href=${createCommandLink('gitlens.home.createPullRequest', branchRefs)}
></action-item>`,
);
actions.push({
label: 'Create Pull Request...',
icon: 'git-pull-request-create',
href: createCommandLink('gitlens.home.createPullRequest', branchRefs),
});
}

if (!actions.length) {
return nothing;
}
return html`<action-nav class="branch-item__actions">${actions}</action-nav>`;
return html`<action-list
@open-actions-menu=${this.handleBranchContext.bind(this, branchRefs)}
limit=${3}
.items=${actions}
class="branch-item__actions"
></action-list>`;
}

private renderBranchStateActions(
Expand Down
Loading

0 comments on commit 9bb9c4a

Please sign in to comment.