-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Social: Refactor Social Note settings to use core (#41153)
* Register settings with core * Update store to use core settings api * changelog * Remove deprecated code * Fix some tests * Fix constant issue * Cast pricing_page option to int as before * Remove boolean castings * Remove casting * Fix TS errors * Address comments on function names
- Loading branch information
Showing
19 changed files
with
266 additions
and
157 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/js-packages/publicize-components/changelog/refactor-social-note-settings-core
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: changed | ||
|
||
Refactored Social Note settings to use core |
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
16 changes: 16 additions & 0 deletions
16
projects/js-packages/publicize-components/src/social-store/actions/pricing-page.ts
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { SHOW_PRICING_PAGE_KEY } from '../constants'; | ||
|
||
/** | ||
* Sets the Show Pricing Page enabled status. | ||
* | ||
* @param isEnabled - The new enabled status. | ||
* @return {Function} A thunk. | ||
*/ | ||
export function setShowPricingPage( isEnabled: boolean ) { | ||
return async function ( { registry } ) { | ||
const { saveSite } = registry.dispatch( coreStore ); | ||
|
||
await saveSite( { [ SHOW_PRICING_PAGE_KEY ]: isEnabled } ); | ||
}; | ||
} |
33 changes: 33 additions & 0 deletions
33
projects/js-packages/publicize-components/src/social-store/actions/social-notes.ts
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { SOCIAL_NOTES_CONFIG_KEY, SOCIAL_NOTES_ENABLED_KEY } from '../constants'; | ||
import { SocialNotesConfig } from '../types'; | ||
|
||
/** | ||
* Sets the Social Notes enabled status. | ||
* | ||
* @param isEnabled - The new enabled status. | ||
* | ||
* @return {Function} A thunk. | ||
*/ | ||
export function toggleSocialNotes( isEnabled: boolean ) { | ||
return async function ( { registry } ) { | ||
const { saveSite } = registry.dispatch( coreStore ); | ||
|
||
await saveSite( { [ SOCIAL_NOTES_ENABLED_KEY ]: isEnabled } ); | ||
}; | ||
} | ||
|
||
/** | ||
* Updates the Social Notes Config | ||
* | ||
* @param {Partial< SocialNotesConfig >} data - The data to save. | ||
* | ||
* @return {Function} A thunk. | ||
*/ | ||
export function updateSocialNotesConfig( data: Partial< SocialNotesConfig > ) { | ||
return async function ( { registry } ) { | ||
const { saveSite } = registry.dispatch( coreStore ); | ||
|
||
await saveSite( { [ SOCIAL_NOTES_CONFIG_KEY ]: data } ); | ||
}; | ||
} |
4 changes: 4 additions & 0 deletions
4
projects/js-packages/publicize-components/src/social-store/constants.ts
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,2 +1,6 @@ | ||
// See projects/packages/publicize/src/jetpack-social-settings/class-settings.php | ||
export const SIG_SETTINGS_KEY = 'jetpack_social_image_generator_settings'; | ||
export const UTM_ENABLED_KEY = 'jetpack_social_utm_settings'; | ||
export const SOCIAL_NOTES_ENABLED_KEY = 'jetpack-social-note'; | ||
export const SOCIAL_NOTES_CONFIG_KEY = 'jetpack_social_notes_config'; | ||
export const SHOW_PRICING_PAGE_KEY = 'jetpack-social_show_pricing_page'; |
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
19 changes: 19 additions & 0 deletions
19
projects/js-packages/publicize-components/src/social-store/selectors/pricing-page.ts
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { createRegistrySelector } from '@wordpress/data'; | ||
import { getSocialScriptData } from '../../utils'; | ||
import { SHOW_PRICING_PAGE_KEY } from '../constants'; | ||
|
||
/** | ||
* Returns the Show Pricing Page enabled status for the current site. | ||
*/ | ||
export const shouldShowPricingPage = createRegistrySelector( select => () => { | ||
const { getSite } = select( coreStore ); | ||
|
||
const settings = getSite( undefined, { _fields: SHOW_PRICING_PAGE_KEY } ); | ||
|
||
// If the settings are not available in the store yet, use the default settings. | ||
return ( | ||
settings?.[ SHOW_PRICING_PAGE_KEY ] ?? | ||
getSocialScriptData().settings?.socialPlugin?.show_pricing_page | ||
); | ||
} ); |
37 changes: 37 additions & 0 deletions
37
projects/js-packages/publicize-components/src/social-store/selectors/social-notes.ts
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { createRegistrySelector } from '@wordpress/data'; | ||
import { getSocialScriptData } from '../../utils'; | ||
import { SOCIAL_NOTES_CONFIG_KEY, SOCIAL_NOTES_ENABLED_KEY } from '../constants'; | ||
|
||
/** | ||
* Returns if Social Notes are enabled for the current site. | ||
*/ | ||
export const isSocialNotesEnabled = createRegistrySelector( select => () => { | ||
const { getSite } = select( coreStore ); | ||
|
||
const settings = getSite( undefined, { | ||
_fields: SOCIAL_NOTES_ENABLED_KEY, | ||
} ); | ||
// If the settings are not available in the store yet, use the default settings. | ||
return ( | ||
settings?.[ SOCIAL_NOTES_ENABLED_KEY ] ?? | ||
getSocialScriptData().settings?.socialPlugin?.social_notes_enabled | ||
); | ||
} ); | ||
|
||
/** | ||
* Returns the Social Notes Config for the current site. | ||
*/ | ||
export const getSocialNotesConfig = createRegistrySelector( select => () => { | ||
const { getSite } = select( coreStore ); | ||
|
||
const settings = getSite( undefined, { | ||
_fields: SOCIAL_NOTES_CONFIG_KEY, | ||
} ); | ||
|
||
// If the settings are not available in the store yet, use the default settings. | ||
return ( | ||
settings?.[ SOCIAL_NOTES_CONFIG_KEY ] ?? | ||
getSocialScriptData().settings?.socialPlugin?.social_notes_config | ||
); | ||
} ); |
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
4 changes: 4 additions & 0 deletions
4
projects/packages/publicize/changelog/refactor-social-note-settings-core
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: changed | ||
|
||
Refactored Social Note settings to use core |
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
4 changes: 4 additions & 0 deletions
4
projects/plugins/social/changelog/refactor-social-note-settings-core
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: changed | ||
|
||
Refactored Social Note settings to use core |
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
Oops, something went wrong.