@@ -93,6 +93,7 @@ class Config extends TableView {
93
93
value = { this . state . modalValue }
94
94
masterKeyOnly = { this . state . modalMasterKeyOnly }
95
95
parseServerVersion = { this . context . serverInfo ?. parseServerVersion }
96
+ loading = { this . state . loading }
96
97
/>
97
98
) ;
98
99
} else if ( this . state . showDeleteParameterDialog ) {
@@ -272,77 +273,93 @@ class Config extends TableView {
272
273
}
273
274
274
275
async saveParam ( { name, value, type, masterKeyOnly, override } ) {
275
- const cachedParams = this . cacheData . get ( 'params' ) ;
276
- const cachedValue = cachedParams . get ( name ) ;
276
+ try {
277
+ this . setState ( { loading : true } ) ;
278
+
279
+ const fetchedParams = this . props . config . data . get ( 'params' ) ;
280
+ const currentValue = fetchedParams . get ( name ) ;
281
+ await this . props . config . dispatch ( ActionTypes . FETCH ) ;
282
+ const fetchedParamsAfter = this . props . config . data . get ( 'params' ) ;
283
+ const currentValueAfter = fetchedParamsAfter . get ( name ) ;
277
284
278
- await this . props . config . dispatch ( ActionTypes . FETCH ) ;
279
- const fetchedParams = this . props . config . data . get ( 'params' ) ;
280
-
281
- if ( cachedValue !== fetchedParams . get ( name ) && ! override ) {
282
- this . setState ( {
283
- confirmModalOpen : true ,
284
- modalOpen : false ,
285
- } ) ;
286
- this . confirmData = {
287
- name,
288
- value,
289
- type,
290
- masterKeyOnly,
291
- } ;
292
- return ;
293
- }
285
+ if ( currentValue !== currentValueAfter && ! override ) {
286
+ this . setState ( {
287
+ confirmModalOpen : true ,
288
+ modalOpen : false ,
289
+ loading : false ,
290
+ } ) ;
291
+ this . confirmData = {
292
+ name,
293
+ value,
294
+ type,
295
+ masterKeyOnly,
296
+ } ;
297
+ return ;
298
+ }
294
299
295
- this . props . config
296
- . dispatch ( ActionTypes . SET , {
300
+ await this . props . config . dispatch ( ActionTypes . SET , {
297
301
param : name ,
298
302
value : value ,
299
303
masterKeyOnly : masterKeyOnly ,
300
- } )
301
- . then (
302
- ( ) => {
303
- this . setState ( { modalOpen : false } ) ;
304
- const limit = this . context . cloudConfigHistoryLimit ;
305
- const applicationId = this . context . applicationId ;
306
- let transformedValue = value ;
307
- if ( type === 'Date' ) {
308
- transformedValue = { __type : 'Date' , iso : value } ;
309
- }
310
- if ( type === 'File' ) {
311
- transformedValue = { name : value . _name , url : value . _url } ;
312
- }
313
- const configHistory = localStorage . getItem ( `${ applicationId } _configHistory` ) ;
314
- if ( ! configHistory ) {
315
- localStorage . setItem (
316
- `${ applicationId } _configHistory` ,
317
- JSON . stringify ( {
318
- [ name ] : [
319
- {
320
- time : new Date ( ) ,
321
- value : transformedValue ,
322
- } ,
323
- ] ,
324
- } )
325
- ) ;
326
- } else {
327
- const oldConfigHistory = JSON . parse ( configHistory ) ;
328
- localStorage . setItem (
329
- `${ applicationId } _configHistory` ,
330
- JSON . stringify ( {
331
- ...oldConfigHistory ,
332
- [ name ] : ! oldConfigHistory [ name ]
333
- ? [ { time : new Date ( ) , value : transformedValue } ]
334
- : [
335
- { time : new Date ( ) , value : transformedValue } ,
336
- ...oldConfigHistory [ name ] ,
337
- ] . slice ( 0 , limit || 100 ) ,
338
- } )
339
- ) ;
340
- }
341
- } ,
342
- ( ) => {
343
- // Catch the error
344
- }
304
+ } ) ;
305
+
306
+ // Update the cached data after successful save
307
+ const params = this . cacheData . get ( 'params' ) ;
308
+ params . set ( name , value ) ;
309
+ if ( masterKeyOnly ) {
310
+ const masterKeyOnlyParams = this . cacheData . get ( 'masterKeyOnly' ) || new Map ( ) ;
311
+ masterKeyOnlyParams . set ( name , masterKeyOnly ) ;
312
+ this . cacheData . set ( 'masterKeyOnly' , masterKeyOnlyParams ) ;
313
+ }
314
+
315
+ this . setState ( { modalOpen : false } ) ;
316
+
317
+ // Update config history in localStorage
318
+ const limit = this . context . cloudConfigHistoryLimit ;
319
+ const applicationId = this . context . applicationId ;
320
+ let transformedValue = value ;
321
+
322
+ if ( type === 'Date' ) {
323
+ transformedValue = { __type : 'Date' , iso : value } ;
324
+ }
325
+ if ( type === 'File' ) {
326
+ transformedValue = { name : value . _name , url : value . _url } ;
327
+ }
328
+
329
+ const configHistory = localStorage . getItem ( `${ applicationId } _configHistory` ) ;
330
+ const newHistoryEntry = {
331
+ time : new Date ( ) ,
332
+ value : transformedValue ,
333
+ } ;
334
+
335
+ if ( ! configHistory ) {
336
+ localStorage . setItem (
337
+ `${ applicationId } _configHistory` ,
338
+ JSON . stringify ( {
339
+ [ name ] : [ newHistoryEntry ] ,
340
+ } )
341
+ ) ;
342
+ } else {
343
+ const oldConfigHistory = JSON . parse ( configHistory ) ;
344
+ const updatedHistory = ! oldConfigHistory [ name ]
345
+ ? [ newHistoryEntry ]
346
+ : [ newHistoryEntry , ...oldConfigHistory [ name ] ] . slice ( 0 , limit || 100 ) ;
347
+
348
+ localStorage . setItem (
349
+ `${ applicationId } _configHistory` ,
350
+ JSON . stringify ( {
351
+ ...oldConfigHistory ,
352
+ [ name ] : updatedHistory ,
353
+ } )
354
+ ) ;
355
+ }
356
+ } catch ( error ) {
357
+ this . context . showError ?. (
358
+ `Failed to save parameter: ${ error . message || 'Unknown error occurred' } `
345
359
) ;
360
+ } finally {
361
+ this . setState ( { loading : false } ) ;
362
+ }
346
363
}
347
364
348
365
deleteParam ( name ) {
0 commit comments