diff --git a/splunk_add_on_ucc_framework/schema/schema.json b/splunk_add_on_ucc_framework/schema/schema.json index d2304217a7..face132782 100644 --- a/splunk_add_on_ucc_framework/schema/schema.json +++ b/splunk_add_on_ucc_framework/schema/schema.json @@ -975,6 +975,9 @@ } ] } + }, + "required" : { + "type": "boolean" } }, "required": ["field", "label", "type", "options"], diff --git a/tests/unit/testdata/valid_config.json b/tests/unit/testdata/valid_config.json index 7b9a3fe143..649e704391 100644 --- a/tests/unit/testdata/valid_config.json +++ b/tests/unit/testdata/valid_config.json @@ -1000,6 +1000,7 @@ "type": "checkboxGroup", "label": "Mixed", "field": "api3", + "required": true, "options": { "groups": [ { diff --git a/ui/src/components/BaseFormView.tsx b/ui/src/components/BaseFormView.tsx index 4962ce9496..ac1c23952b 100644 --- a/ui/src/components/BaseFormView.tsx +++ b/ui/src/components/BaseFormView.tsx @@ -944,7 +944,7 @@ class BaseFormView extends PureComponent { ) => { 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; diff --git a/ui/src/components/CheckboxGroup/checkboxGroupRequiredMocks.json b/ui/src/components/CheckboxGroup/checkboxGroupRequiredMocks.json new file mode 100644 index 0000000000..8bb7f3213b --- /dev/null +++ b/ui/src/components/CheckboxGroup/checkboxGroupRequiredMocks.json @@ -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 + } + } + ] + } + } + ] + } + ] + } + } +} \ No newline at end of file diff --git a/ui/src/components/CheckboxGroup/stories/CheckboxGroupInputPage.stories.tsx b/ui/src/components/CheckboxGroup/stories/CheckboxGroupInputPage.stories.tsx index b469e85efa..3329003b5d 100644 --- a/ui/src/components/CheckboxGroup/stories/CheckboxGroupInputPage.stories.tsx +++ b/ui/src/components/CheckboxGroup/stories/CheckboxGroupInputPage.stories.tsx @@ -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 = { @@ -37,3 +38,20 @@ export default meta; type Story = StoryObj; 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')); + }, +}; diff --git a/ui/src/components/CheckboxGroup/stories/__images__/CheckboxGroup-required-view-chromium.png b/ui/src/components/CheckboxGroup/stories/__images__/CheckboxGroup-required-view-chromium.png new file mode 100644 index 0000000000..0e4d851e1e --- /dev/null +++ b/ui/src/components/CheckboxGroup/stories/__images__/CheckboxGroup-required-view-chromium.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8fa0b818f314fcde49b9f63bfcfba2d1c6211ee8588dfc98cbb5a27de0a0fff0 +size 42374