Skip to content

Commit

Permalink
Normalize the pattern category object in menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Oct 11, 2023
1 parent 62412cc commit 036963d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,23 @@ export default function RenameCategoryMenuItem( { category, onClose } ) {
return null;
}

// User created pattern categories have their properties updated when
// retrieved via `getUserPatternCategories`. The rename modal expects an
// object that will match the pattern category entity.
const normalizedCategory = {
id: category.id,
slug: category.slug,
name: category.label,
};

return (
<>
<MenuItem onClick={ () => setIsModalOpen( true ) }>
{ __( 'Rename' ) }
</MenuItem>
{ isModalOpen && (
<RenamePatternCategoryModal
category={ category }
category={ normalizedCategory }
onClose={ () => {
setIsModalOpen( false );
onClose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ export default function RenamePatternCategoryModal( {
onSuccess,
...props
} ) {
// If the user created category has been retrieved via
// getUserPatternCategories the name value is assigned to the label property
// and `name` is overwritten with the slug value to match categories from
// core, template parts etc.
const originalName = decodeEntities( category.label || category.name );
const [ name, setName ] = useState( originalName );
const [ name, setName ] = useState( decodeEntities( category.name ) );
const [ isSaving, setIsSaving ] = useState( false );

const { saveEntityRecord, invalidateResolution } = useDispatch( coreStore );
Expand Down

0 comments on commit 036963d

Please sign in to comment.