Skip to content

Commit 714c5ee

Browse files
Adds a new control for graph branches visibility (#3929)
* Adds a new control for graph branches visibility * Improves labeling and icon --------- Co-authored-by: Ramin Tadayon <[email protected]>
1 parent 3f4736f commit 714c5ee

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-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_ &mdash; closes [#3788](https://github.com/gitkraken/vscode-gitlens/issues/3788)
1212
- Adds go to home view button to the commit graph title section &mdash; 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 Hidden Branches dropdown next to the Branch Visibility dropdown in the graph toolbar &mdash; closes [#3101](https://github.com/gitkraken/vscode-gitlens/issues/3101)
1415

1516
### Changed
1617

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

Lines changed: 85 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('hiddenRefs')?.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

@@ -1347,6 +1378,60 @@ export function GraphWrapper({
13471378
<SlOption value="current">Current Branch</SlOption>
13481379
</SlSelect>
13491380
</GlTooltip>
1381+
<div className={`shrink ${!Object.values(excludeRefsById ?? {}).length && 'hidden'}`}>
1382+
<GlPopover
1383+
className="popover"
1384+
placement="bottom-start"
1385+
trigger="click focus"
1386+
arrow={false}
1387+
distance={0}
1388+
>
1389+
<GlTooltip placement="top" slot="anchor">
1390+
<button type="button" id="hiddenRefs" className="action-button">
1391+
<CodeIcon icon={`eye-closed`} />
1392+
{Object.values(excludeRefsById ?? {}).length}
1393+
<CodeIcon
1394+
className="action-button__more"
1395+
icon="chevron-down"
1396+
aria-hidden="true"
1397+
/>
1398+
</button>
1399+
<span slot="content">Hidden Branches / Tags</span>
1400+
</GlTooltip>
1401+
<div slot="content">
1402+
<MenuLabel>Hidden Branches / Tags</MenuLabel>
1403+
{excludeRefsById &&
1404+
Object.keys(excludeRefsById).length &&
1405+
[...Object.values(excludeRefsById), null].map(ref =>
1406+
ref ? (
1407+
<MenuItem
1408+
// key prop is skipped intentionally. It allows me to not hide the dropdown after click (I don't know why)
1409+
onClick={event => {
1410+
handleOnToggleRefsVisibilityClick(event, [ref], true);
1411+
}}
1412+
className="flex-gap"
1413+
>
1414+
<CodeIcon icon={getRemoteIcon(ref.type)}></CodeIcon>
1415+
<span>{ref.name}</span>
1416+
</MenuItem>
1417+
) : (
1418+
// One more weird case. If I render it outside the listed items, the dropdown is hidden after click on the last item
1419+
<MenuItem
1420+
onClick={event => {
1421+
handleOnToggleRefsVisibilityClick(
1422+
event,
1423+
Object.values(excludeRefsById ?? {}),
1424+
true,
1425+
);
1426+
}}
1427+
>
1428+
Show All
1429+
</MenuItem>
1430+
),
1431+
)}
1432+
</div>
1433+
</GlPopover>
1434+
</div>
13501435
<GlPopover
13511436
className="popover"
13521437
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)