Skip to content

Commit e101aa3

Browse files
rohanm-crestsrv-rr-github-tokenartemrys
authored
feat(CheckboxGroup): add support for required field (#1131)
- Implemented a new checkboxgroup component named "Required checkbox example" with required validation. - Updated "schema.json" and "valid_config.json" to include the "required" attribute. - Addressed the issue where the "required" validation was not functioning correctly when only a single field was present in the form. --------- Co-authored-by: srv-rr-github-token <[email protected]> Co-authored-by: Artem Rys <[email protected]>
1 parent 1e27f6a commit e101aa3

File tree

6 files changed

+141
-1
lines changed

6 files changed

+141
-1
lines changed

splunk_add_on_ucc_framework/schema/schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,9 @@
975975
}
976976
]
977977
}
978+
},
979+
"required" : {
980+
"type": "boolean"
978981
}
979982
},
980983
"required": ["field", "label", "type", "options"],

tests/unit/testdata/valid_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,7 @@
10001000
"type": "checkboxGroup",
10011001
"label": "Mixed",
10021002
"field": "api3",
1003+
"required": true,
10031004
"options": {
10041005
"groups": [
10051006
{

ui/src/components/BaseFormView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ class BaseFormView extends PureComponent<BaseFormProps, BaseFormState> {
944944
) => {
945945
const index = this.entities?.findIndex((x) => x.field === field);
946946
const validator = [{ type: 'custom', validatorFunc }];
947-
if (index && this.entities?.[index]) {
947+
if (index !== undefined && this.entities?.[index]) {
948948
// here the validators already exist for entities so new type is created here
949949
// @ts-expect-error todo create a generalized type to also consider it
950950
this.entities[index].validators = validator;
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
{
2+
"meta": {
3+
"name": "Splunk_TA_aws",
4+
"displayName": "Splunk Add-on for AWS",
5+
"version": "7.1.0",
6+
"restRoot": "restRoot",
7+
"schemaVersion": "0.0.3"
8+
},
9+
"pages": {
10+
"configuration": {
11+
"title": "",
12+
"tabs": [
13+
{
14+
"name": "a",
15+
"title": "",
16+
"entity": []
17+
}
18+
]
19+
},
20+
"inputs": {
21+
"title": "Inputs",
22+
"table": {
23+
"header": [
24+
{
25+
"field": "name",
26+
"label": "Input Name"
27+
}
28+
],
29+
"moreInfo": [
30+
{
31+
"field": "name",
32+
"label": "Name"
33+
}
34+
],
35+
"actions": [
36+
"edit",
37+
"delete",
38+
"clone"
39+
]
40+
},
41+
"services": [
42+
{
43+
"name": "example_input_required",
44+
"title": "Required checkbox example",
45+
"entity": [
46+
{
47+
"type": "checkboxGroup",
48+
"label": "CheckboxGroupRequired",
49+
"field": "api3",
50+
"required": true,
51+
"options": {
52+
"groups": [
53+
{
54+
"label": "Group 1",
55+
"fields": [
56+
"collect_collaboration",
57+
"collect_file",
58+
"collect_task",
59+
"collect_folder_metadata"
60+
],
61+
"options": {
62+
"isExpandable": true,
63+
"expand": true
64+
}
65+
}
66+
],
67+
"rows": [
68+
{
69+
"field": "collect_collaboration",
70+
"checkbox": {
71+
"label": "Collect folder collaboration"
72+
},
73+
"input": {
74+
"required": true
75+
}
76+
},
77+
{
78+
"field": "collect_file",
79+
"checkbox": {
80+
"label": "Collect file metadata"
81+
},
82+
"input": {
83+
"defaultValue": 1,
84+
"required": true
85+
}
86+
},
87+
{
88+
"field": "collect_task",
89+
"checkbox": {
90+
"label": "Collect tasks and comments"
91+
},
92+
"input": {
93+
"defaultValue": 1,
94+
"required": true
95+
}
96+
},
97+
{
98+
"field": "collect_folder_metadata",
99+
"checkbox": {
100+
"label": "Collect folder metadata"
101+
},
102+
"input": {
103+
"defaultValue": 3600,
104+
"required": true
105+
}
106+
}
107+
]
108+
}
109+
}
110+
]
111+
}
112+
]
113+
}
114+
}
115+
}

ui/src/components/CheckboxGroup/stories/CheckboxGroupInputPage.stories.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import BaseFormView from '../../BaseFormView';
55
import { setUnifiedConfig } from '../../../util/util';
66
import { serverHandlers } from '../checkboxGroupMocks';
77
import checkboxGroupConfig from '../checkboxGroupMocks.json';
8+
import checkboxGroupRequiredConfig from '../checkboxGroupRequiredMocks.json';
89
import InputPage from '../../../pages/Input/InputPage';
910

1011
const meta = {
@@ -37,3 +38,20 @@ export default meta;
3738
type Story = StoryObj<typeof BaseFormView>;
3839

3940
export const InputPageView: Story = {};
41+
42+
export const RequiredView: Story = {
43+
args: {
44+
globalConfig: checkboxGroupRequiredConfig,
45+
},
46+
play: async ({ canvasElement }) => {
47+
const canvas = within(canvasElement);
48+
49+
const newInputBtn = canvas.getByRole('button', { name: 'Create New Input' });
50+
await userEvent.click(newInputBtn);
51+
52+
const root = within(canvasElement.ownerDocument.body);
53+
await expect(await root.findByRole('dialog')).toBeVisible();
54+
55+
await userEvent.click(await root.findByText('Add'));
56+
},
57+
};
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)