-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6718 from google/enhance/6261-key-metrics-setting…
…s-toggle Enhance/6261 key metrics settings toggle
- Loading branch information
Showing
33 changed files
with
968 additions
and
673 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
return ( | ||
<Grid> | ||
<Row> | ||
<Cell size={ 12 }> | ||
<Switch | ||
label={ __( | ||
'Display key metrics in dashboard', | ||
'google-site-kit' | ||
) } | ||
checked={ ! keyMetricsWidgetHidden } | ||
onClick={ handleKeyMetricsToggle } | ||
hideLabel={ false } | ||
/> | ||
</Cell> | ||
</Row> | ||
</Grid> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.