From 00d3490764475721100ac8e959a2dc94b928872f Mon Sep 17 00:00:00 2001 From: andreas-unleash Date: Wed, 10 Apr 2024 12:34:11 +0300 Subject: [PATCH] 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 --- .../common/ProjectSelect/ProjectSelect.tsx | 32 +++++++++++++++++-- frontend/src/component/insights/Insights.tsx | 1 + .../PlaygroundConnectionFieldset.tsx | 1 + 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/frontend/src/component/common/ProjectSelect/ProjectSelect.tsx b/frontend/src/component/common/ProjectSelect/ProjectSelect.tsx index 9cba5b67620..68331c3e04e 100644 --- a/frontend/src/component/common/ProjectSelect/ProjectSelect.tsx +++ b/frontend/src/component/common/ProjectSelect/ProjectSelect.tsx @@ -5,7 +5,7 @@ import { type SetStateAction, type VFC, } 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 useProjects from 'hooks/api/getters/useProjects/useProjects'; @@ -21,6 +21,7 @@ interface IProjectSelectProps { onChange: | Dispatch> | ((projects: string[]) => void); + limitTags: number; dataTestId?: string; sx?: SxProps; disabled?: boolean; @@ -38,7 +39,15 @@ function findAllIndexes(arr: string[], name: string): number[] { export const ProjectSelect: VFC = forwardRef( ( - { selectedProjects, onChange, dataTestId, sx, disabled, ...props }, + { + limitTags, + selectedProjects, + onChange, + dataTestId, + sx, + disabled, + ...props + }, ref, ) => { const { projects: availableProjects } = useProjects(); @@ -95,7 +104,7 @@ export const ProjectSelect: VFC = forwardRef( ref={ref} disablePortal id='projects' - limitTags={3} + limitTags={limitTags} multiple={!isAllProjects} options={projectsOptions} sx={sx} @@ -116,6 +125,23 @@ export const ProjectSelect: VFC = forwardRef( } onChange={onProjectsChange} data-testid={dataTestId ? dataTestId : 'PROJECT_SELECT'} + renderTags={(value, getTagProps) => { + const numTags = value.length; + + return ( + <> + {value.slice(0, limitTags).map((option, index) => ( + + ))} + + {numTags > limitTags && ` +${numTags - limitTags}`} + + ); + }} /> ); }, diff --git a/frontend/src/component/insights/Insights.tsx b/frontend/src/component/insights/Insights.tsx index 9c8b06a5172..d7cfcd447bc 100644 --- a/frontend/src/component/insights/Insights.tsx +++ b/frontend/src/component/insights/Insights.tsx @@ -59,6 +59,7 @@ export const Insights: VFC = () => { selectedProjects={projects} onChange={setProjects} dataTestId={'DASHBOARD_PROJECT_SELECT'} + limitTags={1} sx={{ flex: 1, maxWidth: '360px', diff --git a/frontend/src/component/playground/Playground/PlaygroundForm/PlaygroundConnectionFieldset/PlaygroundConnectionFieldset.tsx b/frontend/src/component/playground/Playground/PlaygroundForm/PlaygroundConnectionFieldset/PlaygroundConnectionFieldset.tsx index a08fa2de027..ca7e024cf93 100644 --- a/frontend/src/component/playground/Playground/PlaygroundForm/PlaygroundConnectionFieldset/PlaygroundConnectionFieldset.tsx +++ b/frontend/src/component/playground/Playground/PlaygroundForm/PlaygroundConnectionFieldset/PlaygroundConnectionFieldset.tsx @@ -254,6 +254,7 @@ export const PlaygroundConnectionFieldset: VFC< onChange={setProjects} dataTestId={'PLAYGROUND_PROJECT_SELECT'} disabled={Boolean(token)} + limitTags={3} />