1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-19 17:52:45 +02:00
unleash.unleash/frontend/src/component/common/GeneralSelect/GeneralSelect.tsx
Fredrik Strand Oseberg 57928d50c6 Fix/environment list sorting (#447)
* fix: wait for api call before refetching

* fix: set active environment from feature instead of cache

* fix: remove console logs

* fix: add permission icon button to project card

* fix: remove project button

* fix: empty tooltip if it is not passed

* fix: add refresh interval

* fix: permission buttons

* fix: project permission buttons

* fix: remove unused imports

* fix: add projectId
2021-10-20 12:05:44 +02:00

75 lines
1.8 KiB
TypeScript

import React from 'react';
import { FormControl, InputLabel, MenuItem, Select } from '@material-ui/core';
import { SELECT_ITEM_ID } from '../../../testIds';
export interface ISelectOption {
key: string;
title?: string;
label?: string;
}
export interface ISelectMenuProps {
name: string;
id: string;
value?: string;
label?: string;
options: ISelectOption[];
style?: object;
onChange?: (
event: React.ChangeEvent<{ name?: string; value: unknown }>,
child: React.ReactNode
) => void;
disabled?: boolean;
className?: string;
classes?: any;
defaultValue?: string;
}
const GeneralSelect: React.FC<ISelectMenuProps> = ({
name,
value = '',
label = '',
options,
onChange,
defaultValue,
id,
disabled = false,
className,
classes,
...rest
}) => {
const renderSelectItems = () =>
options.map(option => (
<MenuItem
key={option.key}
value={option.key}
title={option.title || ''}
data-test={`${SELECT_ITEM_ID}-${option.label}`}
>
{option.label}
</MenuItem>
));
return (
<FormControl variant="outlined" size="small" classes={classes}>
<InputLabel htmlFor={id} id={id}>
{label}
</InputLabel>
<Select
defaultValue={defaultValue}
name={name}
disabled={disabled}
onChange={onChange}
className={className}
label={label}
id={id}
value={value}
{...rest}
>
{renderSelectItems()}
</Select>
</FormControl>
);
};
export default GeneralSelect;