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