mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[8.x] [Fleet] Filter integrations/packages list shown depending on the `policy_templates_behavior` field (#200605) (#200749)
# Backport This will backport the following commits from `main` to `8.x`: - [[Fleet] Filter integrations/packages list shown depending on the `policy_templates_behavior` field (#200605)](https://github.com/elastic/kibana/pull/200605) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Mario Rodriguez Molins","email":"mario.rodriguez@elastic.co"},"sourceCommit":{"committedDate":"2024-11-19T14:27:19Z","message":"[Fleet] Filter integrations/packages list shown depending on the `policy_templates_behavior` field (#200605)\n\n## Summary\r\nCloses https://github.com/elastic/kibana/issues/198145\r\n\r\nAdd support to filter the tiles shown in the integrations UI as well as\r\nthe packages shown in the global search provider depending on the\r\n`policy_templates_behaviour` field introduced in\r\nhttps://github.com/elastic/package-spec/issues/802.\r\n\r\nIf this new field is not present in the package manifest, the same\r\nbehavior is kept. Therefore, it is shown a tile for the package itself\r\nplus a tile for each policy template defined in the manifest.\r\n\r\n\r\nTested using a custom Elastic Package Registry with some packages\r\ndefining this new `policy_templates_behavior` via the key:\r\n```yaml\r\nxpack.fleet.registryUrl: http://localhost:8080\r\n```\r\n\r\n### Screenshots\r\n\r\nChecked option \"Elastic Agent only\" in the integrations UI to avoid\r\ntutorials based on Beats.\r\n\r\nExample with `azure_metrics` package in the Integrations UI:\r\n- `policy_templates_behavior: all`\r\n\r\n\r\n- `policy_templates_behavior: combined_policy`\r\n\r\n\r\n- `policy_templates_behavior: individual_policies`\r\n\r\n\r\n\r\nExample in the Global Search with `azure_metrics` package and `combined\r\npolicy` behavior:\r\n\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies following conditions. \r\n\r\nReviewers should verify this PR satisfies this list as well.\r\n\r\n- [ ] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n- [ ]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [ ] If a plugin configuration key changed, check if it needs to be\r\nallowlisted in the cloud and added to the [docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n- [ ] This was checked for breaking HTTP API changes, and any breaking\r\nchanges have been approved by the breaking-change committee. The\r\n`release_note:breaking` label should be applied in these situations.\r\n- [ ] [Flaky Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\r\nused on any tests changed\r\n- [ ] The PR description includes the appropriate Release Notes section,\r\nand the correct `release_node:*` label is applied per the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n### Identify risks\r\n\r\nDoes this PR introduce any risks? For example, consider risks like hard\r\nto test bugs, performance regression, potential of data loss.\r\n\r\nDescribe the risk, its severity, and mitigation for each identified\r\nrisk. Invite stakeholders and evaluate how to proceed before merging.\r\n\r\n- [ ]","sha":"8352b86f59522319f6d20ae2165d11b621f1f22b","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","Team:Fleet","v9.0.0","backport:prev-minor"],"title":"[Fleet] Filter integrations/packages list shown depending on the `policy_templates_behavior` field","number":200605,"url":"https://github.com/elastic/kibana/pull/200605","mergeCommit":{"message":"[Fleet] Filter integrations/packages list shown depending on the `policy_templates_behavior` field (#200605)\n\n## Summary\r\nCloses https://github.com/elastic/kibana/issues/198145\r\n\r\nAdd support to filter the tiles shown in the integrations UI as well as\r\nthe packages shown in the global search provider depending on the\r\n`policy_templates_behaviour` field introduced in\r\nhttps://github.com/elastic/package-spec/issues/802.\r\n\r\nIf this new field is not present in the package manifest, the same\r\nbehavior is kept. Therefore, it is shown a tile for the package itself\r\nplus a tile for each policy template defined in the manifest.\r\n\r\n\r\nTested using a custom Elastic Package Registry with some packages\r\ndefining this new `policy_templates_behavior` via the key:\r\n```yaml\r\nxpack.fleet.registryUrl: http://localhost:8080\r\n```\r\n\r\n### Screenshots\r\n\r\nChecked option \"Elastic Agent only\" in the integrations UI to avoid\r\ntutorials based on Beats.\r\n\r\nExample with `azure_metrics` package in the Integrations UI:\r\n- `policy_templates_behavior: all`\r\n\r\n\r\n- `policy_templates_behavior: combined_policy`\r\n\r\n\r\n- `policy_templates_behavior: individual_policies`\r\n\r\n\r\n\r\nExample in the Global Search with `azure_metrics` package and `combined\r\npolicy` behavior:\r\n\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies following conditions. \r\n\r\nReviewers should verify this PR satisfies this list as well.\r\n\r\n- [ ] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n- [ ]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [ ] If a plugin configuration key changed, check if it needs to be\r\nallowlisted in the cloud and added to the [docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n- [ ] This was checked for breaking HTTP API changes, and any breaking\r\nchanges have been approved by the breaking-change committee. The\r\n`release_note:breaking` label should be applied in these situations.\r\n- [ ] [Flaky Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\r\nused on any tests changed\r\n- [ ] The PR description includes the appropriate Release Notes section,\r\nand the correct `release_node:*` label is applied per the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n### Identify risks\r\n\r\nDoes this PR introduce any risks? For example, consider risks like hard\r\nto test bugs, performance regression, potential of data loss.\r\n\r\nDescribe the risk, its severity, and mitigation for each identified\r\nrisk. Invite stakeholders and evaluate how to proceed before merging.\r\n\r\n- [ ]","sha":"8352b86f59522319f6d20ae2165d11b621f1f22b"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/200605","number":200605,"mergeCommit":{"message":"[Fleet] Filter integrations/packages list shown depending on the `policy_templates_behavior` field (#200605)\n\n## Summary\r\nCloses https://github.com/elastic/kibana/issues/198145\r\n\r\nAdd support to filter the tiles shown in the integrations UI as well as\r\nthe packages shown in the global search provider depending on the\r\n`policy_templates_behaviour` field introduced in\r\nhttps://github.com/elastic/package-spec/issues/802.\r\n\r\nIf this new field is not present in the package manifest, the same\r\nbehavior is kept. Therefore, it is shown a tile for the package itself\r\nplus a tile for each policy template defined in the manifest.\r\n\r\n\r\nTested using a custom Elastic Package Registry with some packages\r\ndefining this new `policy_templates_behavior` via the key:\r\n```yaml\r\nxpack.fleet.registryUrl: http://localhost:8080\r\n```\r\n\r\n### Screenshots\r\n\r\nChecked option \"Elastic Agent only\" in the integrations UI to avoid\r\ntutorials based on Beats.\r\n\r\nExample with `azure_metrics` package in the Integrations UI:\r\n- `policy_templates_behavior: all`\r\n\r\n\r\n- `policy_templates_behavior: combined_policy`\r\n\r\n\r\n- `policy_templates_behavior: individual_policies`\r\n\r\n\r\n\r\nExample in the Global Search with `azure_metrics` package and `combined\r\npolicy` behavior:\r\n\r\n\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies following conditions. \r\n\r\nReviewers should verify this PR satisfies this list as well.\r\n\r\n- [ ] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n- [ ]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [ ] If a plugin configuration key changed, check if it needs to be\r\nallowlisted in the cloud and added to the [docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n- [ ] This was checked for breaking HTTP API changes, and any breaking\r\nchanges have been approved by the breaking-change committee. The\r\n`release_note:breaking` label should be applied in these situations.\r\n- [ ] [Flaky Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\r\nused on any tests changed\r\n- [ ] The PR description includes the appropriate Release Notes section,\r\nand the correct `release_node:*` label is applied per the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n### Identify risks\r\n\r\nDoes this PR introduce any risks? For example, consider risks like hard\r\nto test bugs, performance regression, potential of data loss.\r\n\r\nDescribe the risk, its severity, and mitigation for each identified\r\nrisk. Invite stakeholders and evaluate how to proceed before merging.\r\n\r\n- [ ]","sha":"8352b86f59522319f6d20ae2165d11b621f1f22b"}}]}] BACKPORT--> --------- Co-authored-by: Mario Rodriguez Molins <mario.rodriguez@elastic.co>
This commit is contained in:
parent
7575f42ebf
commit
4a9f70d814
8 changed files with 421 additions and 26 deletions
|
@ -33,6 +33,7 @@ export {
|
|||
isIntegrationPolicyTemplate,
|
||||
getNormalizedInputs,
|
||||
getNormalizedDataStreams,
|
||||
filterPolicyTemplatesTiles,
|
||||
} from './policy_template';
|
||||
export { doesPackageHaveIntegrations } from './packages_with_integrations';
|
||||
export type {
|
||||
|
|
|
@ -10,6 +10,7 @@ import type {
|
|||
RegistryPolicyIntegrationTemplate,
|
||||
PackageInfo,
|
||||
RegistryVarType,
|
||||
PackageListItem,
|
||||
} from '../types';
|
||||
|
||||
import {
|
||||
|
@ -17,6 +18,7 @@ import {
|
|||
isIntegrationPolicyTemplate,
|
||||
getNormalizedInputs,
|
||||
getNormalizedDataStreams,
|
||||
filterPolicyTemplatesTiles,
|
||||
} from './policy_template';
|
||||
|
||||
describe('isInputOnlyPolicyTemplate', () => {
|
||||
|
@ -280,3 +282,161 @@ describe('getNormalizedDataStreams', () => {
|
|||
expect(result?.[0].streams?.[0]?.vars).toEqual([datasetVar]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('filterPolicyTemplatesTiles', () => {
|
||||
const topPackagePolicy: PackageListItem = {
|
||||
id: 'nginx',
|
||||
integration: 'nginx',
|
||||
title: 'Nginx',
|
||||
name: 'nginx',
|
||||
version: '0.0.1',
|
||||
status: 'not_installed',
|
||||
description: 'nginx',
|
||||
download: 'nginx',
|
||||
path: 'nginx',
|
||||
};
|
||||
|
||||
const childPolicyTemplates: PackageListItem[] = [
|
||||
{
|
||||
id: 'nginx-template1',
|
||||
integration: 'nginx-template-1',
|
||||
title: 'Nginx Template 1',
|
||||
name: 'nginx',
|
||||
version: '0.0.1',
|
||||
status: 'not_installed',
|
||||
description: 'nginx-template-1',
|
||||
download: 'nginx-template-1',
|
||||
path: 'nginx-template-1',
|
||||
},
|
||||
{
|
||||
id: 'nginx-template2',
|
||||
integration: 'nginx-template-2',
|
||||
title: 'Nginx Template 2',
|
||||
name: 'nginx',
|
||||
version: '0.0.1',
|
||||
status: 'not_installed',
|
||||
description: 'nginx-template-2',
|
||||
download: 'nginx-template-2',
|
||||
path: 'nginx-template-2',
|
||||
},
|
||||
];
|
||||
it('should return all tiles as undefined value', () => {
|
||||
expect(filterPolicyTemplatesTiles(undefined, topPackagePolicy, childPolicyTemplates)).toEqual([
|
||||
{
|
||||
id: 'nginx',
|
||||
integration: 'nginx',
|
||||
title: 'Nginx',
|
||||
name: 'nginx',
|
||||
version: '0.0.1',
|
||||
status: 'not_installed',
|
||||
description: 'nginx',
|
||||
download: 'nginx',
|
||||
path: 'nginx',
|
||||
},
|
||||
{
|
||||
id: 'nginx-template1',
|
||||
integration: 'nginx-template-1',
|
||||
title: 'Nginx Template 1',
|
||||
name: 'nginx',
|
||||
version: '0.0.1',
|
||||
status: 'not_installed',
|
||||
description: 'nginx-template-1',
|
||||
download: 'nginx-template-1',
|
||||
path: 'nginx-template-1',
|
||||
},
|
||||
{
|
||||
id: 'nginx-template2',
|
||||
integration: 'nginx-template-2',
|
||||
title: 'Nginx Template 2',
|
||||
name: 'nginx',
|
||||
version: '0.0.1',
|
||||
status: 'not_installed',
|
||||
description: 'nginx-template-2',
|
||||
download: 'nginx-template-2',
|
||||
path: 'nginx-template-2',
|
||||
},
|
||||
]);
|
||||
});
|
||||
it('should return all tiles', () => {
|
||||
expect(filterPolicyTemplatesTiles('all', topPackagePolicy, childPolicyTemplates)).toEqual([
|
||||
{
|
||||
id: 'nginx',
|
||||
integration: 'nginx',
|
||||
title: 'Nginx',
|
||||
name: 'nginx',
|
||||
version: '0.0.1',
|
||||
status: 'not_installed',
|
||||
description: 'nginx',
|
||||
download: 'nginx',
|
||||
path: 'nginx',
|
||||
},
|
||||
{
|
||||
id: 'nginx-template1',
|
||||
integration: 'nginx-template-1',
|
||||
title: 'Nginx Template 1',
|
||||
name: 'nginx',
|
||||
version: '0.0.1',
|
||||
status: 'not_installed',
|
||||
description: 'nginx-template-1',
|
||||
download: 'nginx-template-1',
|
||||
path: 'nginx-template-1',
|
||||
},
|
||||
{
|
||||
id: 'nginx-template2',
|
||||
integration: 'nginx-template-2',
|
||||
title: 'Nginx Template 2',
|
||||
name: 'nginx',
|
||||
version: '0.0.1',
|
||||
status: 'not_installed',
|
||||
description: 'nginx-template-2',
|
||||
download: 'nginx-template-2',
|
||||
path: 'nginx-template-2',
|
||||
},
|
||||
]);
|
||||
});
|
||||
it('should return just the combined policy tile', () => {
|
||||
expect(
|
||||
filterPolicyTemplatesTiles('combined_policy', topPackagePolicy, childPolicyTemplates)
|
||||
).toEqual([
|
||||
{
|
||||
id: 'nginx',
|
||||
integration: 'nginx',
|
||||
title: 'Nginx',
|
||||
name: 'nginx',
|
||||
version: '0.0.1',
|
||||
status: 'not_installed',
|
||||
description: 'nginx',
|
||||
download: 'nginx',
|
||||
path: 'nginx',
|
||||
},
|
||||
]);
|
||||
});
|
||||
it('should return just the individual policies (tiles)', () => {
|
||||
expect(
|
||||
filterPolicyTemplatesTiles('individual_policies', topPackagePolicy, childPolicyTemplates)
|
||||
).toEqual([
|
||||
{
|
||||
id: 'nginx-template1',
|
||||
integration: 'nginx-template-1',
|
||||
title: 'Nginx Template 1',
|
||||
name: 'nginx',
|
||||
version: '0.0.1',
|
||||
status: 'not_installed',
|
||||
description: 'nginx-template-1',
|
||||
download: 'nginx-template-1',
|
||||
path: 'nginx-template-1',
|
||||
},
|
||||
{
|
||||
id: 'nginx-template2',
|
||||
integration: 'nginx-template-2',
|
||||
title: 'Nginx Template 2',
|
||||
name: 'nginx',
|
||||
version: '0.0.1',
|
||||
status: 'not_installed',
|
||||
description: 'nginx-template-2',
|
||||
download: 'nginx-template-2',
|
||||
path: 'nginx-template-2',
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -39,6 +39,7 @@ export function packageHasNoPolicyTemplates(packageInfo: PackageInfo): boolean {
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
export function isInputOnlyPolicyTemplate(
|
||||
policyTemplate: RegistryPolicyTemplate
|
||||
): policyTemplate is RegistryPolicyInputOnlyTemplate {
|
||||
|
@ -142,3 +143,27 @@ const createDefaultDatasetName = (
|
|||
packageInfo: { name: string },
|
||||
policyTemplate: { name: string }
|
||||
): string => packageInfo.name + '.' + policyTemplate.name;
|
||||
|
||||
export function filterPolicyTemplatesTiles<T>(
|
||||
templatesBehavior: string | undefined,
|
||||
packagePolicy: T,
|
||||
packagePolicyTemplates: T[]
|
||||
): T[] {
|
||||
switch (templatesBehavior || 'all') {
|
||||
case 'combined_policy':
|
||||
return [packagePolicy];
|
||||
case 'individual_policies':
|
||||
return [
|
||||
...(packagePolicyTemplates && packagePolicyTemplates.length > 1
|
||||
? packagePolicyTemplates
|
||||
: []),
|
||||
];
|
||||
default:
|
||||
return [
|
||||
packagePolicy,
|
||||
...(packagePolicyTemplates && packagePolicyTemplates.length > 1
|
||||
? packagePolicyTemplates
|
||||
: []),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -311,6 +311,7 @@ export type RegistrySearchResult = Pick<
|
|||
| 'icons'
|
||||
| 'internal'
|
||||
| 'data_streams'
|
||||
| 'policy_templates_behavior'
|
||||
| 'policy_templates'
|
||||
| 'categories'
|
||||
>;
|
||||
|
|
|
@ -24,6 +24,7 @@ export interface PackageSpecManifest {
|
|||
conditions?: PackageSpecConditions;
|
||||
icons?: PackageSpecIcon[];
|
||||
screenshots?: PackageSpecScreenshot[];
|
||||
policy_templates_behavior?: 'all' | 'combined_policy' | 'individual_policies';
|
||||
policy_templates?: RegistryPolicyTemplate[];
|
||||
vars?: RegistryVarsEntry[];
|
||||
owner: { github: string; type?: 'elastic' | 'partner' | 'community' };
|
||||
|
|
|
@ -28,6 +28,7 @@ import { doesPackageHaveIntegrations, ExperimentalFeaturesService } from '../../
|
|||
import {
|
||||
isInputOnlyPolicyTemplate,
|
||||
isIntegrationPolicyTemplate,
|
||||
filterPolicyTemplatesTiles,
|
||||
} from '../../../../../../../../common/services';
|
||||
|
||||
import {
|
||||
|
@ -83,30 +84,33 @@ const packageListToIntegrationsList = (packages: PackageList): PackageList => {
|
|||
categories: getAllCategoriesFromIntegrations(pkg),
|
||||
};
|
||||
|
||||
return [
|
||||
...acc,
|
||||
topPackage,
|
||||
...(doesPackageHaveIntegrations(pkg)
|
||||
? policyTemplates.map((policyTemplate) => {
|
||||
const { name, title, description, icons } = policyTemplate;
|
||||
const integrationsPolicyTemplates = doesPackageHaveIntegrations(pkg)
|
||||
? policyTemplates.map((policyTemplate) => {
|
||||
const { name, title, description, icons } = policyTemplate;
|
||||
|
||||
const categories =
|
||||
isIntegrationPolicyTemplate(policyTemplate) && policyTemplate.categories
|
||||
? policyTemplate.categories
|
||||
: [];
|
||||
const allCategories = [...topCategories, ...categories];
|
||||
return {
|
||||
...restOfPackage,
|
||||
id: `${restOfPackage.id}-${name}`,
|
||||
integration: name,
|
||||
title,
|
||||
description,
|
||||
icons: icons || restOfPackage.icons,
|
||||
categories: uniq(allCategories),
|
||||
};
|
||||
})
|
||||
: []),
|
||||
];
|
||||
const categories =
|
||||
isIntegrationPolicyTemplate(policyTemplate) && policyTemplate.categories
|
||||
? policyTemplate.categories
|
||||
: [];
|
||||
const allCategories = [...topCategories, ...categories];
|
||||
return {
|
||||
...restOfPackage,
|
||||
id: `${restOfPackage.id}-${name}`,
|
||||
integration: name,
|
||||
title,
|
||||
description,
|
||||
icons: icons || restOfPackage.icons,
|
||||
categories: uniq(allCategories),
|
||||
};
|
||||
})
|
||||
: [];
|
||||
|
||||
const tiles = filterPolicyTemplatesTiles<PackageListItem>(
|
||||
pkg.policy_templates_behavior,
|
||||
topPackage,
|
||||
integrationsPolicyTemplates
|
||||
);
|
||||
return [...acc, ...tiles];
|
||||
}, []);
|
||||
};
|
||||
|
||||
|
|
|
@ -112,6 +112,123 @@ const testResponse: GetPackagesResponse['items'] = [
|
|||
},
|
||||
];
|
||||
|
||||
const testResponseBehaviorField: GetPackagesResponse['items'] = [
|
||||
{
|
||||
description: 'testWithPolicyTemplateBehaviorAll',
|
||||
download: 'testWithPolicyTemplateBehaviorAll',
|
||||
id: 'testWithPolicyTemplateBehaviorAll',
|
||||
name: 'testWithPolicyTemplateBehaviorAll',
|
||||
path: 'testWithPolicyTemplateBehaviorAll',
|
||||
release: 'ga',
|
||||
status: 'not_installed',
|
||||
title: 'testWithPolicyTemplateBehaviorAll',
|
||||
version: 'testWithPolicyTemplateBehaviorAll',
|
||||
policy_templates_behavior: 'all',
|
||||
policy_templates: [
|
||||
{
|
||||
description: 'testPolicyTemplate1BehaviorAll',
|
||||
name: 'testPolicyTemplate1BehaviorAll',
|
||||
icons: [
|
||||
{
|
||||
src: 'testPolicyTemplate1BehaviorAll',
|
||||
path: 'testPolicyTemplate1BehaviorAll',
|
||||
},
|
||||
],
|
||||
title: 'testPolicyTemplate1BehaviorAll',
|
||||
type: 'testPolicyTemplate1BehaviorAll',
|
||||
},
|
||||
{
|
||||
description: 'testPolicyTemplate2BehaviorAll',
|
||||
name: 'testPolicyTemplate2BehaviorAll',
|
||||
icons: [
|
||||
{
|
||||
src: 'testPolicyTemplate2BehaviorAll',
|
||||
path: 'testPolicyTemplate2BehaviorAll',
|
||||
},
|
||||
],
|
||||
title: 'testPolicyTemplate2BehaviorAll',
|
||||
type: 'testPolicyTemplate2BehaviorAll',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
description: 'testWithPolicyTemplateBehaviorCombined',
|
||||
download: 'testWithPolicyTemplateBehaviorCombined',
|
||||
id: 'testWithPolicyTemplateBehaviorCombined',
|
||||
name: 'testWithPolicyTemplateBehaviorCombined',
|
||||
path: 'testWithPolicyTemplateBehaviorCombined',
|
||||
release: 'ga',
|
||||
status: 'not_installed',
|
||||
title: 'testWithPolicyTemplateBehaviorCombined',
|
||||
version: 'testWithPolicyTemplateBehaviorCombined',
|
||||
policy_templates_behavior: 'combined_policy',
|
||||
policy_templates: [
|
||||
{
|
||||
description: 'testPolicyTemplate1BehaviorCombined',
|
||||
name: 'testPolicyTemplate1BehaviorCombined',
|
||||
icons: [
|
||||
{
|
||||
src: 'testPolicyTemplate1BehaviorCombined',
|
||||
path: 'testPolicyTemplate1BehaviorCombined',
|
||||
},
|
||||
],
|
||||
title: 'testPolicyTemplate1BehaviorCombined',
|
||||
type: 'testPolicyTemplate1BehaviorCombined',
|
||||
},
|
||||
{
|
||||
description: 'testPolicyTemplate2BehaviorCombined',
|
||||
name: 'testPolicyTemplate2BehaviorCombined',
|
||||
icons: [
|
||||
{
|
||||
src: 'testPolicyTemplate2BehaviorCombined',
|
||||
path: 'testPolicyTemplate2BehaviorCombined',
|
||||
},
|
||||
],
|
||||
title: 'testPolicyTemplate2BehaviorCombined',
|
||||
type: 'testPolicyTemplate2BehaviorCombined',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
description: 'testWithPolicyTemplateBehaviorIndividual',
|
||||
download: 'testWithPolicyTemplateBehaviorIndividual',
|
||||
id: 'testWithPolicyTemplateBehaviorIndividual',
|
||||
name: 'testWithPolicyTemplateBehaviorIndividual',
|
||||
path: 'testWithPolicyTemplateBehaviorIndividual',
|
||||
release: 'ga',
|
||||
status: 'not_installed',
|
||||
title: 'testWithPolicyTemplateBehaviorIndividual',
|
||||
version: 'testWithPolicyTemplateBehaviorIndividual',
|
||||
policy_templates_behavior: 'individual_policies',
|
||||
policy_templates: [
|
||||
{
|
||||
description: 'testPolicyTemplate1BehaviorIndividual',
|
||||
name: 'testPolicyTemplate1BehaviorIndividual',
|
||||
icons: [
|
||||
{
|
||||
src: 'testPolicyTemplate1BehaviorIndividual',
|
||||
path: 'testPolicyTemplate1BehaviorIndividual',
|
||||
},
|
||||
],
|
||||
title: 'testPolicyTemplate1BehaviorIndividual',
|
||||
type: 'testPolicyTemplate1BehaviorIndividual',
|
||||
},
|
||||
{
|
||||
description: 'testPolicyTemplate2BehaviorIndividual',
|
||||
name: 'testPolicyTemplate2BehaviorIndividual',
|
||||
icons: [
|
||||
{
|
||||
src: 'testPolicyTemplate2BehaviorIndividual',
|
||||
path: 'testPolicyTemplate2BehaviorIndividual',
|
||||
},
|
||||
],
|
||||
title: 'testPolicyTemplate2BehaviorIndividual',
|
||||
type: 'testPolicyTemplate2BehaviorIndividual',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const getTestScheduler = () => {
|
||||
return new TestScheduler((actual, expected) => {
|
||||
return expect(actual).toEqual(expected);
|
||||
|
@ -394,6 +511,89 @@ describe('Package search provider', () => {
|
|||
expect(sendGetPackages).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('with integration tag, with policy_templates_behavior field', () => {
|
||||
getTestScheduler().run(({ hot, expectObservable }) => {
|
||||
mockSendGetPackages.mockReturnValue(
|
||||
hot('--(a|)', { a: { data: { response: testResponseBehaviorField } } })
|
||||
);
|
||||
setupMock.getStartServices.mockReturnValue(
|
||||
hot('--(a|)', { a: [coreMock.createStart()] }) as any
|
||||
);
|
||||
const packageSearchProvider = createPackageSearchProvider(setupMock);
|
||||
expectObservable(
|
||||
packageSearchProvider.find(
|
||||
{ types: ['integration'] },
|
||||
{ aborted$: NEVER, maxResults: 100, preference: '' }
|
||||
)
|
||||
).toBe('--(a|)', {
|
||||
a: [
|
||||
{
|
||||
id: 'testWithPolicyTemplateBehaviorAll',
|
||||
score: 80,
|
||||
title: 'testWithPolicyTemplateBehaviorAll',
|
||||
type: 'integration',
|
||||
url: {
|
||||
path: 'undefined/detail/testWithPolicyTemplateBehaviorAll/overview',
|
||||
prependBasePath: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'testPolicyTemplate1BehaviorAll',
|
||||
score: 80,
|
||||
title: 'testPolicyTemplate1BehaviorAll',
|
||||
type: 'integration',
|
||||
url: {
|
||||
path: 'undefined/detail/testWithPolicyTemplateBehaviorAll/overview?integration=testPolicyTemplate1BehaviorAll',
|
||||
prependBasePath: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'testPolicyTemplate2BehaviorAll',
|
||||
score: 80,
|
||||
title: 'testPolicyTemplate2BehaviorAll',
|
||||
type: 'integration',
|
||||
url: {
|
||||
path: 'undefined/detail/testWithPolicyTemplateBehaviorAll/overview?integration=testPolicyTemplate2BehaviorAll',
|
||||
prependBasePath: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'testWithPolicyTemplateBehaviorCombined',
|
||||
score: 80,
|
||||
title: 'testWithPolicyTemplateBehaviorCombined',
|
||||
type: 'integration',
|
||||
url: {
|
||||
path: 'undefined/detail/testWithPolicyTemplateBehaviorCombined/overview',
|
||||
prependBasePath: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'testPolicyTemplate1BehaviorIndividual',
|
||||
score: 80,
|
||||
title: 'testPolicyTemplate1BehaviorIndividual',
|
||||
type: 'integration',
|
||||
url: {
|
||||
path: 'undefined/detail/testWithPolicyTemplateBehaviorIndividual/overview?integration=testPolicyTemplate1BehaviorIndividual',
|
||||
prependBasePath: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'testPolicyTemplate2BehaviorIndividual',
|
||||
score: 80,
|
||||
title: 'testPolicyTemplate2BehaviorIndividual',
|
||||
type: 'integration',
|
||||
url: {
|
||||
path: 'undefined/detail/testWithPolicyTemplateBehaviorIndividual/overview?integration=testPolicyTemplate2BehaviorIndividual',
|
||||
prependBasePath: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
expect(sendGetPackages).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('with integration tag, with search term', () => {
|
||||
getTestScheduler().run(({ hot, expectObservable }) => {
|
||||
mockSendGetPackages.mockReturnValue(
|
||||
|
|
|
@ -16,6 +16,7 @@ import type {
|
|||
} from '@kbn/global-search-plugin/public';
|
||||
|
||||
import { INTEGRATIONS_PLUGIN_ID } from '../common';
|
||||
import { filterPolicyTemplatesTiles } from '../common/services';
|
||||
|
||||
import { sendGetPackages } from './hooks';
|
||||
import type { GetPackagesResponse, PackageListItem } from './types';
|
||||
|
@ -74,10 +75,12 @@ export const toSearchResult = (
|
|||
})
|
||||
);
|
||||
|
||||
return [
|
||||
const tiles = filterPolicyTemplatesTiles<GlobalSearchProviderResult>(
|
||||
pkg.policy_templates_behavior,
|
||||
packageResult,
|
||||
...(policyTemplateResults && policyTemplateResults.length > 1 ? policyTemplateResults : []),
|
||||
];
|
||||
policyTemplateResults || []
|
||||
);
|
||||
return [...tiles];
|
||||
};
|
||||
|
||||
export const createPackageSearchProvider = (core: CoreSetup): GlobalSearchResultProvider => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue