@@ -155,11 +155,12 @@ export class GLIntegrationsChip extends LitElement {
155
155
156
156
override render ( ) {
157
157
const anyConnected = this . hasConnectedIntegrations ;
158
+ const statusFilter = createIconBasedStatusFilter ( this . integrations ) ;
158
159
return html `< gl-popover placement ="bottom " trigger ="hover click focus " hoist >
159
160
< 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
163
164
>
164
165
< div slot ="content " class ="content ">
165
166
< div class ="header ">
@@ -267,3 +268,30 @@ function getIntegrationDetails(integration: IntegrationState): string {
267
268
const last = features . pop ( ) ;
268
269
return `Supports ${ features . join ( ', ' ) } and ${ last } ` ;
269
270
}
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