Skip to content

Commit 48d99db

Browse files
committed
Adds avatarUrl handling to the hidden refs popover
1 parent 06f8cf2 commit 48d99db

File tree

3 files changed

+73
-40
lines changed

3 files changed

+73
-40
lines changed

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

+35-40
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,10 @@ import { GitActionsButtons } from './actions/gitActionsButtons';
9898
import { GlGraphHover } from './hover/graphHover.react';
9999
import type { GraphMinimapDaySelectedEventDetail } from './minimap/minimap';
100100
import { GlGraphMinimapContainer } from './minimap/minimap-container.react';
101+
import { compareGraphRefOpts } from './refHelpers/compareGraphRefOpts';
102+
import { RemoteIcon } from './refHelpers/RemoteIcon';
101103
import { GlGraphSideBar } from './sidebar/sidebar.react';
102104

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-
116105
export interface GraphWrapperProps {
117106
nonce?: string;
118107
state: State;
@@ -1406,33 +1395,39 @@ export function GraphWrapper({
14061395
<MenuLabel>Hidden Branches / Tags</MenuLabel>
14071396
{excludeRefsById &&
14081397
Object.keys(excludeRefsById).length &&
1409-
[...Object.values(excludeRefsById), null].map(ref =>
1410-
ref ? (
1411-
<MenuItem
1412-
// key prop is skipped intentionally. It allows me to not hide the dropdown after click (I don't know why)
1413-
onClick={event => {
1414-
handleOnToggleRefsVisibilityClick(event, [ref], true);
1415-
}}
1416-
className="flex-gap"
1417-
>
1418-
<CodeIcon icon={getRemoteIcon(ref.type)}></CodeIcon>
1419-
<span>{ref.name}</span>
1420-
</MenuItem>
1421-
) : (
1422-
// One more weird case. If I render it outside the listed items, the dropdown is hidden after click on the last item
1423-
<MenuItem
1424-
onClick={event => {
1425-
handleOnToggleRefsVisibilityClick(
1426-
event,
1427-
Object.values(excludeRefsById ?? {}),
1428-
true,
1429-
);
1430-
}}
1431-
>
1432-
Show All
1433-
</MenuItem>
1434-
),
1435-
)}
1398+
(
1399+
Object.values(excludeRefsById)
1400+
.slice()
1401+
.sort(compareGraphRefOpts) as Array<GraphRefOptData | null>
1402+
)
1403+
.concat(null)
1404+
.map(ref =>
1405+
ref ? (
1406+
<MenuItem
1407+
// key prop is skipped intentionally. It allows me to not hide the dropdown after click (I don't know why)
1408+
onClick={event => {
1409+
handleOnToggleRefsVisibilityClick(event, [ref], true);
1410+
}}
1411+
className="flex-gap"
1412+
>
1413+
<RemoteIcon refOptData={ref} />
1414+
<span>{ref.name}</span>
1415+
</MenuItem>
1416+
) : (
1417+
// One more weird case. If I render it outside the listed items, the dropdown is hidden after click on the last item
1418+
<MenuItem
1419+
onClick={event => {
1420+
handleOnToggleRefsVisibilityClick(
1421+
event,
1422+
Object.values(excludeRefsById ?? {}),
1423+
true,
1424+
);
1425+
}}
1426+
>
1427+
Show All
1428+
</MenuItem>
1429+
),
1430+
)}
14361431
</div>
14371432
</GlPopover>
14381433
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
if (refOptData.avatarUrl) {
8+
return <img alt={refOptData.name} style={{ width: 14, aspectRatio: 1 }} src={refOptData.avatarUrl} />;
9+
}
10+
let icon = '';
11+
switch (refOptData.type) {
12+
case 'head':
13+
icon = 'vm';
14+
break;
15+
case 'remote':
16+
icon = 'cloud';
17+
break;
18+
case 'tag':
19+
icon = 'tag';
20+
break;
21+
default:
22+
break;
23+
}
24+
return <CodeIcon size={14} icon={icon} />;
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { GraphRefOptData } from '@gitkraken/gitkraken-components';
2+
3+
// copied from GitkrakenComponents to keep refs order the same as in the graph
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 === 'remote') {
9+
return -1;
10+
}
11+
}
12+
return comparationResult;
13+
}

0 commit comments

Comments
 (0)