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:
parent
1095f4d157
commit
89288f2835
@ -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);
|
||||
|
@ -1,3 +0,0 @@
|
||||
export const exists = (value: any) => {
|
||||
return Boolean(value);
|
||||
};
|
3
frontend/src/utils/nonEmptyArray.ts
Normal file
3
frontend/src/utils/nonEmptyArray.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export const nonEmptyArray = (value: unknown): boolean => {
|
||||
return Boolean(value) && Array.isArray(value) && value.length > 0;
|
||||
};
|
Loading…
Reference in New Issue
Block a user