From 44e9023fb3e8acf6f6a26497c90ef670566d91ea Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Fri, 25 Apr 2025 12:23:18 +0200 Subject: [PATCH] Don't show extra input component if we have "add values" button (#9842) Makes it so that the InputContainer is only rendered if we don't have the add values button up top. We might need to adjust this later (as we get more sketches for other input types, such as single numbers, single semvers etc), but it works for now. With legal values (no add values button) image Without legal values (but add values button) image Because we don't handle single value cases yet, some of those inputs are still stuck in an in-between state: image --- .../EditableConstraint.tsx | 66 ++++++------------- 1 file changed, 20 insertions(+), 46 deletions(-) diff --git a/frontend/src/component/feature/FeatureStrategy/FeatureStrategyConstraints/EditableConstraint.tsx b/frontend/src/component/feature/FeatureStrategy/FeatureStrategyConstraints/EditableConstraint.tsx index fa19e6756d..5b3564726f 100644 --- a/frontend/src/component/feature/FeatureStrategy/FeatureStrategyConstraints/EditableConstraint.tsx +++ b/frontend/src/component/feature/FeatureStrategy/FeatureStrategyConstraints/EditableConstraint.tsx @@ -9,10 +9,7 @@ import { type Operator, } from 'constants/operators'; import useUnleashContext from 'hooks/api/getters/useUnleashContext/useUnleashContext'; -import type { - ILegalValue, - IUnleashContextDefinition, -} from 'interfaces/context'; +import type { IUnleashContextDefinition } from 'interfaces/context'; import type { IConstraint } from 'interfaces/strategy'; import { useEffect, useRef, useState, type FC } from 'react'; import { oneOf } from 'utils/oneOf'; @@ -43,35 +40,8 @@ const TopRow = styled('div')(({ theme }) => ({ flexFlow: 'row nowrap', alignItems: 'flex-start', justifyItems: 'space-between', - borderBottom: `1px dashed ${theme.palette.divider}`, })); -const resolveLegalValues = ( - values: IConstraint['values'], - legalValues: IUnleashContextDefinition['legalValues'], -): { legalValues: ILegalValue[]; deletedLegalValues: ILegalValue[] } => { - if (legalValues?.length === 0) { - return { - legalValues: [], - deletedLegalValues: [], - }; - } - - const deletedLegalValues = (values || []) - .filter( - (value) => - !(legalValues || []).some( - ({ value: legalValue }) => legalValue === value, - ), - ) - .map((v) => ({ value: v, description: '' })); - - return { - legalValues: legalValues || [], - deletedLegalValues, - }; -}; - const ConstraintDetails = styled('div')(({ theme }) => ({ display: 'flex', gap: theme.spacing(1), @@ -82,6 +52,7 @@ const ConstraintDetails = styled('div')(({ theme }) => ({ const InputContainer = styled('div')(({ theme }) => ({ padding: 'var(--padding)', + borderTop: `1px dashed ${theme.palette.divider}`, })); const StyledSelect = styled(GeneralSelect)(({ theme }) => ({ @@ -186,6 +157,7 @@ export const EditableConstraint: FC = ({ const addValuesButtonRef = useRef(null); const showAddValuesButton = OPERATORS_WITH_ADD_VALUES_WIDGET.includes(input); + const showInputField = !showAddValuesButton; /* We need a special case to handle the currentTime context field. Since this field will be the only one to allow DATE_BEFORE and DATE_AFTER operators @@ -330,21 +302,23 @@ export const EditableConstraint: FC = ({ - - - + {showInputField ? ( + + + + ) : null} ); };