Skip to content

Commit cf766a7

Browse files
authored
Merge pull request #767 from complexdatacollective/feature/validation-with-variables
expand variable validation
2 parents 4212d2b + c36d78a commit cf766a7

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

src/__mocks__/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/* eslint-env jest */
22
/* eslint-disable import/prefer-default-export */
33

4-
export const APP_SCHEMA_VERSION = 7;
4+
export const APP_SCHEMA_VERSION = 8;

src/components/Validations/options.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const VALIDATIONS = {
88
'unique',
99
'differentFrom',
1010
'sameAs',
11+
'lessThanVariable',
12+
'greaterThanVariable',
1113
],
1214
number: [
1315
'required',
@@ -16,18 +18,24 @@ const VALIDATIONS = {
1618
'unique',
1719
'differentFrom',
1820
'sameAs',
21+
'lessThanVariable',
22+
'greaterThanVariable',
1923
],
2024
datetime: [
2125
'required',
2226
'unique',
2327
'differentFrom',
2428
'sameAs',
29+
'lessThanVariable',
30+
'greaterThanVariable',
2531
],
2632
scalar: [
2733
'required',
2834
'unique',
2935
'differentFrom',
3036
'sameAs',
37+
'lessThanVariable',
38+
'greaterThanVariable',
3139
],
3240
boolean: [
3341
'required',
@@ -40,6 +48,8 @@ const VALIDATIONS = {
4048
'unique',
4149
'differentFrom',
4250
'sameAs',
51+
'lessThanVariable',
52+
'greaterThanVariable',
4353
],
4454
categorical: [
4555
'required',
@@ -63,6 +73,8 @@ const VALIDATIONS_WITH_NUMBER_VALUES = [
6373
const VALIDATIONS_WITH_LIST_VALUES = [
6474
'differentFrom',
6575
'sameAs',
76+
'lessThanVariable',
77+
'greaterThanVariable',
6678
];
6779

6880
const isValidationWithNumberValue = (validation) => (

src/components/sections/ValidationSection.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import { useSelector, useDispatch } from 'react-redux';
44
import { change, formValueSelector } from 'redux-form';
5+
import { get, pickBy } from 'lodash';
56
import { Section, Row } from '@components/EditorLayout';
67
import Validations from '@components/Validations';
78
import { getFieldId } from '../../utils/issues';
@@ -24,6 +25,7 @@ const ValidationSection = ({
2425
return true;
2526
};
2627

28+
const existingVariablesForType = pickBy(existingVariables, (variable) => get(variable, 'type') === variableType);
2729
return (
2830
<Section
2931
disabled={disabled}
@@ -43,7 +45,7 @@ const ValidationSection = ({
4345
form={form}
4446
name="validation"
4547
variableType={variableType}
46-
existingVariables={existingVariables}
48+
existingVariables={existingVariablesForType}
4749
/>
4850
</Row>
4951
</Section>

src/config/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const COLOR_PALETTE_BY_ENTITY = {
2020
};
2121

2222
// Target protocol schema version. Used to determine compatibility & migration
23-
export const APP_SCHEMA_VERSION = 7;
23+
export const APP_SCHEMA_VERSION = 8;
2424

2525
// Maps for supported asset types within the app. Used by asset chooser.
2626
export const SUPPORTED_EXTENSION_TYPE_MAP = {

0 commit comments

Comments
 (0)