Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Social: Refactor feature option storing #34113

Merged
merged 26 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f37dd1a
Add the new settings object + tests
gmjuhasz Nov 14, 2023
d00d07e
Update initial states + previous usages
gmjuhasz Nov 14, 2023
012eb2c
Update UI + store functions
gmjuhasz Nov 14, 2023
b36d720
changelog
gmjuhasz Nov 14, 2023
5896416
Fix versions
gmjuhasz Nov 14, 2023
b6952a2
Add control for fetching both options together
gmjuhasz Nov 15, 2023
b5de327
Social: Remove deprecated feature files (#34114)
gmjuhasz Nov 20, 2023
2b51295
Social: Refresh store on Publicize module toggle via 1 call (#34142)
gmjuhasz Nov 20, 2023
8fbd642
Merge branch 'trunk' into refactor/social-register-feature-settings
gmjuhasz Nov 20, 2023
aa4ee16
Rename structure
gmjuhasz Nov 20, 2023
659e0a1
Merge branch 'trunk' into refactor/social-register-feature-settings
gmjuhasz Nov 27, 2023
77e27ee
Fixup versions
gmjuhasz Nov 27, 2023
e809f08
Fix template issue, and make sure it's migrated
gmjuhasz Nov 28, 2023
b9ac65c
Merge branch 'trunk' into refactor/social-register-feature-settings
gmjuhasz Nov 28, 2023
9c0234d
Merge branch 'trunk' into refactor/social-register-feature-settings
gmjuhasz Nov 28, 2023
6bec608
fix tests
gmjuhasz Nov 28, 2023
d4b52c6
Test fix
gmjuhasz Nov 28, 2023
484f96f
Merge branch 'trunk' into refactor/social-register-feature-settings
gmjuhasz Nov 30, 2023
0ba898a
Fix auto-conversion migration logic + add test
gmjuhasz Nov 30, 2023
f91feb3
Add auto-conversion sync option
gmjuhasz Nov 30, 2023
a89e7b5
changelog
gmjuhasz Nov 30, 2023
d7949bf
Merge branch 'trunk' into refactor/social-register-feature-settings
gmjuhasz Dec 5, 2023
b7c2568
Merge branch 'trunk' into refactor/social-register-feature-settings
gmjuhasz Dec 7, 2023
9b6020a
Merge branch 'trunk' into refactor/social-register-feature-settings
gmjuhasz Dec 7, 2023
c169499
Update versions
gmjuhasz Dec 7, 2023
df78925
Fix versions
gmjuhasz Dec 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

Social: Refactored storing of feature options to use core functions
2 changes: 1 addition & 1 deletion projects/js-packages/publicize-components/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-publicize-components",
"version": "0.41.5-alpha",
"version": "0.42.0-alpha",
"description": "A library of JS components required by the Publicize editor plugin",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/publicize-components/#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const AutoConversionToggle: React.FC< AutoConversionToggleProps > = ( {

const toggleStatus = useCallback( () => {
const newOption = {
image: ! isEnabled,
enabled: ! isEnabled,
};
updateOptions( newOption );
}, [ isEnabled, updateOptions ] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const TemplatePickerButton: React.FC = () => {

useEffect( () => {
if ( currentTemplate ) {
const newOption = { defaults: { template: currentTemplate } };
const newOption = { template: currentTemplate };
updateOptions( newOption );
}
}, [ currentTemplate, updateOptions ] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function* updateAutoConversionSettings( settings ) {
yield setAutoConversionSettings( settings );
yield updateAutoConversionSettingsControl( settings );
const updatedSettings = yield fetchAutoConversionSettings();
yield setAutoConversionSettings( updatedSettings );
yield setAutoConversionSettings( updatedSettings.jetpack_social_autoconvert_images );
return true;
} catch ( e ) {
const oldSettings = select( SOCIAL_STORE_ID ).getAutoConversionSettings();
Expand All @@ -41,7 +41,7 @@ export function* refreshAutoConversionSettings() {
try {
yield setUpdatingAutoConversionSettings();
const updatedSettings = yield fetchAutoConversionSettings();
yield setAutoConversionSettings( updatedSettings );
yield setAutoConversionSettings( updatedSettings.jetpack_social_autoconvert_images );
return true;
} catch ( e ) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export function* updateSocialImageGeneratorSettings( settings ) {
yield setSocialImageGeneratorSettings( settings );
yield updateSocialImageGeneratorSettingsControl( settings );
const updatedSettings = yield fetchSocialImageGeneratorSettings();
yield setSocialImageGeneratorSettings( updatedSettings );
yield setSocialImageGeneratorSettings(
updatedSettings.jetpack_social_image_generator_settings
);
return true;
} catch ( e ) {
const oldSettings = select( SOCIAL_STORE_ID ).getSocialImageGeneratorSettings();
Expand Down Expand Up @@ -69,7 +71,9 @@ export function* refreshSocialImageGeneratorSettings() {
try {
yield setUpdatingSocialImageGeneratorSettings();
const updatedSettings = yield fetchSocialImageGeneratorSettings();
yield setSocialImageGeneratorSettings( updatedSettings );
yield setSocialImageGeneratorSettings(
updatedSettings.jetpack_social_image_generator_settings
);
return true;
} catch ( e ) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,31 @@ export default {
} );
},
[ FETCH_SOCIAL_IMAGE_GENERATOR_SETTINGS ]: function () {
return apiFetch( { path: '/jetpack/v4/social-image-generator/settings' } );
return apiFetch( {
path: '/wp/v2/settings?_fields=jetpack_social_image_generator_settings',
} );
},
[ UPDATE_SOCIAL_IMAGE_GENERATOR_SETTINGS ]: function ( action ) {
return apiFetch( {
path: '/jetpack/v4/social-image-generator/settings',
path: '/wp/v2/settings',
method: 'POST',
data: action.settings,
data: {
jetpack_social_image_generator_settings: action.settings,
},
} );
},
[ FETCH_AUTO_CONVERSION_SETTINGS ]: function () {
return apiFetch( { path: '/jetpack/v4/auto-conversion/settings' } );
return apiFetch( {
path: '/wp/v2/settings?_fields=jetpack_social_autoconvert_images',
} );
},
[ UPDATE_AUTO_CONVERSION_SETTINGS ]: function ( action ) {
return apiFetch( {
path: '/jetpack/v4/auto-conversion/settings',
path: '/wp/v2/settings',
method: 'POST',
data: action.settings,
Comment on lines 112 to -111
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need multiple API calls? Can we make a single API call to get all the settings at once?

Copy link
Member

Choose a reason for hiding this comment

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

We can add the settings fields separated by comma

/wp/v2/settings?_fields=jetpack_social_image_generator_settings,jetpack_social_autoconvert_images

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, to fetch the settings we can just have one call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I'll do that.

Copy link
Contributor Author

@gmjuhasz gmjuhasz Nov 15, 2023

Choose a reason for hiding this comment

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

This turned out to be a bigger change as I had to remove the old refreshes introduced in #33969, so I added the store functions in b6952a2 and created another PR on this branch for the others #34142

data: {
jetpack_social_autoconvert_images: action.settings,
},
} );
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function* getSocialImageGeneratorSettings() {
try {
const settings = yield fetchSocialImageGeneratorSettings();
if ( settings ) {
return setSocialImageGeneratorSettings( settings );
return setSocialImageGeneratorSettings( settings.jetpack_social_image_generator_settings );
}
} catch ( e ) {
// TODO: Add proper error handling here
Expand All @@ -56,7 +56,7 @@ export function* getAutoConversionSettings() {
try {
const settings = yield fetchAutoConversionSettings();
if ( settings ) {
return setAutoConversionSettings( settings );
return setAutoConversionSettings( settings.jetpack_social_autoconvert_images );
}
} catch ( e ) {
// TODO: Add proper error handling here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const autoConversionSettingsSelectors = {
getAutoConversionSettings: state => state.autoConversionSettings,
isAutoConversionAvailable: state => state.autoConversionSettings.available,
isAutoConversionEnabled: state => state.autoConversionSettings.image,
isAutoConversionEnabled: state => state.autoConversionSettings.enabled,
isAutoConversionSettingsUpdating: state => state.autoConversionSettings.isUpdating,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ const socialImageGeneratorSettingsSelectors = {
isSocialImageGeneratorAvailable: state => state.socialImageGeneratorSettings.available,
isSocialImageGeneratorEnabled: state => state.socialImageGeneratorSettings.enabled,
isUpdatingSocialImageGeneratorSettings: state => state.socialImageGeneratorSettings.isUpdating,
getSocialImageGeneratorDefaultTemplate: state =>
state.socialImageGeneratorSettings.defaultTemplate,
getSocialImageGeneratorDefaultTemplate: state => state.socialImageGeneratorSettings.template,
};

export default socialImageGeneratorSettingsSelectors;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

Social: Refactored storing of feature options to use core functions
2 changes: 1 addition & 1 deletion projects/packages/publicize/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"link-template": "https://github.com/Automattic/jetpack-publicize/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "0.36.x-dev"
"dev-trunk": "0.37.x-dev"
}
},
"config": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/publicize/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-publicize",
"version": "0.36.6-alpha",
"version": "0.37.0-alpha",
"description": "Publicize makes it easy to share your site’s posts on several social media networks automatically when you publish a new post.",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/publicize/#readme",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/publicize/src/class-publicize-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ public function register_post_meta() {
'single' => true,
'default' => array(
'image_generator_settings' => array(
'template' => ( new Social_Image_Generator\Settings() )->get_default_template(),
'template' => ( new Jetpack_Social_Settings\Settings() )->sig_get_default_template(),
'enabled' => false,
),
),
Expand Down
3 changes: 2 additions & 1 deletion projects/packages/publicize/src/class-publicize-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public static function on_jetpack_feature_publicize_enabled() {
add_action( 'rest_api_init', array( new Connections_Post_Field(), 'register_fields' ), 5 );
add_action( 'rest_api_init', array( new REST_Controller(), 'register_rest_routes' ) );
add_action( 'current_screen', array( static::class, 'init_sharing_limits' ) );
add_action( 'rest_api_init', array( new Auto_Conversion\REST_Settings_Controller(), 'register_routes' ) );
add_action( 'rest_api_init', array( new Jetpack_Social_Settings\Settings(), 'register_settings' ) );
add_action( 'admin_init', array( new Jetpack_Social_Settings\Settings(), 'register_settings' ) );

( new Social_Image_Generator\Setup() )->init();
}
Expand Down
Loading
Loading