diff --git a/ui/src/actions/gphl_workflow.js b/ui/src/actions/gphlWorkflow.js similarity index 100% rename from ui/src/actions/gphl_workflow.js rename to ui/src/actions/gphlWorkflow.js diff --git a/ui/src/containers/GphlWorkflowParametersDialog.jsx b/ui/src/containers/GphlWorkflowParametersDialog.jsx index f7760107b..4a42518f3 100644 --- a/ui/src/containers/GphlWorkflowParametersDialog.jsx +++ b/ui/src/containers/GphlWorkflowParametersDialog.jsx @@ -7,7 +7,7 @@ import Form from '@rjsf/core'; import { showGphlWorkflowParametersDialog, gphlWorkflowSubmitParameters, -} from '../actions/gphl_workflow'; +} from '../actions/gphlWorkflow'; class GphlWorkflowParametersDialog extends React.Component { constructor(props) { diff --git a/ui/src/reducers/beamline.js b/ui/src/reducers/beamline.js index eaaa76d74..91a2bc458 100644 --- a/ui/src/reducers/beamline.js +++ b/ui/src/reducers/beamline.js @@ -1,3 +1,4 @@ +/* eslint-disable sonarjs/no-duplicate-string */ import { STATE } from '../actions/beamline'; import { RUNNING, MOTOR_STATE } from '../constants'; @@ -141,7 +142,7 @@ export const INITIAL_STATE = { energyScanElements: [], }; -export default (state = INITIAL_STATE, action) => { +function beamlineReducer(state = INITIAL_STATE, action = {}) { let data = {}; switch (action.type) { @@ -415,4 +416,6 @@ export default (state = INITIAL_STATE, action) => { default: return state; } -}; +} + +export default beamlineReducer; diff --git a/ui/src/reducers/contextMenu.js b/ui/src/reducers/contextMenu.js index a6e6d50c9..2e89f3ddf 100644 --- a/ui/src/reducers/contextMenu.js +++ b/ui/src/reducers/contextMenu.js @@ -1,5 +1,4 @@ -/* eslint-disable import/no-anonymous-default-export */ -const initialState = { +const INITIAL_STATE = { show: false, shape: { type: 'NONE' }, x: 0, @@ -12,7 +11,7 @@ const initialState = { }, }; -export default (state = initialState, action) => { +function contextMenuReducer(state = INITIAL_STATE, action = {}) { switch (action.type) { case 'SHOW_CONTEXT_MENU': { return { @@ -36,4 +35,6 @@ export default (state = initialState, action) => { default: return state; } -}; +} + +export default contextMenuReducer; diff --git a/ui/src/reducers/general.js b/ui/src/reducers/general.js index c1fe64d20..2354ec3a1 100644 --- a/ui/src/reducers/general.js +++ b/ui/src/reducers/general.js @@ -1,4 +1,4 @@ -const initialState = { +const INITIAL_STATE = { loading: false, showErrorPanel: false, errorMessage: '', @@ -13,7 +13,7 @@ const initialState = { applicationFetched: false, }; -export default (state = initialState, action) => { +function generalReducer(state = INITIAL_STATE, action = {}) { switch (action.type) { case 'SET_LOADING': { return { @@ -60,4 +60,6 @@ export default (state = initialState, action) => { default: return state; } -}; +} + +export default generalReducer; diff --git a/ui/src/reducers/gphl_workflow.js b/ui/src/reducers/gphlWorkflow.js similarity index 82% rename from ui/src/reducers/gphl_workflow.js rename to ui/src/reducers/gphlWorkflow.js index 2de15bd50..6e7ea3437 100644 --- a/ui/src/reducers/gphl_workflow.js +++ b/ui/src/reducers/gphlWorkflow.js @@ -1,9 +1,9 @@ -const initialState = { +const INITIAL_STATE = { workflows: [], current: null, }; -export default (state = initialState, action) => { +function gphlWorkflowReducer(state = INITIAL_STATE, action = {}) { switch (action.type) { case 'SET_WORKFLOWS': { return { ...state, workflows: { ...action.workflows } }; @@ -25,4 +25,6 @@ export default (state = initialState, action) => { default: return state; } -}; +} + +export default gphlWorkflowReducer; diff --git a/ui/src/reducers/index.js b/ui/src/reducers/index.js index b9180f32d..8affb9eb0 100644 --- a/ui/src/reducers/index.js +++ b/ui/src/reducers/index.js @@ -15,7 +15,7 @@ import contextMenu from './contextMenu'; import remoteAccess from './remoteAccess'; import shapes from './shapes'; import workflow from './workflow'; -import gphl_workflow from './gphl_workflow'; +import gphl_workflow from './gphlWorkflow'; import taskResult from './taskResult'; import uiproperties from './uiproperties'; diff --git a/ui/src/reducers/logger.js b/ui/src/reducers/logger.js index 1ce44b63f..3647cbcd0 100644 --- a/ui/src/reducers/logger.js +++ b/ui/src/reducers/logger.js @@ -1,9 +1,9 @@ -const initialState = { +const INITIAL_STATE = { logRecords: [], activePage: 0, }; -export default (state = initialState, action) => { +function loggerReducer(state = INITIAL_STATE, action = {}) { switch (action.type) { case 'ADD_LOG_RECORD': { return { ...state, logRecords: [...state.logRecords, action.data] }; @@ -17,4 +17,6 @@ export default (state = initialState, action) => { default: return state; } -}; +} + +export default loggerReducer; diff --git a/ui/src/reducers/login.js b/ui/src/reducers/login.js index bef23c6a7..6f3577784 100644 --- a/ui/src/reducers/login.js +++ b/ui/src/reducers/login.js @@ -1,4 +1,4 @@ -const initialState = { +const INITIAL_STATE = { loggedIn: null, // null means loggedIn state is not known yet showProposalsForm: false, selectedProposal: '', @@ -9,7 +9,7 @@ const initialState = { }, }; -export default (state = initialState, action) => { +function loginReducer(state = INITIAL_STATE, action = {}) { switch (action.type) { case 'SET_LOGIN_INFO': { if (action.loginInfo.user.username !== '') { @@ -56,4 +56,6 @@ export default (state = initialState, action) => { default: return state; } -}; +} + +export default loginReducer; diff --git a/ui/src/reducers/queue.js b/ui/src/reducers/queue.js index d2fd63293..444dcaf22 100644 --- a/ui/src/reducers/queue.js +++ b/ui/src/reducers/queue.js @@ -2,7 +2,7 @@ import update from 'immutability-helper'; import { QUEUE_STOPPED, CLICK_CENTRING } from '../constants'; import { clearAllLastUsedParameters } from '../components/Tasks/fields'; -const initialState = { +const INITIAL_STATE = { queue: [], current: { sampleID: null, running: false }, queueStatus: QUEUE_STOPPED, @@ -14,7 +14,7 @@ const initialState = { groupFolder: '', }; -export default (state = initialState, action) => { +function queueReducer(state = INITIAL_STATE, action = {}) { switch (action.type) { case 'SET_QUEUE': { return { ...state, queue: action.sampleOrder }; @@ -22,13 +22,13 @@ export default (state = initialState, action) => { case 'CLEAR_QUEUE': { return { ...state, - queue: initialState.queue, - current: initialState.current, + queue: INITIAL_STATE.queue, + current: INITIAL_STATE.current, }; } case 'ADD_SAMPLES_TO_QUEUE': { const sampleIDList = action.samplesData.map((s) => s.sampleID); - return { ...state, queue: state.queue.concat(sampleIDList) }; + return { ...state, queue: [...state.queue, ...sampleIDList] }; } case 'SET_QUEUE_STATUS': return { @@ -103,7 +103,7 @@ export default (state = initialState, action) => { return { ...state, [action.settingName]: action.value }; } case 'CLEAR_ALL': { - return { ...state, ...initialState, autoMountNext: state.autoMountNext }; + return { ...state, ...INITIAL_STATE, autoMountNext: state.autoMountNext }; } case 'QUEUE_STATE': { return Object.assign({}, state, ...action.queueState); @@ -128,4 +128,6 @@ export default (state = initialState, action) => { default: return state; } -}; +} + +export default queueReducer; diff --git a/ui/src/reducers/queueGUI.js b/ui/src/reducers/queueGUI.js index 2a3e6fdbd..3cfa6ef2d 100644 --- a/ui/src/reducers/queueGUI.js +++ b/ui/src/reducers/queueGUI.js @@ -1,6 +1,6 @@ import { omit } from 'lodash/object'; -const initialState = { +const INITIAL_STATE = { showRestoreDialog: false, searchString: '', displayData: {}, @@ -10,7 +10,7 @@ const initialState = { showConfirmCollectDialog: false, }; -export default (state = initialState, action) => { +function queueGUIReducer(state = INITIAL_STATE, action = {}) { switch (action.type) { case 'redux-form/CHANGE': { if (action.form === 'search-sample') { @@ -26,7 +26,7 @@ export default (state = initialState, action) => { const newNodes = []; action.sampleOrder.forEach((sampleID) => { - if (action.sampleList.hasOwnProperty(sampleID)) { + if (sampleID in action.sampleList) { action.sampleList[sampleID].tasks.forEach((task) => { if (!existingNodes.includes(task.queueID.toString())) { newNodes.push(task.queueID.toString()); @@ -126,7 +126,7 @@ export default (state = initialState, action) => { const newNodes = []; sampleOrder.forEach((sampleID) => { - if (sampleList.hasOwnProperty(sampleID)) { + if (sampleID in sampleList) { sampleList[sampleID].tasks.forEach((task) => { if (!existingNodes.includes(task.queueID.toString())) { newNodes.push(task.queueID.toString()); @@ -144,9 +144,11 @@ export default (state = initialState, action) => { return { ...state, displayData }; } case 'CLEAR_ALL': { - return initialState; + return INITIAL_STATE; } default: return state; } -}; +} + +export default queueGUIReducer; diff --git a/ui/src/reducers/remoteAccess.js b/ui/src/reducers/remoteAccess.js index 97adf4b8f..0d8faee8b 100644 --- a/ui/src/reducers/remoteAccess.js +++ b/ui/src/reducers/remoteAccess.js @@ -1,4 +1,4 @@ -const initialState = { +const INITIAL_STATE = { // the null value is used to distinguish between signed out (null) or logged in (true/false) sid: null, observers: [], @@ -8,7 +8,7 @@ const initialState = { chatMessageCount: 0, }; -export default (state = initialState, action) => { +function remoteAccessReducer(state = INITIAL_STATE, action = {}) { switch (action.type) { case 'SET_RA_STATE': { return { @@ -51,4 +51,6 @@ export default (state = initialState, action) => { default: return state; } -}; +} + +export default remoteAccessReducer; diff --git a/ui/src/reducers/sampleChanger.js b/ui/src/reducers/sampleChanger.js index ba81c909c..8055e61cb 100644 --- a/ui/src/reducers/sampleChanger.js +++ b/ui/src/reducers/sampleChanger.js @@ -1,3 +1,4 @@ +/* eslint-disable sonarjs/no-duplicate-string */ const INITIAL_STATE = { contents: {}, state: 'READY', @@ -87,7 +88,7 @@ const INITIAL_STATE = { selectedDrop: null, }; -export default (state = INITIAL_STATE, action) => { +function sampleChangerReducer(state = INITIAL_STATE, action = {}) { switch (action.type) { case 'SET_SC_CONTENTS': { return { ...state, contents: action.data.sampleChangerContents }; @@ -122,4 +123,6 @@ export default (state = INITIAL_STATE, action) => { return state; } } -}; +} + +export default sampleChangerReducer; diff --git a/ui/src/reducers/sampleGrid.js b/ui/src/reducers/sampleGrid.js index b4e71c598..3e80960a7 100644 --- a/ui/src/reducers/sampleGrid.js +++ b/ui/src/reducers/sampleGrid.js @@ -37,7 +37,7 @@ const INITIAL_STATE = { }, }; -export default (state = INITIAL_STATE, action) => { +function sampleGridReducer(state = INITIAL_STATE, action = {}) { switch (action.type) { case 'SET_QUEUE': { const sampleList = { ...state.sampleList }; @@ -122,9 +122,11 @@ export default (state = INITIAL_STATE, action) => { const sampleIDList = action.samplesData.map((s) => s.sampleID); const sampleList = { ...state.sampleList }; sampleIDList.forEach((sampleID, i) => { - sampleList[sampleID].tasks.length > 0 - ? sampleList[sampleID].tasks.concat(action.samplesData[i].tasks) - : (sampleList[sampleID].tasks = action.samplesData[i].tasks); + if (sampleList[sampleID].tasks.length > 0) { + sampleList[sampleID].tasks.concat(action.samplesData[i].tasks); + } else { + sampleList[sampleID].tasks = action.samplesData[i].tasks; + } }); return { ...state, sampleList }; @@ -370,4 +372,6 @@ export default (state = INITIAL_STATE, action) => { return state; } } -}; +} + +export default sampleGridReducer; diff --git a/ui/src/reducers/sampleview.js b/ui/src/reducers/sampleview.js index 560c3c605..f091dd084 100644 --- a/ui/src/reducers/sampleview.js +++ b/ui/src/reducers/sampleview.js @@ -1,4 +1,4 @@ -const initialState = { +const INITIAL_STATE = { clickCentring: false, clickCentringPoints: [], clickCentringClicksLeft: -1, @@ -43,7 +43,7 @@ const initialState = { selectedShapes: [], }; -export default (state = initialState, action) => { +function sampleViewReducer(state = INITIAL_STATE, action = {}) { switch (action.type) { case 'TOOGLE_CINEMA': { return { ...state, cinema: !state.cinema }; @@ -169,16 +169,7 @@ export default (state = initialState, action) => { ); return { ...state, selectedShapes }; } - case 'CLEAR_ALL': { - return { - ...state, - distancePoints: [], - clickCentringPoints: [], - gridList: [], - gridCount: 0, - selectedShapes: [], - }; - } + case 'CLEAR_ALL': case 'SET_CURRENT_SAMPLE': { return { ...state, @@ -225,4 +216,6 @@ export default (state = initialState, action) => { default: return state; } -}; +} + +export default sampleViewReducer; diff --git a/ui/src/reducers/shapes.js b/ui/src/reducers/shapes.js index 6ca052abd..cf4f485f4 100644 --- a/ui/src/reducers/shapes.js +++ b/ui/src/reducers/shapes.js @@ -1,10 +1,10 @@ import { omit } from 'lodash/object'; -const initialState = { +const INITIAL_STATE = { shapes: {}, }; -export default (state = initialState, action) => { +function shapesReducer(state = INITIAL_STATE, action = {}) { switch (action.type) { case 'SET_SHAPES': { return { ...state, shapes: action.shapes }; @@ -31,10 +31,10 @@ export default (state = initialState, action) => { return { ...state, overlayLevel: action.level }; } case 'SET_CURRENT_SAMPLE': { - return initialState; + return INITIAL_STATE; } case 'CLEAR_ALL': { - return initialState; + return INITIAL_STATE; } case 'SET_INITIAL_STATE': { return { @@ -45,4 +45,6 @@ export default (state = initialState, action) => { default: return state; } -}; +} + +export default shapesReducer; diff --git a/ui/src/reducers/taskForm.js b/ui/src/reducers/taskForm.js index 984fedf06..80530be8b 100644 --- a/ui/src/reducers/taskForm.js +++ b/ui/src/reducers/taskForm.js @@ -1,4 +1,4 @@ -const initialState = { +const INITIAL_STATE = { sampleIds: [], taskData: {}, pointID: -1, @@ -16,7 +16,7 @@ const initialState = { }, }; -export default (state = initialState, action) => { +function taskFormReducer(state = INITIAL_STATE, action = {}) { switch (action.type) { case 'SHOW_FORM': { return { @@ -53,4 +53,6 @@ export default (state = initialState, action) => { default: return state; } -}; +} + +export default taskFormReducer; diff --git a/ui/src/reducers/taskResult.js b/ui/src/reducers/taskResult.js index 8a3543fcd..ac00036d8 100644 --- a/ui/src/reducers/taskResult.js +++ b/ui/src/reducers/taskResult.js @@ -1,8 +1,8 @@ -const initialState = { +const INITIAL_STATE = { energyScan: [], }; -export default (state = initialState, action) => { +function taskResultReducer(state = INITIAL_STATE, action = {}) { switch (action.type) { case 'SET_ENERGY_SCAN_RESULT': { const results = state.energyScan; @@ -14,9 +14,11 @@ export default (state = initialState, action) => { return { ...state, energyScan: results }; } case 'SET_INITIAL_STATE': { - return { ...initialState }; + return { ...INITIAL_STATE }; } default: return state; } -}; +} + +export default taskResultReducer; diff --git a/ui/src/reducers/uiproperties.js b/ui/src/reducers/uiproperties.js index 0e891461e..b23d25aa7 100644 --- a/ui/src/reducers/uiproperties.js +++ b/ui/src/reducers/uiproperties.js @@ -1,8 +1,8 @@ import { findIndex, setWith, clone } from 'lodash'; -const initialState = {}; +const INITIAL_STATE = {}; -export default (state = initialState, action) => { +function uiPropertiesReducer(state = INITIAL_STATE, action = {}) { switch (action.type) { case 'SET_UI_PROPERTIES': { return { ...state, ...action.data }; @@ -26,4 +26,6 @@ export default (state = initialState, action) => { default: return state; } -}; +} + +export default uiPropertiesReducer; diff --git a/ui/src/reducers/workflow.js b/ui/src/reducers/workflow.js index ff2f4e8ce..96a851407 100644 --- a/ui/src/reducers/workflow.js +++ b/ui/src/reducers/workflow.js @@ -1,9 +1,9 @@ -const initialState = { +const INITIAL_STATE = { workflows: [], current: null, }; -export default (state = initialState, action) => { +function workflowReducer(state = INITIAL_STATE, action = {}) { switch (action.type) { case 'SET_WORKFLOWS': { return { ...state, workflows: { ...action.workflows } }; @@ -25,4 +25,6 @@ export default (state = initialState, action) => { default: return state; } -}; +} + +export default workflowReducer; diff --git a/ui/src/serverIO.js b/ui/src/serverIO.js index 542ed5191..c75056ca4 100644 --- a/ui/src/serverIO.js +++ b/ui/src/serverIO.js @@ -40,7 +40,7 @@ import { setLoading, showConnectionLostDialog } from './actions/general'; import { showWorkflowParametersDialog } from './actions/workflow'; -import { showGphlWorkflowParametersDialog } from './actions/gphl_workflow'; +import { showGphlWorkflowParametersDialog } from './actions/gphlWorkflow'; import { incChatMessageCount, getRaState } from './actions/remoteAccess'; @@ -228,9 +228,10 @@ class ServerIO { const taskCollapsed = store.getState().queueGUI.displayData[record.queueID].collapsed; - if (record.state === 1 && !taskCollapsed) { - this.dispatch(collapseItem(record.queueID)); - } else if (record.state >= 2 && taskCollapsed) { + if ( + (record.state === 1 && !taskCollapsed) || + (record.state >= 2 && taskCollapsed) + ) { this.dispatch(collapseItem(record.queueID)); }