Skip to content

Commit 82acefe

Browse files
committed
sort integrations by status
1 parent 85edd93 commit 82acefe

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

x-pack/plugins/security_solution/server/lib/detection_engine/fleet_integrations/api/get_all_integrations/route.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type { GetAllIntegrationsResponse } from '../../../../../../common/api/de
1313
import { GET_ALL_INTEGRATIONS_URL } from '../../../../../../common/api/detection_engine/fleet_integrations';
1414
import { extractIntegrations } from './extract_integrations';
1515
import { sortPackagesBySecurityCategory } from './sort_packages_by_security_category';
16+
import { sortIntegrationsByStatus } from './sort_integrations_by_status';
1617

1718
/**
1819
* Returns an array of Fleet integrations and their packages
@@ -54,6 +55,8 @@ export const getAllIntegrationsRoute = (router: SecuritySolutionPluginRouter) =>
5455
packagePolicies.items
5556
);
5657

58+
sortIntegrationsByStatus(integrations);
59+
5760
const body: GetAllIntegrationsResponse = {
5861
integrations,
5962
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import type { Integration } from '../../../../../../common/api/detection_engine/fleet_integrations/model/integrations';
9+
10+
/**
11+
* Sorts integrations in place
12+
*/
13+
export function sortIntegrationsByStatus(integration: Integration[]): void {
14+
integration.sort((a, b) => {
15+
if (a.is_enabled && !b.is_enabled) {
16+
return -1;
17+
} else if (!a.is_enabled && b.is_enabled) {
18+
return 1;
19+
}
20+
21+
if (a.is_installed && !b.is_installed) {
22+
return -1;
23+
} else if (!a.is_installed && b.is_installed) {
24+
return 1;
25+
}
26+
27+
return 0;
28+
});
29+
}

0 commit comments

Comments
 (0)