Skip to content

Commit 9ecdc09

Browse files
committed
Filters out GitHub's icon in the bar
(#3901)
1 parent 2256ffc commit 9ecdc09

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

Diff for: 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+
}

Diff for: src/webviews/home/homeWebview.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -842,8 +842,13 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
842842
const i = integrations.find(i => i.id === d.id);
843843
if (i == null) {
844844
integrations.push(d);
845-
} else if (d.weight !== undefined) {
846-
i.weight = d.weight;
845+
} else {
846+
if (d.weight !== undefined) {
847+
i.weight = d.weight;
848+
}
849+
if (i.icon !== d.icon) {
850+
i.icon = d.icon;
851+
}
847852
}
848853
});
849854
integrations.sort((a, b) => {

0 commit comments

Comments
 (0)