Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance/6261 key metrics settings toggle #6718

Merged
merged 43 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6360116
Add `SettingsKeyMetrics` component.
kuasha420 Mar 3, 2023
91fdbc2
Merge branch 'develop' into enhance/6261-key-metrics-settings-toggle.
kuasha420 Mar 3, 2023
4647c7d
Merge branch 'develop' into enhance/6261-key-metrics-settings-toggle.
kuasha420 Mar 9, 2023
cb05d5b
Cleanup incorrect implementation logic.
kuasha420 Mar 9, 2023
b19b7f3
Update Key Metrics section of settings page.
kuasha420 Mar 9, 2023
e6afe31
Merge branch 'develop' into enhance/6261-key-metrics-settings-toggle.
kuasha420 Mar 9, 2023
2951521
Update key metrics related selectors and actions.
kuasha420 Mar 12, 2023
bf56f74
Update fetch store actions.
kuasha420 Mar 12, 2023
9511ea5
Update SettingsKeyMetrics component.
kuasha420 Mar 12, 2023
0f74f2b
Update key-metrics datastore tests.
kuasha420 Mar 12, 2023
3d60c0d
Add loading check to SettingsKeyMetrics.
kuasha420 Mar 12, 2023
792a891
Merge branch 'develop' into enhance/6261-key-metrics-settings-toggle.
kuasha420 Mar 12, 2023
a534afb
Add default value to Key Metrics Settings.
kuasha420 Mar 13, 2023
3b1c139
Update test.
kuasha420 Mar 13, 2023
c18a180
Remove unnecessary return value from resolver.
kuasha420 Mar 13, 2023
c05b1ea
Add class to user input section.
kuasha420 Mar 13, 2023
c3db905
Don't render key matrics toggle if there is no key metrics.
kuasha420 Mar 14, 2023
cbb4567
Fix incorrect stores.
kuasha420 Mar 14, 2023
44bf9b7
Fix typos.
kuasha420 Mar 17, 2023
bf0e78a
Change the `isWidgetHidden` default value.
kuasha420 Mar 20, 2023
741c1b7
Add `isKeyMetricsWidgetHidden` selector.
kuasha420 Mar 20, 2023
af5573d
Add tests for `isKeyMetricsWidgetHidden`.
kuasha420 Mar 20, 2023
3953f3b
Refactor `SettingsKeyMetrics` to use `isKeyMetricsWidgetHidden`.
kuasha420 Mar 20, 2023
d0fc19f
Add `keyMetricsWidgetHidden` check to key metrics widgets.
kuasha420 Mar 20, 2023
945b21c
Update tests for key metrics widgets.
kuasha420 Mar 20, 2023
67846be
Fix typos and mistakes.
kuasha420 Mar 20, 2023
9244803
Merge branch 'develop' into enhance/6261-key-metrics-settings-toggle.
jimmymadon May 14, 2023
b92cc0b
Update Key Metrics Widgets to use Widget API.
kuasha420 May 18, 2023
097051d
Refactor KM widget slugs as constants.
kuasha420 May 18, 2023
2377a22
Update tests.
kuasha420 May 18, 2023
2009950
Move the `Grid` to `SettingsKeyMetrics`.
kuasha420 May 19, 2023
9be7349
Merge branch 'develop' into enhance/6261-key-metrics-settings-toggle.
kuasha420 May 30, 2023
01f5f73
Rename selector.
kuasha420 May 30, 2023
3de5d22
Move key metrics related infra from widgets datastore.
kuasha420 May 30, 2023
fa316fd
Add prop types to key metrics widgets.
kuasha420 May 30, 2023
f9d21e2
Refactor KM widget tests to use provideKeyMetrics.
kuasha420 May 30, 2023
857e4c3
Add row and cell.
kuasha420 May 30, 2023
ee1ece8
Update SettingsAdmin before revert.
kuasha420 May 30, 2023
a2515f5
Move regex to key-metrics.
kuasha420 May 30, 2023
cc40ddd
Merge branch 'develop' into enhance/6261-key-metrics-settings-toggle.
kuasha420 May 30, 2023
b65acf4
Merge branch 'develop' into enhance/6261-key-metrics-settings-toggle.
kuasha420 Jun 1, 2023
bbc6bd3
Remove KM widget test files.
kuasha420 Jun 1, 2023
f1a254d
Fix VRT.
kuasha420 Jun 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 49 additions & 24 deletions assets/js/components/settings/SettingsAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ import OptIn from '../OptIn';
import ResetButton from '../ResetButton';
import UserInputPreview from '../user-input/UserInputPreview';
import { USER_INPUT_QUESTIONS_LIST } from '../user-input/util/constants';
import UserInputSettings from '../notifications/UserInputSettings';
import { useFeature } from '../../hooks/useFeature';
import { trackEvent } from '../../util';
import SettingsPlugin from './SettingsPlugin';
import useViewContext from '../../hooks/useViewContext';
import SettingsKeyMetrics from './SettingsKeyMetrics';
import Link from '../Link';
const { useSelect, useDispatch } = Data;

export default function SettingsAdmin() {
Expand Down Expand Up @@ -80,29 +81,53 @@ export default function SettingsAdmin() {
<Row>
{ userInputEnabled && (
<Cell size={ 12 }>
{ isUserInputCompleted && (
<Layout
title={ __( 'Key metrics', 'google-site-kit' ) }
header
rounded
>
<div className="googlesitekit-settings-module googlesitekit-settings-module--active googlesitekit-settings-user-input">
<Grid>
<UserInputPreview
goTo={ goTo }
noHeader
noFooter
settingsView
showIndividualCTAs
/>
</Grid>
</div>
</Layout>
) }

{ isUserInputCompleted === false && (
<UserInputSettings isDismissible={ false } rounded />
) }
<Layout
title={ __( 'Key metrics', 'google-site-kit' ) }
header
rounded
>
<div className="googlesitekit-settings-module googlesitekit-settings-module--active googlesitekit-settings-user-input">
<SettingsKeyMetrics />
<Grid>
{ isUserInputCompleted && (
<Row>
<Cell size={ 12 }>
<UserInputPreview
goTo={ goTo }
noHeader
noFooter
settingsView
showIndividualCTAs
/>
</Cell>
</Row>
) }
{ isUserInputCompleted === false && (
<Row>
<Cell
className="googlesitekit-user-input__notification"
size={ 12 }
>
<p>
<span>
{ __(
'Answer 3 quick questions to help us show the most relevant data for your site',
'google-site-kit'
) }
</span>
</p>
<Link href={ userInputURL }>
{ __(
'Personalize your metrics',
'google-site-kit'
) }
</Link>
</Cell>
</Row>
) }
</Grid>
</div>
</Layout>
</Cell>
) }

Expand Down
80 changes: 80 additions & 0 deletions assets/js/components/settings/SettingsKeyMetrics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* SettingsKeyMetrics component.
*
* Site Kit by Google, Copyright 2023 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 { useCallback } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { Switch } from 'googlesitekit-components';
import Data from 'googlesitekit-data';
import { CORE_USER } from '../../googlesitekit/datastore/user/constants';
import { Cell, Grid, Row } from '../../material-components';

const { useSelect, useDispatch } = Data;

export default function SettingsKeyMetrics() {
const keyMetricsWidgetHidden = useSelect( ( select ) =>
select( CORE_USER ).isKeyMetricsWidgetHidden()
);

const keyMetrics = useSelect( ( select ) =>
select( CORE_USER ).getKeyMetrics()
);

const { setKeyMetricsSetting, saveKeyMetricsSettings } =
useDispatch( CORE_USER );

const handleKeyMetricsToggle = useCallback( async () => {
await setKeyMetricsSetting(
'isWidgetHidden',
! keyMetricsWidgetHidden
);
await saveKeyMetricsSettings();
}, [
keyMetricsWidgetHidden,
saveKeyMetricsSettings,
setKeyMetricsSetting,
] );

if ( ! keyMetricsWidgetHidden === undefined || ! keyMetrics?.length ) {
return null;
}
eugene-manuilov marked this conversation as resolved.
Show resolved Hide resolved

return (
<Grid>
eugene-manuilov marked this conversation as resolved.
Show resolved Hide resolved
<Row>
<Cell size={ 12 }>
<Switch
label={ __(
'Display key metrics in dashboard',
'google-site-kit'
) }
checked={ ! keyMetricsWidgetHidden }
onClick={ handleKeyMetricsToggle }
hideLabel={ false }
/>
</Cell>
</Row>
</Grid>
);
}
15 changes: 15 additions & 0 deletions assets/js/googlesitekit/datastore/user/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,18 @@ export const PERMISSION_MANAGE_MODULE_SHARING_OPTIONS =
export const PERMISSION_DELEGATE_MODULE_SHARING_MANAGEMENT =
'googlesitekit_delegate_module_sharing_management';
export const PERMISSION_UPDATE_PLUGINS = 'googlesitekit_update_plugins';

// Key Metrics Widgets
export const KM_ANALYTICS_ENGAGED_TRAFFIC_SOURCE =
'kmAnalyticsEngagedTrafficSource';
export const KM_ANALYTICS_LOYAL_VISITORS = 'kmAnalyticsLoyalVisitors';
export const KM_ANALYTICS_NEW_VISITORS = 'kmAnalyticsNewVisitors';
export const KM_ANALYTICS_POPULAR_CONTENT = 'kmAnalyticsPopularContent';
export const KM_ANALYTICS_POPULAR_PRODUCTS = 'kmAnalyticsPopularProducts';
export const KM_ANALYTICS_TOP_CITIES = 'kmAnalyticsTopCities';
export const KM_ANALYTICS_TOP_CONVERTING_TRAFFIC_SOURCE =
'kmTopConvertingTrafficSource';
export const KM_ANALYTICS_TOP_COUNTRIES = 'kmAnalyticsTopCountries';
export const KM_ANALYTICS_TOP_TRAFFIC_SOURCE = 'kmAnalyticsTopTrafficSource';
export const KM_SEARCH_CONSOLE_POPULAR_KEYWORDS =
'kmSearchConsolePopularKeywords';
Loading