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

Migrate standalone widgets editor to use new preferences package #39084

Merged
merged 3 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 30 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ $z-layers: (
".components-popover.customize-widgets-more-menu__content": 99998,
".components-popover.edit-post-more-menu__content": 99998,
".components-popover.edit-site-more-menu__content": 99998,
".components-popover.edit-widgets-more-menu__content": 99998,
".components-popover.preferences-more-menu__content": 99998,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like I accidentally added this in #38873. The more menu is staying in the interface package, so the 'preferences' part here is wrong.

It shouldn't have caused any bugs as nothing should be using this name. As I migrate each editor, the individual z-indices for each editor can be removed in favor of just the interface one.

".components-popover.interface-more-menu__content": 99998,
".components-popover.block-editor-rich-text__inline-format-toolbar": 99998,
".components-popover.block-editor-warning__dropdown": 99998,
".components-popover.edit-navigation-menu-actions__switcher-dropdown": 99998,
Expand Down
76 changes: 75 additions & 1 deletion packages/data/src/plugins/persistence/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,80 @@ function persistencePlugin( registry, pluginOptions ) {
};
}

/**
* Move the 'features' object in local storage from the sourceStoreName to the
* preferences store.
*
* @param {Object} persistence The persistence interface.
* @param {string} sourceStoreName The name of the store that has persisted
* preferences to migrate to the preferences
* package.
*/
export function migrateFeaturePreferencesToPreferencesStore(
persistence,
sourceStoreName
) {
const preferencesStoreName = 'core/preferences';
const interfaceStoreName = 'core/interface';

const state = persistence.get();

// Features most recently (and briefly) lived in the interface package.
// If data exists there, prioritize using that for the migration. If not
// also check the original package as the user may have updated from an
// older block editor version.
const interfaceFeatures =
state[ interfaceStoreName ]?.preferences?.features?.[ sourceStoreName ];
const sourceFeatures = state[ sourceStoreName ]?.preferences?.features;
const featuresToMigrate = interfaceFeatures
? interfaceFeatures
: sourceFeatures;

if ( featuresToMigrate ) {
const targetFeatures = state[ preferencesStoreName ]?.preferences;

// Avoid migrating features again if they've previously been migrated.
if ( ! targetFeatures?.[ sourceStoreName ] ) {
// Set the feature values in the interface store, the features
// object is keyed by 'scope', which matches the store name for
// the source.
persistence.set( preferencesStoreName, {
preferences: {
...targetFeatures,
[ sourceStoreName ]: featuresToMigrate,
},
} );

// Remove migrated feature preferences from `interface`.
if ( interfaceFeatures ) {
const otherInterfaceFeatures =
state[ interfaceStoreName ]?.preferences?.features;

persistence.set( interfaceStoreName, {
preferences: {
features: {
...otherInterfaceFeatures,
[ sourceStoreName ]: undefined,
},
},
} );
}

// Remove migrated feature preferences from the source.
if ( sourceFeatures ) {
const sourcePreferences = state[ sourceStoreName ]?.preferences;

persistence.set( sourceStoreName, {
preferences: {
...sourcePreferences,
features: undefined,
},
} );
}
}
}
}

/**
* Move the 'features' object in local storage from the sourceStoreName to the
* interface store.
Expand Down Expand Up @@ -277,7 +351,7 @@ export function migrateFeaturePreferencesToInterfaceStore(
persistencePlugin.__unstableMigrate = ( pluginOptions ) => {
const persistence = createPersistenceInterface( pluginOptions );

migrateFeaturePreferencesToInterfaceStore(
migrateFeaturePreferencesToPreferencesStore(
persistence,
'core/edit-widgets'
);
Expand Down
Loading