mirror of
https://github.com/Unleash/unleash.git
synced 2025-03-18 00:19:49 +01:00
Chore: constraint context field legal values improvement (#6729)
Improves how we show context field legal values in the new strategy configuration. Refactored makeStyles to styled components Closes # [1-2235](https://linear.app/unleash/issue/1-2235/context-field-ui-in-strategy-configuration) Before:  After:  Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
parent
d3847fd8ee
commit
81aff26394
frontend/src/component/common/NewConstraintAccordion/ConstraintAccordionEdit/ConstraintAccordionEditBody
LegalValueLabel
RestrictiveLegalValues
@ -1,17 +1,24 @@
|
|||||||
import { makeStyles } from 'tss-react/mui';
|
import { styled } from '@mui/material';
|
||||||
|
|
||||||
export const useStyles = makeStyles()((theme) => ({
|
export const StyledContainer = styled('div')(({ theme }) => ({
|
||||||
container: {
|
display: 'inline-block',
|
||||||
display: 'inline-block',
|
wordBreak: 'break-word',
|
||||||
wordBreak: 'break-word',
|
padding: theme.spacing(0.5, 1),
|
||||||
},
|
background: theme.palette.common.white,
|
||||||
value: {
|
border: `1px solid ${theme.palette.divider}`,
|
||||||
lineHeight: 1.33,
|
borderRadius: theme.shape.borderRadius,
|
||||||
fontSize: theme.fontSizes.smallBody,
|
|
||||||
},
|
'&:hover': {
|
||||||
description: {
|
border: `2px solid ${theme.palette.primary.main}`,
|
||||||
lineHeight: 1.33,
|
|
||||||
fontSize: theme.fontSizes.smallerBody,
|
|
||||||
color: theme.palette.action.active,
|
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
export const StyledValue = styled('div')(({ theme }) => ({
|
||||||
|
lineHeight: 1.33,
|
||||||
|
fontSize: theme.fontSizes.smallBody,
|
||||||
|
}));
|
||||||
|
export const StyledDescription = styled('div')(({ theme }) => ({
|
||||||
|
lineHeight: 1.33,
|
||||||
|
fontSize: theme.fontSizes.smallerBody,
|
||||||
|
color: theme.palette.action.active,
|
||||||
|
}));
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
import type { ILegalValue } from 'interfaces/context';
|
import type { ILegalValue } from 'interfaces/context';
|
||||||
import { useStyles } from './LegalValueLabel.styles';
|
import {
|
||||||
|
StyledContainer,
|
||||||
|
StyledValue,
|
||||||
|
StyledDescription,
|
||||||
|
} from './LegalValueLabel.styles';
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
import { FormControlLabel } from '@mui/material';
|
import { FormControlLabel } from '@mui/material';
|
||||||
|
|
||||||
@ -9,23 +13,21 @@ interface ILegalValueTextProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const LegalValueLabel = ({ legal, control }: ILegalValueTextProps) => {
|
export const LegalValueLabel = ({ legal, control }: ILegalValueTextProps) => {
|
||||||
const { classes: styles } = useStyles();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<StyledContainer>
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
value={legal.value}
|
value={legal.value}
|
||||||
control={control}
|
control={control}
|
||||||
label={
|
label={
|
||||||
<>
|
<>
|
||||||
<div className={styles.value}>{legal.value}</div>
|
<StyledValue>{legal.value}</StyledValue>
|
||||||
<div className={styles.description}>
|
<StyledDescription>
|
||||||
{legal.description}
|
{legal.description}
|
||||||
</div>
|
</StyledDescription>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</StyledContainer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
import { Alert, Checkbox } from '@mui/material';
|
import { Alert, Checkbox, styled } from '@mui/material';
|
||||||
import { useThemeStyles } from 'themes/themeStyles';
|
import { useThemeStyles } from 'themes/themeStyles';
|
||||||
import { ConstraintValueSearch } from 'component/common/ConstraintAccordion/ConstraintValueSearch/ConstraintValueSearch';
|
import { ConstraintValueSearch } from 'component/common/ConstraintAccordion/ConstraintValueSearch/ConstraintValueSearch';
|
||||||
import { ConstraintFormHeader } from '../ConstraintFormHeader/ConstraintFormHeader';
|
import { ConstraintFormHeader } from '../ConstraintFormHeader/ConstraintFormHeader';
|
||||||
@ -50,6 +50,17 @@ export const getIllegalValues = (
|
|||||||
return constraintValues.filter((value) => deletedValuesSet.has(value));
|
return constraintValues.filter((value) => deletedValuesSet.has(value));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const StyledValuesContainer = styled('div')(({ theme }) => ({
|
||||||
|
display: 'flex',
|
||||||
|
flexWrap: 'wrap',
|
||||||
|
gap: theme.spacing(1),
|
||||||
|
padding: theme.spacing(2),
|
||||||
|
border: `1px solid ${theme.palette.divider}`,
|
||||||
|
borderRadius: theme.shape.borderRadiusMedium,
|
||||||
|
maxHeight: '378px',
|
||||||
|
overflow: 'auto',
|
||||||
|
}));
|
||||||
|
|
||||||
export const RestrictiveLegalValues = ({
|
export const RestrictiveLegalValues = ({
|
||||||
data,
|
data,
|
||||||
values,
|
values,
|
||||||
@ -136,24 +147,25 @@ export const RestrictiveLegalValues = ({
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{filteredValues.map((match) => (
|
<StyledValuesContainer>
|
||||||
<LegalValueLabel
|
{filteredValues.map((match) => (
|
||||||
key={match.value}
|
<LegalValueLabel
|
||||||
legal={match}
|
key={match.value}
|
||||||
control={
|
legal={match}
|
||||||
<Checkbox
|
control={
|
||||||
checked={Boolean(valuesMap[match.value])}
|
<Checkbox
|
||||||
onChange={() => onChange(match.value)}
|
checked={Boolean(valuesMap[match.value])}
|
||||||
name={match.value}
|
onChange={() => onChange(match.value)}
|
||||||
color='primary'
|
name={match.value}
|
||||||
disabled={deletedLegalValues
|
color='primary'
|
||||||
.map(({ value }) => value)
|
disabled={deletedLegalValues
|
||||||
.includes(match.value)}
|
.map(({ value }) => value)
|
||||||
/>
|
.includes(match.value)}
|
||||||
}
|
/>
|
||||||
/>
|
}
|
||||||
))}
|
/>
|
||||||
|
))}
|
||||||
|
</StyledValuesContainer>
|
||||||
<ConditionallyRender
|
<ConditionallyRender
|
||||||
condition={Boolean(error)}
|
condition={Boolean(error)}
|
||||||
show={<p className={styles.error}>{error}</p>}
|
show={<p className={styles.error}>{error}</p>}
|
||||||
|
Loading…
Reference in New Issue
Block a user