Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Project select should not expand when selecting multiple projects #6811

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions frontend/src/component/common/ProjectSelect/ProjectSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -21,6 +21,7 @@ interface IProjectSelectProps {
onChange:
| Dispatch<SetStateAction<string[]>>
| ((projects: string[]) => void);
limitTags: number;
dataTestId?: string;
sx?: SxProps;
disabled?: boolean;
Expand All @@ -38,7 +39,15 @@ function findAllIndexes(arr: string[], name: string): number[] {

export const ProjectSelect: VFC<IProjectSelectProps> = forwardRef(
(
{ selectedProjects, onChange, dataTestId, sx, disabled, ...props },
{
limitTags,
selectedProjects,
onChange,
dataTestId,
sx,
disabled,
...props
},
ref,
) => {
const { projects: availableProjects } = useProjects();
Expand Down Expand Up @@ -95,7 +104,7 @@ export const ProjectSelect: VFC<IProjectSelectProps> = forwardRef(
ref={ref}
disablePortal
id='projects'
limitTags={3}
limitTags={limitTags}
multiple={!isAllProjects}
options={projectsOptions}
sx={sx}
Expand All @@ -116,6 +125,23 @@ export const ProjectSelect: VFC<IProjectSelectProps> = forwardRef(
}
onChange={onProjectsChange}
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}`}
</>
);
}}
/>
);
},
Expand Down
1 change: 1 addition & 0 deletions frontend/src/component/insights/Insights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const Insights: VFC = () => {
selectedProjects={projects}
onChange={setProjects}
dataTestId={'DASHBOARD_PROJECT_SELECT'}
limitTags={1}
sx={{
flex: 1,
maxWidth: '360px',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export const PlaygroundConnectionFieldset: VFC<
onChange={setProjects}
dataTestId={'PLAYGROUND_PROJECT_SELECT'}
disabled={Boolean(token)}
limitTags={3}
/>
</Tooltip>
</Box>
Expand Down
Loading