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

Chrome: Persist the "opened/closed" state of the sidebar panels in localStorage #2533

Merged
merged 1 commit into from
Aug 28, 2017

Conversation

youknowriad
Copy link
Contributor

This PR uses the preferences persisted reducer to persist the state of the sidebar panels.
I needed to add the possibility to make the PanelBody opened flag "controlled".

solves #450 partially

@youknowriad youknowriad added the General Interface Parts of the UI which don't fall neatly under other labels. label Aug 25, 2017
@youknowriad youknowriad self-assigned this Aug 25, 2017
@codecov
Copy link

codecov bot commented Aug 25, 2017

Codecov Report

Merging #2533 into master will increase coverage by 0.01%.
The diff coverage is 30.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2533      +/-   ##
==========================================
+ Coverage   31.07%   31.09%   +0.01%     
==========================================
  Files         174      174              
  Lines        5258     5278      +20     
  Branches      898      905       +7     
==========================================
+ Hits         1634     1641       +7     
- Misses       3078     3088      +10     
- Partials      546      549       +3
Impacted Files Coverage Δ
editor/actions.js 41.17% <0%> (-1.25%) ⬇️
editor/sidebar/post-status/index.js 0% <0%> (ø) ⬆️
editor/sidebar/discussion-panel/index.js 0% <0%> (ø) ⬆️
editor/sidebar/post-excerpt/index.js 0% <0%> (ø) ⬆️
editor/sidebar/post-taxonomies/index.js 0% <0%> (ø) ⬆️
editor/sidebar/featured-image/index.js 0% <0%> (ø) ⬆️
editor/sidebar/table-of-contents/index.js 0% <0%> (ø) ⬆️
editor/reducer.js 88.81% <100%> (+0.07%) ⬆️
editor/selectors.js 96.37% <100%> (+0.05%) ⬆️
editor/sidebar/page-attributes/index.js 76.19% <60%> (+2.5%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 72d4d00...92d357e. Read the comment docs.

@youknowriad youknowriad changed the title Chrome: Update the "opened/closed" state of the sidebar panels in localStorage Chrome: Persist the "opened/closed" state of the sidebar panels in localStorage Aug 25, 2017
Copy link
Member

@karmatosed karmatosed left a comment

Choose a reason for hiding this comment

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

I ran through some self usability tests and all seemed to pass. Not giving a code review but experience and design wise this is approved.

@youknowriad youknowriad force-pushed the update/persist-sidebar-panels-state branch from 59b22aa to 92d357e Compare August 28, 2017 08:35
@youknowriad youknowriad merged commit 6143210 into master Aug 28, 2017
@youknowriad youknowriad deleted the update/persist-sidebar-panels-state branch August 28, 2017 10:53
@@ -441,13 +441,21 @@ export function mode( state = 'visual', action ) {
return state;
}

export function preferences( state = { isSidebarOpened: ! isMobile }, action ) {
export function preferences( state = { isSidebarOpened: ! isMobile, panels: { 'post-status': true } }, action ) {
Copy link
Member

Choose a reason for hiding this comment

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

This line is pretty long and we might consider breaking out the default to its own constant variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will fix the notes in #2568

...state,
panels: {
...state.panels,
[ action.panel ]: ! get( state, [ 'panels', action.panel ], false ),
Copy link
Member

Choose a reason for hiding this comment

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

Is there any need for get here? state.panels seems it should always be an object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's needed for users who already have the preferences persisted.

*/
export function isEditorSidebarPanelOpened( state, panel ) {
const panels = getPreference( state, 'panels' );
return panels ? !! panels[ panel ] : false;
Copy link
Member

Choose a reason for hiding this comment

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

Similarly, not sure we need to test presence of panels.

@@ -67,17 +74,17 @@ const applyConnect = connect(
( state ) => {
return {
featuredImageId: getEditedPostAttribute( state, 'featured_media' ),
isOpened: isEditorSidebarPanelOpened( state, PANEL_NAME ),
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if we should bind props using PANEL_NAME not only in mapStateToProps, but also in mapDispatchToProps, so toggle callback in the visual component doesn't need to know/pass the value.

const icon = `arrow-${ opened ? 'down' : 'right' }`;
const className = classnames( 'components-panel__body', { 'is-opened': opened } );
const { title, children, opened } = this.props;
const isOpened = opened === undefined ? this.state.opened : opened;
Copy link
Member

Choose a reason for hiding this comment

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

Are there any places this component is used with the state variant now? Wonder if we should just treat it as a controlled component, rather than try to juggle both state and prop values of opened.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not right now, no strong preference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
General Interface Parts of the UI which don't fall neatly under other labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants