mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-15 17:50:48 +02:00
fix: Project select should not expand when selecting multiple projects (#6811)
Currently when you are selecting multiple projects, the autocomplete expands indefinitely when focused. This fixes that behaviour by limiting the project select to 1 visible tag (even when focused) for Insights and 3 tags for Playground (same as it was) Closes [1-2276](https://linear.app/unleash/issue/1-2276/limit-the-project-select-height-or-expand-its-length) https://github.com/Unleash/unleash/assets/104830839/bf42a06e-8d30-49df-ac5b-a4a4f2685fa9 --------- Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
parent
761534d984
commit
00d3490764
@ -5,7 +5,7 @@ import {
|
|||||||
type SetStateAction,
|
type SetStateAction,
|
||||||
type VFC,
|
type VFC,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { Autocomplete, type SxProps, TextField } from '@mui/material';
|
import { Autocomplete, Chip, type SxProps, TextField } from '@mui/material';
|
||||||
import { renderOption } from 'component/playground/Playground/PlaygroundForm/renderOption';
|
import { renderOption } from 'component/playground/Playground/PlaygroundForm/renderOption';
|
||||||
import useProjects from 'hooks/api/getters/useProjects/useProjects';
|
import useProjects from 'hooks/api/getters/useProjects/useProjects';
|
||||||
|
|
||||||
@ -21,6 +21,7 @@ interface IProjectSelectProps {
|
|||||||
onChange:
|
onChange:
|
||||||
| Dispatch<SetStateAction<string[]>>
|
| Dispatch<SetStateAction<string[]>>
|
||||||
| ((projects: string[]) => void);
|
| ((projects: string[]) => void);
|
||||||
|
limitTags: number;
|
||||||
dataTestId?: string;
|
dataTestId?: string;
|
||||||
sx?: SxProps;
|
sx?: SxProps;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
@ -38,7 +39,15 @@ function findAllIndexes(arr: string[], name: string): number[] {
|
|||||||
|
|
||||||
export const ProjectSelect: VFC<IProjectSelectProps> = forwardRef(
|
export const ProjectSelect: VFC<IProjectSelectProps> = forwardRef(
|
||||||
(
|
(
|
||||||
{ selectedProjects, onChange, dataTestId, sx, disabled, ...props },
|
{
|
||||||
|
limitTags,
|
||||||
|
selectedProjects,
|
||||||
|
onChange,
|
||||||
|
dataTestId,
|
||||||
|
sx,
|
||||||
|
disabled,
|
||||||
|
...props
|
||||||
|
},
|
||||||
ref,
|
ref,
|
||||||
) => {
|
) => {
|
||||||
const { projects: availableProjects } = useProjects();
|
const { projects: availableProjects } = useProjects();
|
||||||
@ -95,7 +104,7 @@ export const ProjectSelect: VFC<IProjectSelectProps> = forwardRef(
|
|||||||
ref={ref}
|
ref={ref}
|
||||||
disablePortal
|
disablePortal
|
||||||
id='projects'
|
id='projects'
|
||||||
limitTags={3}
|
limitTags={limitTags}
|
||||||
multiple={!isAllProjects}
|
multiple={!isAllProjects}
|
||||||
options={projectsOptions}
|
options={projectsOptions}
|
||||||
sx={sx}
|
sx={sx}
|
||||||
@ -116,6 +125,23 @@ export const ProjectSelect: VFC<IProjectSelectProps> = forwardRef(
|
|||||||
}
|
}
|
||||||
onChange={onProjectsChange}
|
onChange={onProjectsChange}
|
||||||
data-testid={dataTestId ? dataTestId : 'PROJECT_SELECT'}
|
data-testid={dataTestId ? dataTestId : 'PROJECT_SELECT'}
|
||||||
|
renderTags={(value, getTagProps) => {
|
||||||
|
const numTags = value.length;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{value.slice(0, limitTags).map((option, index) => (
|
||||||
|
<Chip
|
||||||
|
{...getTagProps({ index })}
|
||||||
|
key={index}
|
||||||
|
label={option.label}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
|
||||||
|
{numTags > limitTags && ` +${numTags - limitTags}`}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -59,6 +59,7 @@ export const Insights: VFC = () => {
|
|||||||
selectedProjects={projects}
|
selectedProjects={projects}
|
||||||
onChange={setProjects}
|
onChange={setProjects}
|
||||||
dataTestId={'DASHBOARD_PROJECT_SELECT'}
|
dataTestId={'DASHBOARD_PROJECT_SELECT'}
|
||||||
|
limitTags={1}
|
||||||
sx={{
|
sx={{
|
||||||
flex: 1,
|
flex: 1,
|
||||||
maxWidth: '360px',
|
maxWidth: '360px',
|
||||||
|
@ -254,6 +254,7 @@ export const PlaygroundConnectionFieldset: VFC<
|
|||||||
onChange={setProjects}
|
onChange={setProjects}
|
||||||
dataTestId={'PLAYGROUND_PROJECT_SELECT'}
|
dataTestId={'PLAYGROUND_PROJECT_SELECT'}
|
||||||
disabled={Boolean(token)}
|
disabled={Boolean(token)}
|
||||||
|
limitTags={3}
|
||||||
/>
|
/>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</Box>
|
</Box>
|
||||||
|
Loading…
Reference in New Issue
Block a user