Skip to content

Commit

Permalink
[Fleet] Have EPR register new categories / Show category counts (#114429
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck authored Oct 13, 2021
1 parent 291ea9d commit 488cc68
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 164 deletions.
3 changes: 0 additions & 3 deletions src/plugins/custom_integrations/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ export const INTEGRATION_CATEGORY_DISPLAY = {
// Kibana added
upload_file: 'Upload a file',
language_client: 'Language client',

// Internal
updates_available: 'Updates available',
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/custom_integrations/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function plugin(initializerContext: PluginInitializerContext) {

export { CustomIntegrationsPluginSetup, CustomIntegrationsPluginStart } from './types';

export type { IntegrationCategory, IntegrationCategoryCount, CustomIntegration } from '../common';
export type { IntegrationCategory, CustomIntegration } from '../common';

export const config = {
schema: schema.object({}),
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/fleet/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export type RegistrySearchResult = Pick<
| 'internal'
| 'data_streams'
| 'policy_templates'
| 'categories'
>;

export type ScreenshotItem = RegistryImage | PackageSpecScreenshot;
Expand Down Expand Up @@ -374,6 +375,7 @@ export interface IntegrationCardItem {
icons: Array<PackageSpecIcon | CustomIntegrationIcon>;
integration: string;
id: string;
categories: string[];
}

export type PackagesGroupedByStatus = Record<ValueOf<InstallationStatus>, PackageList>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* 2.0.
*/

import type { PackageListItem } from '../../common/types/models';
import type { CustomIntegration } from '../../../../../src/plugins/custom_integrations/common';
import type { PackageListItem } from '../../../../common/types/models';
import type { CustomIntegration } from '../../../../../../../src/plugins/custom_integrations/common';

import type { IntegrationCategory } from '../../../../../src/plugins/custom_integrations/common';
import type { IntegrationCategory } from '../../../../../../../src/plugins/custom_integrations/common';

import { useMergeEprPackagesWithReplacements } from './use_merge_epr_with_replacements';

Expand Down Expand Up @@ -46,7 +46,7 @@ describe('useMergeEprWithReplacements', () => {
},
]);

expect(useMergeEprPackagesWithReplacements(eprPackages, replacements, '')).toEqual([
expect(useMergeEprPackagesWithReplacements(eprPackages, replacements)).toEqual([
{
name: 'aws',
release: 'ga',
Expand Down Expand Up @@ -80,7 +80,7 @@ describe('useMergeEprWithReplacements', () => {
},
]);

expect(useMergeEprPackagesWithReplacements(eprPackages, replacements, '')).toEqual([
expect(useMergeEprPackagesWithReplacements(eprPackages, replacements)).toEqual([
{
eprOverlap: 'activemq',
id: 'activemq-logs',
Expand Down Expand Up @@ -108,7 +108,7 @@ describe('useMergeEprWithReplacements', () => {
},
]);

expect(useMergeEprPackagesWithReplacements(eprPackages, replacements, '')).toEqual([
expect(useMergeEprPackagesWithReplacements(eprPackages, replacements)).toEqual([
{
name: 'activemq',
release: 'beta',
Expand All @@ -120,32 +120,6 @@ describe('useMergeEprWithReplacements', () => {
]);
});

test('should respect category assignment', () => {
const eprPackages: PackageListItem[] = mockEprPackages([
{
name: 'activemq',
release: 'beta',
},
]);
const replacements: CustomIntegration[] = mockIntegrations([
{
id: 'prometheus',
categories: ['monitoring', 'datastore'],
},
{
id: 'oracle',
categories: ['datastore'],
},
]);

expect(useMergeEprPackagesWithReplacements(eprPackages, replacements, 'web')).toEqual([
{
name: 'activemq',
release: 'beta',
},
]);
});

test('should consists of all 3 types (ga eprs, replacements for non-ga eprs, replacements without epr equivalent', () => {
const eprPackages: PackageListItem[] = mockEprPackages([
{
Expand Down Expand Up @@ -190,7 +164,7 @@ describe('useMergeEprWithReplacements', () => {
},
]);

expect(useMergeEprPackagesWithReplacements(eprPackages, replacements, '')).toEqual([
expect(useMergeEprPackagesWithReplacements(eprPackages, replacements)).toEqual([
{
name: 'aws',
release: 'ga',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
* 2.0.
*/

import type { PackageListItem } from '../../common/types/models';
import type {
CustomIntegration,
IntegrationCategory,
} from '../../../../../src/plugins/custom_integrations/common';
import { filterCustomIntegrations } from '../../../../../src/plugins/custom_integrations/public';
import type { PackageListItem } from '../../../../common/types/models';
import type { CustomIntegration } from '../../../../../../../src/plugins/custom_integrations/common';
import { filterCustomIntegrations } from '../../../../../../../src/plugins/custom_integrations/public';

// Export this as a utility to find replacements for a package (e.g. in the overview-page for an EPR package)
function findReplacementsForEprPackage(
Expand All @@ -26,17 +23,13 @@ function findReplacementsForEprPackage(

export function useMergeEprPackagesWithReplacements(
eprPackages: PackageListItem[],
replacements: CustomIntegration[],
category: IntegrationCategory | ''
replacements: CustomIntegration[]
): Array<PackageListItem | CustomIntegration> {
const merged: Array<PackageListItem | CustomIntegration> = [];

const filteredReplacements = replacements.filter((customIntegration) => {
return !category || customIntegration.categories.includes(category);
});
const filteredReplacements = replacements;

// Either select replacement or select beat
eprPackages.forEach((eprPackage) => {
eprPackages.forEach((eprPackage: PackageListItem) => {
const hits = findReplacementsForEprPackage(
filteredReplacements,
eprPackage.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const args: Args = {
url: '/',
icons: [],
integration: '',
categories: ['foobar'],
};

const argTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const List = (props: Args) => (
url: 'https://example.com',
icons: [],
integration: 'integation',
categories: ['web'],
},
{
title: 'Package Two',
Expand All @@ -58,6 +59,7 @@ export const List = (props: Args) => (
url: 'https://example.com',
icons: [],
integration: 'integation',
categories: ['web'],
},
{
title: 'Package Three',
Expand All @@ -69,6 +71,7 @@ export const List = (props: Args) => (
url: 'https://example.com',
icons: [],
integration: 'integation',
categories: ['web'],
},
{
title: 'Package Four',
Expand All @@ -80,6 +83,7 @@ export const List = (props: Args) => (
url: 'https://example.com',
icons: [],
integration: 'integation',
categories: ['web'],
},
{
title: 'Package Five',
Expand All @@ -91,6 +95,7 @@ export const List = (props: Args) => (
url: 'https://example.com',
icons: [],
integration: 'integation',
categories: ['web'],
},
{
title: 'Package Six',
Expand All @@ -102,6 +107,7 @@ export const List = (props: Args) => (
url: 'https://example.com',
icons: [],
integration: 'integation',
categories: ['web'],
},
]}
onSearchChange={action('onSearchChange')}
Expand Down
Loading

0 comments on commit 488cc68

Please sign in to comment.