From b7c0405d202229f629e5fc18dd4ada3939396194 Mon Sep 17 00:00:00 2001 From: Roman Letsuk Date: Fri, 10 May 2024 15:49:40 +0300 Subject: [PATCH 1/4] FIO-8281: fixed sync validation error for select component with url data src --- src/process/validation/rules/validateAvailableItems.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/process/validation/rules/validateAvailableItems.ts b/src/process/validation/rules/validateAvailableItems.ts index 069311e4..05d4b2e1 100644 --- a/src/process/validation/rules/validateAvailableItems.ts +++ b/src/process/validation/rules/validateAvailableItems.ts @@ -156,6 +156,8 @@ function getAvailableSelectValuesSync(component: SelectComponent, context: Valid 'validate:validateAvailableItems' ); } + case 'url': + return null; default: throw new ProcessorError( `Failed to validate available values in select component '${component.key}': data source ${component.dataSrc} is not valid}`, From 5a2c62c5dafa8cdffa815ec18ac716996563fe52 Mon Sep 17 00:00:00 2001 From: Roman Letsuk Date: Tue, 14 May 2024 16:20:02 +0300 Subject: [PATCH 2/4] FIO-8281: added test cases --- .../__tests__/validateAvailableItems.test.ts | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/process/validation/rules/__tests__/validateAvailableItems.test.ts b/src/process/validation/rules/__tests__/validateAvailableItems.test.ts index f35f2641..04efa22c 100644 --- a/src/process/validation/rules/__tests__/validateAvailableItems.test.ts +++ b/src/process/validation/rules/__tests__/validateAvailableItems.test.ts @@ -9,7 +9,7 @@ import { simpleSelectOptions, } from './fixtures/components'; import { generateProcessorContext } from './fixtures/util'; -import { validateAvailableItems } from '../validateAvailableItems'; +import { validateAvailableItems, validateAvailableItemsSync } from '../validateAvailableItems'; it('Validating a component without the available items validation parameter will return null', async () => { const component = simpleTextField; @@ -120,6 +120,43 @@ it('Validating a simple URL select component without the available items validat expect(result).to.equal(null); }); +it('Validating a simple URL select component synchronously will return null', async () => { + const component: SelectComponent = { + ...simpleSelectOptions, + dataSrc: 'url', + data: { + url: 'http://localhost:8080/numbers', + headers: [], + }, + validate: { onlyAvailableItems: true }, + }; + const data = { + component: 'foo', + }; + const context = generateProcessorContext(component, data); + const result = validateAvailableItemsSync(context); + expect(result).to.equal(null); +}); + +it('Validating a multiple URL select component synchronously will return null', async () => { + const component: SelectComponent = { + ...simpleSelectOptions, + dataSrc: 'url', + data: { + url: 'http://localhost:8080/numbers', + headers: [], + }, + multiple: true, + validate: { onlyAvailableItems: true }, + }; + const data = { + component: ['foo'], + }; + const context = generateProcessorContext(component, data); + const result = validateAvailableItemsSync(context); + expect(result).to.equal(null); +}); + it('Validating a simple JSON select component (string JSON) without the available items validation parameter will return null', async () => { const component: SelectComponent = { ...simpleSelectOptions, From 7f662e7bfffa5307b52a8b983402b4eaa8c2c453 Mon Sep 17 00:00:00 2001 From: Hanna Kurban Date: Mon, 20 May 2024 15:52:47 +0300 Subject: [PATCH 3/4] FIO-8254 fixed available values validation error for Select component --- .../__tests__/validateAvailableItems.test.ts | 22 +++++++++++++++++++ .../rules/validateAvailableItems.ts | 8 ++++++- src/types/Component.ts | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/process/validation/rules/__tests__/validateAvailableItems.test.ts b/src/process/validation/rules/__tests__/validateAvailableItems.test.ts index f35f2641..5ec100e1 100644 --- a/src/process/validation/rules/__tests__/validateAvailableItems.test.ts +++ b/src/process/validation/rules/__tests__/validateAvailableItems.test.ts @@ -103,6 +103,28 @@ it('Validating a simple static values select component with the available items expect(result).to.equal(null); }); +it('Validating a simple static values select component with the available items validation parameter will return null if the selected item is valid and dataSrc is not specified', async () => { + const component: SelectComponent = { + ...simpleSelectOptions, + dataSrc: undefined, + data: { + values: [ + { label: 'foo', value: 'foo' }, + { label: 'bar', value: 'bar' }, + { label: 'baz', value: 'baz' }, + { label: 'baz', value: 'baz' }, + ], + }, + validate: { onlyAvailableItems: true }, + }; + const data = { + component: 'foo', + }; + const context = generateProcessorContext(component, data); + const result = await validateAvailableItems(context); + expect(result).to.equal(null); +}); + it('Validating a simple URL select component without the available items validation parameter will return null', async () => { const component: SelectComponent = { ...simpleSelectOptions, diff --git a/src/process/validation/rules/validateAvailableItems.ts b/src/process/validation/rules/validateAvailableItems.ts index 069311e4..07511a77 100644 --- a/src/process/validation/rules/validateAvailableItems.ts +++ b/src/process/validation/rules/validateAvailableItems.ts @@ -1,4 +1,4 @@ -import isEmpty from 'lodash/isEmpty'; +import { isEmpty, isUndefined} from 'lodash'; import { FieldError, ProcessorError } from 'error'; import { Evaluator } from 'utils'; import { RadioComponent, SelectComponent, RuleFn, RuleFnSync, ValidationContext } from 'types'; @@ -37,6 +37,9 @@ function mapStaticValues(values: { label: string; value: string }[]) { } async function getAvailableSelectValues(component: SelectComponent, context: ValidationContext) { + if (isUndefined(component.dataSrc) && component.data.hasOwnProperty('values')) { + component.dataSrc = 'values'; + }; switch (component.dataSrc) { case 'values': if (Array.isArray(component.data.values)) { @@ -107,6 +110,9 @@ async function getAvailableSelectValues(component: SelectComponent, context: Val } function getAvailableSelectValuesSync(component: SelectComponent, context: ValidationContext) { + if (isUndefined(component.dataSrc) && component.data.hasOwnProperty('values')) { + component.dataSrc = 'values'; + }; switch (component.dataSrc) { case 'values': if (Array.isArray(component.data?.values)) { diff --git a/src/types/Component.ts b/src/types/Component.ts index c050eb8d..f76f79f8 100644 --- a/src/types/Component.ts +++ b/src/types/Component.ts @@ -344,7 +344,7 @@ type StaticValuesSelectData = { data: { values: { label: string; value: string }[]; }; - dataSrc: 'values'; + dataSrc?: undefined | 'values'; }; type JsonValuesSelectData = { From 74ac883e3d7d8cf7eec33b8b0164cb06567c0ad6 Mon Sep 17 00:00:00 2001 From: lane-formio Date: Fri, 24 May 2024 15:20:19 -0500 Subject: [PATCH 4/4] Update Changelog.md --- Changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changelog.md b/Changelog.md index 6dba3606..e8ae3304 100644 --- a/Changelog.md +++ b/Changelog.md @@ -22,6 +22,8 @@ - FIO-8336 fix validation on multiple values - FIO-8037: added number component normalization - FIO-8288: do not validate dates in textfield components with calendar widgets + - FIO-8254 fixed available values validation error for Select component + - FIO-8281: fixed sync validation error for select component with url data src ## 2.0.0-rc.24