1
1
import type { MessageDescriptor } from '@formatjs/intl/src/types' ;
2
- import type { FormGroupProps } from '@patternfly/react-core' ;
3
- import type { FormSelectProps } from '@patternfly/react-core' ;
2
+ import type { FormGroupProps , FormSelectProps } from '@patternfly/react-core' ;
4
3
import { FormGroup , HelperText , HelperTextItem } from '@patternfly/react-core' ;
5
- import type { SelectOptionObject } from '@patternfly/react-core/deprecated' ;
6
- import { Select , SelectOption , SelectVariant } from '@patternfly/react-core/deprecated' ;
7
4
import { intl as defaultIntl } from 'components/i18n' ;
8
5
import React , { useEffect , useState } from 'react' ;
9
6
import type { WrappedComponentProps } from 'react-intl' ;
10
7
import { injectIntl } from 'react-intl' ;
8
+ import type { SelectWrapperOption } from 'routes/components/selectWrapper' ;
9
+ import { SelectWrapper } from 'routes/components/selectWrapper' ;
11
10
12
11
interface SelectorFormGroupOwnProps {
13
12
helperTextInvalid ?: MessageDescriptor | string ;
14
13
isInvalid ?: boolean ;
15
14
label ?: MessageDescriptor | string ;
16
- appendMenuTo ?: HTMLElement | 'parent' | 'inline' | ( ( ) => HTMLElement ) ;
15
+ appendMenuTo ?: HTMLElement | ( ( ) => HTMLElement ) | 'inline' | 'parent' ;
17
16
toggleAriaLabel ?: string ;
18
- maxHeight ?: string | number ;
17
+ maxMenuHeight ?: string ;
19
18
placeholderText ?: string ;
20
19
direction ?: 'up' | 'down' ;
21
20
options : {
@@ -25,12 +24,6 @@ interface SelectorFormGroupOwnProps {
25
24
} [ ] ;
26
25
}
27
26
28
- interface SelectorOption extends SelectOptionObject {
29
- toString ( ) : string ; // label
30
- value ?: string ;
31
- description ?: string ;
32
- }
33
-
34
27
type SelectorFormGroupProps = Pick < FormGroupProps , 'style' > ;
35
28
type SelectorFormSelectProps = Pick <
36
29
FormSelectProps ,
@@ -43,25 +36,25 @@ type SelectorProps = SelectorFormGroupOwnProps &
43
36
WrappedComponentProps ;
44
37
45
38
const SelectorBase : React . FC < SelectorProps > = ( {
39
+ appendMenuTo,
46
40
'aria-label' : ariaLabel ,
41
+ direction = 'down' ,
47
42
helperTextInvalid : helpText ,
48
43
id,
49
44
intl = defaultIntl , // Default required for testing
50
- toggleAriaLabel,
51
- maxHeight,
52
- placeholderText,
53
- direction = 'down' ,
54
45
isInvalid = false ,
55
46
isRequired = false ,
56
- appendMenuTo = 'parent' ,
57
47
label,
58
- value ,
48
+ maxMenuHeight ,
59
49
onChange,
60
50
options,
51
+ placeholderText,
52
+ toggleAriaLabel,
53
+ value,
54
+
61
55
style,
62
56
} ) => {
63
- const [ isOpen , setIsOpen ] = useState ( false ) ;
64
- const [ selection , setSelection ] = useState < SelectorOption > ( null ) ;
57
+ const [ selection , setSelection ] = useState < SelectWrapperOption > ( null ) ;
65
58
66
59
useEffect ( ( ) => {
67
60
if ( ! value ) {
@@ -71,47 +64,67 @@ const SelectorBase: React.FC<SelectorProps> = ({
71
64
}
72
65
} , [ value ] ) ;
73
66
74
- const getSelectorOptions = ( ) : SelectorOption [ ] => {
75
- const ret = options . map ( option => {
67
+ const getSelectOptions = ( ) : SelectWrapperOption [ ] => {
68
+ const selectOptions = options . map ( option => {
76
69
return {
70
+ description : option . description ,
77
71
toString : ( ) => ( typeof option . label === 'object' ? intl . formatMessage ( option . label ) : option . label ) ,
78
72
value : option . value ,
79
- description : option . description ,
80
- } as SelectorOption ;
73
+ } ;
81
74
} ) ;
82
- return ret ;
75
+ return selectOptions ;
83
76
} ;
77
+
78
+ const handleOnSelect = ( _evt , sel : SelectWrapperOption ) => {
79
+ setSelection ( sel ) ;
80
+ onChange ( null , sel . value ) ;
81
+ } ;
82
+
84
83
return (
85
84
< FormGroup
86
85
isRequired = { isRequired }
87
86
style = { style }
88
87
fieldId = { id }
89
88
label = { label !== null && typeof label === 'object' ? intl . formatMessage ( label ) : ( label as string ) }
90
89
>
91
- < Select
90
+ TEST
91
+ < SelectWrapper
92
+ appendTo = { appendMenuTo }
93
+ ariaLabel = { ariaLabel }
94
+ direction = { direction }
92
95
id = { id }
93
- ouiaId = { id }
94
- maxHeight = { maxHeight }
96
+ maxMenuHeight = { maxMenuHeight }
97
+ onSelect = { handleOnSelect }
98
+ options = { getSelectOptions ( ) }
99
+ placeholder = { placeholderText }
100
+ selection = { selection }
101
+ status = { isInvalid ? 'danger' : undefined }
95
102
toggleAriaLabel = { toggleAriaLabel }
96
- variant = { SelectVariant . single }
97
- placeholderText = { placeholderText }
98
- aria-label = { ariaLabel }
99
- direction = { direction }
100
- menuAppendTo = { appendMenuTo }
101
- isOpen = { isOpen }
102
- onSelect = { ( _evt , sel : SelectorOption ) => {
103
- setSelection ( sel ) ;
104
- onChange ( null , sel . value ) ;
105
- setIsOpen ( false ) ;
106
- } }
107
- onToggle = { ( ) => setIsOpen ( ! isOpen ) }
108
- selections = { selection }
109
- validated = { isInvalid ? 'error' : 'default' }
110
- >
111
- { getSelectorOptions ( ) . map ( opt => (
112
- < SelectOption key = { `${ opt . value } ` } value = { opt } description = { opt . description } />
113
- ) ) }
114
- </ Select >
103
+ />
104
+ { /* <Select*/ }
105
+ { /* id={id}*/ }
106
+ { /* ouiaId={id}*/ }
107
+ { /* maxHeight={maxHeight}*/ }
108
+ { /* toggleAriaLabel={toggleAriaLabel}*/ }
109
+ { /* variant={SelectVariant.single}*/ }
110
+ { /* placeholderText={placeholderText}*/ }
111
+ { /* aria-label={ariaLabel}*/ }
112
+ { /* direction={direction}*/ }
113
+ { /* menuAppendTo={appendMenuTo}*/ }
114
+ { /* isOpen={isOpen}*/ }
115
+ { /* onSelect={(_evt, sel: SelectWrapperOption) => {*/ }
116
+ { /* setSelection(sel);*/ }
117
+ { /* onChange(null, sel.value);*/ }
118
+ { /* setIsOpen(false);*/ }
119
+ { /* }}*/ }
120
+ { /* onToggle={() => setIsOpen(!isOpen)}*/ }
121
+ { /* selections={selection}*/ }
122
+ { /* validated={isInvalid ? 'error' : 'default'}*/ }
123
+ { /* >*/ }
124
+ { /* {getSelectorOptions().map(opt => (*/ }
125
+ { /* <SelectOption key={`${opt.value}`} value={opt} description={opt.description} />*/ }
126
+ { /* ))}*/ }
127
+ { /* </Select>*/ }
115
128
{ isInvalid && typeof helpText === 'object' && (
116
129
< HelperText >
117
130
< HelperTextItem variant = "error" > { intl . formatMessage ( helpText ) } </ HelperTextItem >
0 commit comments