Skip to content

Commit

Permalink
Code restructuring.
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitrox committed Feb 24, 2025
1 parent b8d40f7 commit 42dd0b4
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Fragment } from '@wordpress/element';
// eslint-disable-next-line import/no-unresolved
import { PluginDocumentSettingPanel } from '@wordpress-core/edit-post';

Expand All @@ -32,19 +31,16 @@ import SettingsForm from './SettingsForm';

export default function SettingPanel() {
return (
<Fragment>
<PluginDocumentSettingPanel
name="googlesitekit-rrm-panel"
title={ __( 'Google Site Kit', 'google-site-kit' ) }
icon={ <GoogleLogoIcon height="16" width="16" /> }
>
<section>
<h3>
{ __( 'Reader Revenue Manager', 'google-site-kit' ) }
</h3>
<SettingsForm />
</section>
</PluginDocumentSettingPanel>
</Fragment>
<PluginDocumentSettingPanel
className="googlesitekit-rrm-settings-panel"
name="googlesitekit-rrm-panel"
title={ __( 'Google Site Kit', 'google-site-kit' ) }
icon={ <GoogleLogoIcon height="16" width="16" /> }
>
<section>
<h3>{ __( 'Reader Revenue Manager', 'google-site-kit' ) }</h3>
<SettingsForm />
</section>
</PluginDocumentSettingPanel>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ import { __, sprintf } from '@wordpress/i18n';
// eslint-disable-next-line import/no-unresolved
import { SelectControl } from '@wordpress-core/components';
// eslint-disable-next-line import/no-unresolved
import { Fragment, useState } from '@wordpress-core/element';
import { useState } from '@wordpress-core/element';

/**
* Internal dependencies
*/
import Data from 'googlesitekit-data';
import { MODULES_READER_REVENUE_MANAGER } from '../../../assets/js/modules/reader-revenue-manager/datastore/constants';
import { CORE_EDITOR } from '../common/constants';

const { select, dispatch } = Data;
const CORE_EDITOR = 'core/editor';

export default function SettingsForm() {
const productIDs =
Expand Down Expand Up @@ -64,52 +64,50 @@ export default function SettingsForm() {
}

return (
<Fragment>
<SelectControl
className="googlesitekit-rrm-panel__select-control"
label={ __(
'Decide how site visitors should access this post (if they will see CTAs by Reader Revenue Manager, which you activated via Site Kit):',
'google-site-kit'
) }
onChange={ onChange }
value={ selectedValue }
options={ [
{
label: __(
'Keep the default selection',
'google-site-kit'
),
value: '',
},
{
label: __(
'Exclude from Reader Revenue Manager',
'google-site-kit'
<SelectControl
className="googlesitekit-rrm-panel__select-control"
label={ __(
'Decide how site visitors should access this post (if they will see CTAs by Reader Revenue Manager, which you activated via Site Kit):',
'google-site-kit'
) }
onChange={ onChange }
value={ selectedValue }
options={ [
{
label: __(
'Keep the default selection',
'google-site-kit'
),
value: '',
},
{
label: __(
'Exclude from Reader Revenue Manager',
'google-site-kit'
),
value: 'none',
},
{
label: __( 'Use "open access"', 'google-site-kit' ),
value: 'openaccess',
},
...productIDs.map( ( productID ) => {
const productIDParts = productID.split( ':' );
const label =
productIDParts.length > 1
? productIDParts[ 1 ]
: productID;
return {
label: sprintf(
/* translators: %s: Product ID */
__( 'Use "%s"', 'google-site-kit' ),
label
),
value: 'none',
},
{
label: __( 'Use "open access"', 'google-site-kit' ),
value: 'openaccess',
},
...productIDs.map( ( productID ) => {
const productIDParts = productID.split( ':' );
const label =
productIDParts.length > 1
? productIDParts[ 1 ]
: productID;
return {
label: sprintf(
/* translators: %s: Product ID */
__( 'Use "%s"', 'google-site-kit' ),
label
),
value: productID,
};
} ),
] }
help={ help }
/>
</Fragment>
value: productID,
};
} ),
] }
help={ help }
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Reader Revenue Manager: Editor Styles
*
* Site Kit by Google, Copyright 2025 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.
*/

.editor-sidebar {
.googlesitekit-rrm-settings-panel {

.googlesitekit-rrm-panel__select-control {
label {
text-transform: none;
white-space: break-spaces;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
* limitations under the License.
*/

import Data from 'googlesitekit-data';
import { registerStore } from '../../../assets/js/modules/reader-revenue-manager/datastore';
import { registerReaderRevenueManagerPlugin } from './plugin-registration';

registerStore( Data );

registerReaderRevenueManagerPlugin();
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@ import { registerPlugin } from '@wordpress-core/plugins';
* Internal dependencies
*/
import Data from 'googlesitekit-data';
import { registerStore } from '../../assets/js/modules/reader-revenue-manager/datastore';
import { CORE_MODULES } from '../../assets/js/googlesitekit/modules/datastore/constants';
import SettingPanel from './components/SettingPanel';
import { MODULES_READER_REVENUE_MANAGER } from '../../assets/js/modules/reader-revenue-manager/datastore/constants';
import { CORE_MODULES } from '../../../assets/js/googlesitekit/modules/datastore/constants';
import SettingPanel from './SettingPanel';
import { MODULES_READER_REVENUE_MANAGER } from '../../../assets/js/modules/reader-revenue-manager/datastore/constants';

const { select, resolveSelect } = Data;

registerStore( Data );

export function registerReaderRevenueManagerPlugin() {
return Promise.all( [
resolveSelect( CORE_MODULES ).getModules(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ jest.mock( '@wordpress-core/components', () => ( {} ), {
jest.mock( '@wordpress-core/element', () => ( {} ), { virtual: true } );

import Data from 'googlesitekit-data';
import SettingPanel from './SettingPanel';
import { MODULES_READER_REVENUE_MANAGER } from '../../../assets/js/modules/reader-revenue-manager/datastore/constants';
import { provideModules } from '../../../tests/js/utils';
import { registerPlugin } from '@wordpress-core/plugins';
import { registerStore } from '../../../assets/js/modules/reader-revenue-manager/datastore';
import { registerReaderRevenueManagerPlugin } from './plugin-registration';
import SettingPanel from './components/SettingPanel';
import { CORE_MODULES } from '../../assets/js/googlesitekit/modules/datastore/constants';
import { MODULES_READER_REVENUE_MANAGER } from '../../assets/js/modules/reader-revenue-manager/datastore/constants';

registerStore( Data );

const { dispatch } = Data;

Expand All @@ -53,14 +56,11 @@ describe( 'registerReaderRevenueManagerPlugin', () => {
} );

it( 'should register the plugin if the module is connected', async () => {
dispatch( CORE_MODULES ).receiveGetModules( [
provideModules( Data, [
{
slug: 'reader-revenue-manager',
active: true,
connected: true,
shareable: true,
recoverable: true,
internal: false,
},
] );

Expand All @@ -75,7 +75,13 @@ describe( 'registerReaderRevenueManagerPlugin', () => {
} );

it( 'should not register the plugin if the module is not connected', async () => {
dispatch( CORE_MODULES ).receiveGetModules( [] );
provideModules( Data, [
{
slug: 'reader-revenue-manager',
active: true,
connected: false,
},
] );

await registerReaderRevenueManagerPlugin();

Expand Down
19 changes: 19 additions & 0 deletions blocks/reader-revenue-manager/common/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Reader Revenue Manager blocks constants.
*
* Site Kit by Google, Copyright 2025 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 CORE_EDITOR = 'core/editor';
4 changes: 2 additions & 2 deletions includes/Modules/Reader_Revenue_Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ protected function setup_assets() {
$assets[] = new Script(
'googlesitekit-reader-revenue-manager-block-editor-plugin',
array(
'src' => $this->context->url( 'dist/assets/js/blocks/reader-revenue-manager/index.js' ),
'src' => $base_url . 'js/blocks/reader-revenue-manager/block-editor-plugin/index.js',
'dependencies' => array(
'googlesitekit-data',
'googlesitekit-i18n',
Expand All @@ -466,7 +466,7 @@ protected function setup_assets() {
$assets[] = new Stylesheet(
'googlesitekit-block-editor-css',
array(
'src' => $base_url . 'css/googlesitekit-block-editor-css.css',
'src' => $base_url . 'js/blocks/reader-revenue-manager/block-editor-plugin/editor-styles.css',
'dependencies' => array(),
'load_contexts' => array( Asset::CONTEXT_ADMIN_POST_EDITOR ),
)
Expand Down
1 change: 0 additions & 1 deletion webpack/adminCss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ module.exports = ( mode ) => ( {
'googlesitekit-wp-dashboard-css': './assets/sass/wpdashboard.scss',
'googlesitekit-authorize-application-css':
'./assets/sass/authorize-application.scss',
'googlesitekit-block-editor-css': './assets/sass/block-editor.scss',
},
module: {
rules: [
Expand Down
6 changes: 4 additions & 2 deletions webpack/gutenbergBlocks.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ const {
module.exports = ( mode ) => ( {
entry: {
// Reader Revenue Manager
'reader-revenue-manager/index':
'./blocks/reader-revenue-manager/index.js',
'reader-revenue-manager/block-editor-plugin/index':
'./blocks/reader-revenue-manager/block-editor-plugin/index.js',
'reader-revenue-manager/block-editor-plugin/editor-styles':
'./blocks/reader-revenue-manager/block-editor-plugin/editor-styles.scss',
// Sign in with Google block.
'sign-in-with-google/index': './blocks/sign-in-with-google/index.js',
'sign-in-with-google/editor-styles':
Expand Down

0 comments on commit 42dd0b4

Please sign in to comment.