Skip to content

SEO Tools: Fix removal of custom title formatting#13327

Merged
vindl merged 3 commits intomasterfrom
fix/seo-custom-title-deletion
May 3, 2017
Merged

SEO Tools: Fix removal of custom title formatting#13327
vindl merged 3 commits intomasterfrom
fix/seo-custom-title-deletion

Conversation

@vindl
Copy link
Copy Markdown
Member

@vindl vindl commented Apr 24, 2017

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-code
For Jetpack sites test with: Automattic/jetpack#7044 (merged)

@vindl vindl added [Status] In Progress Bug When a feature is broken and / or not performing as intended labels Apr 24, 2017
@vindl vindl added this to the Advanced SEO milestone Apr 24, 2017
@vindl vindl self-assigned this Apr 24, 2017
@matticbot matticbot added the [Size] S Small sized issue label Apr 24, 2017
@matticbot
Copy link
Copy Markdown
Contributor

@vindl vindl requested review from dmsnell and roundhill April 24, 2017 12:49
@vindl vindl added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels Apr 24, 2017

Object.keys( emptyFormatTypes ).forEach( ( type ) => emptyFormatTypes[ type ] = '' );

return Object.assign( {}, updatedTitleFormats, emptyFormatTypes );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might find lodash.mapValues() helpful here…

prepareEmptyFormats = formats =>
	mapValues(
		formats,
		format => isArray( format ) && 0 === format.length ? '' : format,
	)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion! I've added it in 8fa5c7e.

Copy link
Copy Markdown
Member

@dmsnell dmsnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good (left a comment about the updater). Is this ready for testing?

@vindl
Copy link
Copy Markdown
Member Author

vindl commented Apr 25, 2017

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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 09c1651.

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 );
Copy link
Copy Markdown
Member

@dmsnell dmsnell Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, agreed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 09c1651.

Copy link
Copy Markdown
Member

@dmsnell dmsnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and reproduce the bug in master while seeing it fixed in this branch :shipit:

@vindl vindl force-pushed the fix/seo-custom-title-deletion branch from 09c1651 to f7c01c9 Compare May 1, 2017 22:56
@vindl vindl removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label May 3, 2017
vindl added 3 commits May 3, 2017 10:41
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.
@vindl vindl force-pushed the fix/seo-custom-title-deletion branch from f7c01c9 to 2595649 Compare May 3, 2017 17:42
@vindl vindl merged commit a632f6e into master May 3, 2017
@vindl vindl deleted the fix/seo-custom-title-deletion branch May 3, 2017 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug When a feature is broken and / or not performing as intended [Size] S Small sized issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants