Skip to content

Commit

Permalink
sort integrations by status
Browse files Browse the repository at this point in the history
  • Loading branch information
maximpn committed May 2, 2024
1 parent 85edd93 commit 82acefe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { GetAllIntegrationsResponse } from '../../../../../../common/api/de
import { GET_ALL_INTEGRATIONS_URL } from '../../../../../../common/api/detection_engine/fleet_integrations';
import { extractIntegrations } from './extract_integrations';
import { sortPackagesBySecurityCategory } from './sort_packages_by_security_category';
import { sortIntegrationsByStatus } from './sort_integrations_by_status';

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

sortIntegrationsByStatus(integrations);

const body: GetAllIntegrationsResponse = {
integrations,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { Integration } from '../../../../../../common/api/detection_engine/fleet_integrations/model/integrations';

/**
* Sorts integrations in place
*/
export function sortIntegrationsByStatus(integration: Integration[]): void {
integration.sort((a, b) => {
if (a.is_enabled && !b.is_enabled) {
return -1;
} else if (!a.is_enabled && b.is_enabled) {
return 1;
}

if (a.is_installed && !b.is_installed) {
return -1;
} else if (!a.is_installed && b.is_installed) {
return 1;
}

return 0;
});
}

0 comments on commit 82acefe

Please sign in to comment.