Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement openSidebarSections in redux store #9381

Conversation

maartenleenders
Copy link
Contributor

Summary

This PR can be summarized in the following changelog entry:

  • Makes sure you can open multiple keyword sections at the same time.

Relevant technical choices:

  • Previously activeKeyword kept track of the keyword tab that was opened. We now opted for an array that keeps track of all open sections, which can be multiple.
  • In comparison to PR 9377, we now leave activeKeywords intact next to openSidebarSections. The activeKeywords fields should be removed when completely moving to the sidebar. See: Remove activeKeywords and related logic when moving to sidebar #9380

Test instructions

This PR can be tested by following these steps:

  • Checkout branch and run yarn install and yarn test (when the tests have passed CR you can assume they are fine, though do check them).
  • You could expose the store and action to the window in edit.js, and dispatch (store.dispatch( action() ) and see whether the state was changed correctly.

Quality assurance

  • I have tested this code to the best of my abilities
  • I have added unittests to verify the code works as intended

Fixes #9305

@maartenleenders maartenleenders changed the base branch from trunk to feature/content-analysis-in-sidebar March 29, 2018 09:36
/**
* Helper function: returns an array with the requested item removed.
*
* @param {Array} openSections The array from which the item should be removed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name doesn't match parameter openSidebarSections

* Helper function: returns an array with the requested item removed.
*
* @param {Array} openSections The array from which the item should be removed.
* @param {string} removeItem The item to be removed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name doesn't match parameter removeSection

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I think the name of the param should just be sectionId. Same goes for sidebarSectionCloser.

Copy link
Contributor Author

@maartenleenders maartenleenders Mar 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure we would use ids, names, indexes, etc.

So I called it item. I'd rather change the action's fields to address your concerns.

*
* @returns {Array} The array without the item that should be removed.
*/
let sidebarSectionCloser = ( openSidebarSections, removeSection ) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be const

return openSidebarSections.filter( item => item !== removeSection );
};

let sidebarSectionOpener = ( openSidebarSections, addSection ) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be const

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't have documentation

@@ -0,0 +1,49 @@
import { CLOSE_ALL_SIDEBAR_SECTIONS, OPEN_SIDEBAR_SECTION, CLOSE_SIDEBAR_SECTION } from "../actions/openSidebarSections";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you write functions to handle state change I think it's better to name them after the action instead of their responsibility. So I think sidebarSectionOpener should just be openSidebarSection for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but for readability's sake I used sidebarSectionOpener() because of overlap with the redux action OPEN_SIDEBAR_SECTION and its creator openSidebarSection().

Will consider changing.

];
};

/**
Copy link
Contributor

@abotteram abotteram Mar 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't make it more elaborate than it needs to be ;)

/**
 * A reducer that manages the open state for sections.
 *
 * @param {string} state The current state of the object.
 * @param {Object} action The current action received.
 *
 * @returns {string} The state.
 */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I agree I went a little overboard here, what I was going for was documenting which part of the state this reducer actually manages. In this file you cannot see this anywhere, you'd have to visit the rootReducer in edit.js. To have everything together, it could be worthwhile to write down the name of the state that is managed per reducer.

@abotteram
Copy link
Contributor

Just saying I disagree with the usage of an array in this case.

@maartenleenders
Copy link
Contributor Author

I did too, initially, but @atimmer convinced me. I think for now an array solves the issue adequately.

@abotteram
Copy link
Contributor

CR 👍

@abotteram
Copy link
Contributor

Acceptance 👍

@abotteram abotteram closed this Apr 3, 2018
@abotteram abotteram reopened this Apr 3, 2018
@abotteram abotteram merged commit ec9aaf0 into feature/content-analysis-in-sidebar Apr 3, 2018
@abotteram abotteram deleted the stories/9305-2-implement-openSections branch April 3, 2018 08:19
@atimmer atimmer added this to the Content Analysis in Sidebar milestone Apr 3, 2018
@IreneStr IreneStr restored the stories/9305-2-implement-openSections branch July 10, 2018 11:19
@IreneStr IreneStr deleted the stories/9305-2-implement-openSections branch July 10, 2018 11:19
IreneStr added a commit that referenced this pull request Jul 10, 2018
…openSections"

This reverts commit ec9aaf0, reversing
changes made to 32913c6.

Reverting this redux because we've decided to handle openness of collapsibles in the local state of the collapsibles themselves.
maartenleenders added a commit that referenced this pull request Jul 12, 2018
…ns-redux

Revert "Merge pull request #9381 from Yoast/stories/9305-2-implement-openSections"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants