Skip to content

Commit 7af2775

Browse files
committed
Merge remote-tracking branch 'origin/develop' into enhancement/10091-storybook-dependencies-latest-nodejs.
2 parents 5efde98 + 92d8456 commit 7af2775

File tree

9 files changed

+648
-35
lines changed

9 files changed

+648
-35
lines changed

assets/js/googlesitekit/datastore/site/google-tag-gateway.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { MODULE_SLUG_ADS } from '@/js/modules/ads/constants';
4141
import { MODULE_SLUG_ANALYTICS_4 } from '@/js/modules/analytics-4/constants';
4242
import { createFetchStore } from '@/js/googlesitekit/data/create-fetch-store';
4343
import { isFeatureEnabled } from '@/js/features';
44+
import { MODULE_SLUG_TAGMANAGER } from '@/js/modules/tagmanager/constants';
4445

4546
const SET_GOOGLE_TAG_GATEWAY_ENABLED = 'SET_GOOGLE_TAG_GATEWAY_ENABLED';
4647
const RESET_GOOGLE_TAG_GATEWAY_SETTINGS = 'RESET_GOOGLE_TAG_GATEWAY_SETTINGS';
@@ -295,7 +296,8 @@ const baseSelectors = {
295296

296297
return (
297298
isModuleConnected( MODULE_SLUG_ANALYTICS_4 ) ||
298-
isModuleConnected( MODULE_SLUG_ADS )
299+
isModuleConnected( MODULE_SLUG_ADS ) ||
300+
isModuleConnected( MODULE_SLUG_TAGMANAGER )
299301
);
300302
}
301303
),

assets/js/modules/ads/components/settings/SettingsEdit.stories.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ GTGEnabled.decorators = [
206206
export const GTGDisabledWithWarning = Template.bind( null );
207207
GTGDisabledWithWarning.storyName =
208208
'With Google tag gateway disabled with warning';
209+
GTGDisabledWithWarning.parameters = {
210+
features: [ 'googleTagGateway' ],
211+
};
209212
GTGDisabledWithWarning.decorators = [
210213
( Story ) => {
211214
function setupRegistry( registry ) {

assets/js/modules/tagmanager/components/settings/SettingsEdit.stories.js

Lines changed: 114 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
* limitations under the License.
1717
*/
1818

19+
/**
20+
* External dependencies
21+
*/
22+
import fetchMock from 'fetch-mock';
23+
1924
/**
2025
* Internal dependencies
2126
*/
@@ -40,6 +45,7 @@ import { CORE_FORMS } from '@/js/googlesitekit/datastore/forms/constants';
4045
import {
4146
AMP_MODE_PRIMARY,
4247
AMP_MODE_SECONDARY,
48+
CORE_SITE,
4349
} from '@/js/googlesitekit/datastore/site/constants';
4450

4551
const defaultSettings = {
@@ -52,6 +58,38 @@ const defaultSettings = {
5258
ownerID: 0,
5359
};
5460

61+
const gtgServerRequirementsEndpoint = new RegExp(
62+
'^/google-site-kit/v1/core/site/data/gtg-server-requirement-status'
63+
);
64+
65+
function setupRegistryWithDefaultSettings( registry ) {
66+
// eslint-disable-next-line sitekit/acronym-case
67+
const accountID = fixtures.accounts[ 0 ].accountId;
68+
registry.dispatch( MODULES_TAGMANAGER ).setAccountID( accountID );
69+
registry
70+
.dispatch( MODULES_TAGMANAGER )
71+
.receiveGetAccounts( fixtures.accounts );
72+
registry
73+
.dispatch( MODULES_TAGMANAGER )
74+
.receiveGetContainers( fixtures.getContainers.all, {
75+
accountID,
76+
} );
77+
const [ container ] = registry
78+
.select( MODULES_TAGMANAGER )
79+
.getWebContainers( accountID );
80+
registry
81+
.dispatch( MODULES_TAGMANAGER )
82+
// eslint-disable-next-line sitekit/acronym-case
83+
.setContainerID( container.publicId );
84+
registry
85+
.dispatch( MODULES_TAGMANAGER )
86+
// eslint-disable-next-line sitekit/acronym-case
87+
.setInternalContainerID( container.containerId );
88+
registry
89+
.dispatch( MODULES_TAGMANAGER )
90+
.receiveGetSettings( defaultSettings );
91+
}
92+
5593
function Template( args ) {
5694
return (
5795
<div className="googlesitekit-layout">
@@ -75,33 +113,7 @@ function Template( args ) {
75113
export const Default = Template.bind( {} );
76114
Default.storyName = 'Default';
77115
Default.args = {
78-
setupRegistry: ( registry ) => {
79-
// eslint-disable-next-line sitekit/acronym-case
80-
const accountID = fixtures.accounts[ 0 ].accountId;
81-
registry.dispatch( MODULES_TAGMANAGER ).setAccountID( accountID );
82-
registry
83-
.dispatch( MODULES_TAGMANAGER )
84-
.receiveGetAccounts( fixtures.accounts );
85-
registry
86-
.dispatch( MODULES_TAGMANAGER )
87-
.receiveGetContainers( fixtures.getContainers.all, {
88-
accountID,
89-
} );
90-
const [ container ] = registry
91-
.select( MODULES_TAGMANAGER )
92-
.getWebContainers( accountID );
93-
registry
94-
.dispatch( MODULES_TAGMANAGER )
95-
// eslint-disable-next-line sitekit/acronym-case
96-
.setContainerID( container.publicId );
97-
registry
98-
.dispatch( MODULES_TAGMANAGER )
99-
// eslint-disable-next-line sitekit/acronym-case
100-
.setInternalContainerID( container.containerId );
101-
registry
102-
.dispatch( MODULES_TAGMANAGER )
103-
.receiveGetSettings( defaultSettings );
104-
},
116+
setupRegistry: setupRegistryWithDefaultSettings,
105117
};
106118

107119
export const NoAccounts = Template.bind( {} );
@@ -408,6 +420,81 @@ SecondaryAMPNonUniqueContainer.args = {
408420
ampMode: AMP_MODE_SECONDARY,
409421
};
410422

423+
export const GTGEnabled = Template.bind( null );
424+
GTGEnabled.storyName = 'With Google tag gateway enabled';
425+
GTGEnabled.parameters = {
426+
features: [ 'googleTagGateway' ],
427+
};
428+
GTGEnabled.decorators = [
429+
( Story ) => {
430+
function setupRegistry( registry ) {
431+
setupRegistryWithDefaultSettings( registry );
432+
433+
const gtgSettings = {
434+
isEnabled: true,
435+
isGTGHealthy: true,
436+
isScriptAccessEnabled: true,
437+
};
438+
439+
fetchMock.getOnce(
440+
gtgServerRequirementsEndpoint,
441+
{
442+
body: gtgSettings,
443+
},
444+
{ overwriteRoutes: true }
445+
);
446+
447+
registry
448+
.dispatch( CORE_SITE )
449+
.receiveGetGoogleTagGatewaySettings( gtgSettings );
450+
}
451+
452+
return (
453+
<WithRegistrySetup func={ setupRegistry }>
454+
<Story />
455+
</WithRegistrySetup>
456+
);
457+
},
458+
];
459+
460+
export const GTGDisabledWithWarning = Template.bind( null );
461+
GTGDisabledWithWarning.storyName =
462+
'With Google tag gateway disabled with warning';
463+
GTGDisabledWithWarning.parameters = {
464+
features: [ 'googleTagGateway' ],
465+
};
466+
GTGDisabledWithWarning.decorators = [
467+
( Story ) => {
468+
function setupRegistry( registry ) {
469+
setupRegistryWithDefaultSettings( registry );
470+
471+
const gtgSettings = {
472+
isEnabled: true,
473+
isGTGHealthy: false,
474+
isScriptAccessEnabled: false,
475+
};
476+
477+
fetchMock.getOnce(
478+
gtgServerRequirementsEndpoint,
479+
{
480+
body: gtgSettings,
481+
},
482+
{ overwriteRoutes: true }
483+
);
484+
485+
registry
486+
.dispatch( CORE_SITE )
487+
.receiveGetGoogleTagGatewaySettings( gtgSettings );
488+
}
489+
490+
return (
491+
<WithRegistrySetup func={ setupRegistry }>
492+
<Story />
493+
</WithRegistrySetup>
494+
);
495+
},
496+
];
497+
411498
export default {
412499
title: 'Modules/TagManager/Settings/SettingsEdit',
413500
component: SettingsEdit,

assets/js/modules/tagmanager/components/settings/SettingsForm.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ import { MODULE_SLUG_TAGMANAGER } from '@/js/modules/tagmanager/constants';
4545
import { CORE_MODULES } from '@/js/googlesitekit/modules/datastore/constants';
4646
import SettingsUseSnippetSwitch from './SettingsUseSnippetSwitch';
4747
import Notice from '@/js/components/Notice';
48+
import SettingsGroup from '@/js/components/settings/SettingsGroup';
49+
import GoogleTagGatewayToggle from '@/js/components/google-tag-gateway/GoogleTagGatewayToggle';
50+
import { useFeature } from '@/js/hooks/useFeature';
4851

4952
export default function SettingsForm( { hasModuleAccess } ) {
53+
const gtgEnabled = useFeature( 'googleTagGateway' );
54+
5055
const module = useSelect( ( select ) =>
5156
select( CORE_MODULES ).getModule( MODULE_SLUG_TAGMANAGER )
5257
);
@@ -99,6 +104,17 @@ export default function SettingsForm( { hasModuleAccess } ) {
99104
<div className="googlesitekit-setup-module__inputs googlesitekit-setup-module__inputs--multiline">
100105
<SettingsUseSnippetSwitch />
101106
</div>
107+
108+
{ gtgEnabled && (
109+
<SettingsGroup
110+
title={ __(
111+
'Improve your measurement',
112+
'google-site-kit'
113+
) }
114+
>
115+
<GoogleTagGatewayToggle />
116+
</SettingsGroup>
117+
) }
102118
</div>
103119
);
104120
}

assets/js/modules/tagmanager/datastore/base.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@
2222
import Modules from 'googlesitekit-modules';
2323
import { MODULES_TAGMANAGER } from './constants';
2424
import { MODULE_SLUG_TAGMANAGER } from '@/js/modules/tagmanager/constants';
25-
import { submitChanges, validateCanSubmitChanges } from './settings';
25+
import {
26+
submitChanges,
27+
validateCanSubmitChanges,
28+
rollbackChanges,
29+
validateHaveSettingsChanged,
30+
} from './settings';
2631

2732
let baseModuleStore = Modules.createModuleStore( MODULE_SLUG_TAGMANAGER, {
2833
ownedSettingsSlugs: [
@@ -43,7 +48,9 @@ let baseModuleStore = Modules.createModuleStore( MODULE_SLUG_TAGMANAGER, {
4348
'ownerID',
4449
],
4550
submitChanges,
51+
rollbackChanges,
4652
validateCanSubmitChanges,
53+
validateHaveSettingsChanged,
4754
} );
4855

4956
// Rename generated pieces to adhere to our convention.

assets/js/modules/tagmanager/datastore/settings.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* External dependencies
2121
*/
2222
import invariant from 'invariant';
23+
import { isEqual, pick } from 'lodash';
2324

2425
/**
2526
* Internal dependencies
@@ -53,6 +54,8 @@ import { CORE_SITE } from '@/js/googlesitekit/datastore/site/constants';
5354
import { createStrictSelect } from '@/js/googlesitekit/data/utils';
5455
import { MODULES_ANALYTICS_4 } from '@/js/modules/analytics-4/datastore/constants';
5556
import { MODULE_SLUG_ANALYTICS_4 } from '@/js/modules/analytics-4/constants';
57+
import { CORE_NOTIFICATIONS } from '@/js/googlesitekit/notifications/datastore/constants';
58+
import { GTG_SETUP_CTA_BANNER_NOTIFICATION } from '@/js/googlesitekit/notifications/constants';
5659

5760
// Invariant error messages.
5861
export const INVARIANT_INVALID_ACCOUNT_ID =
@@ -153,6 +156,32 @@ export async function submitChanges( { select, dispatch } ) {
153156
}
154157
}
155158

159+
if ( select( CORE_SITE ).haveGoogleTagGatewaySettingsChanged() ) {
160+
const { error } = await dispatch(
161+
CORE_SITE
162+
).saveGoogleTagGatewaySettings();
163+
164+
if ( error ) {
165+
return { error };
166+
}
167+
168+
if (
169+
select( CORE_SITE ).isGoogleTagGatewayEnabled() &&
170+
! select( CORE_NOTIFICATIONS ).isNotificationDismissed(
171+
GTG_SETUP_CTA_BANNER_NOTIFICATION
172+
)
173+
) {
174+
const { error: dismissError } =
175+
( await dispatch( CORE_NOTIFICATIONS ).dismissNotification(
176+
GTG_SETUP_CTA_BANNER_NOTIFICATION
177+
) ) || {};
178+
179+
if ( dismissError ) {
180+
return { error: dismissError };
181+
}
182+
}
183+
}
184+
156185
await invalidateCache( 'modules', MODULE_SLUG_TAGMANAGER );
157186

158187
return {};
@@ -253,3 +282,30 @@ export function validateCanSubmitChanges( select ) {
253282
}
254283
}
255284
}
285+
286+
export function rollbackChanges( { select, dispatch } ) {
287+
if ( select( MODULES_TAGMANAGER ).haveSettingsChanged() ) {
288+
dispatch( MODULES_TAGMANAGER ).rollbackSettings();
289+
dispatch( CORE_SITE ).resetGoogleTagGatewaySettings();
290+
}
291+
}
292+
293+
export function validateHaveSettingsChanged( select, state, keys ) {
294+
const { settings, savedSettings } = state;
295+
const haveGoogleTagGatewaySettingsChanged =
296+
select( CORE_SITE ).haveGoogleTagGatewaySettingsChanged();
297+
298+
if ( keys ) {
299+
invariant(
300+
isEqual( pick( settings, keys ), pick( savedSettings, keys ) ) ||
301+
haveGoogleTagGatewaySettingsChanged,
302+
INVARIANT_SETTINGS_NOT_CHANGED
303+
);
304+
}
305+
306+
invariant(
307+
! isEqual( settings, savedSettings ) ||
308+
haveGoogleTagGatewaySettingsChanged,
309+
INVARIANT_SETTINGS_NOT_CHANGED
310+
);
311+
}

0 commit comments

Comments
 (0)