From 68537d9ca6b074de1a8ffdf291f1ad5ab17d442a Mon Sep 17 00:00:00 2001 From: Rebecca Madsen Date: Thu, 28 Apr 2022 22:25:34 -0400 Subject: [PATCH 1/2] add less than and greater than variable validation --- src/components/Validations/options.js | 12 ++++++++++++ src/components/sections/ValidationSection.js | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/components/Validations/options.js b/src/components/Validations/options.js index 4af3389cf..c5843a88b 100644 --- a/src/components/Validations/options.js +++ b/src/components/Validations/options.js @@ -8,6 +8,8 @@ const VALIDATIONS = { 'unique', 'differentFrom', 'sameAs', + 'lessThanVariable', + 'greaterThanVariable', ], number: [ 'required', @@ -16,18 +18,24 @@ const VALIDATIONS = { 'unique', 'differentFrom', 'sameAs', + 'lessThanVariable', + 'greaterThanVariable', ], datetime: [ 'required', 'unique', 'differentFrom', 'sameAs', + 'lessThanVariable', + 'greaterThanVariable', ], scalar: [ 'required', 'unique', 'differentFrom', 'sameAs', + 'lessThanVariable', + 'greaterThanVariable', ], boolean: [ 'required', @@ -40,6 +48,8 @@ const VALIDATIONS = { 'unique', 'differentFrom', 'sameAs', + 'lessThanVariable', + 'greaterThanVariable', ], categorical: [ 'required', @@ -63,6 +73,8 @@ const VALIDATIONS_WITH_NUMBER_VALUES = [ const VALIDATIONS_WITH_LIST_VALUES = [ 'differentFrom', 'sameAs', + 'lessThanVariable', + 'greaterThanVariable', ]; const isValidationWithNumberValue = (validation) => ( diff --git a/src/components/sections/ValidationSection.js b/src/components/sections/ValidationSection.js index e77401f49..add63a2e9 100644 --- a/src/components/sections/ValidationSection.js +++ b/src/components/sections/ValidationSection.js @@ -2,6 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { useSelector, useDispatch } from 'react-redux'; import { change, formValueSelector } from 'redux-form'; +import { get, filter } from 'lodash'; import { Section, Row } from '@components/EditorLayout'; import Validations from '@components/Validations'; import { getFieldId } from '../../utils/issues'; @@ -24,6 +25,7 @@ const ValidationSection = ({ return true; }; + const existingVariablesForType = filter(existingVariables, (variable) => get(variable, 'type') === variableType); return (
From c36d78a80e44e3d4e5c23c0f2819baa32e17443c Mon Sep 17 00:00:00 2001 From: Rebecca Madsen Date: Fri, 29 Apr 2022 00:09:13 -0400 Subject: [PATCH 2/2] update protocol validation --- src/__mocks__/config.js | 2 +- src/components/sections/ValidationSection.js | 4 ++-- src/config/index.js | 2 +- src/protocol-validation | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/__mocks__/config.js b/src/__mocks__/config.js index dfb266b91..cadeb302e 100644 --- a/src/__mocks__/config.js +++ b/src/__mocks__/config.js @@ -1,4 +1,4 @@ /* eslint-env jest */ /* eslint-disable import/prefer-default-export */ -export const APP_SCHEMA_VERSION = 7; +export const APP_SCHEMA_VERSION = 8; diff --git a/src/components/sections/ValidationSection.js b/src/components/sections/ValidationSection.js index add63a2e9..0891a39d6 100644 --- a/src/components/sections/ValidationSection.js +++ b/src/components/sections/ValidationSection.js @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { useSelector, useDispatch } from 'react-redux'; import { change, formValueSelector } from 'redux-form'; -import { get, filter } from 'lodash'; +import { get, pickBy } from 'lodash'; import { Section, Row } from '@components/EditorLayout'; import Validations from '@components/Validations'; import { getFieldId } from '../../utils/issues'; @@ -25,7 +25,7 @@ const ValidationSection = ({ return true; }; - const existingVariablesForType = filter(existingVariables, (variable) => get(variable, 'type') === variableType); + const existingVariablesForType = pickBy(existingVariables, (variable) => get(variable, 'type') === variableType); return (