Skip to content

Commit

Permalink
Merge branch 'develop' into enhancement/8796-sync-publication-onboard…
Browse files Browse the repository at this point in the history
…ing-state-action.
  • Loading branch information
ankitrox committed Jul 18, 2024
2 parents e89e18b + 84f0b62 commit 9586f22
Show file tree
Hide file tree
Showing 70 changed files with 1,370 additions and 924 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"googlesitekit-api",
"googlesitekit-widgets",
"googlesitekit-components",
"googlesitekit-notifications",
"@wordpress/i18n__non-shim",
"@wordpress/api-fetch__non-shim"
],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/zips.yml
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ jobs:
- name: Extract
run: |
unzip /tmp/google-site-kit.zip
echo .distignore > .distignore
- uses: 10up/[email protected]
with:
dry-run: ${{ inputs.dry_run }}
env:
BUILD_DIR: ./google-site-kit
SLUG: google-site-kit
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
Expand Down
3 changes: 1 addition & 2 deletions assets/js/components/DateRangeSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ import { Menu, Button } from 'googlesitekit-components';
import DateRangeIcon from '../../svg/icons/date-range.svg';
import { CORE_USER } from '../googlesitekit/datastore/user/constants';
import { useKeyCodesInside } from '../hooks/useKeyCodesInside';
import { getAvailableDateRanges } from '../util/date-range';
import { trackEvent } from '../util';
import { getAvailableDateRanges, trackEvent } from '../util';
import { CORE_UI } from '../googlesitekit/datastore/ui/constants';
import useViewContext from '../hooks/useViewContext';

Expand Down
3 changes: 1 addition & 2 deletions assets/js/components/GoogleChart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ import {
getCombinedChartEvents,
getChartOptions,
} from './utils';
import { stringToDate, getDateString } from '../../util/date-range';
import { getLocale } from '../../util';
import { stringToDate, getDateString, getLocale } from '../../util';
import { useBreakpoint } from '../../hooks/useBreakpoint';

export default function GoogleChart( props ) {
Expand Down
3 changes: 1 addition & 2 deletions assets/js/components/GoogleChart/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import { cloneDeep, findLast, merge, set } from 'lodash';
* Internal dependencies
*/
import { BREAKPOINT_SMALL } from '../../hooks/useBreakpoint';
import { getLocale } from '../../util';
import { stringToDate } from '../../util/date-range/string-to-date';
import { getLocale, stringToDate } from '../../util';

/**
* Returns the Google chart data, filtered by selected stats if present.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { useSelect, useDispatch } from 'googlesitekit-data';
import { Checkbox, ProgressBar } from 'googlesitekit-components';
import { CORE_SITE } from '../../../googlesitekit/datastore/site/constants';
import { CORE_MODULES } from '../../../googlesitekit/modules/datastore/constants';
import { getTimeInSeconds } from '../../../util';
import { DAY_IN_SECONDS } from '../../../util';
import BannerNotification from '../../notifications/BannerNotification';
import Errors from './Errors';

Expand Down Expand Up @@ -261,7 +261,7 @@ export default function ModuleRecoveryAlert() {
learnMoreLabel={ __( 'Learn more', 'google-site-kit' ) }
isDismissible={ isDismissible }
dismiss={ __( 'Remind me later', 'google-site-kit' ) }
dismissExpires={ getTimeInSeconds( 'day' ) }
dismissExpires={ DAY_IN_SECONDS }
>
{ children }
</BannerNotification>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Fragment, useCallback, useEffect, useState } from '@wordpress/element';
import { SpinnerButton } from 'googlesitekit-components';
import { useSelect, useDispatch } from 'googlesitekit-data';
import { CORE_SITE } from '../../../googlesitekit/datastore/site/constants';
import { getTimeInSeconds } from '../../../util';
import { MINUTE_IN_SECONDS } from '../../../util';
import useQueryArg from '../../../hooks/useQueryArg';
import {
CORE_USER,
Expand Down Expand Up @@ -101,7 +101,7 @@ function EnableAutoUpdateBannerNotification() {
CACHE_KEY_HIDE_NOTIFICATION_ON_FIRST_SETUP,
true,
{
ttl: getTimeInSeconds() * 10,
ttl: MINUTE_IN_SECONDS * 10,
}
);
setIsFirstPluginSetup( isFirstSetup );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { useSelect } from 'googlesitekit-data';
import BannerNotification from './BannerNotification';
import { MODULES_ANALYTICS_4 } from '../../modules/analytics-4/datastore/constants';
import { CORE_SITE } from '../../googlesitekit/datastore/site/constants';
import { getTimeInSeconds } from '../../util';
import { MINUTE_IN_SECONDS } from '../../util';
import { Cell, Grid, Row } from '../../material-components';

export default function WebDataStreamNotAvailableNotification() {
Expand Down Expand Up @@ -86,7 +86,7 @@ export default function WebDataStreamNotAvailableNotification() {
dismiss={ __( 'Maybe later', 'google-site-kit' ) }
// This is arbitrarily set to 55 minutes to ensure that the notification
// will become ready to be displayed again in an hour.
dismissExpires={ getTimeInSeconds( 'minute' ) * 55 }
dismissExpires={ MINUTE_IN_SECONDS * 55 }
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { useSelect } from 'googlesitekit-data';
import BannerNotification from '../BannerNotification';
import GatheringDataIcon from '../../../../svg/graphics/zero-state-red.svg';
import { CORE_SITE } from '../../../googlesitekit/datastore/site/constants';
import { getTimeInSeconds, trackEvent } from '../../../util';
import { DAY_IN_SECONDS, trackEvent } from '../../../util';
import useViewContext from '../../../hooks/useViewContext';

export default function GatheringDataNotification( {
Expand Down Expand Up @@ -81,7 +81,7 @@ export default function GatheringDataNotification( {
ctaLink={ `${ settingsAdminURL }#/connect-more-services` }
onCTAClick={ handleCTAClick }
dismiss={ __( 'Maybe later', 'google-site-kit' ) }
dismissExpires={ getTimeInSeconds( 'day' ) }
dismissExpires={ DAY_IN_SECONDS }
SmallImageSVG={ GatheringDataIcon }
onDismiss={ handleOnDismiss }
isDismissible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { __ } from '@wordpress/i18n';
import { CORE_SITE } from '../../../googlesitekit/datastore/site/constants';
import BannerNotification from '../BannerNotification';
import ZeroStateIcon from '../../../../svg/graphics/zero-state-blue.svg';
import { getTimeInSeconds, trackEvent } from '../../../util';
import { DAY_IN_SECONDS, trackEvent } from '../../../util';
import useViewContext from '../../../hooks/useViewContext';

export default function ZeroDataNotification() {
Expand Down Expand Up @@ -69,7 +69,7 @@ export default function ZeroDataNotification() {
learnMoreLabel={ __( 'Learn more', 'google-site-kit' ) }
learnMoreURL={ notEnoughTrafficURL }
dismiss={ __( 'Remind me later', 'google-site-kit' ) }
dismissExpires={ getTimeInSeconds( 'day' ) }
dismissExpires={ DAY_IN_SECONDS }
SmallImageSVG={ ZeroStateIcon }
onView={ handleOnView }
onDismiss={ handleOnDismiss }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function WPDashboardUniqueVisitorsChartGA4( props ) {
select( CORE_UI ).getValue( 'googleChartsCollisionError' )
);
const refDate = useSelect( ( select ) =>
select( CORE_USER ).getReferenceDate( { parsed: true } )
select( CORE_USER ).getReferenceDate()
);

const { startDate, endDate, compareStartDate, compareEndDate } = useSelect(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* `isValidDateRange` utility tests.
* Public Notifications API entrypoint.
*
* Site Kit by Google, Copyright 2021 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.
Expand All @@ -19,23 +19,23 @@
/**
* Internal dependencies
*/
import { isValidDateRange } from './is-valid-date-range';
import Data from 'googlesitekit-data';
import {
registerStore,
createNotifications,
registerNotifications,
} from './googlesitekit/notifications';

describe( 'isValidDateString', () => {
// [ dateRange, expectedReturnValue ]
const valuesToTest = [
[ 'last-1-days', true ],
[ 'last-7-days', true ],
[ 'last-28-days', true ],
[ 'last-1-day', false ],
[ 'invalid-range', false ],
[ 'invalid-date-range', false ],
];
registerStore( Data );

it.each( valuesToTest )(
'with date range of %s should return %s',
( dateRange, expected ) => {
expect( isValidDateRange( dateRange ) ).toEqual( expected );
}
);
} );
const Notifications = createNotifications( Data );
registerNotifications( Notifications );

if ( typeof global.googlesitekit === 'undefined' ) {
global.googlesitekit = {};
}

global.googlesitekit.notifications = Notifications;

// This is only exported for Jest and is not used in production.
export default Notifications;
11 changes: 4 additions & 7 deletions assets/js/googlesitekit/datastore/user/date-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
isValidDateString,
INVALID_DATE_RANGE_ERROR,
INVALID_DATE_STRING_ERROR,
} from '../../../util/date-range';
} from '../../../util';

export const initialState = {
dateRange: 'last-28-days',
Expand Down Expand Up @@ -205,15 +205,12 @@ export const selectors = {
* Returns the current reference date, typically today.
*
* @since 1.22.0
* @since 1.130.0 Added options to allow getting the reference date as a Date instance.
*
* @param {Object} state The current data store's state.
* @param {Object} [options] Options parameter. Default is: {}.
* @param {number} [options.parsed] Number of days to offset. Default is: 0.
* @param {Object} state The current data store's state.
* @return {string} The current reference date as YYYY-MM-DD.
*/
getReferenceDate( state, { parsed = false } = {} ) {
return parsed ? new Date( state.referenceDate ) : state.referenceDate;
getReferenceDate( state ) {
return state.referenceDate;
},
};

Expand Down
2 changes: 1 addition & 1 deletion assets/js/googlesitekit/datastore/user/date-range.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
import { createTestRegistry } from '../../../../../tests/js/utils';
import { CORE_USER } from './constants';
import { getDateString } from '../../../util/date-range';
import { getDateString } from '../../../util';

describe( 'core/user date-range', () => {
let registry;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`core/notifications Notifications actions registerNotification should register the notification with the given settings and component 1`] = `
<div>
Hello
world
!
</div>
`;
37 changes: 37 additions & 0 deletions assets/js/googlesitekit/notifications/datastore/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* 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 {
VIEW_CONTEXT_ENTITY_DASHBOARD,
VIEW_CONTEXT_ENTITY_DASHBOARD_VIEW_ONLY,
VIEW_CONTEXT_MAIN_DASHBOARD,
VIEW_CONTEXT_MAIN_DASHBOARD_VIEW_ONLY,
} from '../../constants';

export const CORE_NOTIFICATIONS = 'core/notifications';

export const NOTIFICATION_AREAS = {
ERRORS: 'notification-area-errors',
BANNERS_ABOVE_NAV: 'notification-area-banners-above-nav',
BANNERS_BELOW_NAV: 'notification-area-banners-below-nav',
};

export const NOTIFICATION_VIEW_CONTEXTS = [
VIEW_CONTEXT_MAIN_DASHBOARD,
VIEW_CONTEXT_ENTITY_DASHBOARD,
VIEW_CONTEXT_MAIN_DASHBOARD_VIEW_ONLY,
VIEW_CONTEXT_ENTITY_DASHBOARD_VIEW_ONLY,
];
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/**
* `isValidDateInstance` utility.
*
* Site Kit by Google, Copyright 2021 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.
Expand All @@ -17,14 +15,16 @@
*/

/**
* Asserts whether a given date instance is valid or invalid.
*
* @since 1.18.0
*
* @param {Date} date Date instance to be asserted against.
* @return {boolean} True if the given date instance is valid.
* Internal dependencies
*/
export const isValidDateInstance = ( date ) => {
// type coercion provided by isNaN is preferred here over Number.isNaN
return date instanceof Date && ! isNaN( date );
import Data from 'googlesitekit-data';
import { CORE_NOTIFICATIONS } from './constants';
import notifications from './notifications';

const store = Data.combineStores( Data.commonStore, notifications );

export const registerStore = ( registry ) => {
registry.registerStore( CORE_NOTIFICATIONS, store );
};

export default store;
Loading

0 comments on commit 9586f22

Please sign in to comment.