Skip to content

Commit

Permalink
Changes order of GitHub.com and GitHub Enterprise in the dropdown list
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeibbb committed Jan 13, 2025
1 parent 72d3c2d commit e34a903
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/constants.integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,22 @@ export interface IntegrationDescriptor {
name: string;
icon: string;
supports: IntegrationFeatures[];
weight?: number;
}
export const supportedCloudIntegrationDescriptors: IntegrationDescriptor[] = [
{
id: HostingIntegrationId.GitHub,
name: 'GitHub',
icon: 'gl-provider-github',
supports: ['prs', 'issues'],
weight: 1,
},
{
id: SelfHostedIntegrationId.CloudGitHubEnterprise,
name: 'GitHub Enterprise',
icon: 'gl-provider-github',
supports: ['prs', 'issues'],
weight: 0,
},
{
id: HostingIntegrationId.GitLab,
Expand Down
25 changes: 17 additions & 8 deletions src/webviews/home/homeWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -830,22 +830,31 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
);

const integrationsResults = await Promise.allSettled(promises);
const integrations = [...filterMap(integrationsResults, r => getSettledValue(r))];
const integrations: IntegrationState[] = [...filterMap(integrationsResults, r => getSettledValue(r))];

this._defaultSupportedCloudIntegrations ??= supportedCloudIntegrationDescriptors.map(d => ({
...d,
connected: false,
}));

// union (uniquely by id) with supportedCloudIntegrationDescriptors
integrations.push(
...this._defaultSupportedCloudIntegrations.filter(d => !integrations.some(i => i.id === d.id)),
);
integrations.sort(
(a, b) =>
this._defaultSupportedCloudIntegrations.forEach(d => {
const i = integrations.find(i => i.id === d.id);
if (i == null) {
integrations.push(d);
} else if (d.weight !== undefined) {
i.weight = d.weight;
}
});
integrations.sort((a, b) => {
if (a.weight !== undefined && b.weight !== undefined) {
return -(a.weight - b.weight);
}
return (
supportedOrderedCloudIntegrationIds.indexOf(a.id) -
supportedOrderedCloudIntegrationIds.indexOf(b.id),
);
supportedOrderedCloudIntegrationIds.indexOf(b.id)
);
});

this._integrationStates = integrations;
}
Expand Down

0 comments on commit e34a903

Please sign in to comment.