Skip to content

Commit 3590fb1

Browse files
committed
Adds avatar in hidden refs popover
1 parent 51a20db commit 3590fb1

File tree

2 files changed

+57
-22
lines changed

2 files changed

+57
-22
lines changed

src/webviews/apps/plus/graph/graph-header.ts

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { GraphRefOptData } from '@gitkraken/gitkraken-components';
2+
import { refTypes } from '@gitkraken/gitkraken-components';
23
import { consume } from '@lit/context';
34
import { SignalWatcher } from '@lit-labs/signals';
45
import { html, LitElement, nothing } from 'lit';
@@ -137,6 +138,10 @@ export class GlGraphHeader extends SignalWatcher(LitElement) {
137138
return Object.values(this.hostState.excludeTypes).includes(true);
138139
}
139140

141+
get excludeRefs() {
142+
return Object.values(this.hostState.excludeRefs ?? {}).sort(compareGraphRefOpts);
143+
}
144+
140145
private async onJumpToRefPromise(alt: boolean): Promise<{ name: string; sha: string } | undefined> {
141146
try {
142147
// Assuming we have a command to get the ref details
@@ -902,35 +907,40 @@ export class GlGraphHeader extends SignalWatcher(LitElement) {
902907
</gl-tooltip>
903908
<div slot="content">
904909
<menu-label>Hidden Branches / Tags</menu-label>
905-
${when(this.hostState.excludeRefs, excludeRefs => {
906-
if (!Object.keys(excludeRefs).length) {
907-
return nothing;
908-
}
909-
return repeat([...Object.values(excludeRefs), null], ref => {
910-
if (ref) {
911-
return html` <menu-item
912-
@click=${(event: CustomEvent) => {
913-
this.handleOnToggleRefsVisibilityClick(event, [ref], true);
914-
}}
915-
class="flex-gap"
916-
>
917-
<code-icon icon=${getRemoteIcon(ref.type)}></code-icon>
918-
<span>${ref.name}</span>
919-
</menu-item>`;
920-
}
921-
return html` <menu-item
910+
${when(
911+
this.excludeRefs.length > 0,
912+
() => html`
913+
${repeat(
914+
this.excludeRefs,
915+
ref => html`
916+
<menu-item
917+
@click=${(event: CustomEvent) => {
918+
this.handleOnToggleRefsVisibilityClick(
919+
event,
920+
[ref],
921+
true,
922+
);
923+
}}
924+
class="flex-gap"
925+
>
926+
${this.renderRemoteAvatarOrIcon(ref)}
927+
<span>${ref.name}</span>
928+
</menu-item>
929+
`,
930+
)}
931+
<menu-item
922932
@click=${(event: CustomEvent) => {
923933
this.handleOnToggleRefsVisibilityClick(
924934
event,
925-
Object.values(excludeRefs ?? {}),
935+
this.excludeRefs,
926936
true,
927937
);
928938
}}
929939
>
930940
Show All
931-
</menu-item>`;
932-
});
933-
})}
941+
</menu-item>
942+
`,
943+
)}
934944
</div>
935945
</gl-popover>
936946
</div>
@@ -1160,4 +1170,23 @@ export class GlGraphHeader extends SignalWatcher(LitElement) {
11601170
</div>
11611171
</header>`;
11621172
}
1173+
1174+
private renderRemoteAvatarOrIcon(refOptData: GraphRefOptData) {
1175+
if (refOptData.avatarUrl) {
1176+
return html`<img class="branch-menu__avatar" alt=${refOptData.name} src=${refOptData.avatarUrl} />`;
1177+
}
1178+
return html`<code-icon class="branch-menu__icon" icon=${getRemoteIcon(refOptData.type)}></code-icon>`;
1179+
}
1180+
}
1181+
1182+
// TODO: this should be exported by the graph library
1183+
export function compareGraphRefOpts(a: GraphRefOptData, b: GraphRefOptData): number {
1184+
const comparationResult = a.name.localeCompare(b.name);
1185+
if (comparationResult === 0) {
1186+
// If names are equals
1187+
if (a.type === refTypes.REMOTE) {
1188+
return -1;
1189+
}
1190+
}
1191+
return comparationResult;
11631192
}

src/webviews/apps/plus/graph/styles/header.css.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,18 @@ export const graphHeaderControlStyles = css`
138138
margin-left: -0.5rem;
139139
}
140140
141-
.flex-gap {
141+
.branch-menu {
142142
display: flex;
143143
gap: 0.5em;
144144
align-items: center;
145145
}
146146
147+
.branch-menu__avatar {
148+
width: 1.4rem;
149+
aspect-ratio: 1;
150+
vertical-align: text-bottom;
151+
}
152+
147153
.action-divider {
148154
display: inline-block;
149155
width: 0.1rem;

0 commit comments

Comments
 (0)