Fix panel toggle for Gutenberg 9.1
[MAILPOET-3154]
This commit is contained in:
@ -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') {
|
||||
|
@ -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"');
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user