mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-04 13:48:56 +02:00
limit items in filters
This commit is contained in:
parent
66ceab1fbf
commit
e5863cc0fe
@ -1,13 +1,19 @@
|
|||||||
import {
|
import {
|
||||||
|
Alert,
|
||||||
Autocomplete,
|
Autocomplete,
|
||||||
Box,
|
|
||||||
Checkbox,
|
Checkbox,
|
||||||
Chip,
|
Chip,
|
||||||
FormControlLabel,
|
FormControlLabel,
|
||||||
|
styled,
|
||||||
TextField,
|
TextField,
|
||||||
|
Typography,
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import type { FC } from 'react';
|
import type { FC } from 'react';
|
||||||
|
|
||||||
|
const StyledSelectAllLabel = styled('span')(({ theme }) => ({
|
||||||
|
fontSize: theme.fontSizes.smallBody,
|
||||||
|
}));
|
||||||
|
|
||||||
type LabelFilterItemProps = {
|
type LabelFilterItemProps = {
|
||||||
labelKey: string;
|
labelKey: string;
|
||||||
options: string[];
|
options: string[];
|
||||||
@ -25,6 +31,7 @@ export const LabelFilterItem: FC<LabelFilterItemProps> = ({
|
|||||||
const isAllSelected = value.includes('*');
|
const isAllSelected = value.includes('*');
|
||||||
const autocompleteId = `autocomplete-${labelKey}`;
|
const autocompleteId = `autocomplete-${labelKey}`;
|
||||||
const selectAllId = `select-all-${labelKey}`;
|
const selectAllId = `select-all-${labelKey}`;
|
||||||
|
const isTruncated = options.length >= 1_000;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -46,16 +53,7 @@ export const LabelFilterItem: FC<LabelFilterItemProps> = ({
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
label={
|
label={<StyledSelectAllLabel>Select all</StyledSelectAllLabel>}
|
||||||
<Box
|
|
||||||
component='span'
|
|
||||||
sx={(theme) => ({
|
|
||||||
fontSize: theme.fontSizes.smallBody,
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
Select all
|
|
||||||
</Box>
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
multiple
|
multiple
|
||||||
@ -66,37 +64,68 @@ export const LabelFilterItem: FC<LabelFilterItemProps> = ({
|
|||||||
onChange(newValues);
|
onChange(newValues);
|
||||||
}}
|
}}
|
||||||
disabled={isAllSelected}
|
disabled={isAllSelected}
|
||||||
renderTags={(value, getTagProps) =>
|
renderTags={(value, getTagProps) => {
|
||||||
value.map((option, index) => {
|
const overflowCount = 5;
|
||||||
const { key, ...chipProps } = getTagProps({
|
const displayedValues = value.slice(-overflowCount);
|
||||||
index,
|
const remainingCount = value.length - overflowCount;
|
||||||
});
|
|
||||||
return (
|
return (
|
||||||
<Chip
|
<>
|
||||||
{...chipProps}
|
{displayedValues.map((option, index) => {
|
||||||
key={key}
|
const { key, ...chipProps } = getTagProps({
|
||||||
label={option}
|
index,
|
||||||
size='small'
|
});
|
||||||
/>
|
return (
|
||||||
);
|
<Chip
|
||||||
})
|
{...chipProps}
|
||||||
}
|
key={key}
|
||||||
|
label={option}
|
||||||
|
size='small'
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
{remainingCount > 0 ? (
|
||||||
|
<Typography
|
||||||
|
component='span'
|
||||||
|
sx={{ color: 'text.secondary' }}
|
||||||
|
>
|
||||||
|
{' '}
|
||||||
|
(+{remainingCount})
|
||||||
|
</Typography>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}}
|
||||||
renderInput={(params) => (
|
renderInput={(params) => (
|
||||||
<TextField
|
<>
|
||||||
{...params}
|
<TextField
|
||||||
label={labelKey}
|
{...params}
|
||||||
placeholder={
|
label={labelKey}
|
||||||
isAllSelected ? undefined : 'Select values…'
|
placeholder={
|
||||||
}
|
isAllSelected ? undefined : 'Select values…'
|
||||||
variant='outlined'
|
}
|
||||||
size='small'
|
variant='outlined'
|
||||||
inputProps={{
|
size='small'
|
||||||
...params.inputProps,
|
inputProps={{
|
||||||
'aria-describedby': isAllSelected
|
...params.inputProps,
|
||||||
? `${selectAllId}-description`
|
'aria-describedby': isAllSelected
|
||||||
: undefined,
|
? `${selectAllId}-description`
|
||||||
}}
|
: undefined,
|
||||||
/>
|
}}
|
||||||
|
/>
|
||||||
|
{isTruncated && (
|
||||||
|
<Alert
|
||||||
|
severity='warning'
|
||||||
|
sx={(theme) => ({
|
||||||
|
padding: theme.spacing(1, 2),
|
||||||
|
marginTop: theme.spacing(1),
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
Maximum of 1000 values loaded due to
|
||||||
|
performance.
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
Loading…
Reference in New Issue
Block a user