1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

feat: adjust styling for search filters (#5587)

This commit is contained in:
Mateusz Kwasniewski 2023-12-11 13:11:26 +01:00 committed by GitHub
parent 9bae14a2cc
commit ba50d1ef69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 2 deletions

View File

@ -67,6 +67,19 @@ describe('FilterItem Component', () => {
]);
});
it('renders explicit and extra options', async () => {
const mockState = {
operator: 'IS_ANY_OF',
values: ['1', '3', '2'],
};
const recordedChanges = setup(mockState);
const valuesElement = await screen.findByText('1, 3 +1');
await screen.findByText('is any of');
expect(valuesElement).toBeInTheDocument();
});
it('adjusts operator to match singular item', async () => {
const mockState = {
operator: 'IS_ANY_OF',

View File

@ -40,6 +40,13 @@ const StyledCategoryIconWrapper = styled('div')(({ theme }) => ({
const StyledOptions = styled('span')(({ theme }) => ({
color: theme.palette.text.primary,
fontWeight: theme.typography.fontWeightRegular,
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
overflow: 'hidden',
maxWidth: '200px',
[theme.breakpoints.up('md')]: {
maxWidth: '800px',
},
}));
const StyledIconButton = styled(IconButton)(({ theme }) => ({
@ -78,6 +85,9 @@ export const FilterItemChip: FC<IFilterItemChipProps> = ({
onDelete,
}) => {
const hasSelectedOptions = selectedOptions.length > 0;
const maxExplicitOptions = 2;
const explicitOptions = selectedOptions.slice(0, maxExplicitOptions);
const remainingOptions = selectedOptions.length - maxExplicitOptions;
return (
<StyledChip
@ -99,7 +109,10 @@ export const FilterItemChip: FC<IFilterItemChipProps> = ({
onChange={onChangeOperator}
/>
<StyledOptions>
{selectedOptions.join(', ')}
{explicitOptions.join(', ')}
{remainingOptions > 0
? ` +${remainingOptions}`
: ''}
</StyledOptions>
</>
)}

View File

@ -15,6 +15,7 @@ const StyledBox = styled(Box)(({ theme }) => ({
display: 'flex',
padding: theme.spacing(2, 3),
gap: theme.spacing(1),
flexWrap: 'wrap',
}));
export type FeatureTogglesListFilters = {
@ -122,8 +123,8 @@ export const FeatureToggleFilters: VFC<IFeatureToggleFiltersProps> = ({
filterKey: 'segment',
singularOperators: ['INCLUDE', 'DO_NOT_INCLUDE'],
pluralOperators: [
'INCLUDE_ALL_OF',
'INCLUDE_ANY_OF',
'INCLUDE_ALL_OF',
'EXCLUDE_IF_ANY_OF',
'EXCLUDE_ALL',
],