Skip to content

Commit b33027c

Browse files
committedJan 15, 2025
Filters out GitHub's icon in the bar
(#3901, #3922)
1 parent 714d3ed commit b33027c

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed
 

‎src/webviews/apps/plus/shared/components/integrations-chip.ts

+31-3
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,12 @@ export class GLIntegrationsChip extends LitElement {
155155

156156
override render() {
157157
const anyConnected = this.hasConnectedIntegrations;
158+
const statusFilter = createIconBasedStatusFilter(this.integrations);
158159
return html`<gl-popover placement="bottom" trigger="hover click focus" hoist>
159160
<span slot="anchor" class="chip" tabindex="0"
160-
>${!anyConnected ? html`<span class="chip__label">Connect</span>` : ''}${this.integrations.map(i =>
161-
this.renderIntegrationStatus(i, anyConnected),
162-
)}</span
161+
>${!anyConnected ? html`<span class="chip__label">Connect</span>` : ''}${this.integrations
162+
.filter(statusFilter)
163+
.map(i => this.renderIntegrationStatus(i, anyConnected))}</span
163164
>
164165
<div slot="content" class="content">
165166
<div class="header">
@@ -267,3 +268,30 @@ function getIntegrationDetails(integration: IntegrationState): string {
267268
const last = features.pop();
268269
return `Supports ${features.join(', ')} and ${last}`;
269270
}
271+
272+
function createIconBasedStatusFilter(integrations: IntegrationState[]) {
273+
const nothing = -1;
274+
const icons = integrations.reduce<{
275+
[key: string]: undefined | { connectedIndex: number; firstIndex: number };
276+
}>((icons, i, index) => {
277+
const state = icons[i.icon];
278+
if (!state) {
279+
icons[i.icon] = { connectedIndex: i.connected ? index : nothing, firstIndex: index };
280+
} else if (i.connected && state.connectedIndex === nothing) {
281+
state.connectedIndex = index;
282+
}
283+
return icons;
284+
}, {});
285+
286+
// This filter returns true or false to allow or decline the integration.
287+
// If nothing is connected with the same icon then allows the first one.
288+
// If any connected then allows the first connected.
289+
return function filter(i: IntegrationState, index: number) {
290+
const state = icons[i.icon];
291+
if (state === undefined) return true;
292+
if (state.connectedIndex !== nothing) {
293+
return state.connectedIndex === index;
294+
}
295+
return state.firstIndex === index;
296+
};
297+
}

‎src/webviews/home/homeWebview.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -879,9 +879,15 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
879879
}));
880880

881881
// union (uniquely by id) with supportedCloudIntegrationDescriptors
882-
integrations.push(
883-
...this._defaultSupportedCloudIntegrations.filter(d => !integrations.some(i => i.id === d.id)),
884-
);
882+
this._defaultSupportedCloudIntegrations.forEach(d => {
883+
const i = integrations.find(i => i.id === d.id);
884+
if (i == null) {
885+
integrations.push(d);
886+
} else if (i.icon !== d.icon) {
887+
i.icon = d.icon;
888+
}
889+
});
890+
885891
integrations.sort(
886892
(a, b) =>
887893
supportedOrderedCloudIntegrationIds.indexOf(a.id) -

0 commit comments

Comments
 (0)
Please sign in to comment.