-
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.
Add indicator for metadata changes to Save Panel when reviewing modif…
…ied entities (#61811) * Add rough prototype showing meta in entities panel * Simplify detection of metadata changes Removed unnecessary code added in previous commit and instead modified existing functions to add a flag on existing dirtyEntityRecord structures to indicate when metadata changes have been made. * Remove obsolete code * Add indicator for bindings to save entities panel * Modify message to read 'Post Meta' * Add store function to check if meta has changed * Remove obsolete check * Simplify logic to check if meta has changed * Update tests * Make hasMetaChanges selector private * Suggestion: Move logic to `hasPostMetaChanges` selector * Change test formatting * Don't show save panel in pre-publish * Get `hasPostMetaChanges` from the proper place * Add end-to-end test * Update class name * Clarify naming * Show Post Meta in relevant post * Remove extra change * Move test metadata test util * Update comments * Prevent save panel from appearing when just footnotes are modified * Update package-lock.json --------- Co-authored-by: Mario Santos <[email protected]>
- Loading branch information
1 parent
db66bc9
commit 5576d89
Showing
8 changed files
with
227 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
61 changes: 45 additions & 16 deletions
61
packages/editor/src/components/entities-saved-states/entity-record-item.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 |
---|---|---|
@@ -1,49 +1,78 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { CheckboxControl, PanelRow } from '@wordpress/components'; | ||
import { Icon, CheckboxControl, Flex, PanelRow } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { decodeEntities } from '@wordpress/html-entities'; | ||
import { connection } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editorStore } from '../../store'; | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
export default function EntityRecordItem( { record, checked, onChange } ) { | ||
const { name, kind, title, key } = record; | ||
|
||
// Handle templates that might use default descriptive titles. | ||
const entityRecordTitle = useSelect( | ||
const { entityRecordTitle, hasPostMetaChanges } = useSelect( | ||
( select ) => { | ||
if ( 'postType' !== kind || 'wp_template' !== name ) { | ||
return title; | ||
return { | ||
entityRecordTitle: title, | ||
hasPostMetaChanges: unlock( | ||
select( editorStore ) | ||
).hasPostMetaChanges( name, key ), | ||
}; | ||
} | ||
|
||
const template = select( coreStore ).getEditedEntityRecord( | ||
kind, | ||
name, | ||
key | ||
); | ||
return select( editorStore ).__experimentalGetTemplateInfo( | ||
template | ||
).title; | ||
return { | ||
entityRecordTitle: | ||
select( editorStore ).__experimentalGetTemplateInfo( | ||
template | ||
).title, | ||
hasPostMetaChanges: unlock( | ||
select( editorStore ) | ||
).hasPostMetaChanges( name, key ), | ||
}; | ||
}, | ||
[ name, kind, title, key ] | ||
); | ||
|
||
return ( | ||
<PanelRow> | ||
<CheckboxControl | ||
__nextHasNoMarginBottom | ||
label={ | ||
decodeEntities( entityRecordTitle ) || __( 'Untitled' ) | ||
} | ||
checked={ checked } | ||
onChange={ onChange } | ||
/> | ||
</PanelRow> | ||
<> | ||
<PanelRow> | ||
<CheckboxControl | ||
__nextHasNoMarginBottom | ||
label={ | ||
decodeEntities( entityRecordTitle ) || __( 'Untitled' ) | ||
} | ||
checked={ checked } | ||
onChange={ onChange } | ||
/> | ||
</PanelRow> | ||
{ hasPostMetaChanges && ( | ||
<PanelRow> | ||
<Flex className="entities-saved-states__post-meta"> | ||
<Icon | ||
className="entities-saved-states__connections-icon" | ||
icon={ connection } | ||
size={ 24 } | ||
/> | ||
<span className="entities-saved-states__bindings-text"> | ||
{ __( 'Post Meta.' ) } | ||
</span> | ||
</Flex> | ||
</PanelRow> | ||
) } | ||
</> | ||
); | ||
} |
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