Skip to content

Commit 0549b9f

Browse files
committed
Adds a new control for graph branches visibility
1 parent 9bbeecb commit 0549b9f

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1111
- Adds new ability to search for a GitLab MR in the _Launchpad_ — closes [#3788](https://github.com/gitkraken/vscode-gitlens/issues/3788)
1212
- Adds go to home view button to the commit graph title section — closes [#3873](https://github.com/gitkraken/vscode-gitlens/issues/3873)
1313
- Adds a _Contributors_ section to comparison results in the views
14+
- Adds a new control for graph branches visibility — closes [#3101](https://github.com/gitkraken/vscode-gitlens/issues/3101)
1415

1516
### Changed
1617

src/webviews/apps/plus/graph/GraphWrapper.tsx

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@ import type { GraphMinimapDaySelectedEventDetail } from './minimap/minimap';
100100
import { GlGraphMinimapContainer } from './minimap/minimap-container.react';
101101
import { GlGraphSideBar } from './sidebar/sidebar.react';
102102

103+
function getRemoteIcon(type: string | number) {
104+
switch (type) {
105+
case 'head':
106+
return 'vm';
107+
case 'remote':
108+
return 'cloud';
109+
case 'tag':
110+
return 'tag';
111+
default:
112+
return '';
113+
}
114+
}
115+
103116
export interface GraphWrapperProps {
104117
nonce?: string;
105118
state: State;
@@ -873,7 +886,25 @@ export function GraphWrapper({
873886
onChangeColumns?.(graphColumnsConfig);
874887
};
875888

889+
// dirty trick to avoid mutations on the GraphContainer side
890+
const fixedExcludeRefsById = useMemo(() => ({ ...excludeRefsById }), [excludeRefsById]);
876891
const handleOnToggleRefsVisibilityClick = (_event: any, refs: GraphRefOptData[], visible: boolean) => {
892+
if (!visible) {
893+
document.getElementById('test')?.animate(
894+
[
895+
{ offset: 0, background: 'transparent' },
896+
{
897+
offset: 0.4,
898+
background: 'var(--vscode-statusBarItem-warningBackground)',
899+
},
900+
{ offset: 1, background: 'transparent' },
901+
],
902+
{
903+
duration: 1000,
904+
iterations: !Object.keys(fixedExcludeRefsById ?? {}).length ? 2 : 1,
905+
},
906+
);
907+
}
877908
onChangeRefsVisibility?.(refs, visible);
878909
};
879910

@@ -1029,6 +1060,8 @@ export function GraphWrapper({
10291060
onChangeSelection?.(rows);
10301061
};
10311062

1063+
const hasExcludedRefs = excludeRefsById && Object.keys(excludeRefsById).length;
1064+
10321065
return (
10331066
<>
10341067
<header className="titlebar graph-app__header">
@@ -1347,6 +1380,59 @@ export function GraphWrapper({
13471380
<SlOption value="current">Current Branch</SlOption>
13481381
</SlSelect>
13491382
</GlTooltip>
1383+
<div className={`shrink ${!Object.values(excludeRefsById ?? {}).length && 'hidden'}`}>
1384+
<GlPopover
1385+
className="popover"
1386+
placement="bottom-start"
1387+
trigger="click focus"
1388+
arrow={false}
1389+
distance={0}
1390+
>
1391+
<GlTooltip placement="top" slot="anchor">
1392+
<button type="button" id="test" className="action-button">
1393+
<CodeIcon icon={`eye`} />
1394+
{Object.values(excludeRefsById ?? {}).length}
1395+
<CodeIcon
1396+
className="action-button__more"
1397+
icon="chevron-down"
1398+
aria-hidden="true"
1399+
/>
1400+
</button>
1401+
<span slot="content">Hidden branches</span>
1402+
</GlTooltip>
1403+
<div slot="content">
1404+
<MenuLabel>Hidden branches</MenuLabel>
1405+
{hasExcludedRefs &&
1406+
[...Object.values(excludeRefsById), null].map(ref =>
1407+
ref ? (
1408+
<MenuItem
1409+
// key prop is skipped intentionally. It allows me to not hide the dropdown after click (I don't know why)
1410+
onClick={event => {
1411+
handleOnToggleRefsVisibilityClick(event, [ref], true);
1412+
}}
1413+
className="flex-gap"
1414+
>
1415+
<CodeIcon icon={getRemoteIcon(ref.type)}></CodeIcon>
1416+
<span>{ref.name}</span>
1417+
</MenuItem>
1418+
) : (
1419+
// One more weird case. If I render it outside the listed items, the dropdown is hidden after click on the last item
1420+
<MenuItem
1421+
onClick={event => {
1422+
handleOnToggleRefsVisibilityClick(
1423+
event,
1424+
Object.values(excludeRefsById ?? {}),
1425+
true,
1426+
);
1427+
}}
1428+
>
1429+
Show all
1430+
</MenuItem>
1431+
),
1432+
)}
1433+
</div>
1434+
</GlPopover>
1435+
</div>
13501436
<GlPopover
13511437
className="popover"
13521438
placement="bottom-start"

src/webviews/apps/plus/graph/graph.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,20 @@ button:not([disabled]),
250250
--button-foreground: var(--color-foreground);
251251
}
252252

253+
.shrink {
254+
max-width: fit-content;
255+
transition: all .2s;
256+
257+
&.hidden {
258+
max-width: 0;
259+
overflow: hidden;
260+
.titlebar__group &:not(:first-child) {
261+
// compensate the parent gap
262+
margin-left: -0.5rem;
263+
}
264+
}
265+
}
266+
253267
.action-button {
254268
position: relative;
255269
appearance: none;
@@ -475,6 +489,12 @@ button:not([disabled]),
475489
z-index: 1040;
476490
}
477491

492+
.flex-gap {
493+
display: flex;
494+
gap: 0.5em;
495+
align-items: center;
496+
}
497+
478498
.alert {
479499
--alert-foreground: var(--color-alert-foreground);
480500
--alert-background: var(--color-alert-infoBackground);

0 commit comments

Comments
 (0)