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

refactor: improve constraint values form (#790)

* refactor: preserve white-space in constraint values

* refactor: deduplicate constraint values
This commit is contained in:
olav 2022-03-15 15:06:19 +01:00 committed by GitHub
parent e4b0cf1c11
commit fa72952098
4 changed files with 21 additions and 4 deletions

View File

@ -30,5 +30,8 @@ export const useStyles = makeStyles(theme => ({
column: { column: {
flexDirection: 'column', flexDirection: 'column',
}, },
values: { marginLeft: '1.5rem' }, values: {
marginLeft: '1.5rem',
whiteSpace: 'pre-wrap',
},
})); }));

View File

@ -127,6 +127,9 @@ export const useStyles = makeStyles(theme => ({
chip: { chip: {
margin: '0 0.5rem 0.5rem 0', margin: '0 0.5rem 0.5rem 0',
}, },
chipValue: {
whiteSpace: 'pre',
},
headerActions: { headerActions: {
marginLeft: 'auto', marginLeft: 'auto',
[theme.breakpoints.down(660)]: { [theme.breakpoints.down(660)]: {

View File

@ -14,7 +14,12 @@ interface IFreeTextInputProps {
} }
const useStyles = makeStyles(theme => ({ const useStyles = makeStyles(theme => ({
valueChip: { margin: '0 0.5rem 0.5rem 0' }, valueChip: {
margin: '0 0.5rem 0.5rem 0',
},
chipValue: {
whiteSpace: 'pre',
},
inputContainer: { inputContainer: {
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',
@ -74,9 +79,9 @@ export const FreeTextInput = ({
.split(',') .split(',')
.filter(values => values) .filter(values => values)
.map(value => value.trim()); .map(value => value.trim());
setValues([...values, ...newValues]); setValues(uniqueValues([...values, ...newValues]));
} else { } else {
setValues([...values, inputValues.trim()]); setValues(uniqueValues([...values, inputValues.trim()]));
} }
setInputValues(''); setInputValues('');
@ -145,6 +150,7 @@ const ConstraintValueChips = ({
text={value} text={value}
maxLength={35} maxLength={35}
maxWidth="100" maxWidth="100"
className={styles.chipValue}
/> />
} }
key={`${value}-${index}`} key={`${value}-${index}`}
@ -156,3 +162,7 @@ const ConstraintValueChips = ({
</> </>
); );
}; };
const uniqueValues = <T,>(values: T[]): T[] => {
return Array.from(new Set(values));
};

View File

@ -106,6 +106,7 @@ const MultipleValues = ({ values }: IMultipleValuesProps) => {
maxWidth="200" maxWidth="200"
text={value} text={value}
maxLength={25} maxLength={25}
className={styles.chipValue}
/> />
} }
className={styles.chip} className={styles.chip}