-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pattern overrides: Update overrides attribute data structure and rena…
…me it to `content` (#58596) * Add a migration for changing the `overrides` format and renaming the attribute to `content` * Update the pattern block edit function to use the new content attribute and nested `values` property * Update naming conventions and add some doc blocks * Update `pattern/overrides` context to use content attribute (with some back compat) and use new values property in the block bindings callback for overrides * Revert "Update naming conventions and add some doc blocks" (this caused a hard to find bug somewhere) This reverts commit f243630. * Update naming conventions used by utility functions * Update more naming conventions within the pattern block edit function * Fix bug where every content values is updated immediately * Code quality: Reduce some lengthy lines * Update e2e test to expect new data structure * Fix incorrect type Co-authored-by: Kai Hao <kevin830726@gmail.com> * Use a simpler format for `defaultValues without the nested `values` property * Fix invalid type --------- Co-authored-by: Kai Hao <kevin830726@gmail.com>
- Loading branch information
1 parent
023916c
commit 2f44afa
Showing
8 changed files
with
159 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
"ref": { | ||
"type": "number" | ||
}, | ||
"overrides": { | ||
"content": { | ||
"type": "object" | ||
} | ||
}, | ||
|
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,57 @@ | ||
// v1: Migrate and rename the `overrides` attribute to the `content` attribute. | ||
const v1 = { | ||
attributes: { | ||
ref: { | ||
type: 'number', | ||
}, | ||
overrides: { | ||
type: 'object', | ||
}, | ||
}, | ||
supports: { | ||
customClassName: false, | ||
html: false, | ||
inserter: false, | ||
renaming: false, | ||
}, | ||
// Force this deprecation to run whenever there's an `overrides` object. | ||
isEligible( { overrides } ) { | ||
return !! overrides; | ||
}, | ||
/* | ||
* Old attribute format: | ||
* overrides: { | ||
* // An key is an id that represents a block. | ||
* // The values are the attribute values of the block. | ||
* "V98q_x": { content: 'dwefwefwefwe' } | ||
* } | ||
* | ||
* New attribute format: | ||
* content: { | ||
* "V98q_x": { | ||
* // The attribute values are now stored as a 'values' sub-property. | ||
* values: { content: 'dwefwefwefwe' }, | ||
* // ... additional metadata, like the block name can be stored here. | ||
* } | ||
* } | ||
* | ||
*/ | ||
migrate( attributes ) { | ||
const { overrides, ...retainedAttributes } = attributes; | ||
|
||
const content = {}; | ||
|
||
Object.keys( overrides ).forEach( ( id ) => { | ||
content[ id ] = { | ||
values: overrides[ id ], | ||
}; | ||
} ); | ||
|
||
return { | ||
...retainedAttributes, | ||
content, | ||
}; | ||
}, | ||
}; | ||
|
||
export default [ v1 ]; |
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
Oops, something went wrong.