Skip to content

Commit c6a5767

Browse files
committed
Adds avatarUrl handling to the hidden refs popover
1 parent f884fc6 commit c6a5767

File tree

3 files changed

+74
-40
lines changed

3 files changed

+74
-40
lines changed

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

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,8 @@ import { GlGraphHover } from './hover/graphHover.react';
9999
import type { GraphMinimapDaySelectedEventDetail } from './minimap/minimap';
100100
import { GlGraphMinimapContainer } from './minimap/minimap-container.react';
101101
import { GlGraphSideBar } from './sidebar/sidebar.react';
102-
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-
}
102+
import { compareGraphRefOpts } from './utils/compareGraphRefOpts';
103+
import { RemoteIcon } from './utils/RemoteIcon';
115104

116105
export interface GraphWrapperProps {
117106
nonce?: string;
@@ -1402,33 +1391,39 @@ export function GraphWrapper({
14021391
<MenuLabel>Hidden Branches / Tags</MenuLabel>
14031392
{excludeRefsById &&
14041393
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-
)}
1394+
(
1395+
Object.values(excludeRefsById)
1396+
.slice()
1397+
.sort(compareGraphRefOpts) as Array<GraphRefOptData | null>
1398+
)
1399+
.concat(null)
1400+
.map(ref =>
1401+
ref ? (
1402+
<MenuItem
1403+
// key prop is skipped intentionally. It allows me to not hide the dropdown after click (I don't know why)
1404+
onClick={event => {
1405+
handleOnToggleRefsVisibilityClick(event, [ref], true);
1406+
}}
1407+
className="flex-gap"
1408+
>
1409+
<RemoteIcon refOptData={ref} />
1410+
<span>{ref.name}</span>
1411+
</MenuItem>
1412+
) : (
1413+
// One more weird case. If I render it outside the listed items, the dropdown is hidden after click on the last item
1414+
<MenuItem
1415+
onClick={event => {
1416+
handleOnToggleRefsVisibilityClick(
1417+
event,
1418+
Object.values(excludeRefsById ?? {}),
1419+
true,
1420+
);
1421+
}}
1422+
>
1423+
Show All
1424+
</MenuItem>
1425+
),
1426+
)}
14321427
</div>
14331428
</GlPopover>
14341429
</div>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { GraphRefOptData } from '@gitkraken/gitkraken-components';
2+
import React from 'react';
3+
import { CodeIcon } from '../../../shared/components/code-icon.react';
4+
5+
// eslint-disable-next-line @typescript-eslint/naming-convention
6+
export function RemoteIcon({ refOptData }: Readonly<{ refOptData: GraphRefOptData }>) {
7+
console.log({ ref: refOptData });
8+
if (refOptData.avatarUrl) {
9+
return <img alt={refOptData.name} style={{ width: 14, aspectRatio: 1 }} src={refOptData.avatarUrl} />;
10+
}
11+
let icon = '';
12+
switch (refOptData.type) {
13+
case 'head':
14+
icon = 'vm';
15+
break;
16+
case 'remote':
17+
icon = 'cloud';
18+
break;
19+
case 'tag':
20+
icon = 'tag';
21+
break;
22+
default:
23+
break;
24+
}
25+
return <CodeIcon size={14} icon={icon} />;
26+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { GraphRefOptData } from '@gitkraken/gitkraken-components';
2+
import { refTypes } from '@gitkraken/gitkraken-components';
3+
4+
export function compareGraphRefOpts(a: GraphRefOptData, b: GraphRefOptData): number {
5+
const comparationResult = a.name.localeCompare(b.name);
6+
if (comparationResult === 0) {
7+
// If names are equals
8+
if (a.type === refTypes.REMOTE) {
9+
return -1;
10+
}
11+
}
12+
return comparationResult;
13+
}

0 commit comments

Comments
 (0)