1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-13 11:17:26 +02:00
unleash.unleash/frontend/src/component/common/GeneralSelect/GeneralSelect.tsx
Youssef Khedher ee730e0708 Feat/custom strategy screen (#722)
* feat: setup new screen structure

* refactor: strategyParameter

* feat: add strategy input errors for required fields

* feat: add create strategy to routes

* feat: add EditStrategy component

* feat: edit strategy view and EditStrategy component

* feat: update EditStrategy component

* test: update snapshots

* fix: styles

* test: update snapshots

* refactor: rename StrategyForm and fix ts errors

* test: update snapshots

* fix: remove test route

* fix: update PR based on feedback

* fix: update PR based on feedback

* refactor: restore feature settings (#712)

* refactor: resotre feature settings

* fix: update PR based on feedback

* feat: add feature information in Metadata container

* fix: update PR based on feedback

* fix: update PR based on feedback

Co-authored-by: Fredrik Strand Oseberg <fredrik.no@gmail.com>

* chore(deps): update dependency @types/react-dom to v17.0.13

* refactor: expect existing TS errors (#767)

* refactor: expect existing TS errors

* refactor: fail build on new TS errors

* fix: styles

* refactor: rename StrategyForm and fix ts errors

* fix: update PR based on feedback

* fix: cleaning up

* fix: remove errors and warnings

* fix: remove ts-expect-error and fix errors

* fix: ts errors

* Update src/component/strategies/StrategyView/StrategyView.tsx

* Update src/component/strategies/StrategyView/StrategyView.tsx

Co-authored-by: Fredrik Strand Oseberg <fredrik.no@gmail.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: olav <mail@olav.io>
2022-03-04 23:39:41 +01:00

85 lines
2.0 KiB
TypeScript

import React from 'react';
import { FormControl, InputLabel, MenuItem, Select } from '@material-ui/core';
import { SELECT_ITEM_ID } from '../../../testIds';
import { KeyboardArrowDownOutlined } from '@material-ui/icons';
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?: OnGeneralSelectChange;
disabled?: boolean;
fullWidth?: boolean;
className?: string;
classes?: any;
defaultValue?: string;
}
export type OnGeneralSelectChange = (
event: React.ChangeEvent<{ name?: string; value: unknown }>,
child: React.ReactNode
) => void;
const GeneralSelect: React.FC<ISelectMenuProps> = ({
name,
value = '',
label = '',
options,
onChange,
defaultValue,
id,
disabled = false,
className,
classes,
fullWidth,
...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}
fullWidth={fullWidth}
>
<InputLabel htmlFor={id}>{label}</InputLabel>
<Select
defaultValue={defaultValue}
name={name}
disabled={disabled}
onChange={onChange}
className={className}
label={label}
id={id}
value={value}
IconComponent={KeyboardArrowDownOutlined}
{...rest}
>
{renderSelectItems()}
</Select>
</FormControl>
);
};
export default GeneralSelect;