From 337efd37ab14df2bedcc38bfa8966d231749922c Mon Sep 17 00:00:00 2001 From: Elmir Jagudin Date: Mon, 28 Aug 2023 16:52:47 +0200 Subject: [PATCH] UI: manage SC state from one source Make sure that sample changer state is managed by the SET_SC_STATE action only. Previously the sample changer state was set by two different actions, one originating from SampleChanger HW object and the other from SampleChangerMaint HW object. That creates problems, as the state can potentionally be set to different values by these two objects. Let the SampleChanger HW object be the source of truth for the current sample changer state. --- mxcube3/routes/signals.py | 10 ++++++++-- ui/src/reducers/sampleChanger.js | 6 ------ ui/src/reducers/sampleChangerMaintenance.js | 2 -- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/mxcube3/routes/signals.py b/mxcube3/routes/signals.py index 05fa4eba7..8258f6630 100644 --- a/mxcube3/routes/signals.py +++ b/mxcube3/routes/signals.py @@ -187,12 +187,18 @@ def sc_contents_update(): server.emit("sc_contents_update") -def sc_maintenance_update(state_list, cmd_state, message): +def sc_maintenance_update(*args): + if len(args) == 3: + # be backward compatible with older HW objects, + # which are emitting signal with 3 arguments + _, cmd_state, message = args + else: + cmd_state, message = args + try: server.emit( "sc_maintenance_update", { - "state": json.dumps(state_list), "commands_state": json.dumps(cmd_state), "message": message, }, diff --git a/ui/src/reducers/sampleChanger.js b/ui/src/reducers/sampleChanger.js index d2bcf5ba6..ba81c909c 100644 --- a/ui/src/reducers/sampleChanger.js +++ b/ui/src/reducers/sampleChanger.js @@ -118,12 +118,6 @@ export default (state = INITIAL_STATE, action) => { case 'SET_SC_SELECTED_DROP': { return { ...state, selectedDrop: action.drop_index }; } - case 'SET_SC_GLOBAL_STATE': { - return { - ...state, - state: JSON.parse(action.data.state).state, - }; - } default: { return state; } diff --git a/ui/src/reducers/sampleChangerMaintenance.js b/ui/src/reducers/sampleChangerMaintenance.js index 543c4ef1e..3885e2a03 100644 --- a/ui/src/reducers/sampleChangerMaintenance.js +++ b/ui/src/reducers/sampleChangerMaintenance.js @@ -20,8 +20,6 @@ export default (state = INITIAL_STATE, action) => { case 'SET_SC_GLOBAL_STATE': { return { ...state, - state: JSON.parse(action.data.state), - global_state: JSON.parse(action.data.global_state), commands_state: JSON.parse(action.data.commands_state), message: action.data.message, };