Skip to content

Commit

Permalink
correctly handle unique validation not requiring a value
Browse files Browse the repository at this point in the history
  • Loading branch information
jthrilly committed May 30, 2024
1 parent 06fbc91 commit dfdfcb4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "network-canvas-architect",
"version": "6.5.2",
"version": "6.5.3",
"productName": "Network Canvas Architect",
"description": "A tool for building Network Canvas interviews.",
"author": "Complex Data Collective <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion public/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "network-canvas-architect",
"version": "6.5.2",
"version": "6.5.3",
"productName": "Network Canvas Architect",
"description": "A tool for building Network Canvas interviews.",
"author": "Complex Data Collective",
Expand Down
3 changes: 3 additions & 0 deletions src/components/Validations/Validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const validate = (validations) => {

const check = values.reduce(
(acc, [key, value]) => {
// 'unique' validation is a special case where there is no value
if (key === 'unique') { return acc; }

if (!isNull(value)) { return acc; }
return [...acc, key];
},
Expand Down
8 changes: 8 additions & 0 deletions src/components/Validations/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ const VALIDATIONS_WITH_LIST_VALUES = [
// 'greaterThanVariable',
];

const VALIDATIONS_WITHOUT_VALUES = [
'required',
'unique',
];

const isValidationWithoutValue = (validation) => VALIDATIONS_WITHOUT_VALUES.includes(validation);

const isValidationWithNumberValue = (validation) => (
VALIDATIONS_WITH_NUMBER_VALUES.includes(validation));
const isValidationWithListValue = (validation) => VALIDATIONS_WITH_LIST_VALUES.includes(validation);
Expand All @@ -97,6 +104,7 @@ export {
getValidationOptionsForVariableType,
isValidationWithNumberValue,
isValidationWithListValue,
isValidationWithoutValue,
VALIDATIONS,
};

Expand Down
6 changes: 3 additions & 3 deletions src/components/Validations/withUpdateHandlers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { omit } from 'lodash';
import { withHandlers } from 'recompose';
import { isValidationWithListValue, isValidationWithNumberValue } from './options';
import { isValidationWithListValue, isValidationWithNumberValue, isValidationWithoutValue } from './options';

/**
* Function called when a validation is added or updated. Returns a value
Expand All @@ -12,8 +12,8 @@ import { isValidationWithListValue, isValidationWithNumberValue } from './option
* @returns {string} The new value.
*/
const getAutoValue = (type, oldType, value) => {
// Required is special - always return true.
if (type === 'required') {
// If the validation type doesn't require a value, return true.
if (isValidationWithoutValue(type)) {
return true;
}

Expand Down

0 comments on commit dfdfcb4

Please sign in to comment.