From 78579b37f3489ec15d1abe049b373400b934549d Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Mon, 1 Jul 2024 23:26:02 +0530 Subject: [PATCH 01/41] Add Reader Revenue Manager Settings components. --- .../components/settings/index.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/components/settings/index.js diff --git a/assets/js/modules/reader-revenue-manager/components/settings/index.js b/assets/js/modules/reader-revenue-manager/components/settings/index.js new file mode 100644 index 00000000000..a5495ca2804 --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/components/settings/index.js @@ -0,0 +1,20 @@ +/** + * Reader Revenue Manager Settings components. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { default as SettingsEdit } from './SettingsEdit'; +export { default as SettingsView } from './SettingsView'; From 0dd60bdbad3d8409977fafdd3d89561a22e7946a Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Mon, 1 Jul 2024 23:26:19 +0530 Subject: [PATCH 02/41] Add Reader Revenue Manager module entrypoint. --- ...esitekit-modules-reader-revenue-manager.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 assets/js/googlesitekit-modules-reader-revenue-manager.js diff --git a/assets/js/googlesitekit-modules-reader-revenue-manager.js b/assets/js/googlesitekit-modules-reader-revenue-manager.js new file mode 100644 index 00000000000..beff1a09e08 --- /dev/null +++ b/assets/js/googlesitekit-modules-reader-revenue-manager.js @@ -0,0 +1,30 @@ +/** + * Reader Revenue Manager module entrypoint. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Internal dependencies + */ +import Data from 'googlesitekit-data'; +import Modules from 'googlesitekit-modules'; +import { + registerStore, + registerModule, +} from './modules/reader-revenue-manager'; + +registerStore( Data ); +registerModule( Modules ); From cb85d3f266d4a76b9eb3845c258218c7c54c1a42 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Mon, 1 Jul 2024 23:26:44 +0530 Subject: [PATCH 03/41] Add Settings constants. --- assets/js/components/settings/constants.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 assets/js/components/settings/constants.js diff --git a/assets/js/components/settings/constants.js b/assets/js/components/settings/constants.js new file mode 100644 index 00000000000..60a60c78933 --- /dev/null +++ b/assets/js/components/settings/constants.js @@ -0,0 +1,19 @@ +/** + * Settings constants. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export const NEW_MODULES = [ 'ads', 'reader-revenue-manager' ]; From 2bebd7f1b6ab893f3ebca63f7554cc29804a228d Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Mon, 1 Jul 2024 23:27:26 +0530 Subject: [PATCH 04/41] Add new badge for RRM in SetupModule. --- assets/js/components/settings/SetupModule.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/assets/js/components/settings/SetupModule.js b/assets/js/components/settings/SetupModule.js index fa5f9d4ce57..5849eaaf796 100644 --- a/assets/js/components/settings/SetupModule.js +++ b/assets/js/components/settings/SetupModule.js @@ -42,6 +42,7 @@ import { CORE_SITE } from '../../googlesitekit/datastore/site/constants'; import { CORE_MODULES } from '../../googlesitekit/modules/datastore/constants'; import { CORE_LOCATION } from '../../googlesitekit/datastore/location/constants'; import { EXPERIMENTAL_MODULES } from '../dashboard-sharing/DashboardSharingSettings/constants'; +import { NEW_MODULES } from './constants'; import { trackEvent } from '../../util'; import useViewContext from '../../hooks/useViewContext'; @@ -114,7 +115,9 @@ export default function SetupModule( { slug, name, description } ) { label={ __( 'Experimental', 'google-site-kit' ) } /> ) } - { slug === 'ads' && } + { NEW_MODULES.includes( slug ) && ( + + ) }

From cb5cb2bfa4ec32963e3bd42e094ebfd4ad548b86 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Mon, 1 Jul 2024 23:28:06 +0530 Subject: [PATCH 05/41] Add new badge for RRM in SettingsActiveModule Header. --- assets/js/components/settings/SettingsActiveModule/Header.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/assets/js/components/settings/SettingsActiveModule/Header.js b/assets/js/components/settings/SettingsActiveModule/Header.js index 4a54bc343b9..7500cf8320b 100644 --- a/assets/js/components/settings/SettingsActiveModule/Header.js +++ b/assets/js/components/settings/SettingsActiveModule/Header.js @@ -37,6 +37,7 @@ import { useSelect } from 'googlesitekit-data'; import { Button } from 'googlesitekit-components'; import { CORE_MODULES } from '../../../googlesitekit/modules/datastore/constants'; import { EXPERIMENTAL_MODULES } from '../../dashboard-sharing/DashboardSharingSettings/constants'; +import { NEW_MODULES } from '../constants'; import { Grid, Row, Cell } from '../../../material-components'; import { useKeyCodesInside } from '../../../hooks/useKeyCodesInside'; import ModuleIcon from '../../ModuleIcon'; @@ -180,7 +181,9 @@ export default function Header( { slug } ) { hasLeftSpacing /> ) } - { slug === 'ads' && } + { NEW_MODULES.includes( slug ) && ( + + ) } From 3c8bfdb71d5fd3b5d83eceabf46bd5a859ac961b Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Mon, 1 Jul 2024 23:28:22 +0530 Subject: [PATCH 06/41] Add Reader Revenue Manager module initialization. --- .../modules/reader-revenue-manager/index.js | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/index.js diff --git a/assets/js/modules/reader-revenue-manager/index.js b/assets/js/modules/reader-revenue-manager/index.js new file mode 100644 index 00000000000..f9d717be37d --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/index.js @@ -0,0 +1,77 @@ +/** + * Reader Revenue Manager module initialization. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; + +/** + * Internal dependencies + */ +import { SetupMain } from './components/setup'; +import { SettingsEdit, SettingsView } from './components/settings'; +import ReaderRevenueManagerIcon from '../../../svg/graphics/reader-revenue-manager.svg'; +import { + MODULES_READER_REVENUE_MANAGER, + ERROR_CODE_NON_HTTPS_SITE, +} from './datastore/constants'; +import { CORE_SITE } from '../../googlesitekit/datastore/site/constants'; +import { isFeatureEnabled } from '../../features'; +import { isURLUsingHTTPS } from './utils/validation'; + +export { registerStore } from './datastore'; + +const isRrmModuleEnabled = + ( func ) => + ( ...args ) => { + if ( isFeatureEnabled( 'rrmModule' ) ) { + func( ...args ); + } + }; + +export const registerModule = isRrmModuleEnabled( ( modules ) => { + modules.registerModule( 'reader-revenue-manager', { + storeName: MODULES_READER_REVENUE_MANAGER, + SettingsEditComponent: SettingsEdit, + SettingsViewComponent: SettingsView, + SetupComponent: SetupMain, + Icon: ReaderRevenueManagerIcon, + features: [ + __( 'Create tags without updating code', 'google-site-kit' ), + ], + checkRequirements: async ( registry ) => { + const homeURL = await registry + .__experimentalResolveSelect( CORE_SITE ) + .getHomeURL(); + + if ( isURLUsingHTTPS( homeURL ) ) { + return; + } + + throw { + code: ERROR_CODE_NON_HTTPS_SITE, + message: __( + 'The site should use HTTPS to set up Reader Revenue Manager', + 'google-site-kit' + ), + data: null, + }; + }, + } ); +} ); From 35e600b27e8ba5f4a2a206c67cba1bc5efc7aaea Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Mon, 1 Jul 2024 23:28:35 +0530 Subject: [PATCH 07/41] Add Reader Revenue Manager SettingsEdit component. --- .../components/settings/SettingsEdit.js | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/components/settings/SettingsEdit.js diff --git a/assets/js/modules/reader-revenue-manager/components/settings/SettingsEdit.js b/assets/js/modules/reader-revenue-manager/components/settings/SettingsEdit.js new file mode 100644 index 00000000000..19e6cf56ad3 --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/components/settings/SettingsEdit.js @@ -0,0 +1,37 @@ +/** + * Reader Revenue Manager SettingsEdit component. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; + +export default function SettingsEdit() { + return ( +

+

+ { __( + 'Reader Revenue Manager Settings Edit', + 'google-site-kit' + ) } +

+ + { /* TODO: Add the rest of the settings steps */ } +
+ ); +} From 5968db24ed2371c6cbaee2ba9c0fa0ac8b857f0b Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Mon, 1 Jul 2024 23:28:49 +0530 Subject: [PATCH 08/41] Add Reader Revenue Manager SettingsView component. --- .../components/settings/SettingsView.js | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/components/settings/SettingsView.js diff --git a/assets/js/modules/reader-revenue-manager/components/settings/SettingsView.js b/assets/js/modules/reader-revenue-manager/components/settings/SettingsView.js new file mode 100644 index 00000000000..dfe95f39571 --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/components/settings/SettingsView.js @@ -0,0 +1,37 @@ +/** + * Reader Revenue Manager SettingsView component. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; + +export default function SettingsView() { + return ( +
+

+ { __( + 'Reader Revenue Manager Settings View', + 'google-site-kit' + ) } +

+ + { /* TODO: Add the rest of the settings steps */ } +
+ ); +} From cc32f18dc257d630557a0990703d041c1355720b Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Mon, 1 Jul 2024 23:29:12 +0530 Subject: [PATCH 09/41] Add Reader Revenue Manager SetupMain component. --- .../components/setup/SetupMain.js | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/components/setup/SetupMain.js diff --git a/assets/js/modules/reader-revenue-manager/components/setup/SetupMain.js b/assets/js/modules/reader-revenue-manager/components/setup/SetupMain.js new file mode 100644 index 00000000000..97fc654097e --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/components/setup/SetupMain.js @@ -0,0 +1,47 @@ +/** + * Reader Revenue Manager SetupMain component. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * WordPress dependencies + */ +import { _x } from '@wordpress/i18n'; + +/** + * Internal dependencies + */ +import ReaderRevenueManagerIcon from '../../../../../svg/graphics/reader-revenue-manager.svg'; + +export default function SetupMain() { + return ( +
+
+ +
+ +

+ { _x( + 'Reader Revenue Manager', + 'Service name', + 'google-site-kit' + ) } +

+ + { /* TODO: Add the rest of the setup steps */ } +
+ ); +} From 45a3be24706da682efaa0f5924fa08ebefb11448 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Mon, 1 Jul 2024 23:29:49 +0530 Subject: [PATCH 10/41] Add RRM base data store. --- .../reader-revenue-manager/datastore/base.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/datastore/base.js diff --git a/assets/js/modules/reader-revenue-manager/datastore/base.js b/assets/js/modules/reader-revenue-manager/datastore/base.js new file mode 100644 index 00000000000..da7cfb7a972 --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/datastore/base.js @@ -0,0 +1,29 @@ +/** + * `modules/reader-revenue-manager` base data store. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Internal dependencies + */ +import Modules from 'googlesitekit-modules'; +import { MODULES_READER_REVENUE_MANAGER } from './constants'; +import { validateCanSubmitChanges } from './settings'; + +export default Modules.createModuleStore( 'reader-revenue-manager', { + storeName: MODULES_READER_REVENUE_MANAGER, + validateCanSubmitChanges, +} ); From 2a9f3b45be6d0ff0dbbbf0b42b54b7bd2bddbbc7 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Mon, 1 Jul 2024 23:30:24 +0530 Subject: [PATCH 11/41] Add RRM data store constants. --- .../datastore/constants.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/datastore/constants.js diff --git a/assets/js/modules/reader-revenue-manager/datastore/constants.js b/assets/js/modules/reader-revenue-manager/datastore/constants.js new file mode 100644 index 00000000000..bd47a04d973 --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/datastore/constants.js @@ -0,0 +1,21 @@ +/** + * `modules/reader-revenue-manager` data store constants. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export const MODULES_READER_REVENUE_MANAGER = 'modules/reader-revenue-manager'; + +export const ERROR_CODE_NON_HTTPS_SITE = 'non_https_site'; From e175967dcc8b3775c231837fb361188b88095703 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Mon, 1 Jul 2024 23:30:48 +0530 Subject: [PATCH 12/41] Add RRM registerStore. --- .../reader-revenue-manager/datastore/index.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/datastore/index.js diff --git a/assets/js/modules/reader-revenue-manager/datastore/index.js b/assets/js/modules/reader-revenue-manager/datastore/index.js new file mode 100644 index 00000000000..9ce3ea73875 --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/datastore/index.js @@ -0,0 +1,39 @@ +/** + * `modules/reader-revenue-manager` data store. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Internal dependencies + */ +import { combineStores } from 'googlesitekit-data'; +import { MODULES_READER_REVENUE_MANAGER } from './constants'; +import baseModuleStore from './base'; + +const store = combineStores( baseModuleStore ); + +export const initialState = store.initialState; +export const actions = store.actions; +export const controls = store.controls; +export const reducer = store.reducer; +export const resolvers = store.resolvers; +export const selectors = store.selectors; + +export const registerStore = ( registry ) => { + registry.registerStore( MODULES_READER_REVENUE_MANAGER, store ); +}; + +export default store; From e56ecf59b6c71701c7c5ec511977b62ab8f1160a Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Mon, 1 Jul 2024 23:33:04 +0530 Subject: [PATCH 13/41] Add RRM setup_assets method. --- includes/Modules/Reader_Revenue_Manager.php | 37 ++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/includes/Modules/Reader_Revenue_Manager.php b/includes/Modules/Reader_Revenue_Manager.php index bd49d782cef..e44e05bee03 100644 --- a/includes/Modules/Reader_Revenue_Manager.php +++ b/includes/Modules/Reader_Revenue_Manager.php @@ -10,7 +10,10 @@ namespace Google\Site_Kit\Modules; +use Google\Site_Kit\Core\Assets\Script; use Google\Site_Kit\Core\Modules\Module; +use Google\Site_Kit\Core\Modules\Module_With_Assets; +use Google\Site_Kit\Core\Modules\Module_With_Assets_Trait; use Google\Site_Kit\Core\Modules\Module_With_Scopes; use Google\Site_Kit\Core\Modules\Module_With_Scopes_Trait; @@ -21,7 +24,8 @@ * @access private * @ignore */ -final class Reader_Revenue_Manager extends Module implements Module_With_Scopes { +final class Reader_Revenue_Manager extends Module implements Module_With_Scopes, Module_With_Assets { + use Module_With_Assets_Trait; use Module_With_Scopes_Trait; /** @@ -67,4 +71,35 @@ protected function setup_info() { 'homepage' => __( 'https://readerrevenue.withgoogle.com/', 'google-site-kit' ), ); } + + /** + * Sets up the module's assets to register. + * + * @since n.e.x.t + * + * @return Asset[] List of Asset objects. + */ + protected function setup_assets() { + $base_url = $this->context->url( 'dist/assets/' ); + + return array( + new Script( + 'googlesitekit-modules-reader-revenue-manager', + array( + 'src' => $base_url . 'js/googlesitekit-modules-reader-revenue-manager.js', + 'dependencies' => array( + 'googlesitekit-vendor', + 'googlesitekit-api', + 'googlesitekit-data', + 'googlesitekit-modules', + 'googlesitekit-datastore-site', + 'googlesitekit-datastore-user', + 'googlesitekit-datastore-forms', + 'googlesitekit-components', + 'googlesitekit-modules-data', + ), + ) + ), + ); + } } From c64fd9789674df66cd6a220f12b037c57d9a2da9 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Mon, 1 Jul 2024 23:33:26 +0530 Subject: [PATCH 14/41] Add RRM settings datastore. --- .../datastore/settings.js | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/datastore/settings.js diff --git a/assets/js/modules/reader-revenue-manager/datastore/settings.js b/assets/js/modules/reader-revenue-manager/datastore/settings.js new file mode 100644 index 00000000000..9365891d8c3 --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/datastore/settings.js @@ -0,0 +1,56 @@ +/** + * `modules/reader-revenue-manager` data store: settings actions. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * External dependencies + */ +import invariant from 'invariant'; + +/** + * Internal dependencies + */ +import { MODULES_READER_REVENUE_MANAGER } from './constants'; +import { + INVARIANT_DOING_SUBMIT_CHANGES, + INVARIANT_SETTINGS_NOT_CHANGED, +} from '../../../googlesitekit/data/create-settings-store'; +import { createStrictSelect } from '../../../googlesitekit/data/utils'; +import { isValidPublicationID } from '../utils/validation'; + +// Invariant error messages. +export const INVARIANT_INVALID_PUBLICATION_ID = + 'a valid publicationID is required'; + +export function validateCanSubmitChanges( select ) { + const strictSelect = createStrictSelect( select ); + // Strict select will cause all selector functions to throw an error + // if `undefined` is returned, otherwise it behaves the same as `select`. + // This ensures that the selector returns `false` until all data dependencies are resolved. + const { haveSettingsChanged, isDoingSubmitChanges, getPublicationID } = + strictSelect( MODULES_READER_REVENUE_MANAGER ); + + // Note: these error messages are referenced in test assertions. + invariant( ! isDoingSubmitChanges(), INVARIANT_DOING_SUBMIT_CHANGES ); + invariant( haveSettingsChanged(), INVARIANT_SETTINGS_NOT_CHANGED ); + + const publicationID = getPublicationID(); + invariant( + isValidPublicationID( publicationID ), + INVARIANT_INVALID_PUBLICATION_ID + ); +} From 74b9219bf460e30694290aa2cadbfcd32aea0d95 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Mon, 1 Jul 2024 23:33:40 +0530 Subject: [PATCH 15/41] Add RRM Validation utilities.. --- .../utils/validation.js | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/utils/validation.js diff --git a/assets/js/modules/reader-revenue-manager/utils/validation.js b/assets/js/modules/reader-revenue-manager/utils/validation.js new file mode 100644 index 00000000000..9d53e8eda5c --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/utils/validation.js @@ -0,0 +1,49 @@ +/** + * Validation utilities. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Checks if the given publication ID appears to be a valid. + * + * @since n.e.x.t + * + * @param {string} publicationID Publication ID to test. + * @return {boolean} `true` if the given publication ID is valid, `false` otherwise. + */ +export function isValidPublicationID( publicationID ) { + return ( + typeof publicationID === 'string' && + /^[A-Za-z0-9_.-]+$/.test( publicationID ) + ); +} + +/** + * Checks if a given URL uses HTTPS. + * + * @since n.e.x.t + * + * @param {string} url The URL to check. + * @return {boolean} True if the URL uses HTTPS, false otherwise. + */ +export const isURLUsingHTTPS = ( url ) => { + try { + const parsedURL = new URL( url ); + return parsedURL.protocol === 'https:'; + } catch ( error ) { + return false; + } +}; From 82c4cdb6a5c4b0ca24881b97b603fe7832a7ea35 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Mon, 1 Jul 2024 23:33:55 +0530 Subject: [PATCH 16/41] Add RRM svg logo. --- .../svg/graphics/reader-revenue-manager.svg | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 assets/svg/graphics/reader-revenue-manager.svg diff --git a/assets/svg/graphics/reader-revenue-manager.svg b/assets/svg/graphics/reader-revenue-manager.svg new file mode 100644 index 00000000000..8860e5d866d --- /dev/null +++ b/assets/svg/graphics/reader-revenue-manager.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + From b2a4e602d91032d388dcc26116a13275f7b1b84c Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Mon, 1 Jul 2024 23:34:27 +0530 Subject: [PATCH 17/41] Add RRM module entry in webpack config. --- webpack/modules.config.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/webpack/modules.config.js b/webpack/modules.config.js index d8301f79f48..31d115159e3 100644 --- a/webpack/modules.config.js +++ b/webpack/modules.config.js @@ -74,6 +74,8 @@ module.exports = ( mode, rules, ANALYZE ) => { './assets/js/googlesitekit-modules-analytics-4.js', 'googlesitekit-modules-pagespeed-insights': 'assets/js/googlesitekit-modules-pagespeed-insights.js', + 'googlesitekit-modules-reader-revenue-manager': + './assets/js/googlesitekit-modules-reader-revenue-manager.js', 'googlesitekit-modules-search-console': './assets/js/googlesitekit-modules-search-console.js', 'googlesitekit-modules-tagmanager': From 71cbe5af64b121f6e15ea1920a575f9253cc4760 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Mon, 1 Jul 2024 23:38:18 +0530 Subject: [PATCH 18/41] Add Reader Revenue Manager Setup components. --- .../components/setup/index.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/components/setup/index.js diff --git a/assets/js/modules/reader-revenue-manager/components/setup/index.js b/assets/js/modules/reader-revenue-manager/components/setup/index.js new file mode 100644 index 00000000000..d0c584f8d23 --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/components/setup/index.js @@ -0,0 +1,19 @@ +/** + * Reader Revenue Manager Setup components. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { default as SetupMain } from './SetupMain'; From d3b1623009dda7a5574758d369390f79db196365 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Tue, 2 Jul 2024 12:09:34 +0530 Subject: [PATCH 19/41] Add rrm base data store tests. --- .../datastore/base.test.js | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/datastore/base.test.js diff --git a/assets/js/modules/reader-revenue-manager/datastore/base.test.js b/assets/js/modules/reader-revenue-manager/datastore/base.test.js new file mode 100644 index 00000000000..98413b2567e --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/datastore/base.test.js @@ -0,0 +1,51 @@ +/** + * `modules/reader-revenue-manager` base data store tests. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Internal dependencies + */ +import { + createTestRegistry, + provideSiteInfo, +} from '../../../../../tests/js/utils'; +import { MODULES_READER_REVENUE_MANAGER } from './constants'; + +describe( 'modules/reader-revenue-manager base data store', () => { + let registry; + let store; + + beforeEach( () => { + jest.resetModules(); + + registry = createTestRegistry(); + provideSiteInfo( registry ); + } ); + + it( 'does not define the admin page', () => { + store = require( './base' ).default; + registry.registerStore( MODULES_READER_REVENUE_MANAGER, store ); + + expect( + registry + .select( MODULES_READER_REVENUE_MANAGER ) + .getAdminScreenURL() + ).toBe( + 'http://example.com/wp-admin/admin.php?page=googlesitekit-dashboard' + ); + } ); +} ); From ef742746c56e69bdc739ad1deacfec9c1bfde9f3 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Tue, 2 Jul 2024 12:09:58 +0530 Subject: [PATCH 20/41] Add rrm index test base. --- .../datastore/index.test.js | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/datastore/index.test.js diff --git a/assets/js/modules/reader-revenue-manager/datastore/index.test.js b/assets/js/modules/reader-revenue-manager/datastore/index.test.js new file mode 100644 index 00000000000..4d86c0d6034 --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/datastore/index.test.js @@ -0,0 +1,43 @@ +/** + * `modules/reader-revenue-manager` data store: selectors test. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Internal dependencies + */ +import { + createTestRegistry, + unsubscribeFromAll, +} from '../../../../../tests/js/utils'; + +describe( 'modules/reader-revenue-manager', () => { + let registry; + + beforeEach( () => { + registry = createTestRegistry(); + } ); + + afterEach( () => { + unsubscribeFromAll( registry ); + } ); + + describe( 'store', () => { + it( 'is registered correctly', () => { + // TODO: Implement tests for the reader-revenue-manager store. + } ); + } ); +} ); From f941c7dc55b61ce3cecec70f7112a2bc712e88fd Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Tue, 2 Jul 2024 12:42:09 +0530 Subject: [PATCH 21/41] Add rrm settings test base file. --- .../datastore/index.test.js | 4 +- .../datastore/settings.test.js | 50 +++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 assets/js/modules/reader-revenue-manager/datastore/settings.test.js diff --git a/assets/js/modules/reader-revenue-manager/datastore/index.test.js b/assets/js/modules/reader-revenue-manager/datastore/index.test.js index 4d86c0d6034..1d7dfd0f5f9 100644 --- a/assets/js/modules/reader-revenue-manager/datastore/index.test.js +++ b/assets/js/modules/reader-revenue-manager/datastore/index.test.js @@ -24,7 +24,7 @@ import { unsubscribeFromAll, } from '../../../../../tests/js/utils'; -describe( 'modules/reader-revenue-manager', () => { +describe( 'modules/reader-revenue-manager properties', () => { let registry; beforeEach( () => { @@ -37,7 +37,7 @@ describe( 'modules/reader-revenue-manager', () => { describe( 'store', () => { it( 'is registered correctly', () => { - // TODO: Implement tests for the reader-revenue-manager store. + // TODO: Implement tests as part of #8793. } ); } ); } ); diff --git a/assets/js/modules/reader-revenue-manager/datastore/settings.test.js b/assets/js/modules/reader-revenue-manager/datastore/settings.test.js new file mode 100644 index 00000000000..eae66f48b0b --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/datastore/settings.test.js @@ -0,0 +1,50 @@ +/** + * `modules/reader-revenue-manager` data store: settings tests. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Internal dependencies + */ +import API from 'googlesitekit-api'; +import { + createTestRegistry, + unsubscribeFromAll, +} from '../../../../../tests/js/utils'; + +describe( 'modules/reader-revenue-manager settings', () => { + let registry; + + beforeAll( () => { + API.setUsingCache( false ); + } ); + + beforeEach( () => { + registry = createTestRegistry(); + } ); + + afterEach( () => { + unsubscribeFromAll( registry ); + } ); + + afterAll( () => { + API.setUsingCache( true ); + } ); + + describe( 'validateCanSubmitChanges', () => { + // TODO: Implement tests as part of #8793. + } ); +} ); From c556ad5052dcae60196b9bc709888df6dcf8555d Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Tue, 2 Jul 2024 12:48:54 +0530 Subject: [PATCH 22/41] Add Validation function tests. --- .../utils/validation.test.js | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/utils/validation.test.js diff --git a/assets/js/modules/reader-revenue-manager/utils/validation.test.js b/assets/js/modules/reader-revenue-manager/utils/validation.test.js new file mode 100644 index 00000000000..c2ff6e87105 --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/utils/validation.test.js @@ -0,0 +1,57 @@ +/** + * Validation function tests. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Internal dependencies + */ +import { isValidPublicationID, isURLUsingHTTPS } from './validation'; + +describe( 'utility functions', () => { + describe( 'isValidPublicationID', () => { + it( 'should return TRUE when a valid publication ID is passed', () => { + expect( isValidPublicationID( 'valid-publication_123.ID' ) ).toBe( + true + ); + } ); + + it.each( [ + [ 'false', false ], + [ 'an integer', 12345 ], + [ 'an empty string', '' ], + [ 'a string with invalid characters', 'invalid-publication!ID' ], + ] )( 'should return FALSE when %s is passed', ( _, publicationID ) => { + expect( isValidPublicationID( publicationID ) ).toBe( false ); + } ); + } ); + + describe( 'isURLUsingHTTPS', () => { + it( 'should return TRUE when a URL with HTTPS is passed', () => { + expect( isURLUsingHTTPS( 'https://example.com' ) ).toBe( true ); + } ); + + it.each( [ + [ 'an HTTP URL', 'http://example.com' ], + [ 'an invalid URL', 'htp://example.com' ], + [ 'a string without protocol', 'example.com' ], + [ 'an empty string', '' ], + [ 'false', false ], + ] )( 'should return FALSE when %s is passed', ( _, url ) => { + expect( isURLUsingHTTPS( url ) ).toBe( false ); + } ); + } ); +} ); From 306e1a62905aad32376951d7e4ebf60c3cd4b0a1 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Tue, 2 Jul 2024 15:44:55 +0530 Subject: [PATCH 23/41] Add SettingsEdit storybook. --- .../settings/SettingsEdit.stories.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/components/settings/SettingsEdit.stories.js diff --git a/assets/js/modules/reader-revenue-manager/components/settings/SettingsEdit.stories.js b/assets/js/modules/reader-revenue-manager/components/settings/SettingsEdit.stories.js new file mode 100644 index 00000000000..95bdae39dbf --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/components/settings/SettingsEdit.stories.js @@ -0,0 +1,34 @@ +/** + * Reader Revenue Manager SettingsEdit component stories. + * + * Site Kit by Google, Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Internal dependencies + */ +import SettingsEdit from './SettingsEdit'; + +function Template() { + return ; +} + +export const Default = Template.bind( {} ); +Default.storyName = 'Default'; + +export default { + title: 'Modules/ReaderRevenueManager/Settings/SettingsEdit', + component: SettingsEdit, +}; From d0c88862d10bc3c9f4d2f8253c6e810a30864c44 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Tue, 2 Jul 2024 15:45:07 +0530 Subject: [PATCH 24/41] Add SettingsEdit test file. --- .../components/settings/SettingsEdit.test.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/components/settings/SettingsEdit.test.js diff --git a/assets/js/modules/reader-revenue-manager/components/settings/SettingsEdit.test.js b/assets/js/modules/reader-revenue-manager/components/settings/SettingsEdit.test.js new file mode 100644 index 00000000000..66bf0edc12c --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/components/settings/SettingsEdit.test.js @@ -0,0 +1,30 @@ +/** + * Reader Revenue Manager SettingsEdit component tests. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { render } from '../../../../../../tests/js/test-utils'; +import SettingsEdit from './SettingsEdit'; + +describe( 'SettingsEdit', () => { + it( 'should render the component', () => { + const { getByText } = render( ); + + expect( + getByText( /Reader Revenue Manager Settings Edit/i ) + ).toBeInTheDocument(); + } ); +} ); From 712ed3db7caedbc433e905b6a08068706ca0fcb7 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Tue, 2 Jul 2024 15:45:20 +0530 Subject: [PATCH 25/41] Add SettingsView storybook. --- .../settings/SettingsView.stories.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/components/settings/SettingsView.stories.js diff --git a/assets/js/modules/reader-revenue-manager/components/settings/SettingsView.stories.js b/assets/js/modules/reader-revenue-manager/components/settings/SettingsView.stories.js new file mode 100644 index 00000000000..086602a2a8a --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/components/settings/SettingsView.stories.js @@ -0,0 +1,34 @@ +/** + * Reader Revenue Manager SettingsView component stories. + * + * Site Kit by Google, Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Internal dependencies + */ +import SettingsView from './SettingsView'; + +function Template() { + return ; +} + +export const Default = Template.bind( {} ); +Default.storyName = 'Default'; + +export default { + title: 'Modules/ReaderRevenueManager/Settings/SettingsView', + component: SettingsView, +}; From 16531146c7a5edc9a22c80abddfc1dbf8642fc2a Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Tue, 2 Jul 2024 15:45:31 +0530 Subject: [PATCH 26/41] Add SettingsView test file. --- .../components/settings/SettingsView.test.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/components/settings/SettingsView.test.js diff --git a/assets/js/modules/reader-revenue-manager/components/settings/SettingsView.test.js b/assets/js/modules/reader-revenue-manager/components/settings/SettingsView.test.js new file mode 100644 index 00000000000..96e585ac452 --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/components/settings/SettingsView.test.js @@ -0,0 +1,30 @@ +/** + * Reader Revenue Manager SettingsView component tests. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { render } from '../../../../../../tests/js/test-utils'; +import SettingsView from './SettingsView'; + +describe( 'SettingsView', () => { + it( 'should render the component', () => { + const { getByText } = render( ); + + expect( + getByText( /Reader Revenue Manager Settings View/i ) + ).toBeInTheDocument(); + } ); +} ); From d1a9dded0fe4cd31f4e5c7bd96d3094e4dcb9799 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Tue, 2 Jul 2024 15:45:42 +0530 Subject: [PATCH 27/41] Add SetupMain storybook. --- .../components/setup/SetupMain.stories.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/components/setup/SetupMain.stories.js diff --git a/assets/js/modules/reader-revenue-manager/components/setup/SetupMain.stories.js b/assets/js/modules/reader-revenue-manager/components/setup/SetupMain.stories.js new file mode 100644 index 00000000000..c938d28c75d --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/components/setup/SetupMain.stories.js @@ -0,0 +1,34 @@ +/** + * Reader Revenue Manager SetupMain component stories. + * + * Site Kit by Google, Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Internal dependencies + */ +import SetupMain from './SetupMain'; + +function Template() { + return ; +} + +export const Default = Template.bind( {} ); +Default.storyName = 'Default'; + +export default { + title: 'Modules/ReaderRevenueManager/Setup/SetupMain', + component: SetupMain, +}; From 741087e9a90cb1c8af4090f276cdde15b5d22b33 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Tue, 2 Jul 2024 15:45:53 +0530 Subject: [PATCH 28/41] Add SetupMain test file. --- .../components/setup/SetupMain.test.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 assets/js/modules/reader-revenue-manager/components/setup/SetupMain.test.js diff --git a/assets/js/modules/reader-revenue-manager/components/setup/SetupMain.test.js b/assets/js/modules/reader-revenue-manager/components/setup/SetupMain.test.js new file mode 100644 index 00000000000..62b8d736342 --- /dev/null +++ b/assets/js/modules/reader-revenue-manager/components/setup/SetupMain.test.js @@ -0,0 +1,28 @@ +/** + * Reader Revenue Manager SetupMain component tests. + * + * Site Kit by Google, Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { render } from '../../../../../../tests/js/test-utils'; +import SetupMain from './SetupMain'; + +describe( 'SetupMain', () => { + it( 'should render the component', () => { + const { getByText } = render( ); + + expect( getByText( /Reader Revenue Manager/i ) ).toBeInTheDocument(); + } ); +} ); From 1640fd2be1eb7d42f1b6a9162201cb2b7731c792 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Tue, 2 Jul 2024 15:58:55 +0530 Subject: [PATCH 29/41] Add todo comment in the registerModule features. --- assets/js/modules/reader-revenue-manager/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/modules/reader-revenue-manager/index.js b/assets/js/modules/reader-revenue-manager/index.js index f9d717be37d..cbf6c1be88b 100644 --- a/assets/js/modules/reader-revenue-manager/index.js +++ b/assets/js/modules/reader-revenue-manager/index.js @@ -53,7 +53,7 @@ export const registerModule = isRrmModuleEnabled( ( modules ) => { SetupComponent: SetupMain, Icon: ReaderRevenueManagerIcon, features: [ - __( 'Create tags without updating code', 'google-site-kit' ), + // TODO: Implement the features as part of #8845. ], checkRequirements: async ( registry ) => { const homeURL = await registry From 35ab985e242ecfec4c145d16303ba0abe5fa1ac0 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Tue, 2 Jul 2024 16:22:01 +0530 Subject: [PATCH 30/41] Add modulesReaderRevenueManager in tests/js/utils. --- tests/js/utils.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/js/utils.js b/tests/js/utils.js index ad379800e2b..45c9f13343c 100644 --- a/tests/js/utils.js +++ b/tests/js/utils.js @@ -42,6 +42,7 @@ import * as modulesAds from '../../assets/js/modules/ads'; import * as modulesAdSense from '../../assets/js/modules/adsense'; import * as modulesAnalytics4 from '../../assets/js/modules/analytics-4'; import * as modulesPageSpeedInsights from '../../assets/js/modules/pagespeed-insights'; +import * as modulesReaderRevenueManager from '../../assets/js/modules/reader-revenue-manager'; import * as modulesSearchConsole from '../../assets/js/modules/search-console'; import * as modulesTagManager from '../../assets/js/modules/tagmanager'; import { CORE_SITE } from '../../assets/js/googlesitekit/datastore/site/constants'; @@ -74,6 +75,7 @@ const allCoreModules = [ modulesAdSense, modulesAnalytics4, modulesPageSpeedInsights, + modulesReaderRevenueManager, modulesSearchConsole, modulesTagManager, ]; From 328ca751310883a7b42fe972d87cd027844d4160 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Tue, 2 Jul 2024 16:22:19 +0530 Subject: [PATCH 31/41] Fix settings test. --- .../modules/reader-revenue-manager/datastore/settings.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/assets/js/modules/reader-revenue-manager/datastore/settings.test.js b/assets/js/modules/reader-revenue-manager/datastore/settings.test.js index eae66f48b0b..f772e88a2bb 100644 --- a/assets/js/modules/reader-revenue-manager/datastore/settings.test.js +++ b/assets/js/modules/reader-revenue-manager/datastore/settings.test.js @@ -45,6 +45,8 @@ describe( 'modules/reader-revenue-manager settings', () => { } ); describe( 'validateCanSubmitChanges', () => { - // TODO: Implement tests as part of #8793. + it( 'it validates', () => { + // TODO: Implement tests as part of #8793. + } ); } ); } ); From cbf8f7e52b0133c1b62a7f3e4e6405055a708010 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Tue, 2 Jul 2024 16:26:13 +0530 Subject: [PATCH 32/41] Order imports. --- assets/js/modules/reader-revenue-manager/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/assets/js/modules/reader-revenue-manager/index.js b/assets/js/modules/reader-revenue-manager/index.js index cbf6c1be88b..955b600b4a5 100644 --- a/assets/js/modules/reader-revenue-manager/index.js +++ b/assets/js/modules/reader-revenue-manager/index.js @@ -24,14 +24,14 @@ import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ -import { SetupMain } from './components/setup'; -import { SettingsEdit, SettingsView } from './components/settings'; -import ReaderRevenueManagerIcon from '../../../svg/graphics/reader-revenue-manager.svg'; +import { CORE_SITE } from '../../googlesitekit/datastore/site/constants'; import { MODULES_READER_REVENUE_MANAGER, ERROR_CODE_NON_HTTPS_SITE, } from './datastore/constants'; -import { CORE_SITE } from '../../googlesitekit/datastore/site/constants'; +import { SetupMain } from './components/setup'; +import { SettingsEdit, SettingsView } from './components/settings'; +import ReaderRevenueManagerIcon from '../../../svg/graphics/reader-revenue-manager.svg'; import { isFeatureEnabled } from '../../features'; import { isURLUsingHTTPS } from './utils/validation'; From 2761f760257f114fa450396070d5b37adedc5971 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Tue, 2 Jul 2024 22:20:23 +0530 Subject: [PATCH 33/41] Improve isURLUsingHTTPS fn. --- .../reader-revenue-manager/utils/validation.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/assets/js/modules/reader-revenue-manager/utils/validation.js b/assets/js/modules/reader-revenue-manager/utils/validation.js index 9d53e8eda5c..b26015bf27e 100644 --- a/assets/js/modules/reader-revenue-manager/utils/validation.js +++ b/assets/js/modules/reader-revenue-manager/utils/validation.js @@ -41,9 +41,18 @@ export function isValidPublicationID( publicationID ) { */ export const isURLUsingHTTPS = ( url ) => { try { + if ( typeof url !== 'string' || ! url ) { + throw new TypeError( `Invalid URL: ${ url }` ); + } + const parsedURL = new URL( url ); - return parsedURL.protocol === 'https:'; + if ( parsedURL.protocol !== 'https:' ) { + throw new TypeError( `Invalid URL: ${ url }` ); + } + + return true; } catch ( error ) { + global.console.warn( 'Invalid URL:', error ); return false; } }; From 861a4646de5894e6572f0bb59442ee19604b34ce Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Tue, 2 Jul 2024 22:20:35 +0530 Subject: [PATCH 34/41] Improve isURLUsingHTTPS tests. --- .../utils/validation.test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/assets/js/modules/reader-revenue-manager/utils/validation.test.js b/assets/js/modules/reader-revenue-manager/utils/validation.test.js index c2ff6e87105..1d419ebb678 100644 --- a/assets/js/modules/reader-revenue-manager/utils/validation.test.js +++ b/assets/js/modules/reader-revenue-manager/utils/validation.test.js @@ -40,8 +40,24 @@ describe( 'utility functions', () => { } ); describe( 'isURLUsingHTTPS', () => { + beforeAll( () => { + jest.spyOn( console, 'warn' ).mockImplementation( () => {} ); + } ); + + afterAll( () => { + // eslint-disable-next-line no-console + console.warn.mockRestore(); + } ); + + afterEach( () => { + // eslint-disable-next-line no-console + console.warn.mockClear(); + } ); + it( 'should return TRUE when a URL with HTTPS is passed', () => { expect( isURLUsingHTTPS( 'https://example.com' ) ).toBe( true ); + // eslint-disable-next-line no-console + expect( console.warn ).not.toHaveBeenCalled(); } ); it.each( [ @@ -52,6 +68,8 @@ describe( 'utility functions', () => { [ 'false', false ], ] )( 'should return FALSE when %s is passed', ( _, url ) => { expect( isURLUsingHTTPS( url ) ).toBe( false ); + // eslint-disable-next-line no-console + expect( console.warn ).toHaveBeenCalled(); } ); } ); } ); From 914360964410c7c6a2ea3b00b04682e9f70e9b4c Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Tue, 2 Jul 2024 22:22:40 +0530 Subject: [PATCH 35/41] Ensure the site info is resolved to get the home URL. --- assets/js/modules/reader-revenue-manager/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/assets/js/modules/reader-revenue-manager/index.js b/assets/js/modules/reader-revenue-manager/index.js index 955b600b4a5..8f95b53edac 100644 --- a/assets/js/modules/reader-revenue-manager/index.js +++ b/assets/js/modules/reader-revenue-manager/index.js @@ -56,9 +56,11 @@ export const registerModule = isRrmModuleEnabled( ( modules ) => { // TODO: Implement the features as part of #8845. ], checkRequirements: async ( registry ) => { - const homeURL = await registry + // Ensure the site info is resolved to get the home URL. + await registry .__experimentalResolveSelect( CORE_SITE ) - .getHomeURL(); + .getSiteInfo(); + const homeURL = registry.select( CORE_SITE ).getHomeURL(); if ( isURLUsingHTTPS( homeURL ) ) { return; From fff0ef4d35be3969fb50d3fb2bf4e366d3a2691a Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Tue, 2 Jul 2024 22:23:02 +0530 Subject: [PATCH 36/41] Address review feedback. --- .../components/settings/SettingsEdit.stories.js | 2 +- .../components/settings/SettingsView.stories.js | 2 +- .../components/setup/SetupMain.stories.js | 2 +- assets/js/modules/reader-revenue-manager/datastore/settings.js | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/assets/js/modules/reader-revenue-manager/components/settings/SettingsEdit.stories.js b/assets/js/modules/reader-revenue-manager/components/settings/SettingsEdit.stories.js index 95bdae39dbf..9901e1830c6 100644 --- a/assets/js/modules/reader-revenue-manager/components/settings/SettingsEdit.stories.js +++ b/assets/js/modules/reader-revenue-manager/components/settings/SettingsEdit.stories.js @@ -1,7 +1,7 @@ /** * Reader Revenue Manager SettingsEdit component stories. * - * Site Kit by Google, Copyright 2022 Google LLC + * Site Kit by Google, Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/assets/js/modules/reader-revenue-manager/components/settings/SettingsView.stories.js b/assets/js/modules/reader-revenue-manager/components/settings/SettingsView.stories.js index 086602a2a8a..3f317700f12 100644 --- a/assets/js/modules/reader-revenue-manager/components/settings/SettingsView.stories.js +++ b/assets/js/modules/reader-revenue-manager/components/settings/SettingsView.stories.js @@ -1,7 +1,7 @@ /** * Reader Revenue Manager SettingsView component stories. * - * Site Kit by Google, Copyright 2022 Google LLC + * Site Kit by Google, Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/assets/js/modules/reader-revenue-manager/components/setup/SetupMain.stories.js b/assets/js/modules/reader-revenue-manager/components/setup/SetupMain.stories.js index c938d28c75d..f83618bbdc4 100644 --- a/assets/js/modules/reader-revenue-manager/components/setup/SetupMain.stories.js +++ b/assets/js/modules/reader-revenue-manager/components/setup/SetupMain.stories.js @@ -1,7 +1,7 @@ /** * Reader Revenue Manager SetupMain component stories. * - * Site Kit by Google, Copyright 2022 Google LLC + * Site Kit by Google, Copyright 2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/assets/js/modules/reader-revenue-manager/datastore/settings.js b/assets/js/modules/reader-revenue-manager/datastore/settings.js index 9365891d8c3..57c408bef23 100644 --- a/assets/js/modules/reader-revenue-manager/datastore/settings.js +++ b/assets/js/modules/reader-revenue-manager/datastore/settings.js @@ -44,7 +44,6 @@ export function validateCanSubmitChanges( select ) { const { haveSettingsChanged, isDoingSubmitChanges, getPublicationID } = strictSelect( MODULES_READER_REVENUE_MANAGER ); - // Note: these error messages are referenced in test assertions. invariant( ! isDoingSubmitChanges(), INVARIANT_DOING_SUBMIT_CHANGES ); invariant( haveSettingsChanged(), INVARIANT_SETTINGS_NOT_CHANGED ); From e1f755bd45050b709c4d72bc9075e0fdb5d48a93 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Wed, 3 Jul 2024 11:43:11 +0530 Subject: [PATCH 37/41] Update publication ID validation to match base64 characters. --- assets/js/modules/reader-revenue-manager/utils/validation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/modules/reader-revenue-manager/utils/validation.js b/assets/js/modules/reader-revenue-manager/utils/validation.js index b26015bf27e..6693dc8bbdf 100644 --- a/assets/js/modules/reader-revenue-manager/utils/validation.js +++ b/assets/js/modules/reader-revenue-manager/utils/validation.js @@ -27,7 +27,7 @@ export function isValidPublicationID( publicationID ) { return ( typeof publicationID === 'string' && - /^[A-Za-z0-9_.-]+$/.test( publicationID ) + /^[A-Za-z0-9_-]+$/.test( publicationID ) ); } From 3fbfd99a58ced7cefabe0f127216fdfa358e45e3 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Wed, 3 Jul 2024 11:43:59 +0530 Subject: [PATCH 38/41] Fix tests for the updated validation. --- .../modules/reader-revenue-manager/utils/validation.test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/assets/js/modules/reader-revenue-manager/utils/validation.test.js b/assets/js/modules/reader-revenue-manager/utils/validation.test.js index 1d419ebb678..77e22b848e9 100644 --- a/assets/js/modules/reader-revenue-manager/utils/validation.test.js +++ b/assets/js/modules/reader-revenue-manager/utils/validation.test.js @@ -24,7 +24,7 @@ import { isValidPublicationID, isURLUsingHTTPS } from './validation'; describe( 'utility functions', () => { describe( 'isValidPublicationID', () => { it( 'should return TRUE when a valid publication ID is passed', () => { - expect( isValidPublicationID( 'valid-publication_123.ID' ) ).toBe( + expect( isValidPublicationID( 'valid_publication-123' ) ).toBe( true ); } ); @@ -33,7 +33,8 @@ describe( 'utility functions', () => { [ 'false', false ], [ 'an integer', 12345 ], [ 'an empty string', '' ], - [ 'a string with invalid characters', 'invalid-publication!ID' ], + [ 'a string with invalid characters', 'invalid.publication!ID' ], + [ 'a string with periods', 'invalid.publication.ID' ], ] )( 'should return FALSE when %s is passed', ( _, publicationID ) => { expect( isValidPublicationID( publicationID ) ).toBe( false ); } ); From c802cadfae8443b1246af8639ce2601a18089c0c Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Wed, 3 Jul 2024 18:24:12 +0530 Subject: [PATCH 39/41] Improve isURLUsingHTTPS logic. --- .../js/modules/reader-revenue-manager/utils/validation.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/assets/js/modules/reader-revenue-manager/utils/validation.js b/assets/js/modules/reader-revenue-manager/utils/validation.js index 6693dc8bbdf..507a2693c06 100644 --- a/assets/js/modules/reader-revenue-manager/utils/validation.js +++ b/assets/js/modules/reader-revenue-manager/utils/validation.js @@ -46,11 +46,7 @@ export const isURLUsingHTTPS = ( url ) => { } const parsedURL = new URL( url ); - if ( parsedURL.protocol !== 'https:' ) { - throw new TypeError( `Invalid URL: ${ url }` ); - } - - return true; + return parsedURL.protocol === 'https:'; } catch ( error ) { global.console.warn( 'Invalid URL:', error ); return false; From 0be6bd6b39490525ab4a2c9346d6550c26960863 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Wed, 3 Jul 2024 18:24:34 +0530 Subject: [PATCH 40/41] Improve isURLUsingHTTPS tests. --- .../utils/validation.test.js | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/assets/js/modules/reader-revenue-manager/utils/validation.test.js b/assets/js/modules/reader-revenue-manager/utils/validation.test.js index 77e22b848e9..b2000b896a8 100644 --- a/assets/js/modules/reader-revenue-manager/utils/validation.test.js +++ b/assets/js/modules/reader-revenue-manager/utils/validation.test.js @@ -41,36 +41,29 @@ describe( 'utility functions', () => { } ); describe( 'isURLUsingHTTPS', () => { - beforeAll( () => { - jest.spyOn( console, 'warn' ).mockImplementation( () => {} ); - } ); - - afterAll( () => { - // eslint-disable-next-line no-console - console.warn.mockRestore(); - } ); - - afterEach( () => { - // eslint-disable-next-line no-console - console.warn.mockClear(); - } ); - it( 'should return TRUE when a URL with HTTPS is passed', () => { expect( isURLUsingHTTPS( 'https://example.com' ) ).toBe( true ); - // eslint-disable-next-line no-console - expect( console.warn ).not.toHaveBeenCalled(); + expect( console ).not.toHaveWarned(); } ); it.each( [ - [ 'an HTTP URL', 'http://example.com' ], - [ 'an invalid URL', 'htp://example.com' ], [ 'a string without protocol', 'example.com' ], [ 'an empty string', '' ], [ 'false', false ], - ] )( 'should return FALSE when %s is passed', ( _, url ) => { + ] )( 'should return FALSE and warn when %s is passed', ( _, url ) => { expect( isURLUsingHTTPS( url ) ).toBe( false ); - // eslint-disable-next-line no-console - expect( console.warn ).toHaveBeenCalled(); + expect( console ).toHaveWarned(); } ); + + it.each( [ + [ 'an HTTP URL', 'http://example.com' ], + [ 'an invalid URL', 'htp://example.com' ], + ] )( + 'should return FALSE but not warn when %s is passed', + ( _, url ) => { + expect( isURLUsingHTTPS( url ) ).toBe( false ); + expect( console ).not.toHaveWarned(); + } + ); } ); } ); From 180e164bbf526db5a907beceb0f949d1df26e301 Mon Sep 17 00:00:00 2001 From: Hussain Thajutheen Date: Wed, 3 Jul 2024 18:26:49 +0530 Subject: [PATCH 41/41] Remove datastore-forms and modules-data from RRM assets. --- includes/Modules/Reader_Revenue_Manager.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/includes/Modules/Reader_Revenue_Manager.php b/includes/Modules/Reader_Revenue_Manager.php index e44e05bee03..c19d98202f5 100644 --- a/includes/Modules/Reader_Revenue_Manager.php +++ b/includes/Modules/Reader_Revenue_Manager.php @@ -94,9 +94,7 @@ protected function setup_assets() { 'googlesitekit-modules', 'googlesitekit-datastore-site', 'googlesitekit-datastore-user', - 'googlesitekit-datastore-forms', 'googlesitekit-components', - 'googlesitekit-modules-data', ), ) ),