1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

fix: ignore empty legal values arrays (#893)

This commit is contained in:
olav 2022-04-20 15:57:01 +02:00 committed by GitHub
parent 1095f4d157
commit 89288f2835
3 changed files with 8 additions and 8 deletions

View File

@ -8,7 +8,6 @@ import {
import { IUnleashContextDefinition } from 'interfaces/context';
import { IConstraint } from 'interfaces/strategy';
import React, { useCallback, useEffect, useState } from 'react';
import { exists } from 'utils/exists';
import { oneOf } from 'utils/oneOf';
import {
@ -18,6 +17,7 @@ import {
dateValidatorGenerator,
ConstraintValidatorOutput,
} from './constraintValidators';
import { nonEmptyArray } from 'utils/nonEmptyArray';
interface IUseConstraintInputProps {
contextDefinition: IUnleashContextDefinition;
@ -75,22 +75,22 @@ export const useConstraintInput = ({
const resolveInputType = useCallback(() => {
if (
exists(contextDefinition.legalValues) &&
nonEmptyArray(contextDefinition.legalValues) &&
oneOf(inOperators, localConstraint.operator)
) {
setInput(IN_OPERATORS_LEGAL_VALUES);
} else if (
exists(contextDefinition.legalValues) &&
nonEmptyArray(contextDefinition.legalValues) &&
oneOf(stringOperators, localConstraint.operator)
) {
setInput(STRING_OPERATORS_LEGAL_VALUES);
} else if (
exists(contextDefinition.legalValues) &&
nonEmptyArray(contextDefinition.legalValues) &&
oneOf(numOperators, localConstraint.operator)
) {
setInput(NUM_OPERATORS_LEGAL_VALUES);
} else if (
exists(contextDefinition.legalValues) &&
nonEmptyArray(contextDefinition.legalValues) &&
oneOf(semVerOperators, localConstraint.operator)
) {
setInput(SEMVER_OPERATORS_LEGAL_VALUES);

View File

@ -1,3 +0,0 @@
export const exists = (value: any) => {
return Boolean(value);
};

View File

@ -0,0 +1,3 @@
export const nonEmptyArray = (value: unknown): boolean => {
return Boolean(value) && Array.isArray(value) && value.length > 0;
};