1
1
// @flow
2
2
import React , { useMemo } from "react"
3
3
import Survey from "material-survey/components/Survey"
4
- import { setIn } from "seamless-immutable"
4
+ import { setIn , asMutable } from "seamless-immutable"
5
5
import { CssBaseline , GlobalStyles } from "@mui/material" ;
6
6
import { useTranslation } from "react-i18next"
7
7
@@ -21,12 +21,12 @@ export default ({ config, onChange }) => {
21
21
type : "boolean" ,
22
22
} ,
23
23
{
24
- name : "regionTypesAllowed" ,
25
- title : t ( "configuration.region_types_allowed" ) ,
26
- description : t ( "configuration.region_types_allowed.description" ) ,
27
- type : "checkbox " ,
28
- choices : [ "bounding-box" , "polygon" , "circle" ] ,
29
- } ,
24
+ name : "regionTypesAllowed" ,
25
+ title : t ( "configuration.region_types_allowed" ) ,
26
+ description : t ( "configuration.region_types_allowed.description" ) ,
27
+ type : "multiple-dropdown " ,
28
+ choices : [ "bounding-box" , "polygon" , "circle" ] ,
29
+ } ,
30
30
{
31
31
name : "labels" ,
32
32
title : t ( "configuration.labels" ) ,
@@ -40,32 +40,22 @@ export default ({ config, onChange }) => {
40
40
title : t ( "configuration.labels.option.id" ) ,
41
41
} ,
42
42
] ,
43
- } ,
44
- {
45
- name : "regions" ,
46
- title : t ( "configuration.regions" ) ,
47
- description : t ( "configuration.regions.description" ) ,
48
- type : "dropdown" ,
49
- choices : [
50
- "Polygon" ,
51
- "Bounding Box" ,
52
- "Point" ,
53
- ] ,
54
43
}
55
44
] ,
56
45
}
57
46
58
47
const defaultAnswers = useMemo (
59
- ( ) => ( {
48
+ ( ) => asMutable ( {
60
49
multipleRegions : config . multipleRegions ?? false ,
61
50
multipleRegionLabels : config . multipleRegionLabels ?? false ,
62
51
regionTypesAllowed : config . regionTypesAllowed ? config . regionTypesAllowed : [ ] ,
63
52
labels :
64
53
( config . labels || [ ] ) . map ( ( a ) => {
65
54
return typeof a === "string" ? { id : a , description : a } : a
66
55
} ) || [ ] ,
67
- regions : config . regions ?? "Polygon"
68
- } ) ,
56
+ } ,
57
+ { deep : true }
58
+ ) ,
69
59
[ config . labels , config . multipleRegions ]
70
60
)
71
61
return (
@@ -97,16 +87,16 @@ export default ({ config, onChange }) => {
97
87
variant = "flat"
98
88
defaultAnswers = { defaultAnswers }
99
89
onQuestionChange = { ( questionId , newValue ) => {
100
- if ( questionId !== "regionTypesAllowed" && questionId !== "multipleRegions" && questionId !== "multipleRegionLabels" ) {
101
- let arrayId = [ ]
102
- if ( Array . isArray ( newValue ) ) {
103
- newValue = newValue . filter ( ( json ) => {
104
- if ( arrayId . includes ( json . id ) ) return false
105
- arrayId . push ( json . id )
106
- return true
107
- } )
108
- onChange ( setIn ( config , [ questionId ] , newValue ) )
109
- }
90
+ if ( questionId !== "regionTypesAllowed" && questionId !== "multipleRegions" && questionId !== "multipleRegionLabels" ) {
91
+ let arrayId = [ ]
92
+ if ( Array . isArray ( newValue ) ) {
93
+ newValue = newValue . filter ( ( json ) => {
94
+ if ( arrayId . includes ( json . id ) ) return false
95
+ arrayId . push ( json . id )
96
+ return true
97
+ } )
98
+ onChange ( setIn ( config , [ questionId ] , newValue ) )
99
+ }
110
100
} else {
111
101
onChange ( setIn ( config , [ questionId ] , newValue ) )
112
102
}
0 commit comments