Total Complexity | 1 |
Complexity/F | 0 |
Lines of Code | 59 |
Function Count | 0 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import * as React from 'react'; |
||
2 | import { Dropdown, DropdownProps } from 'semantic-ui-react'; |
||
3 | import { css } from 'emotion'; |
||
4 | import { useMemo } from 'react'; |
||
5 | |||
6 | export interface EnvironmentSelectProps { |
||
7 | env: string; |
||
8 | disabled: boolean; |
||
9 | options: string[]; |
||
10 | |||
11 | onEnvironmentChange(env: string): void; |
||
12 | } |
||
13 | |||
14 | export const EnvironmentSelect: React.FC<EnvironmentSelectProps> = ({ env, options, disabled, onEnvironmentChange }) => { |
||
15 | const dropdownOptions = useMemo( |
||
16 | () => |
||
17 | options.map((type: string) => ({ |
||
18 | text: type, |
||
19 | value: type, |
||
20 | })), |
||
21 | [options] |
||
22 | ); |
||
23 | |||
24 | const handleEnvironmentChange = (event: React.SyntheticEvent<HTMLElement>, data: DropdownProps) => { |
||
25 | if (data.value) { |
||
26 | onEnvironmentChange(data.value as string); |
||
27 | } |
||
28 | }; |
||
29 | |||
30 | return ( |
||
31 | <div className={dropdownContainerCls}> |
||
32 | <span>Select Environment</span> |
||
33 | |||
34 | <Dropdown |
||
35 | className={dropdownCls} |
||
36 | data-test="environment-select" |
||
37 | fluid={true} |
||
38 | multiple={false} |
||
39 | selection={true} |
||
40 | options={dropdownOptions} |
||
41 | onChange={handleEnvironmentChange} |
||
42 | value={env} |
||
43 | disabled={disabled} |
||
44 | /> |
||
45 | </div> |
||
46 | ); |
||
47 | }; |
||
48 | |||
49 | const dropdownContainerCls = css({ |
||
50 | label: 'env-select-container', |
||
51 | minWidth: 100, |
||
52 | }); |
||
53 | |||
54 | const dropdownCls = css({ |
||
55 | label: 'env-select', |
||
56 | minWidth: 100, |
||
57 | display: 'inline-block', |
||
58 | }); |
||
59 |