@@ -27,6 +27,7 @@ import { FRAME_CLASS_MAP } from "../../helpers/mavlinkConstants.js"
2727import {
2828 showErrorNotification ,
2929 showSuccessNotification ,
30+ showWarningNotification ,
3031} from "../../helpers/notification.js"
3132import SocketFactory from "../../helpers/socket"
3233import {
@@ -90,13 +91,18 @@ import {
9091 setUpdatePlannedHomePositionFromLoadModal ,
9192} from "../slices/missionSlice"
9293import {
94+ resetParamsWriteProgressData ,
9395 setAutoPilotRebootModalOpen ,
9496 setFetchingVars ,
9597 setFetchingVarsProgress ,
9698 setHasFetchedOnce ,
9799 setModifiedParams ,
98100 setParams ,
99101 setParamSearchValue ,
102+ setParamsFailedToWrite ,
103+ setParamsFailedToWriteModalOpen ,
104+ setParamsWriteProgressData ,
105+ setParamsWriteProgressModalOpen ,
100106 setRebootData ,
101107 setShownParams ,
102108 updateParamValue ,
@@ -136,6 +142,7 @@ const ParamSpecificSocketEvents = Object.freeze({
136142 onParamSetSuccess : "param_set_success" ,
137143 onParamError : "params_error" ,
138144 onExportParamsResult : "export_params_result" ,
145+ onSetMultipleParamsProgress : "set_multiple_params_progress" ,
139146} )
140147
141148const MissionSpecificSocketEvents = Object . freeze ( {
@@ -549,17 +556,49 @@ const socketMiddleware = (store) => {
549556 )
550557
551558 socket . socket . on ( ParamSpecificSocketEvents . onParamSetSuccess , ( msg ) => {
552- showSuccessNotification ( msg . message )
553- store . dispatch ( setModifiedParams ( [ ] ) )
559+ const paramsSetSuccessfully = msg . data . params_set_successfully
560+ const paramsNotSet = msg . data . params_could_not_set
561+ if ( paramsNotSet . length > 0 && paramsSetSuccessfully . length > 0 ) {
562+ showWarningNotification ( msg . message )
563+ } else if ( paramsNotSet . length > 0 ) {
564+ showErrorNotification ( msg . message )
565+ } else {
566+ showSuccessNotification ( msg . message )
567+ }
568+
569+ const modifiedParams = store . getState ( ) . paramsSlice . modifiedParams
570+
571+ // Only clear the params that got set successfully
572+ store . dispatch (
573+ setModifiedParams (
574+ modifiedParams . filter (
575+ ( param ) =>
576+ ! paramsSetSuccessfully . some (
577+ ( setParam ) => setParam . param_id === param . param_id ,
578+ ) ,
579+ ) ,
580+ ) ,
581+ )
582+
554583 // Update the param in the params list also
555- for ( let param of msg . data ) {
584+ for ( let param of paramsSetSuccessfully ) {
556585 store . dispatch ( updateParamValue ( param ) )
557586 }
587+
588+ store . dispatch ( resetParamsWriteProgressData ( ) )
589+ store . dispatch ( setParamsWriteProgressModalOpen ( false ) )
590+
591+ if ( paramsNotSet . length !== 0 ) {
592+ store . dispatch ( setParamsFailedToWrite ( paramsNotSet ) )
593+ store . dispatch ( setParamsFailedToWriteModalOpen ( true ) )
594+ }
558595 } )
559596
560597 socket . socket . on ( ParamSpecificSocketEvents . onParamError , ( msg ) => {
561598 showErrorNotification ( msg . message )
562599 store . dispatch ( setFetchingVars ( false ) )
600+ store . dispatch ( resetParamsWriteProgressData ( ) )
601+ store . dispatch ( setParamsWriteProgressModalOpen ( false ) )
563602 } )
564603
565604 socket . socket . on (
@@ -573,6 +612,20 @@ const socketMiddleware = (store) => {
573612 } ,
574613 )
575614
615+ socket . socket . on (
616+ ParamSpecificSocketEvents . onSetMultipleParamsProgress ,
617+ ( msg ) => {
618+ store . dispatch (
619+ setParamsWriteProgressData ( {
620+ message : msg . message ,
621+ param_id : msg . param_id ,
622+ current_index : msg . current_index ,
623+ total_params : msg . total_params ,
624+ } ) ,
625+ )
626+ } ,
627+ )
628+
576629 socket . socket . on (
577630 DroneSpecificSocketEvents . onNavRepositionResult ,
578631 ( msg ) => {
0 commit comments