-
Notifications
You must be signed in to change notification settings - Fork 33
Add Traffic Boost settings infrastructure #2942
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
Merged
acicovic
merged 2 commits into
add/traffic-boost
from
add/traffic-boost-settings-infrastructure
Nov 15, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 +1 @@ | ||
| <?php return array('dependencies' => array('react', 'react-dom', 'wp-dom-ready', 'wp-element'), 'version' => '18278c930ac085311870'); | ||
| <?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-data', 'wp-dom-ready', 'wp-element', 'wp-i18n'), 'version' => '801d6f5bef2f27842da3'); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 +1 @@ | ||
| <?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => 'd7059d961c9fe0a71c34'); | ||
| <?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => '91832340c46f7a9be8e6'); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
8 changes: 8 additions & 0 deletions
8
src/content-helper/common/settings/types/traffic-boost-settings.d.ts
This file contains hidden or 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,8 @@ | ||
| /** | ||
| * Defines the Traffic Boost settings structure. | ||
| * | ||
| * @since 3.18.0 | ||
| */ | ||
| export interface TrafficBoostSettings { | ||
| Setting1: string; | ||
| } | ||
acicovic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or 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
This file contains hidden or 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
67 changes: 63 additions & 4 deletions
67
src/content-helper/dashboard-page/pages/dashboard/page-component.tsx
This file contains hidden or 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,13 +1,72 @@ | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { SettingsProvider, TrafficBoostSettings } from '../../../common/settings'; | ||
| import { getContentHelperPermissions } from '../../../common/utils/permissions'; | ||
| import { VerifyCredentials } from '../../../common/verify-credentials'; | ||
|
|
||
| /** | ||
| * Gets the settings from the passed JSON. | ||
| * | ||
| * If missing settings or invalid values are detected, they get set to their | ||
| * defaults. | ||
| * | ||
| * @since 3.18.0 | ||
| * | ||
| * @param {string} settingsJson The JSON containing the settings. | ||
| * | ||
| * @return {TrafficBoostSettings} The resulting settings object. | ||
| */ | ||
| const getSettingsFromJson = ( settingsJson: string ): TrafficBoostSettings => { | ||
| // Default settings object. | ||
| const defaultSettings: TrafficBoostSettings = { | ||
| Setting1: 'Hello World!', | ||
| }; | ||
|
|
||
| // If the settings are empty, try to get them from the global variable. | ||
| if ( '' === settingsJson ) { | ||
| settingsJson = window.wpParselyContentHelperSettings; | ||
| } | ||
|
|
||
| let parsedSettings: TrafficBoostSettings; | ||
|
|
||
| try { | ||
| parsedSettings = JSON.parse( settingsJson ); | ||
| } catch ( e ) { | ||
| // Return defaults when parsing failed or the string is empty. | ||
| return defaultSettings; | ||
| } | ||
|
|
||
| // Merge parsed settings with default settings. | ||
| const mergedSettings = { ...defaultSettings, ...parsedSettings }; | ||
|
|
||
| // Fix invalid values if any are found. | ||
| if ( typeof mergedSettings.Setting1 !== 'string' ) { | ||
| mergedSettings.Setting1 = defaultSettings.Setting1; | ||
| } | ||
|
|
||
| return mergedSettings; | ||
| }; | ||
|
|
||
| /** | ||
| * The main dashboard page component. | ||
| * | ||
| * @since 3.18.0 | ||
| */ | ||
| export const DashboardPage = () => { | ||
| return ( | ||
| <> | ||
| <h1>Parse.ly Dashboard</h1> | ||
| <p>Welcome to the main Parse.ly dashboard page.</p> | ||
| </> | ||
| <SettingsProvider | ||
| endpoint="traffic-boost" | ||
| defaultSettings={ getSettingsFromJson( window.wpParselyContentHelperSettings ) } | ||
| > | ||
| <VerifyCredentials> | ||
| <> | ||
| <h1>Parse.ly</h1> | ||
| <p>Welcome to the Parse.ly Dashboard page!</p> | ||
| <p>Content Helper Permissions: { JSON.stringify( getContentHelperPermissions() ) }</p> | ||
| <p>Traffic Boost Settings: { JSON.stringify( getSettingsFromJson( window.wpParselyContentHelperSettings ) ) }</p> | ||
| </> | ||
acicovic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </VerifyCredentials> | ||
| </SettingsProvider> | ||
| ); | ||
| }; | ||
58 changes: 58 additions & 0 deletions
58
src/rest-api/settings/class-endpoint-traffic-boost-settings.php
This file contains hidden or 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,58 @@ | ||
| <?php | ||
| /** | ||
| * API Endpoint: Traffic Boost Settings | ||
| * | ||
| * @package Parsely | ||
| * @since 3.18.0 | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Parsely\REST_API\Settings; | ||
|
|
||
| /** | ||
| * Endpoint for saving and retrieving Content Helper Traffic Boost settings. | ||
| * | ||
| * @since 3.18.0 | ||
| * | ||
| * @phpstan-import-type Subvalue_Spec from Base_Settings_Endpoint | ||
| */ | ||
| class Endpoint_Traffic_Boost_Settings extends Base_Settings_Endpoint { | ||
| /** | ||
| * Returns the endpoint's name. | ||
| * | ||
| * @since 3.18.0 | ||
| * | ||
| * @return string | ||
| */ | ||
| public static function get_endpoint_name(): string { | ||
| return 'traffic-boost'; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the meta entry's key. | ||
| * | ||
| * @since 3.18.0 | ||
| * | ||
| * @return string The meta entry's key. | ||
| */ | ||
| protected function get_meta_key(): string { | ||
| return 'parsely_content_helper_settings_traffic_boost'; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the endpoint's subvalues specifications. | ||
| * | ||
| * @since 3.18.0 | ||
| * | ||
| * @return array<string, Subvalue_Spec> | ||
| */ | ||
| protected function get_subvalues_specs(): array { | ||
| return array( | ||
| 'Setting1' => array( | ||
| 'values' => array(), | ||
| 'default' => 'Hello World!', | ||
| ), | ||
| ); | ||
| } | ||
acicovic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.