@@ -4,6 +4,8 @@ import { useSelector, useDispatch } from "react-redux";
44import {
55 getToolFromConfiguration ,
66 updateToolInConfiguration ,
7+ getIn ,
8+ setIn ,
79} from "../../../../../core/utils" ;
810
911import { setModal , setConfiguration } from "../../../../../core/ConfigureStore" ;
@@ -179,6 +181,62 @@ const ToolModal = (props) => {
179181 const dispatch = useDispatch ( ) ;
180182
181183 const handleClose = ( ) => {
184+ const nextConfiguration = JSON . parse ( JSON . stringify ( configuration ) ) ;
185+ nextConfiguration . tools . forEach ( ( currentTool , idx ) => {
186+ if ( currentTool . name === toolName && toolConfig ?. config ?. rows ) {
187+ toolConfig . config . rows . forEach ( ( r ) => {
188+ r . components . forEach ( ( c ) => {
189+ // Skip non-field components and unchangeable ones
190+ if (
191+ c . field == null ||
192+ c . field === "name" ||
193+ c . field === "js" ||
194+ c . field === "variables"
195+ )
196+ return ;
197+
198+ const currentValue = getIn ( currentTool , c . field . split ( "." ) , null ) ;
199+ if ( currentValue != null )
200+ setIn ( currentTool , c . field . split ( "." ) , currentValue , true ) ;
201+
202+ if ( c . type === "dropdown" || c . type === "colordropdown" ) {
203+ const currentValue = getIn ( currentTool , c . field ) ;
204+ if ( currentValue == null ) {
205+ setIn ( currentTool , c . field . split ( "." ) , c . options [ 0 ] , true ) ;
206+ }
207+ } else if ( c . type === "checkbox" || c . type === "switch" ) {
208+ const currentValue = getIn ( currentTool , c . field ) ;
209+ if ( currentValue == null && c . defaultChecked != null ) {
210+ setIn ( currentTool , c . field . split ( "." ) , c . defaultChecked , true ) ;
211+ }
212+ } else if ( c . type === "slider" ) {
213+ const currentValue = getIn ( currentTool , c . field ) ;
214+ if ( currentValue == null && c . default != null ) {
215+ setIn (
216+ currentTool ,
217+ c . field . split ( "." ) ,
218+ c . default || c . min || 0 ,
219+ true
220+ ) ;
221+ }
222+ } else if ( c . type === "colorpicker" ) {
223+ const currentValue = getIn ( currentTool , c . field ) ;
224+ if ( currentValue == null ) {
225+ setIn (
226+ currentTool ,
227+ c . field . split ( "." ) ,
228+ c . default || "#FFFFFF" ,
229+ true
230+ ) ;
231+ }
232+ }
233+ } ) ;
234+ } ) ;
235+ nextConfiguration . tools [ idx ] = currentTool ;
236+ dispatch ( setConfiguration ( nextConfiguration ) ) ;
237+ }
238+ } ) ;
239+
182240 // close modal
183241 dispatch ( setModal ( { name : MODAL_NAME , on : false } ) ) ;
184242 } ;
0 commit comments