Skip to content

Commit

Permalink
fix: group elements use all functionalities (#1500)
Browse files Browse the repository at this point in the history
**Issue number:**
N/A
### PR Type

**What kind of change does this PR introduce?**
* [ ] Feature
* [x] Bug Fix
* [ ] Refactoring (no functional or API changes)
* [ ] Documentation Update
* [ ] Maintenance (dependency updates, CI, etc.)

## Summary

Modifications did not work for fields inside any group.

### Changes

Pass all parameters when rendering groups.

Please provide a summary of the changes.

### User experience

Modifications works correctly when using groups.

Please describe the user experience before and after this change.
Screenshots are welcome for additional context.

## Checklist

If an item doesn't apply to your changes, leave it unchecked.

* [x] I have performed a self-review of this change according to the
[development
guidelines](https://splunk.github.io/addonfactory-ucc-generator/contributing/#development-guidelines)
* [x] Tests have been added/modified to cover the changes [(testing
doc)](https://splunk.github.io/addonfactory-ucc-generator/contributing/#build-and-test)
* [ ] Changes are documented
* [x] PR title and description follows the [contributing
principles](https://splunk.github.io/addonfactory-ucc-generator/contributing/#pull-requests)

---------

Co-authored-by: srv-rr-github-token <[email protected]>
  • Loading branch information
soleksy-splunk and srv-rr-github-token authored Dec 5, 2024
1 parent a7c36ff commit 01c88aa
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 158 deletions.
351 changes: 197 additions & 154 deletions ui/src/components/BaseFormView/BaseFormConfigMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,115 @@ export function getGlobalConfigMockCustomControl() {
return GlobalConfigSchema.parse(globalConfigMockCustomControl);
}

const getGlobalConfigMockGroups = ({
entitiesConfig,
entityGroupsConfig,
entitiesInputs,
entityGroupsInputs,
}: {
entitiesConfig?: z.input<typeof AnyOfEntity>[];
entityGroupsConfig?: typeof GROUPS_FOR_EXAMPLE_ENTITIES;
entitiesInputs?: z.input<typeof AnyOfEntity>[];
entityGroupsInputs?: typeof GROUPS_FOR_EXAMPLE_ENTITIES;
}) =>
({
pages: {
configuration: {
tabs: [
{
name: 'account',
table: {
actions: ['edit', 'delete', 'clone'],
header: [
{
label: 'Name',
field: 'name',
},
],
},
entity: [
{
type: 'text',
label: 'Name',
validators: [
{
type: 'regex',
errorMsg:
'Account Name must begin with a letter and consist exclusively of alphanumeric characters and underscores.',
pattern: '^[a-zA-Z]\\w*$',
},
],
field: 'name',
help: 'A unique name for the account.',
required: true,
},
...(entitiesConfig || []),
],
groups: entityGroupsConfig,
title: 'Accounts',
},
],
title: 'Configuration',
description: 'Set up your add-on',
},
inputs: {
services: [
{
name: 'demo_input',
entity: [
{
type: 'text',
label: 'Name',
validators: [
{
type: 'regex',
errorMsg:
'Input Name must begin with a letter and consist exclusively of alphanumeric characters and underscores.',
pattern: '^[a-zA-Z]\\w*$',
},
{
type: 'string',
errorMsg:
'Length of input name should be between 1 and 100',
minLength: 1,
maxLength: 100,
},
],
field: 'name',
help: 'A unique name for the data input.',
required: true,
encrypted: false,
},
...(entitiesInputs || []),
],
groups: entityGroupsInputs,
title: 'demo_input',
},
],
title: 'Inputs',
description: 'Manage your data inputs',
table: {
actions: ['edit', 'delete', 'clone'],
header: [
{
label: 'Name',
field: 'name',
},
],
},
},
},
meta: {
name: 'demo_addon_for_splunk',
restRoot: 'demo_addon_for_splunk',
version: '5.31.1R85f0e18e',
displayName: 'Demo Add-on for Splunk',
schemaVersion: '0.0.3',
checkForUpdates: false,
searchViewDefault: false,
},
} satisfies z.input<typeof GlobalConfigSchema>);

const EXAMPLE_GROUPS_ENTITIES = [
{
type: 'text',
Expand Down Expand Up @@ -238,171 +347,105 @@ const GROUPS_FOR_EXAMPLE_ENTITIES = [
},
];

const globalConfigMockGroupsForConfigPage = {
pages: {
configuration: {
tabs: [
{
name: 'account',
table: {
actions: ['edit', 'delete', 'clone'],
header: [
{
label: 'Name',
field: 'name',
},
],
},
entity: [
{
type: 'text',
label: 'Name',
validators: [
{
type: 'regex',
errorMsg:
'Account Name must begin with a letter and consist exclusively of alphanumeric characters and underscores.',
pattern: '^[a-zA-Z]\\w*$',
},
],
field: 'name',
help: 'A unique name for the account.',
required: true,
},
...EXAMPLE_GROUPS_ENTITIES,
],
groups: GROUPS_FOR_EXAMPLE_ENTITIES,
title: 'Accounts',
},
],
title: 'Configuration',
description: 'Set up your add-on',
},
inputs: {
services: [],
title: 'Inputs',
description: 'Manage your data inputs',
table: {
actions: ['edit', 'delete', 'clone'],
header: [
{
label: 'Name',
field: 'name',
},
],
},
},
},
meta: {
name: 'demo_addon_for_splunk',
restRoot: 'demo_addon_for_splunk',
version: '5.31.1R85f0e18e',
displayName: 'Demo Add-on for Splunk',
schemaVersion: '0.0.3',
checkForUpdates: false,
searchViewDefault: false,
},
} satisfies z.input<typeof GlobalConfigSchema>;

export function getGlobalConfigMockGroupsForConfigPage(): GlobalConfig {
return GlobalConfigSchema.parse(globalConfigMockGroupsForConfigPage);
return GlobalConfigSchema.parse(
getGlobalConfigMockGroups({
entitiesConfig: EXAMPLE_GROUPS_ENTITIES,
entityGroupsConfig: GROUPS_FOR_EXAMPLE_ENTITIES,
})
);
}

const globalConfigMockGroupsForInputPage = {
pages: {
configuration: {
tabs: [
{
name: 'account',
table: {
actions: ['edit', 'delete', 'clone'],
header: [
{
label: 'Name',
field: 'name',
},
],
},
entity: [
{
type: 'text',
label: 'Name',
validators: [
{
type: 'regex',
errorMsg:
'Account Name must begin with a letter and consist exclusively of alphanumeric characters and underscores.',
pattern: '^[a-zA-Z]\\w*$',
},
],
field: 'name',
help: 'A unique name for the account.',
required: true,
export function getGlobalConfigMockGroupsForInputPage(): GlobalConfig {
return GlobalConfigSchema.parse(
getGlobalConfigMockGroups({
entitiesInputs: EXAMPLE_GROUPS_ENTITIES,
entityGroupsInputs: GROUPS_FOR_EXAMPLE_ENTITIES,
})
);
}

const GROUP_ENTITIES_MODIFICATIONS = [
{
type: 'text',
label: 'Text 1 Group 2',
field: 'text_field_1_group_2',
required: false,
modifyFieldsOnValue: [
{
fieldValue: '[[any_other_value]]',
fieldsToModify: [
{
fieldId: 'text_field_2_group_2',
disabled: false,
required: false,
help: 'help after mods 2-2',
label: 'label after mods 2-2',
markdownMessage: {
text: 'markdown message after mods 2-2',
},
],
title: 'Accounts',
},
],
title: 'Configuration',
description: 'Set up your add-on',
},
inputs: {
services: [
{
name: 'demo_input',
entity: [
{
type: 'text',
label: 'Name',
validators: [
{
type: 'regex',
errorMsg:
'Input Name must begin with a letter and consist exclusively of alphanumeric characters and underscores.',
pattern: '^[a-zA-Z]\\w*$',
},
{
type: 'string',
errorMsg: 'Length of input name should be between 1 and 100',
minLength: 1,
maxLength: 100,
},
],
field: 'name',
help: 'A unique name for the data input.',
required: true,
encrypted: false,
},
{
fieldId: 'text_field_2_group_1',
disabled: false,
required: true,
help: 'help after mods 2-1',
label: 'label after mods 2-1',
markdownMessage: {
text: 'markdown message after mods 2-1',
},
...EXAMPLE_GROUPS_ENTITIES,
],
groups: GROUPS_FOR_EXAMPLE_ENTITIES,
title: 'demo_input',
},
],
title: 'Inputs',
description: 'Manage your data inputs',
table: {
actions: ['edit', 'delete', 'clone'],
header: [
},
{
label: 'Name',
field: 'name',
fieldId: 'text_field_1_group_1',
disabled: true,
},
],
},
],
},
{
type: 'text',
label: 'Text 2 Group 2',
field: 'text_field_2_group_2',
required: false,
},
{
type: 'text',
label: 'Text 1 Group 1',
field: 'text_field_1_group_1',
required: false,
},
{
type: 'text',
label: 'Text 2 Group 1',
field: 'text_field_2_group_1',
required: false,
options: {
enable: false,
},
},
meta: {
name: 'demo_addon_for_splunk',
restRoot: 'demo_addon_for_splunk',
version: '5.31.1R85f0e18e',
displayName: 'Demo Add-on for Splunk',
schemaVersion: '0.0.3',
checkForUpdates: false,
searchViewDefault: false,
{
type: 'text',
label: 'Text 1 Group 3',
field: 'text_field_1_group_3',
required: false,
options: {
enable: false,
},
},
} satisfies z.input<typeof GlobalConfigSchema>;
{
type: 'text',
label: 'Text 2 Group 3',
field: 'text_field_2_group_3',
required: false,
},
] satisfies z.input<typeof AnyOfEntity>[];

export function getGlobalConfigMockGroupsFoInputPage(): GlobalConfig {
return GlobalConfigSchema.parse(globalConfigMockGroupsForInputPage);
export function getGlobalConfigMockModificationToGroupsConfig(): GlobalConfig {
return GlobalConfigSchema.parse(
getGlobalConfigMockGroups({
entitiesConfig: GROUP_ENTITIES_MODIFICATIONS,
entityGroupsConfig: GROUPS_FOR_EXAMPLE_ENTITIES,
})
);
}
4 changes: 2 additions & 2 deletions ui/src/components/BaseFormView/BaseFormView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getBuildDirPath } from '../../util/script';
import mockCustomControlMockForTest from '../CustomControl/CustomControlMockForTest';
import {
getGlobalConfigMockCustomControl,
getGlobalConfigMockGroupsFoInputPage,
getGlobalConfigMockGroupsForInputPage,
getGlobalConfigMockGroupsForConfigPage,
} from './BaseFormConfigMock';

Expand Down Expand Up @@ -97,7 +97,7 @@ it.each([
},
{
page: 'inputs' as const,
config: getGlobalConfigMockGroupsFoInputPage(),
config: getGlobalConfigMockGroupsForInputPage(),
service: 'demo_input',
},
])('entities grouping for page works properly %s', async ({ config, page, service }) => {
Expand Down
Loading

0 comments on commit 01c88aa

Please sign in to comment.