mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-31 13:47:02 +02:00
Remove uses of one of / use operator checks instead (#10328)
Updates a few remaining places where we check constraint operators with
the new constraint operator checks. Additionally, because there was only
one remaining place where we used the `oneOf` function, I replaced it
with a normal `includes` check and deleted the `oneOf` util. From what I
can tell, there's no need to have that utility function; it doesn't
provide much benefit over using the language built-ins 🤷🏼
This commit is contained in:
parent
068ef585be
commit
e2853acf15
@ -11,13 +11,13 @@ import Input from 'component/common/Input/Input';
|
|||||||
import { ProjectActionsFormItem } from '../ProjectActionsFormItem.tsx';
|
import { ProjectActionsFormItem } from '../ProjectActionsFormItem.tsx';
|
||||||
import {
|
import {
|
||||||
inOperators,
|
inOperators,
|
||||||
|
isStringOperator,
|
||||||
numOperators,
|
numOperators,
|
||||||
type Operator,
|
type Operator,
|
||||||
semVerOperators,
|
semVerOperators,
|
||||||
stringOperators,
|
stringOperators,
|
||||||
} from 'constants/operators';
|
} from 'constants/operators';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { oneOf } from 'utils/oneOf';
|
|
||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
import { CaseSensitiveButton } from './StyledToggleButton/CaseSensitiveButton/CaseSensitiveButton.tsx';
|
import { CaseSensitiveButton } from './StyledToggleButton/CaseSensitiveButton/CaseSensitiveButton.tsx';
|
||||||
import { InvertedOperatorButton } from './StyledToggleButton/InvertedOperatorButton/InvertedOperatorButton.tsx';
|
import { InvertedOperatorButton } from './StyledToggleButton/InvertedOperatorButton/InvertedOperatorButton.tsx';
|
||||||
@ -169,7 +169,7 @@ export const ProjectActionsFilterItem = ({
|
|||||||
}, [value, error]);
|
}, [value, error]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (oneOf(stringOperators, operator)) {
|
if (isStringOperator(operator)) {
|
||||||
setShowCaseSensitiveButton(true);
|
setShowCaseSensitiveButton(true);
|
||||||
} else {
|
} else {
|
||||||
setShowCaseSensitiveButton(false);
|
setShowCaseSensitiveButton(false);
|
||||||
@ -177,7 +177,7 @@ export const ProjectActionsFilterItem = ({
|
|||||||
}, [operator]);
|
}, [operator]);
|
||||||
|
|
||||||
const onOperatorChange = (operator: Operator) => {
|
const onOperatorChange = (operator: Operator) => {
|
||||||
if (oneOf(stringOperators, operator)) {
|
if (isStringOperator(operator)) {
|
||||||
setShowCaseSensitiveButton(true);
|
setShowCaseSensitiveButton(true);
|
||||||
} else {
|
} else {
|
||||||
setShowCaseSensitiveButton(false);
|
setShowCaseSensitiveButton(false);
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { Alert } from '@mui/material';
|
import { Alert } from '@mui/material';
|
||||||
import { oneOf } from 'utils/oneOf';
|
|
||||||
import type { ChangeRequestType } from '../component/changeRequest/changeRequest.types';
|
import type { ChangeRequestType } from '../component/changeRequest/changeRequest.types';
|
||||||
|
|
||||||
export const useChangeRequestInReviewWarning = (
|
export const useChangeRequestInReviewWarning = (
|
||||||
@ -11,7 +10,7 @@ export const useChangeRequestInReviewWarning = (
|
|||||||
return draft.some(
|
return draft.some(
|
||||||
(changeRequest) =>
|
(changeRequest) =>
|
||||||
changeRequest.environment === environment &&
|
changeRequest.environment === environment &&
|
||||||
oneOf(['In review', 'Approved'], changeRequest.state),
|
['In review', 'Approved'].includes(changeRequest.state),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
import { singleValueOperators } from 'constants/operators';
|
|
||||||
import type { IConstraint } from 'interfaces/strategy';
|
import type { IConstraint } from 'interfaces/strategy';
|
||||||
import { oneOf } from 'utils/oneOf';
|
|
||||||
import produce from 'immer';
|
import produce from 'immer';
|
||||||
|
import { isSingleValueOperator } from 'constants/operators';
|
||||||
|
|
||||||
export const cleanConstraint = (
|
export const cleanConstraint = (
|
||||||
constraint: Readonly<IConstraint>,
|
constraint: Readonly<IConstraint>,
|
||||||
): IConstraint => {
|
): IConstraint => {
|
||||||
return produce(constraint, (draft) => {
|
return produce(constraint, (draft) => {
|
||||||
if (oneOf(singleValueOperators, constraint.operator)) {
|
if (isSingleValueOperator(constraint.operator)) {
|
||||||
delete draft.values;
|
delete draft.values;
|
||||||
} else {
|
} else {
|
||||||
delete draft.value;
|
delete draft.value;
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
export const oneOf = (values: string[], match: string) => {
|
|
||||||
return values.some((value) => value === match);
|
|
||||||
};
|
|
@ -1,23 +1,22 @@
|
|||||||
import {
|
import {
|
||||||
allOperators,
|
allOperators,
|
||||||
dateOperators,
|
isDateOperator,
|
||||||
type Operator,
|
type Operator,
|
||||||
} from 'constants/operators';
|
} from 'constants/operators';
|
||||||
import { oneOf } from 'utils/oneOf';
|
|
||||||
|
|
||||||
export const CURRENT_TIME_CONTEXT_FIELD = 'currentTime';
|
export const CURRENT_TIME_CONTEXT_FIELD = 'currentTime';
|
||||||
|
|
||||||
export const operatorsForContext = (contextName: string): Operator[] => {
|
export const operatorsForContext = (contextName: string): Operator[] => {
|
||||||
return allOperators.filter((operator) => {
|
return allOperators.filter((operator) => {
|
||||||
if (
|
if (
|
||||||
oneOf(dateOperators, operator) &&
|
isDateOperator(operator) &&
|
||||||
contextName !== CURRENT_TIME_CONTEXT_FIELD
|
contextName !== CURRENT_TIME_CONTEXT_FIELD
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!oneOf(dateOperators, operator) &&
|
!isDateOperator(operator) &&
|
||||||
contextName === CURRENT_TIME_CONTEXT_FIELD
|
contextName === CURRENT_TIME_CONTEXT_FIELD
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user