Skip to content

Commit a378b88

Browse files
committed
Adds GitHub Enterprize menu item and filter out its icon in the bar
(#3901)
1 parent d455109 commit a378b88

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

Diff for: src/constants.integrations.ts

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ export const supportedCloudIntegrationDescriptors: IntegrationDescriptor[] = [
4747
icon: 'gl-provider-github',
4848
supports: ['prs', 'issues'],
4949
},
50+
{
51+
id: SelfHostedIntegrationId.GitHubEnterprise,
52+
name: 'GitHub Enterprise',
53+
icon: 'gl-provider-github',
54+
supports: ['prs', 'issues'],
55+
},
5056
{
5157
id: HostingIntegrationId.GitLab,
5258
name: 'GitLab',

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+
}

0 commit comments

Comments
 (0)