@@ -11,30 +11,32 @@ interface State {
11
11
value : any [ ] ;
12
12
}
13
13
14
- type Props = BaseFeatureProps < ListFeature > & { parentFeatures : ( CompositeFeature | GenericExposedFeature ) [ ] } & WithTranslation < 'list' > ;
14
+ type Props = BaseFeatureProps < ListFeature > & {
15
+ parentFeatures : ( CompositeFeature | GenericExposedFeature ) [ ] ;
16
+ } & WithTranslation < 'list' > ;
15
17
16
18
class List extends Component < Props , State > {
17
19
constructor ( props : Props ) {
18
20
super ( props ) ;
19
- const { deviceState, feature} = this . props ;
20
- const { property} = feature ;
21
- const value = ( property ? ( ( deviceState [ property ] ?? [ ] ) as any [ ] ) : [ ] ) ; ;
22
- this . state = { value}
21
+ const { deviceState, feature } = this . props ;
22
+ const { property } = feature ;
23
+ const value = property ? ( ( deviceState [ property ] ?? [ ] ) as any [ ] ) : [ ] ;
24
+ this . state = { value } ;
23
25
}
24
26
25
27
onChange = ( value : any [ ] ) : void => {
26
- const { endpoint, property} = this . props . feature ;
27
- this . setState ( { value} ) ;
28
+ const { endpoint, property } = this . props . feature ;
29
+ this . setState ( { value } ) ;
28
30
if ( ! this . isListRoot ( ) ) {
29
31
this . props . onChange ( endpoint as Endpoint , property ? { [ property ] : value } : value ) ;
30
32
}
31
- }
33
+ } ;
32
34
33
35
onApply = ( ) => {
34
- const { value} = this . state ;
35
- const { endpoint, property} = this . props . feature ;
36
+ const { value } = this . state ;
37
+ const { endpoint, property } = this . props . feature ;
36
38
this . props . onChange ( endpoint as Endpoint , property ? { [ property ] : value } : value ) ;
37
- }
39
+ } ;
38
40
39
41
isListRoot = ( ) : boolean => {
40
42
return this . props . parentFeatures ?. length === 1 ;
@@ -45,34 +47,28 @@ class List extends Component<Props, State> {
45
47
const { access = FeatureAccessMode . ACCESS_WRITE , item_type : itemType } = feature ;
46
48
if ( access & FeatureAccessMode . ACCESS_WRITE ) {
47
49
if ( itemType == 'number' ) {
48
- return (
49
- < RangeListEditor
50
- onChange = { this . onChange }
51
- value = { this . state . value }
52
- minimal = { minimal }
53
- />
54
- ) ;
50
+ return < RangeListEditor onChange = { this . onChange } value = { this . state . value } minimal = { minimal } /> ;
55
51
} else {
56
52
const result = [
57
53
< ListEditor
58
- key = '1'
54
+ key = "1"
59
55
feature = { itemType }
60
56
parentFeatures = { [ ...parentFeatures , feature ] }
61
57
onChange = { this . onChange }
62
58
value = { this . state . value }
63
- />
59
+ /> ,
64
60
] ;
65
61
66
62
if ( this . isListRoot ( ) ) {
67
63
result . push (
68
- < div key = '2' >
64
+ < div key = "2" >
69
65
< Button
70
66
className = { cx ( 'btn btn-primary float-end' , { 'btn-sm' : minimal } ) }
71
67
onClick = { this . onApply }
72
68
>
73
69
{ t ( 'common:apply' ) }
74
70
</ Button >
75
- </ div >
71
+ </ div > ,
76
72
) ;
77
73
}
78
74
@@ -84,6 +80,6 @@ class List extends Component<Props, State> {
84
80
return < NoAccessError { ...this . props } /> ;
85
81
}
86
82
}
87
- } ;
83
+ }
88
84
89
85
export default withTranslation ( [ 'list' , 'common' ] ) ( React . memo ( List ) ) ;
0 commit comments