@@ -10,11 +10,17 @@ import Label from 'components/Label/Label.react';
1010import Modal from 'components/Modal/Modal.react' ;
1111import React from 'react' ;
1212import TextInput from 'components/TextInput/TextInput.react' ;
13+ import Checkbox from 'components/Checkbox/Checkbox.react' ;
1314
1415export default class AddArrayEntryDialog extends React . Component {
1516 constructor ( ) {
1617 super ( ) ;
17- this . state = { value : '' , showWarning : false , parsedValue : null , parsedType : '' } ;
18+ this . state = {
19+ value : '' ,
20+ showMismatchRow : false ,
21+ mismatchConfirmed : false ,
22+ parsedType : '' ,
23+ } ;
1824 this . inputRef = React . createRef ( ) ;
1925 }
2026
@@ -25,7 +31,13 @@ export default class AddArrayEntryDialog extends React.Component {
2531 }
2632
2733 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 ;
2941 }
3042
3143 getValue ( ) {
@@ -50,12 +62,28 @@ export default class AddArrayEntryDialog extends React.Component {
5062 const parsed = this . getValue ( ) ;
5163 const entryType = this . getType ( parsed ) ;
5264 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+ }
5678 }
79+
5780 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+ } ) ;
5987 }
6088
6189 render ( ) {
@@ -82,34 +110,35 @@ export default class AddArrayEntryDialog extends React.Component {
82110 placeholder = { 'Enter value' }
83111 ref = { this . inputRef }
84112 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+ }
86120 />
87121 }
88122 />
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+ ) }
89139 </ Modal >
90140 ) ;
91141
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 ;
114143 }
115144}
0 commit comments