@@ -356,53 +356,52 @@ export class ModuleEditorComponent implements OnInit, OnDestroy {
356356 }
357357 } ) ;
358358
359- // Subscription for saving panels
360- // ... (No changes here)
361-
362359 // Subscription for saving power data
363360 this . savePower$
364361 . pipe (
365362 switchMap ( ( ) => {
363+ // Check if the power form is valid
366364 if ( this . formGroupPower . invalid ) {
367365 this . snackBar . open ( 'Please enter valid power values.' , undefined , {
368366 duration : 5000
369367 } ) ;
370368 return EMPTY ;
371369 }
372370
371+ // Gather power data from controls
373372 const powerData = {
374- positive12V : this . powerRailPositive . control . value ,
375- negative12V : this . powerRailNegative . control . value ,
376- positive5V : this . powerRailFiveVolts . control . value
373+ powerPos12 : this . powerRailPositive . control . value ,
374+ powerNeg12 : this . powerRailNegative . control . value ,
375+ powerPos5 : this . powerRailFiveVolts . control . value
377376 } ;
378377
379- // Placeholder for backend method to update power data
378+ // Perform a single update call with the full module data merged with the power data.
379+ // Ensure that the backend update method returns the updated module.
380380 return this . backend . update . module ( {
381- ...this . data ,
382- powerPos12 : powerData . positive12V ,
383- powerNeg12 : powerData . negative12V ,
384- powerPos5 : powerData . positive5V
385- }
386- ) ;
381+ ...this . data ,
382+ ...powerData
383+ } ) ;
387384 } ) ,
388- switchMap ( ( ) => this . backend . update . module ( { id : this . data . id } ) ) ,
389385 catchError ( error => {
390386 console . error ( 'Error saving power data:' , error ) ;
391387 this . snackBar . open ( 'An error occurred while saving power data.' , undefined , {
392388 duration : 5000
393389 } ) ;
394390 return EMPTY ;
395391 } ) ,
396- withLatestFrom ( this . dataService . updateSingleModuleData$ ) ,
397- takeUntil ( this . destroyEvent$ ) ,
392+ takeUntil ( this . destroyEvent$ )
398393 )
399- . subscribe ( ( [ , updateSingleModuleData ] ) => {
400- this . dataService . updateSingleModuleData$ . next ( updateSingleModuleData ) ;
401- this . snackBar . open ( 'Power data saved successfully.' , undefined , {
402- duration : 5000
403- } ) ;
394+ . subscribe ( updatedModule => {
395+ if ( updatedModule ) {
396+ this . snackBar . open ( 'Power data saved successfully.' , undefined , {
397+ duration : 5000
398+ } ) ;
399+ this . dataService . updateSingleModuleData$ . next ( this . data . id ) ;
400+ }
401+
404402 } ) ;
405403
404+
406405 // subscription for adding depth and weight
407406 this . savePhysical$
408407 . pipe (
0 commit comments