Skip to content

feat(CheckboxGroup): add support for required field #1131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 11, 2024
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
3 changes: 3 additions & 0 deletions splunk_add_on_ucc_framework/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,9 @@
}
]
}
},
"required" : {
"type": "boolean"
}
},
"required": ["field", "label", "type", "options"],
Expand Down
1 change: 1 addition & 0 deletions tests/unit/testdata/valid_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,7 @@
"type": "checkboxGroup",
"label": "Mixed",
"field": "api3",
"required": true,
"options": {
"groups": [
{
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/BaseFormView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ class BaseFormView extends PureComponent<BaseFormProps, BaseFormState> {
) => {
const index = this.entities?.findIndex((x) => x.field === field);
const validator = [{ type: 'custom', validatorFunc }];
if (index && this.entities?.[index]) {
if (index !== undefined && this.entities?.[index]) {
// here the validators already exist for entities so new type is created here
// @ts-expect-error todo create a generalized type to also consider it
this.entities[index].validators = validator;
Expand Down
115 changes: 115 additions & 0 deletions ui/src/components/CheckboxGroup/checkboxGroupRequiredMocks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"meta": {
"name": "Splunk_TA_aws",
"displayName": "Splunk Add-on for AWS",
"version": "7.1.0",
"restRoot": "restRoot",
"schemaVersion": "0.0.3"
},
"pages": {
"configuration": {
"title": "",
"tabs": [
{
"name": "a",
"title": "",
"entity": []
}
]
},
"inputs": {
"title": "Inputs",
"table": {
"header": [
{
"field": "name",
"label": "Input Name"
}
],
"moreInfo": [
{
"field": "name",
"label": "Name"
}
],
"actions": [
"edit",
"delete",
"clone"
]
},
"services": [
{
"name": "example_input_required",
"title": "Required checkbox example",
"entity": [
{
"type": "checkboxGroup",
"label": "CheckboxGroupRequired",
"field": "api3",
"required": true,
"options": {
"groups": [
{
"label": "Group 1",
"fields": [
"collect_collaboration",
"collect_file",
"collect_task",
"collect_folder_metadata"
],
"options": {
"isExpandable": true,
"expand": true
}
}
],
"rows": [
{
"field": "collect_collaboration",
"checkbox": {
"label": "Collect folder collaboration"
},
"input": {
"required": true
}
},
{
"field": "collect_file",
"checkbox": {
"label": "Collect file metadata"
},
"input": {
"defaultValue": 1,
"required": true
}
},
{
"field": "collect_task",
"checkbox": {
"label": "Collect tasks and comments"
},
"input": {
"defaultValue": 1,
"required": true
}
},
{
"field": "collect_folder_metadata",
"checkbox": {
"label": "Collect folder metadata"
},
"input": {
"defaultValue": 3600,
"required": true
}
}
]
}
}
]
}
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import BaseFormView from '../../BaseFormView';
import { setUnifiedConfig } from '../../../util/util';
import { serverHandlers } from '../checkboxGroupMocks';
import checkboxGroupConfig from '../checkboxGroupMocks.json';
import checkboxGroupRequiredConfig from '../checkboxGroupRequiredMocks.json';
import InputPage from '../../../pages/Input/InputPage';

const meta = {
Expand Down Expand Up @@ -37,3 +38,20 @@ export default meta;
type Story = StoryObj<typeof BaseFormView>;

export const InputPageView: Story = {};

export const RequiredView: Story = {
args: {
globalConfig: checkboxGroupRequiredConfig,
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);

const newInputBtn = canvas.getByRole('button', { name: 'Create New Input' });
await userEvent.click(newInputBtn);

const root = within(canvasElement.ownerDocument.body);
await expect(await root.findByRole('dialog')).toBeVisible();

await userEvent.click(await root.findByText('Add'));
},
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.