diff --git a/assets/js/src/form_editor/store/reducers/toggle_sidebar_panel.jsx b/assets/js/src/form_editor/store/reducers/toggle_sidebar_panel.jsx index 3522ad944d..6c58bcd418 100644 --- a/assets/js/src/form_editor/store/reducers/toggle_sidebar_panel.jsx +++ b/assets/js/src/form_editor/store/reducers/toggle_sidebar_panel.jsx @@ -21,11 +21,11 @@ const getRequiredAction = (openedPanels, panelId, toggleTo) => { * @return {object} Modified state object */ export default (state, action) => { - if (action.toggleTo !== undefined && !['opened', 'closed'].includes(action.toggleTo)) { - throw new Error(`Unexpected toggleTo value "${action.toggleTo}"`); - } + let toggleTo; + if (action.toggleTo === true) toggleTo = 'opened'; + if (action.toggleTo === false) toggleTo = 'closed'; const openedPanels = [...state.sidebar.openedPanels]; - const requiredAction = getRequiredAction(openedPanels, action.id, action.toggleTo); + const requiredAction = getRequiredAction(openedPanels, action.id, toggleTo); if (requiredAction === 'open') { openedPanels.push(action.id); } else if (requiredAction === 'close') { diff --git a/tests/javascript/form_editor/store/reducers/toggle_sidebar_panel.spec.js b/tests/javascript/form_editor/store/reducers/toggle_sidebar_panel.spec.js index 5ef66578a7..48a28197e0 100644 --- a/tests/javascript/form_editor/store/reducers/toggle_sidebar_panel.spec.js +++ b/tests/javascript/form_editor/store/reducers/toggle_sidebar_panel.spec.js @@ -46,23 +46,13 @@ describe('Toggle Sidebar Panel Reducer', () => { const action = { type: 'TOGGLE_SIDEBAR_PANEL', id: 'nice-panel', - toggleTo: 'opened', + toggleTo: true, }; reducer(initialState, action); let finalState = reducer(initialState, action); expect(finalState.sidebar.openedPanels).to.include('nice-panel'); - action.toggleTo = 'closed'; + action.toggleTo = false; finalState = reducer(initialState, action); expect(finalState.sidebar.openedPanels).to.not.include('nice-panel'); }); - - it('Should throw an error for unexpected toggleTo value', () => { - const action = { - type: 'TOGGLE_SIDEBAR_PANEL', - id: 'nice-panel', - toggleTo: 'nonsense', - }; - expect(() => (reducer(initialState, action))) - .to.throw('Unexpected toggleTo value "nonsense"'); - }); });