|
1 | 1 | import type { GraphRefOptData } from '@gitkraken/gitkraken-components'; |
| 2 | +import { refTypes } from '@gitkraken/gitkraken-components'; |
2 | 3 | import { consume } from '@lit/context'; |
3 | 4 | import { SignalWatcher } from '@lit-labs/signals'; |
4 | 5 | import { html, LitElement, nothing } from 'lit'; |
@@ -137,6 +138,10 @@ export class GlGraphHeader extends SignalWatcher(LitElement) { |
137 | 138 | return Object.values(this.hostState.excludeTypes).includes(true); |
138 | 139 | } |
139 | 140 |
|
| 141 | + get excludeRefs() { |
| 142 | + return Object.values(this.hostState.excludeRefs ?? {}).sort(compareGraphRefOpts); |
| 143 | + } |
| 144 | + |
140 | 145 | private async onJumpToRefPromise(alt: boolean): Promise<{ name: string; sha: string } | undefined> { |
141 | 146 | try { |
142 | 147 | // Assuming we have a command to get the ref details |
@@ -902,35 +907,40 @@ export class GlGraphHeader extends SignalWatcher(LitElement) { |
902 | 907 | </gl-tooltip> |
903 | 908 | <div slot="content"> |
904 | 909 | <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 |
922 | 932 | @click=${(event: CustomEvent) => { |
923 | 933 | this.handleOnToggleRefsVisibilityClick( |
924 | 934 | event, |
925 | | - Object.values(excludeRefs ?? {}), |
| 935 | + this.excludeRefs, |
926 | 936 | true, |
927 | 937 | ); |
928 | 938 | }} |
929 | 939 | > |
930 | 940 | Show All |
931 | | - </menu-item>`; |
932 | | - }); |
933 | | - })} |
| 941 | + </menu-item> |
| 942 | + `, |
| 943 | + )} |
934 | 944 | </div> |
935 | 945 | </gl-popover> |
936 | 946 | </div> |
@@ -1160,4 +1170,23 @@ export class GlGraphHeader extends SignalWatcher(LitElement) { |
1160 | 1170 | </div> |
1161 | 1171 | </header>`; |
1162 | 1172 | } |
| 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; |
1163 | 1192 | } |
0 commit comments