-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
37 additions
and
17 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
28 changes: 28 additions & 0 deletions
28
packages/editor/src/store/utils/is-template-part-revertable.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,28 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { TEMPLATE_ORIGINS } from '../constants'; | ||
|
||
/** | ||
* Check if a template part is revertable to its original theme-provided template file. | ||
* | ||
* @param {Object} templatePart The template part entity to check. | ||
* @return {boolean} Whether the template part is revertable. | ||
*/ | ||
export default function isTemplatePartRevertable( templatePart ) { | ||
if ( ! templatePart ) { | ||
return false; | ||
} | ||
// In patterns list page we map the templates parts to a different object | ||
// than the one returned from the endpoint. This is why we need to check for | ||
// two props whether is custom or has a theme file. | ||
const hasThemeFile = | ||
templatePart.has_theme_file || | ||
templatePart.templatePart?.has_theme_file; | ||
const isCustom = [ | ||
templatePart.source, | ||
templatePart.templatePart?.source, | ||
].includes( TEMPLATE_ORIGINS.custom ); | ||
|
||
return hasThemeFile && isCustom; | ||
} |