-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid persisting preference every time the sidebar tab is changed (#4…
…0923) * Turn complementary areas into a standard action/selector/reducer, unhooking it from the preferences store * Handle visibility in selectors, and resolve issues with actions and reducer * Update test description * My site editor general sidebar active by default * Revert "My site editor general sidebar active by default" This reverts commit 334734c. * Preserve site editor behavior as best as possible by denoting a default area * Use an explicit action when setting up the site editor app to denote the default action * Migrate any stored data * Remove DISABLE_COMPLEMENTARY_AREA handling in interface reducer
- Loading branch information
Showing
12 changed files
with
254 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { combineReducers } from '@wordpress/data'; | ||
|
||
export function complementaryAreas( state = {}, action ) { | ||
switch ( action.type ) { | ||
case 'SET_DEFAULT_COMPLEMENTARY_AREA': { | ||
const { scope, area } = action; | ||
|
||
// If there's already an area, don't overwrite it. | ||
if ( state[ scope ] ) { | ||
return state; | ||
} | ||
|
||
return { | ||
...state, | ||
[ scope ]: area, | ||
}; | ||
} | ||
case 'ENABLE_COMPLEMENTARY_AREA': { | ||
const { scope, area } = action; | ||
return { | ||
...state, | ||
[ scope ]: area, | ||
}; | ||
} | ||
} | ||
|
||
return state; | ||
} | ||
|
||
export default combineReducers( { | ||
complementaryAreas, | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...rences-persistence/src/migrations/preferences-package-data/convert-complementary-areas.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export default function convertComplementaryAreas( state ) { | ||
return Object.keys( state ).reduce( ( stateAccumulator, scope ) => { | ||
const scopeData = state[ scope ]; | ||
|
||
// If a complementary area is truthy, convert it to the `isComplementaryAreaVisible` boolean. | ||
if ( scopeData?.complementaryArea ) { | ||
const updatedScopeData = { ...scopeData }; | ||
delete updatedScopeData.complementaryArea; | ||
updatedScopeData.isComplementaryAreaVisible = true; | ||
stateAccumulator[ scope ] = updatedScopeData; | ||
return stateAccumulator; | ||
} | ||
|
||
return stateAccumulator; | ||
}, state ); | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/preferences-persistence/src/migrations/preferences-package-data/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import convertComplementaryAreas from './convert-complementary-areas'; | ||
|
||
export default function convertPreferencesPackageData( data ) { | ||
return convertComplementaryAreas( data ); | ||
} |
36 changes: 36 additions & 0 deletions
36
...s-persistence/src/migrations/preferences-package-data/test/convert-complementary-areas.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import convertComplementaryAreas from '../convert-complementary-areas'; | ||
|
||
describe( 'convertComplementaryAreas', () => { | ||
it( 'converts the `complementaryArea` property in each scope to an `isComplementaryAreaVisible` boolean', () => { | ||
const input = { | ||
'core/customize-widgets': { | ||
complementaryArea: 'edit-post/block', | ||
}, | ||
'core/edit-site': { | ||
complementaryArea: 'edit-site/template', | ||
}, | ||
'core/edit-post': { | ||
complementaryArea: 'edit-post/block', | ||
}, | ||
'core/edit-widgets': {}, | ||
}; | ||
|
||
const expectedOutput = { | ||
'core/customize-widgets': { | ||
isComplementaryAreaVisible: true, | ||
}, | ||
'core/edit-site': { | ||
isComplementaryAreaVisible: true, | ||
}, | ||
'core/edit-post': { | ||
isComplementaryAreaVisible: true, | ||
}, | ||
'core/edit-widgets': {}, | ||
}; | ||
|
||
expect( convertComplementaryAreas( input ) ).toEqual( expectedOutput ); | ||
} ); | ||
} ); |
84 changes: 84 additions & 0 deletions
84
packages/preferences-persistence/src/migrations/preferences-package-data/test/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import convertPreferencesPackageData from '../'; | ||
|
||
const input = { | ||
'core/customize-widgets': { | ||
welcomeGuide: false, | ||
fixedToolbar: true, | ||
}, | ||
'core/edit-widgets': { | ||
welcomeGuide: false, | ||
fixedToolbar: true, | ||
showBlockBreadcrumbs: false, | ||
complementaryArea: 'edit-widgets/block-areas', | ||
}, | ||
'core/edit-post': { | ||
welcomeGuide: false, | ||
fixedToolbar: true, | ||
fullscreenMode: false, | ||
hiddenBlockTypes: [ 'core/audio', 'core/cover' ], | ||
editorMode: 'visual', | ||
preferredStyleVariations: { | ||
'core/quote': 'large', | ||
}, | ||
inactivePanels: [], | ||
openPanels: [ 'post-status' ], | ||
pinnedItems: { | ||
'my-sidebar-plugin/title-sidebar': false, | ||
}, | ||
}, | ||
'core/edit-site': { | ||
welcomeGuide: false, | ||
welcomeGuideStyles: false, | ||
fixedToolbar: true, | ||
complementaryArea: 'edit-site/global-styles', | ||
}, | ||
}; | ||
|
||
describe( 'convertPreferencesPackageData', () => { | ||
it( 'converts data to the expected format', () => { | ||
expect( convertPreferencesPackageData( input ) ) | ||
.toMatchInlineSnapshot( ` | ||
Object { | ||
"core/customize-widgets": Object { | ||
"fixedToolbar": true, | ||
"welcomeGuide": false, | ||
}, | ||
"core/edit-post": Object { | ||
"editorMode": "visual", | ||
"fixedToolbar": true, | ||
"fullscreenMode": false, | ||
"hiddenBlockTypes": Array [ | ||
"core/audio", | ||
"core/cover", | ||
], | ||
"inactivePanels": Array [], | ||
"openPanels": Array [ | ||
"post-status", | ||
], | ||
"pinnedItems": Object { | ||
"my-sidebar-plugin/title-sidebar": false, | ||
}, | ||
"preferredStyleVariations": Object { | ||
"core/quote": "large", | ||
}, | ||
"welcomeGuide": false, | ||
}, | ||
"core/edit-site": Object { | ||
"fixedToolbar": true, | ||
"isComplementaryAreaVisible": true, | ||
"welcomeGuide": false, | ||
"welcomeGuideStyles": false, | ||
}, | ||
"core/edit-widgets": Object { | ||
"fixedToolbar": true, | ||
"isComplementaryAreaVisible": true, | ||
"showBlockBreadcrumbs": false, | ||
"welcomeGuide": false, | ||
}, | ||
} | ||
` ); | ||
} ); | ||
} ); |