Skip to content

Commit

Permalink
Fix FormulaWidget column check (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Clebal authored Jun 22, 2022
1 parent 18fbb75 commit a153d4f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Not released

- Fix FormulaWidget column check [#437](https://github.com/CartoDB/carto-react/pull/437)

## 1.3

### 1.3.0-beta.2 (2022-06-20)
Expand Down
6 changes: 4 additions & 2 deletions packages/react-widgets/src/widgets/utils/propTypesFns.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ export const checkFormulaColumn = (props, propName) => {
const isValidString = !!propValue && typeof propValue === 'string';
const isValidArray = Array.isArray(propValue) && propValue.length;

const isValid = isValidString || isValidArray;

const validationError = new Error(`Prop ${propName} must be a string or an array`);

if (props.operation === AggregationTypes.COUNT) {
if (propValue && !(isValidString || isValidArray)) {
if (propValue && !isValid) {
return validationError;
}
} else {
if (!propValue) {
return new Error(`Prop ${propName} must be defined`);
}

if (!isValidArray || !isValidString) {
if (!isValid) {
return validationError;
}
}
Expand Down

0 comments on commit a153d4f

Please sign in to comment.