Skip to content

Commit

Permalink
Merge pull request #767 from complexdatacollective/feature/validation…
Browse files Browse the repository at this point in the history
…-with-variables

expand variable validation
  • Loading branch information
jthrilly authored Aug 8, 2022
2 parents 4212d2b + c36d78a commit cf766a7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/__mocks__/config.js
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 12 additions & 0 deletions src/components/Validations/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const VALIDATIONS = {
'unique',
'differentFrom',
'sameAs',
'lessThanVariable',
'greaterThanVariable',
],
number: [
'required',
Expand All @@ -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',
Expand All @@ -40,6 +48,8 @@ const VALIDATIONS = {
'unique',
'differentFrom',
'sameAs',
'lessThanVariable',
'greaterThanVariable',
],
categorical: [
'required',
Expand All @@ -63,6 +73,8 @@ const VALIDATIONS_WITH_NUMBER_VALUES = [
const VALIDATIONS_WITH_LIST_VALUES = [
'differentFrom',
'sameAs',
'lessThanVariable',
'greaterThanVariable',
];

const isValidationWithNumberValue = (validation) => (
Expand Down
4 changes: 3 additions & 1 deletion src/components/sections/ValidationSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, pickBy } from 'lodash';
import { Section, Row } from '@components/EditorLayout';
import Validations from '@components/Validations';
import { getFieldId } from '../../utils/issues';
Expand All @@ -24,6 +25,7 @@ const ValidationSection = ({
return true;
};

const existingVariablesForType = pickBy(existingVariables, (variable) => get(variable, 'type') === variableType);
return (
<Section
disabled={disabled}
Expand All @@ -43,7 +45,7 @@ const ValidationSection = ({
form={form}
name="validation"
variableType={variableType}
existingVariables={existingVariables}
existingVariables={existingVariablesForType}
/>
</Row>
</Section>
Expand Down
2 changes: 1 addition & 1 deletion src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const COLOR_PALETTE_BY_ENTITY = {
};

// Target protocol schema version. Used to determine compatibility & migration
export const APP_SCHEMA_VERSION = 7;
export const APP_SCHEMA_VERSION = 8;

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

0 comments on commit cf766a7

Please sign in to comment.