@@ -10,11 +10,17 @@ import Label from 'components/Label/Label.react';
10
10
import Modal from 'components/Modal/Modal.react' ;
11
11
import React from 'react' ;
12
12
import TextInput from 'components/TextInput/TextInput.react' ;
13
+ import Checkbox from 'components/Checkbox/Checkbox.react' ;
13
14
14
15
export default class AddArrayEntryDialog extends React . Component {
15
16
constructor ( ) {
16
17
super ( ) ;
17
- this . state = { value : '' , showWarning : false , parsedValue : null , parsedType : '' } ;
18
+ this . state = {
19
+ value : '' ,
20
+ showMismatchRow : false ,
21
+ mismatchConfirmed : false ,
22
+ parsedType : '' ,
23
+ } ;
18
24
this . inputRef = React . createRef ( ) ;
19
25
}
20
26
@@ -25,7 +31,13 @@ export default class AddArrayEntryDialog extends React.Component {
25
31
}
26
32
27
33
valid ( ) {
28
- return this . state . value !== '' ;
34
+ if ( this . state . value === '' ) {
35
+ return false ;
36
+ }
37
+ if ( this . state . showMismatchRow && ! this . state . mismatchConfirmed ) {
38
+ return false ;
39
+ }
40
+ return true ;
29
41
}
30
42
31
43
getValue ( ) {
@@ -50,12 +62,28 @@ export default class AddArrayEntryDialog extends React.Component {
50
62
const parsed = this . getValue ( ) ;
51
63
const entryType = this . getType ( parsed ) ;
52
64
const lastType = this . props . lastType ;
53
- if ( lastType && entryType !== lastType && ! this . state . showWarning ) {
54
- this . setState ( { showWarning : true , parsedValue : parsed , parsedType : entryType } ) ;
55
- return ;
65
+
66
+ if ( lastType && entryType !== lastType ) {
67
+ if ( ! this . state . showMismatchRow ) {
68
+ this . setState ( {
69
+ showMismatchRow : true ,
70
+ mismatchConfirmed : false ,
71
+ parsedType : entryType ,
72
+ } ) ;
73
+ return ;
74
+ }
75
+ if ( ! this . state . mismatchConfirmed ) {
76
+ return ;
77
+ }
56
78
}
79
+
57
80
this . props . onConfirm ( parsed ) ;
58
- this . setState ( { showWarning : false , parsedValue : null , parsedType : '' } ) ;
81
+ this . setState ( {
82
+ value : '' ,
83
+ showMismatchRow : false ,
84
+ mismatchConfirmed : false ,
85
+ parsedType : '' ,
86
+ } ) ;
59
87
}
60
88
61
89
render ( ) {
@@ -82,34 +110,35 @@ export default class AddArrayEntryDialog extends React.Component {
82
110
placeholder = { 'Enter value' }
83
111
ref = { this . inputRef }
84
112
value = { this . state . value }
85
- onChange = { value => this . setState ( { value } ) }
113
+ onChange = { value =>
114
+ this . setState ( {
115
+ value,
116
+ showMismatchRow : false ,
117
+ mismatchConfirmed : false ,
118
+ } )
119
+ }
86
120
/>
87
121
}
88
122
/>
123
+ { this . state . showMismatchRow && (
124
+ < Field
125
+ label = {
126
+ < Label
127
+ text = "Confirm type"
128
+ description = { `Previous item is ${ this . props . lastType } , new entry is ${ this . state . parsedType } .` }
129
+ />
130
+ }
131
+ input = {
132
+ < Checkbox
133
+ checked = { this . state . mismatchConfirmed }
134
+ onChange = { checked => this . setState ( { mismatchConfirmed : checked } ) }
135
+ />
136
+ }
137
+ />
138
+ ) }
89
139
</ Modal >
90
140
) ;
91
141
92
- const warningModal = this . state . showWarning ? (
93
- < Modal
94
- type = { Modal . Types . WARNING }
95
- icon = "warn-outline"
96
- title = "Type Mismatch"
97
- confirmText = "Add"
98
- cancelText = "Cancel"
99
- onCancel = { ( ) => this . setState ( { showWarning : false } ) }
100
- onConfirm = { ( ) => this . handleConfirm ( ) }
101
- >
102
- < div >
103
- The type of the previous item (< strong > { this . props . lastType } </ strong > ) does not correspond to the type of the entry (< strong > { this . state . parsedType } </ strong > ). Do you want to proceed?
104
- </ div >
105
- </ Modal >
106
- ) : null ;
107
-
108
- return (
109
- < >
110
- { addEntryModal }
111
- { warningModal }
112
- </ >
113
- ) ;
142
+ return addEntryModal ;
114
143
}
115
144
}
0 commit comments