SEO Tools: Fix removal of custom title formatting#13327
Conversation
|
|
||
| Object.keys( emptyFormatTypes ).forEach( ( type ) => emptyFormatTypes[ type ] = '' ); | ||
|
|
||
| return Object.assign( {}, updatedTitleFormats, emptyFormatTypes ); |
There was a problem hiding this comment.
we might find lodash.mapValues() helpful here…
prepareEmptyFormats = formats =>
mapValues(
formats,
format => isArray( format ) && 0 === format.length ? '' : format,
)
dmsnell
left a comment
There was a problem hiding this comment.
Code looks good (left a comment about the updater). Is this ready for testing?
@dmsnell yes, this is ready for testing now. One thing to note:
|
| updatedOptions.advanced_seo_front_page_description = this.state.frontPageMetaDescription; | ||
| } | ||
|
|
||
| // Empty arrays for title formats were not working properly with saveSiteSettings. |
There was a problem hiding this comment.
we probably don't need to mention that this code was broken in the past, only explain why it's here now
Since the absence of data indicates that there are no changes in the network request
we need to send an indicator that we specifically want to clear the format
We will pass an empty string in this case
| mapValues( formats, format => isArray( format ) && 0 === format.length ? '' : format ); | ||
|
|
||
| // Replace empty arrays with empty strings to fix custom format deletion bug. | ||
| updatedOptions.advanced_seo_title_formats = prepareEmptyFormats( updatedOptions.advanced_seo_title_formats ); |
There was a problem hiding this comment.
note that we don't have much reason to split the function call from its definition since it's just a single line. we could inline here
updatedOptions.advanced_seo_title_formats = mapValues(
updatedOptions.advanced_seo_title_formats,
format => isArray( format ) && 0 === format.length ? '' : format,
);
// or
import { update } from 'lodash';
update(
updatedOptions,
'advanced_seo_title_formats',
format => isArray( format ) && 0 === format.length ? '' : format,
);
dmsnell
left a comment
There was a problem hiding this comment.
Tested and reproduce the bug in master while seeing it fixed in this branch ![]()
09c1651 to
f7c01c9
Compare
Previously, it was not possible to delete existing custom title formats. This was caused because passed empty format arrays were discarded by saveSiteSettings. These are now replaced with empty strings instead, in order for them to be correctly transmitted to API.
f7c01c9 to
2595649
Compare
Fixes #10003
Previously, it was not possible to delete existing custom title formats.
This was caused because passed empty format arrays were discarded
by
saveSiteSettings. These are now replaced with empty strings instead,in order for them to be correctly transmitted to API.
Test with:
D5298-codeFor Jetpack sites test with:
Automattic/jetpack#7044(merged)