Skip to content

Commit 8d456cd

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

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

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

Lines changed: 82 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

@@ -1347,6 +1378,57 @@ 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="test" className="action-button">
1391+
<CodeIcon icon={`eye`} />
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</span>
1400+
</GlTooltip>
1401+
<div slot="content">
1402+
<MenuLabel>Hidden branches</MenuLabel>
1403+
{Object.values(excludeRefsById ?? {}).map(ref => (
1404+
<MenuItem
1405+
// key prop is skipped intentionally. It allows me to not hide the dropdown after click (I don't know why)
1406+
onClick={event => {
1407+
handleOnToggleRefsVisibilityClick(event, [ref], true);
1408+
}}
1409+
className="flex-gap"
1410+
>
1411+
<CodeIcon icon={getRemoteIcon(ref.type)}></CodeIcon>
1412+
<span>{ref.name}</span>
1413+
</MenuItem>
1414+
))}
1415+
{/* One more weird case. If I render it unconditionally, the dropdown is not hidden after click */}
1416+
{Boolean(Object.values(excludeRefsById ?? {}).length) && (
1417+
<MenuItem
1418+
onClick={event => {
1419+
handleOnToggleRefsVisibilityClick(
1420+
event,
1421+
Object.values(excludeRefsById ?? {}),
1422+
true,
1423+
);
1424+
}}
1425+
>
1426+
Show all
1427+
</MenuItem>
1428+
)}
1429+
</div>
1430+
</GlPopover>
1431+
</div>
13501432
<GlPopover
13511433
className="popover"
13521434
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)