1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-06-27 01:19:00 +02:00

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)
<img width="765" alt="image"
src="https://github.com/user-attachments/assets/032cc848-584e-4c3f-83ed-be1fb1cdc0f8"
/>

Without legal values (but add values button)
<img width="763" alt="image"
src="https://github.com/user-attachments/assets/1a8fa68e-a73b-42fc-a1b8-e8f5997f3c5d"
/>

Because we don't handle single value cases yet, some of those inputs are
still stuck in an in-between state:
<img width="775" alt="image"
src="https://github.com/user-attachments/assets/25b6ae89-9267-4f06-a32d-3460abe4a847"
/>
This commit is contained in:
Thomas Heartman 2025-04-25 12:23:18 +02:00 committed by GitHub
parent 085c62c99a
commit 44e9023fb3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,10 +9,7 @@ import {
type Operator, type Operator,
} from 'constants/operators'; } from 'constants/operators';
import useUnleashContext from 'hooks/api/getters/useUnleashContext/useUnleashContext'; import useUnleashContext from 'hooks/api/getters/useUnleashContext/useUnleashContext';
import type { import type { IUnleashContextDefinition } from 'interfaces/context';
ILegalValue,
IUnleashContextDefinition,
} from 'interfaces/context';
import type { IConstraint } from 'interfaces/strategy'; import type { IConstraint } from 'interfaces/strategy';
import { useEffect, useRef, useState, type FC } from 'react'; import { useEffect, useRef, useState, type FC } from 'react';
import { oneOf } from 'utils/oneOf'; import { oneOf } from 'utils/oneOf';
@ -43,35 +40,8 @@ const TopRow = styled('div')(({ theme }) => ({
flexFlow: 'row nowrap', flexFlow: 'row nowrap',
alignItems: 'flex-start', alignItems: 'flex-start',
justifyItems: 'space-between', 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 }) => ({ const ConstraintDetails = styled('div')(({ theme }) => ({
display: 'flex', display: 'flex',
gap: theme.spacing(1), gap: theme.spacing(1),
@ -82,6 +52,7 @@ const ConstraintDetails = styled('div')(({ theme }) => ({
const InputContainer = styled('div')(({ theme }) => ({ const InputContainer = styled('div')(({ theme }) => ({
padding: 'var(--padding)', padding: 'var(--padding)',
borderTop: `1px dashed ${theme.palette.divider}`,
})); }));
const StyledSelect = styled(GeneralSelect)(({ theme }) => ({ const StyledSelect = styled(GeneralSelect)(({ theme }) => ({
@ -186,6 +157,7 @@ export const EditableConstraint: FC<Props> = ({
const addValuesButtonRef = useRef<HTMLButtonElement>(null); const addValuesButtonRef = useRef<HTMLButtonElement>(null);
const showAddValuesButton = const showAddValuesButton =
OPERATORS_WITH_ADD_VALUES_WIDGET.includes(input); OPERATORS_WITH_ADD_VALUES_WIDGET.includes(input);
const showInputField = !showAddValuesButton;
/* We need a special case to handle the currentTime context field. Since /* 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 this field will be the only one to allow DATE_BEFORE and DATE_AFTER operators
@ -330,21 +302,23 @@ export const EditableConstraint: FC<Props> = ({
</IconButton> </IconButton>
</HtmlTooltip> </HtmlTooltip>
</TopRow> </TopRow>
<InputContainer> {showInputField ? (
<ResolveInput <InputContainer>
setValues={setValues} <ResolveInput
setValuesWithRecord={setValuesWithRecord} setValues={setValues}
setValue={setValue} setValuesWithRecord={setValuesWithRecord}
setError={setError} setValue={setValue}
localConstraint={localConstraint} setError={setError}
constraintValues={constraint?.values || []} localConstraint={localConstraint}
constraintValue={constraint?.value || ''} constraintValues={constraint?.values || []}
input={input} constraintValue={constraint?.value || ''}
error={error} input={input}
contextDefinition={contextDefinition} error={error}
removeValue={removeValue} contextDefinition={contextDefinition}
/> removeValue={removeValue}
</InputContainer> />
</InputContainer>
) : null}
</Container> </Container>
); );
}; };