1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-06-04 01:18:20 +02:00
unleash.unleash/frontend/src/component/project/ProjectAccess/ProjectRoleSelect/ProjectRoleSelect.tsx
Tymoteusz Czech 9ac962da45 Feat: Contexts and Project access tables (#1028)
* feat: new contexts table

* improve context list actions

* refactor: disabled icon colors

* fix: update snapshots

* fix: icons

* fix: context fields typo

* feat: new project access table

* fix: header cell styles
2022-05-26 10:37:33 +02:00

83 lines
2.4 KiB
TypeScript

import {
FormControl,
InputLabel,
Select,
MenuItem,
SelectChangeEvent,
} from '@mui/material';
import React from 'react';
import { IProjectRole } from 'interfaces/role';
import { useStyles } from '../ProjectAccess.styles';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
interface IProjectRoleSelect {
roles: IProjectRole[];
labelId?: string;
id: string;
placeholder?: string;
onChange: (evt: SelectChangeEvent) => void;
value: any;
}
export const ProjectRoleSelect: React.FC<IProjectRoleSelect> = ({
roles,
onChange,
labelId,
id,
value,
placeholder,
children,
}) => {
const { classes: styles } = useStyles();
return (
<FormControl variant="outlined" size="small">
<ConditionallyRender
condition={Boolean(labelId)}
show={() => (
<InputLabel
style={{ backgroundColor: '#fff' }}
id={labelId}
>
Role
</InputLabel>
)}
/>
<Select
labelId={labelId}
id={id}
classes={{ select: styles.projectRoleSelect }}
placeholder={placeholder}
value={value || ''}
onChange={onChange}
renderValue={roleId => {
const role = roles?.find(role => {
return String(role.id) === String(roleId);
});
return role?.name || '';
}}
>
{children}
{roles?.map(role => (
<MenuItem
key={role.id}
value={role.id}
classes={{
root: styles.menuItem,
}}
>
<div>
<span className={styles.roleName}>{role.name}</span>
<p>
{role.description ||
'No role description available.'}
</p>
</div>
</MenuItem>
))}
</Select>
</FormControl>
);
};