Skip to content

Commit

Permalink
Filters out GitHub's icon in the bar
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeibbb committed Jan 13, 2025
1 parent e34a903 commit 4a285c0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
34 changes: 31 additions & 3 deletions src/webviews/apps/plus/shared/components/integrations-chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,12 @@ export class GLIntegrationsChip extends LitElement {

override render() {
const anyConnected = this.hasConnectedIntegrations;
const statusFilter = createIconBasedStatusFilter(this.integrations);
return html`<gl-popover placement="bottom" trigger="hover click focus" hoist>
<span slot="anchor" class="chip" tabindex="0"
>${!anyConnected ? html`<span class="chip__label">Connect</span>` : ''}${this.integrations.map(i =>
this.renderIntegrationStatus(i, anyConnected),
)}</span
>${!anyConnected ? html`<span class="chip__label">Connect</span>` : ''}${this.integrations
.filter(statusFilter)
.map(i => this.renderIntegrationStatus(i, anyConnected))}</span
>
<div slot="content" class="content">
<div class="header">
Expand Down Expand Up @@ -267,3 +268,30 @@ function getIntegrationDetails(integration: IntegrationState): string {
const last = features.pop();
return `Supports ${features.join(', ')} and ${last}`;
}

function createIconBasedStatusFilter(integrations: IntegrationState[]) {
const nothing = -1;
const icons = integrations.reduce<{
[key: string]: undefined | { connectedIndex: number; firstIndex: number };
}>((icons, i, index) => {
const state = icons[i.icon];
if (!state) {
icons[i.icon] = { connectedIndex: i.connected ? index : nothing, firstIndex: index };
} else if (i.connected && state.connectedIndex === nothing) {
state.connectedIndex = index;
}
return icons;
}, {});

// This filter returns true or false to allow or decline the integration.
// If nothing is connected with the same icon then allows the first one.
// If any connected then allows the first connected.
return function filter(i: IntegrationState, index: number) {
const state = icons[i.icon];
if (state === undefined) return true;
if (state.connectedIndex !== nothing) {
return state.connectedIndex === index;
}
return state.firstIndex === index;
};
}
9 changes: 7 additions & 2 deletions src/webviews/home/homeWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,13 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
const i = integrations.find(i => i.id === d.id);
if (i == null) {
integrations.push(d);
} else if (d.weight !== undefined) {
i.weight = d.weight;
} else {
if (d.weight !== undefined) {
i.weight = d.weight;
}
if (i.icon !== d.icon) {
i.icon = d.icon;
}
}
});
integrations.sort((a, b) => {
Expand Down

0 comments on commit 4a285c0

Please sign in to comment.