Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ export const varsReducer = (
configObject: PackagePolicyConfigRecord,
registryVar: RegistryVarsEntry
): PackagePolicyConfigRecord => {
// section_header vars are decorative only and hold no value
if (registryVar.type === 'section_header') {
return configObject;
}
const configEntry: PackagePolicyConfigRecordEntry = {
value: !registryVar.default && registryVar.multi ? [] : registryVar.default,
};
Expand Down
17 changes: 15 additions & 2 deletions x-pack/platform/plugins/shared/fleet/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export enum RegistryPolicyTemplateKeys {
dynamic_signal_types = 'dynamic_signal_types',
var_groups = 'var_groups',
deprecated = 'deprecated',
sections = 'sections',
}
interface BaseTemplate {
[RegistryPolicyTemplateKeys.name]: string;
Expand Down Expand Up @@ -300,6 +301,7 @@ export interface RegistryPolicyInputOnlyTemplate extends BaseTemplate {
[RegistryPolicyTemplateKeys.required_vars]?: RegistryRequiredVars;
[RegistryPolicyTemplateKeys.vars]?: RegistryVarsEntry[];
[RegistryPolicyTemplateKeys.var_groups]?: RegistryVarGroup[];
[RegistryPolicyTemplateKeys.sections]?: RegistrySection[];
[RegistryPolicyTemplateKeys.dynamic_signal_types]?: boolean;
}

Expand All @@ -325,6 +327,7 @@ export enum RegistryInputKeys {
migrate_from = 'migrate_from',
dynamic_signal_types = 'dynamic_signal_types',
show_divider = 'show_divider',
sections = 'sections',
}

export type RegistryInputGroup = 'logs' | 'metrics';
Expand All @@ -350,6 +353,7 @@ export interface RegistryInput {
[RegistryInputKeys.dynamic_signal_types]?: boolean;
/** When false, suppresses the automatic horizontal divider rendered after the input-level config section. Defaults to true. */
[RegistryInputKeys.show_divider]?: boolean;
[RegistryInputKeys.sections]?: RegistrySection[];
}

export enum RegistryStreamKeys {
Expand All @@ -365,6 +369,7 @@ export enum RegistryStreamKeys {
var_groups = 'var_groups',
deprecated = 'deprecated',
migrate_from = 'migrate_from',
sections = 'sections',
}

export interface RegistryStream {
Expand All @@ -380,6 +385,7 @@ export interface RegistryStream {
[RegistryStreamKeys.var_groups]?: RegistryVarGroup[];
[RegistryStreamKeys.deprecated]?: DeprecationInfo;
[RegistryStreamKeys.migrate_from]?: string;
[RegistryStreamKeys.sections]?: RegistrySection[];
}

export type RegistryStreamWithDataStream = RegistryStream & { data_stream: RegistryDataStream };
Expand Down Expand Up @@ -554,8 +560,13 @@ export type RegistryVarType =
| 'string'
| 'textarea'
| 'duration'
| 'url'
| 'section_header';
| 'url';

export interface RegistrySection {
name: string;
title: string;
description?: string;
}
export enum RegistryVarsEntryKeys {
name = 'name',
title = 'title',
Expand All @@ -574,6 +585,7 @@ export enum RegistryVarsEntryKeys {
max_duration = 'max_duration',
url_allowed_schemes = 'url_allowed_schemes',
deprecated = 'deprecated',
section = 'section',
}

// EPR types this as `[]map[string]interface{}`
Expand Down Expand Up @@ -601,6 +613,7 @@ export interface RegistryVarsEntry {
[RegistryVarsEntryKeys.max_duration]?: string;
[RegistryVarsEntryKeys.url_allowed_schemes]?: string[];
[RegistryVarsEntryKeys.deprecated]?: DeprecationInfo;
[RegistryVarsEntryKeys.section]?: string;
}

// Deprecated as part of the removing public references to saved object schemas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
DeprecationInfo,
RegistryElasticsearch,
RegistryPolicyTemplate,
RegistrySection,
RegistryVarsEntry,
} from './epm';

Expand Down Expand Up @@ -63,6 +64,7 @@ export interface PackageSpecManifest {
policy_templates?: RegistryPolicyTemplate[];
vars?: RegistryVarsEntry[];
var_groups?: RegistryVarGroup[];
sections?: RegistrySection[];
owner: { github?: string; type?: 'elastic' | 'partner' | 'community' };
elasticsearch?: Pick<
RegistryElasticsearch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,106 @@ describe('PackagePolicyInputConfig', () => {
expect(utils.queryByText('Deprecated Var')).not.toBeInTheDocument();
});

it('should render section titles for vars with a matching section attribute', () => {
const renderer = createFleetTestRendererMock();
const mockOnChange = jest.fn();

const utils = renderer.render(
<PackagePolicyInputConfig
hasInputStreams={false}
inputValidationResults={{}}
packagePolicyInput={{
enabled: true,
type: 'input',
streams: [],
}}
updatePackagePolicyInput={mockOnChange}
packageInputVars={[
{
name: 'ungrouped_var',
title: 'Ungrouped Var',
type: 'text',
show_user: true,
},
{
name: 'auth_var',
title: 'Auth Var',
type: 'text',
show_user: true,
section: 'auth_section',
},
]}
sections={[{ name: 'auth_section', title: 'Authentication', description: 'Auth settings' }]}
/>
);

expect(utils.queryByText('Ungrouped Var')).toBeInTheDocument();
expect(utils.queryByText('Authentication')).toBeInTheDocument();
expect(utils.queryByText('Auth settings')).toBeInTheDocument();
expect(utils.queryByText('Auth Var')).toBeInTheDocument();
});

it('should render vars without a section attribute as ungrouped even when sections are defined', () => {
const renderer = createFleetTestRendererMock();
const mockOnChange = jest.fn();

const utils = renderer.render(
<PackagePolicyInputConfig
hasInputStreams={false}
inputValidationResults={{}}
packagePolicyInput={{
enabled: true,
type: 'input',
streams: [],
}}
updatePackagePolicyInput={mockOnChange}
packageInputVars={[
{
name: 'ungrouped_var',
title: 'Ungrouped Var',
type: 'text',
show_user: true,
},
]}
sections={[{ name: 'auth_section', title: 'Authentication' }]}
/>
);

expect(utils.queryByText('Ungrouped Var')).toBeInTheDocument();
// Section header should not render if no vars reference it
expect(utils.queryByText('Authentication')).not.toBeInTheDocument();
});

it('should not render section titles when no sections prop is provided', () => {
const renderer = createFleetTestRendererMock();
const mockOnChange = jest.fn();

const utils = renderer.render(
<PackagePolicyInputConfig
hasInputStreams={false}
inputValidationResults={{}}
packagePolicyInput={{
enabled: true,
type: 'input',
streams: [],
}}
updatePackagePolicyInput={mockOnChange}
packageInputVars={[
{
name: 'auth_var',
title: 'Auth Var',
type: 'text',
show_user: true,
section: 'auth_section',
},
]}
/>
);

expect(utils.queryByText('Auth Var')).toBeInTheDocument();
expect(utils.queryByText('Authentication')).not.toBeInTheDocument();
});

it('should show deprecated vars on edit page (isEditPage=true)', () => {
const renderer = createFleetTestRendererMock();
const mockOnChange = jest.fn();
Expand Down
Loading
Loading