Skip to content

Commit

Permalink
Merge branch 'develop' into poc/8955-event-provider-js-not-loading-pr…
Browse files Browse the repository at this point in the history
…oduction-build.
  • Loading branch information
tofumatt committed Jul 4, 2024
2 parents d114b5f + 12e537d commit ac5e398
Show file tree
Hide file tree
Showing 92 changed files with 3,015 additions and 519 deletions.
29 changes: 21 additions & 8 deletions assets/js/components/ModalDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function ModalDialog( {
inProgress = false,
small = false,
medium = false,
buttonLink = null,
} ) {
const instanceID = useInstanceId( ModalDialog );
const describedByID = `googlesitekit-dialog-description-${ instanceID }`;
Expand Down Expand Up @@ -125,14 +126,25 @@ function ModalDialog( {
>
{ __( 'Cancel', 'google-site-kit' ) }
</Button>
<SpinnerButton
onClick={ handleConfirm }
danger={ danger }
disabled={ inProgress }
isSaving={ inProgress }
>
{ confirmButton || __( 'Disconnect', 'google-site-kit' ) }
</SpinnerButton>
{ buttonLink ? (
<Button
href={ buttonLink }
target="_blank"
danger={ danger }
>
{ confirmButton }
</Button>
) : (
<SpinnerButton
onClick={ handleConfirm }
danger={ danger }
disabled={ inProgress }
isSaving={ inProgress }
>
{ confirmButton ||
__( 'Disconnect', 'google-site-kit' ) }
</SpinnerButton>
) }
</DialogFooter>
</Dialog>
);
Expand All @@ -150,6 +162,7 @@ ModalDialog.propTypes = {
danger: PropTypes.bool,
small: PropTypes.bool,
medium: PropTypes.bool,
buttonLink: PropTypes.string,
};

export default ModalDialog;
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ function AuthenticatedPermissionsModal() {
// If we have a datastores to snapshot before navigating away to the
// authorization page, do that first.
await snapshotAllStores( registry );

// Navigate to the authorization page.
navigateTo( connectURL );
}, [ registry, connectURL, navigateTo, permissionsError, setValues ] );

Expand Down
6 changes: 6 additions & 0 deletions assets/js/components/notifications/ErrorNotifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ export default function ErrorNotifications() {
}
}

if (
temporaryPersistedPermissionsError?.data?.skipDefaultErrorNotifications
) {
return null;
}

return (
<Fragment>
<InternalServerError />
Expand Down
16 changes: 15 additions & 1 deletion assets/js/components/notifications/SetupErrorNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { __ } from '@wordpress/i18n';
import { useSelect } from 'googlesitekit-data';
import BannerNotification from './BannerNotification';
import { CORE_SITE } from '../../googlesitekit/datastore/site/constants';
import { CORE_FORMS } from '../../googlesitekit/datastore/forms/constants';
import { FORM_TEMPORARY_PERSIST_PERMISSION_ERROR } from '../../googlesitekit/datastore/user/constants';

export default function SetupErrorNotification() {
// These will be `null` if no errors exist.
Expand All @@ -37,7 +39,19 @@ export default function SetupErrorNotification() {
select( CORE_SITE ).getSetupErrorRedoURL()
);

if ( ! setupErrorMessage ) {
const { data: permissionsErrorData } = useSelect(
( select ) =>
select( CORE_FORMS ).getValue(
FORM_TEMPORARY_PERSIST_PERMISSION_ERROR,
'permissionsError'
) || {}
);

// If there's no setup error message or the temporary persisted permissions error has skipDefaultErrorNotifications flag set, return null.
if (
! setupErrorMessage ||
permissionsErrorData?.skipDefaultErrorNotifications
) {
return null;
}

Expand Down
5 changes: 4 additions & 1 deletion assets/js/components/settings/SettingsActiveModule/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -180,7 +181,9 @@ export default function Header( { slug } ) {
hasLeftSpacing
/>
) }
{ slug === 'ads' && <NewBadge hasLeftSpacing /> }
{ NEW_MODULES.includes( slug ) && (
<NewBadge hasLeftSpacing />
) }
</div>
</Cell>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ describe( 'SettingsModule', () => {
// Hack to avoid act error due to state change during render.
await act( () =>
registry
.__experimentalResolveSelect( CORE_MODULES )
.resolveSelect( CORE_MODULES )
.canActivateModule( 'tagmanager' )
);

Expand Down
5 changes: 4 additions & 1 deletion assets/js/components/settings/SetupModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -114,7 +115,9 @@ export default function SetupModule( { slug, name, description } ) {
label={ __( 'Experimental', 'google-site-kit' ) }
/>
) }
{ slug === 'ads' && <NewBadge hasNoSpacing /> }
{ NEW_MODULES.includes( slug ) && (
<NewBadge hasNoSpacing />
) }
</div>
</div>
<p className="googlesitekit-settings-connect-module__text">
Expand Down
19 changes: 19 additions & 0 deletions assets/js/components/settings/constants.js
Original file line number Diff line number Diff line change
@@ -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' ];
3 changes: 1 addition & 2 deletions assets/js/components/setup/ModuleSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ export default function ModuleSetup( { moduleSlug } ) {
return;
}

const { select, __experimentalResolveSelect: resolveSelect } =
registry;
const { select, resolveSelect } = registry;
await resolveSelect( CORE_SITE ).getSiteInfo();
const adminURL = select( CORE_SITE ).getAdminURL(
'googlesitekit-dashboard',
Expand Down
31 changes: 14 additions & 17 deletions assets/js/components/user-input/UserInputPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import useQueryArg from '../../hooks/useQueryArg';
import ErrorNotice from '../ErrorNotice';
import LoadingWrapper from '../LoadingWrapper';
import CancelUserInputButton from './CancelUserInputButton';
import { Row, Cell } from '../../material-components';
import { hasErrorForAnswer } from './util/validation';

export default function UserInputPreview( props ) {
Expand Down Expand Up @@ -128,22 +127,20 @@ export default function UserInputPreview( props ) {
</p>
) }
{ settingsView && (
<Row>
<Cell className="googlesitekit-settings-user-input__heading-container">
<LoadingWrapper
loading={ loading }
width="275px"
height="16px"
>
<p className="googlesitekit-settings-user-input__heading">
{ __(
'Edit your answers for more personalized metrics:',
'google-site-kit'
) }
</p>
</LoadingWrapper>
</Cell>
</Row>
<div className="googlesitekit-settings-user-input__heading-container">
<LoadingWrapper
loading={ loading }
width="275px"
height="16px"
>
<p className="googlesitekit-settings-user-input__heading">
{ __(
'Edit your answers for more personalized metrics:',
'google-site-kit'
) }
</p>
</LoadingWrapper>
</div>
) }
<UserInputPreviewGroup
slug={ USER_INPUT_QUESTIONS_PURPOSE }
Expand Down
30 changes: 30 additions & 0 deletions assets/js/googlesitekit-modules-reader-revenue-manager.js
Original file line number Diff line number Diff line change
@@ -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 );
7 changes: 7 additions & 0 deletions assets/js/googlesitekit/data/create-settings-store.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,20 @@ describe( 'createSettingsStore store', () => {
] )( '%s', ( selector ) => {
it( 'should use provided validateHaveSettingsChanged function', () => {
const validateHaveSettingsChanged = jest.fn();

storeDefinition = createSettingsStore( ...STORE_ARGS, {
settingSlugs: [ 'isSkyBlue' ],
validateHaveSettingsChanged,
registry,
} );

registry.registerStore(
storeDefinition.STORE_NAME,
storeDefinition
);

storeDefinition.selectors[ selector ]();

expect( validateHaveSettingsChanged ).toHaveBeenCalled();
} );
} );
Expand Down
4 changes: 2 additions & 2 deletions assets/js/googlesitekit/datastore/site/enable-auto-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ const baseActions = {
const registry = yield commonActions.getRegistry();

yield commonActions.await(
registry.__experimentalResolveSelect( CORE_USER ).getNonces()
registry.resolveSelect( CORE_USER ).getNonces()
);
yield commonActions.await(
registry.__experimentalResolveSelect( CORE_SITE ).getSiteInfo()
registry.resolveSelect( CORE_SITE ).getSiteInfo()
);

const nonce = registry.select( CORE_USER ).getNonce( 'updates' );
Expand Down
4 changes: 1 addition & 3 deletions assets/js/googlesitekit/datastore/site/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ const baseControls = {
[ WAIT_FOR_HTML_FOR_URL ]: createRegistryControl(
( registry ) =>
( { payload: { url } } ) =>
registry
.__experimentalResolveSelect( CORE_SITE )
.getHTMLForURL( url )
registry.resolveSelect( CORE_SITE ).getHTMLForURL( url )
),
[ CHECK_FOR_SETUP_TAG ]: createRegistryControl(
( registry ) => async () => {
Expand Down
32 changes: 32 additions & 0 deletions assets/js/googlesitekit/datastore/site/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const RECEIVE_SITE_INFO = 'RECEIVE_SITE_INFO';
const RECEIVE_PERMALINK_PARAM = 'RECEIVE_PERMALINK_PARAM';
const SET_SITE_KIT_AUTO_UPDATES_ENABLED = 'SET_SITE_KIT_AUTO_UPDATES_ENABLED';
const SET_KEY_METRICS_SETUP_COMPLETED_BY = 'SET_KEY_METRICS_SETUP_COMPLETED_BY';
const SET_SETUP_ERROR_CODE = 'SET_SETUP_ERROR_CODE';

export const initialState = {
siteInfo: undefined,
Expand Down Expand Up @@ -126,6 +127,27 @@ export const actions = {
type: SET_KEY_METRICS_SETUP_COMPLETED_BY,
};
},

/**
* Sets `setupErrorCode` value.
*
* @since n.e.x.t
*
* @param {string|null} setupErrorCode Error code from setup, or `null` if no error.
* @return {Object} Redux-style action.
*/
setSetupErrorCode( setupErrorCode ) {
// setupErrorCode can be a string or null.
invariant(
typeof setupErrorCode === 'string' || setupErrorCode === null,
'setupErrorCode must be a string or null.'
);

return {
payload: { setupErrorCode },
type: SET_SETUP_ERROR_CODE,
};
},
};

export const controls = {};
Expand Down Expand Up @@ -228,6 +250,16 @@ export const reducer = ( state, { payload, type } ) => {
},
};

case SET_SETUP_ERROR_CODE:
const { setupErrorCode } = payload;
return {
...state,
siteInfo: {
...state.siteInfo,
setupErrorCode,
},
};

default: {
return state;
}
Expand Down
38 changes: 38 additions & 0 deletions assets/js/googlesitekit/datastore/site/info.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,44 @@ describe( 'core/site site info', () => {
);
} );
} );

describe( 'setSetupErrorCode', () => {
it( 'sets the `setupErrorCode` property', () => {
registry
.dispatch( CORE_SITE )
.setSetupErrorCode( 'error_code' );

expect( store.getState().siteInfo.setupErrorCode ).toBe(
'error_code'
);
} );

it( 'requires a string or null argument', () => {
expect( () => {
registry.dispatch( CORE_SITE ).setSetupErrorCode();
} ).toThrow( 'setupErrorCode must be a string or null.' );

expect( () => {
registry
.dispatch( CORE_SITE )
.setSetupErrorCode( undefined );
} ).toThrow( 'setupErrorCode must be a string or null.' );

expect( () => {
registry.dispatch( CORE_SITE ).setSetupErrorCode( true );
} ).toThrow( 'setupErrorCode must be a string or null.' );

expect( () => {
registry.dispatch( CORE_SITE ).setSetupErrorCode( 1 );
} ).toThrow( 'setupErrorCode must be a string or null.' );

expect( () => {
registry.dispatch( CORE_SITE ).setSetupErrorCode( null );

registry.dispatch( CORE_SITE ).setSetupErrorCode( 'error' );
} ).not.toThrow( 'setupErrorCode must be a string or null.' );
} );
} );
} );

describe( 'selectors', () => {
Expand Down
Loading

0 comments on commit ac5e398

Please sign in to comment.