From af902eae6df89e1d2df3ed1a799144c32c5a8bb7 Mon Sep 17 00:00:00 2001 From: IreneStr Date: Tue, 10 Jul 2018 13:38:22 +0200 Subject: [PATCH 1/2] Revert "Merge pull request #9381 from Yoast/stories/9305-2-implement-openSections" This reverts commit ec9aaf09af63a3689acd3001ae7017c24c20ddcb, reversing changes made to 32913c6d0e5af485f6cf2c30e74df9d81548edc3. Reverting this redux because we've decided to handle openness of collapsibles in the local state of the collapsibles themselves. --- js/src/redux/actions/openSidebarSections.js | 44 ------------- js/src/redux/reducers/openSidebarSections.js | 57 ---------------- .../redux/actions/openSidebarSections.test.js | 34 ---------- .../reducers/openSidebarSections.test.js | 66 ------------------- 4 files changed, 201 deletions(-) delete mode 100644 js/src/redux/actions/openSidebarSections.js delete mode 100644 js/src/redux/reducers/openSidebarSections.js delete mode 100644 js/tests/redux/actions/openSidebarSections.test.js delete mode 100644 js/tests/redux/reducers/openSidebarSections.test.js diff --git a/js/src/redux/actions/openSidebarSections.js b/js/src/redux/actions/openSidebarSections.js deleted file mode 100644 index 20453f0dad0..00000000000 --- a/js/src/redux/actions/openSidebarSections.js +++ /dev/null @@ -1,44 +0,0 @@ -const PREFIX = "WPSEO_"; - -export const OPEN_SIDEBAR_SECTION = `${ PREFIX }OPEN_SIDEBAR_SECTION`; -export const CLOSE_SIDEBAR_SECTION = `${ PREFIX }CLOSE_SIDEBAR_SECTION`; -export const CLOSE_ALL_SIDEBAR_SECTIONS = `${ PREFIX }CLOSE_ALL_SIDEBAR_SECTIONS`; - -/** - * An action creator for the action that opens a section. - * - * @param {string} sectionId The to be opened section. - * - * @returns {Object} A (WPSEO_)OPEN_SECTION action. - */ -export const openSidebarSection = function( sectionId ) { - return { - type: OPEN_SIDEBAR_SECTION, - sectionId, - }; -}; - -/** - * An action creator for the action that closes a section. - * - * @param {string} sectionId The to be closed section. - * - * @returns {Object} A (WPSEO_)CLOSE_SECTION action. - */ -export const closeSidebarSection = function( sectionId ) { - return { - type: CLOSE_SIDEBAR_SECTION, - sectionId, - }; -}; - -/** - * An action creator for the action that closes all sections. - * - * @returns {Object} A (WPSEO_)CLOSE_ALL_SECTIONS action. - */ -export const closeAllSidebarSections = function() { - return { - type: CLOSE_ALL_SIDEBAR_SECTIONS, - }; -}; diff --git a/js/src/redux/reducers/openSidebarSections.js b/js/src/redux/reducers/openSidebarSections.js deleted file mode 100644 index faac8850aa3..00000000000 --- a/js/src/redux/reducers/openSidebarSections.js +++ /dev/null @@ -1,57 +0,0 @@ -import { CLOSE_ALL_SIDEBAR_SECTIONS, OPEN_SIDEBAR_SECTION, CLOSE_SIDEBAR_SECTION } from "../actions/openSidebarSections"; - -const INITIAL_STATE = []; - -/** - * Helper function: returns an array with the passed item added. - * - * @param {Array} openSidebarSections The array to which the item should be added. - * @param {string} sectionId The item to be added. - * - * @returns {Array} The array including the item that should be added. - */ -const sidebarSectionOpener = ( openSidebarSections, sectionId ) => { - if ( typeof sectionId !== "string" || openSidebarSections.includes( sectionId ) ) { - return openSidebarSections; - } - - return [ - ...openSidebarSections, - sectionId, - ]; -}; - -/** - * Helper function: returns an array with the passed item removed. - * - * @param {Array} openSidebarSections The array from which the item should be removed. - * @param {string} sectionId The item to be removed. - * - * @returns {Array} The array without the item that should be removed. - */ -const sidebarSectionCloser = ( openSidebarSections, sectionId ) => { - return openSidebarSections.filter( item => item !== sectionId ); -}; - -/** - * A reducer for adding and removing sections from openSidebarSections. - * - * @param {Object} state The current state, which in this case is openSidebarSections. - * @param {Object} action The current action received. - * - * @returns {Object} The new state. - */ -function openSidebarSectionsReducer( state = INITIAL_STATE, action ) { - switch( action.type ) { - case OPEN_SIDEBAR_SECTION: - return sidebarSectionOpener( state, action.sectionId ); - case CLOSE_SIDEBAR_SECTION: - return sidebarSectionCloser( state, action.sectionId ); - case CLOSE_ALL_SIDEBAR_SECTIONS: - return []; - default: - return state; - } -} - -export default openSidebarSectionsReducer; diff --git a/js/tests/redux/actions/openSidebarSections.test.js b/js/tests/redux/actions/openSidebarSections.test.js deleted file mode 100644 index a54a372176c..00000000000 --- a/js/tests/redux/actions/openSidebarSections.test.js +++ /dev/null @@ -1,34 +0,0 @@ -/* global describe, it, expect */ - -import * as actions from "../../../src/redux/actions/openSidebarSections"; - -describe( "openSidebarSections actions", () => { - it( "should pass along the id when opening a section", () => { - const expected = { - type: actions.OPEN_SIDEBAR_SECTION, - sectionId: "sectionOpened", - }; - const actual = actions.openSidebarSection( "sectionOpened" ); - - expect( actual ).toEqual( expected ); - } ); - - it( "should pass along the keyword when closing a section", () => { - const expected = { - type: actions.CLOSE_SIDEBAR_SECTION, - sectionId: "sectionClosed", - }; - const actual = actions.closeSidebarSection( "sectionClosed" ); - - expect( actual ).toEqual( expected ); - } ); - - it( "should pass nothing but the type in the action object when closing all sections", () => { - const expected = { - type: actions.CLOSE_ALL_SIDEBAR_SECTIONS, - }; - const actual = actions.closeAllSidebarSections(); - - expect( actual ).toEqual( expected ); - } ); -} ); diff --git a/js/tests/redux/reducers/openSidebarSections.test.js b/js/tests/redux/reducers/openSidebarSections.test.js deleted file mode 100644 index 94b81c00dad..00000000000 --- a/js/tests/redux/reducers/openSidebarSections.test.js +++ /dev/null @@ -1,66 +0,0 @@ -/* global describe, it, expect */ - -import { openSidebarSection, closeSidebarSection, closeAllSidebarSections } from "../../../src/redux/actions/openSidebarSections"; -import openSidebarSectionsReducer from "../../../src/redux/reducers/openSidebarSections"; - -describe( "openSidebarSections reducers", () => { - describe( "openSidebarSection", () => { - it( "should add the to be opened section to the openSidebarSections array", () => { - const state = []; - const action = openSidebarSection( "openThisSection" ); - const expected = [ "openThisSection" ]; - const actual = openSidebarSectionsReducer( state, action ); - - expect( actual ).toEqual( expected ); - } ); - - it( "should not add a section that is already open to the openSidebarSections array", () => { - const state = [ "alreadyOpen", "alsoOpen" ]; - const action = openSidebarSection( "alreadyOpen" ); - const expected = [ "alreadyOpen", "alsoOpen" ]; - const actual = openSidebarSectionsReducer( state, action ); - - expect( actual ).toEqual( expected ); - } ); - - it( "should not add the section to the array if the passed argument is not a string", () => { - const state = [ "alreadyOpen", "alsoOpen" ]; - const action = openSidebarSection( 1234 ); - const expected = [ "alreadyOpen", "alsoOpen" ]; - const actual = openSidebarSectionsReducer( state, action ); - - expect( actual ).toEqual( expected ); - } ); - } ); - - describe( "closeSidebarSection", () => { - it( "should remove the to be closed section from the openSidebarSections array", () => { - const state = [ "alreadyOpen", "alsoOpen" ]; - const action = closeSidebarSection( "alsoOpen" ); - const expected = [ "alreadyOpen" ]; - const actual = openSidebarSectionsReducer( state, action ); - - expect( actual ).toEqual( expected ); - } ); - - it( "should not change the array when closing a section that was already closed", () => { - const state = [ "alreadyOpen", "alsoOpen" ]; - const action = closeSidebarSection( "fictionalSection" ); - const expected = [ "alreadyOpen", "alsoOpen" ]; - const actual = openSidebarSectionsReducer( state, action ); - - expect( actual ).toEqual( expected ); - } ); - } ); - - describe( "closeAllSidebarSections", () => { - it( "should empty the openSidebarSections array", () => { - const state = [ "alreadyOpen", "alsoOpen" ]; - const action = closeAllSidebarSections(); - const expected = []; - const actual = openSidebarSectionsReducer( state, action ); - - expect( actual ).toEqual( expected ); - } ); - } ); -} ); From 656cf742f5d7c7f7d8091122e24aa887dd77db72 Mon Sep 17 00:00:00 2001 From: IreneStr Date: Wed, 11 Jul 2018 16:59:18 +0200 Subject: [PATCH 2/2] Remove removed reducer from index.js --- js/src/redux/reducers/index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/js/src/redux/reducers/index.js b/js/src/redux/reducers/index.js index 90dbbba112d..196f1d8264d 100644 --- a/js/src/redux/reducers/index.js +++ b/js/src/redux/reducers/index.js @@ -5,7 +5,6 @@ import activeTab from "./activeTab"; import isCornerstone from "./cornerstoneContent"; import keywords from "./keywords"; import marksButtonStatus from "./markerButtons"; -import openSidebarSections from "./openSidebarSections"; import snippetEditor from "./snippetEditor"; import analysisDataReducer from "./analysisData"; @@ -16,7 +15,6 @@ export default { isCornerstone, keywords, marksButtonStatus, - openSidebarSections, snippetEditor, analysisData: analysisDataReducer, };