Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand variable validation #767

Merged
merged 2 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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