-
Notifications
You must be signed in to change notification settings - Fork 296
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 #5465 from google/enhancement/5376-view-only-recov…
…erable-modules
- Loading branch information
Showing
8 changed files
with
430 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* RecoverableModules component. | ||
* | ||
* Site Kit by Google, Copyright 2022 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. | ||
*/ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, _x, sprintf } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Data from 'googlesitekit-data'; | ||
import { CORE_MODULES } from '../googlesitekit/modules/datastore/constants'; | ||
import CTA from './notifications/CTA'; | ||
|
||
const { useSelect } = Data; | ||
|
||
export default function RecoverableModules( { moduleSlugs } ) { | ||
const moduleNames = useSelect( ( select ) => { | ||
const modules = select( CORE_MODULES ).getModules(); | ||
|
||
if ( modules === undefined ) { | ||
return undefined; | ||
} | ||
|
||
return moduleSlugs.map( ( moduleSlug ) => modules[ moduleSlug ].name ); | ||
} ); | ||
|
||
if ( moduleNames === undefined ) { | ||
return null; | ||
} | ||
|
||
const description = | ||
moduleNames.length === 1 | ||
? sprintf( | ||
/* translators: %s: Module name */ | ||
__( | ||
'%s data was previously shared by an admin who no longer has access. Please contact another admin to restore it.', | ||
'google-site-kit' | ||
), | ||
moduleNames[ 0 ] | ||
) | ||
: sprintf( | ||
/* translators: %s: List of module names */ | ||
__( | ||
'The data for the following modules was previously shared by an admin who no longer has access: %s. Please contact another admin to restore it.', | ||
'google-site-kit' | ||
), | ||
moduleNames.join( | ||
_x( ', ', 'Recoverable modules', 'google-site-kit' ) | ||
) | ||
); | ||
|
||
return ( | ||
<CTA | ||
title={ __( 'Data Unavailable', 'google-site-kit' ) } | ||
description={ description } | ||
/> | ||
); | ||
} | ||
|
||
RecoverableModules.propTypes = { | ||
moduleSlugs: PropTypes.arrayOf( PropTypes.string ).isRequired, | ||
}; |
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
62 changes: 62 additions & 0 deletions
62
assets/js/googlesitekit/widgets/components/WidgetRecoverableModules.js
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,62 @@ | ||
/** | ||
* WidgetRecoverableModules component. | ||
* | ||
* Site Kit by Google, Copyright 2022 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. | ||
*/ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useMemo } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import useWidgetStateEffect from '../hooks/useWidgetStateEffect'; | ||
import RecoverableModules from '../../../components/RecoverableModules'; | ||
|
||
// The supported props must match `RecoverableModules` (except `widgetSlug`). | ||
export default function WidgetRecoverableModules( { | ||
widgetSlug, | ||
moduleSlugs, | ||
...props | ||
} ) { | ||
const metadata = useMemo( | ||
() => ( { | ||
// Here we serialize to `moduleSlug` for compatibility with the logic in | ||
// `combineWidgets()`. In future we may wish to take a less "hacky" approach. | ||
// See https://github.com/google/site-kit-wp/issues/5376#issuecomment-1165771399. | ||
moduleSlug: [ ...moduleSlugs ].sort().join( ',' ), | ||
// We also store `moduleSlugs` in the metadata in order for it to be passed back | ||
// into RecoverableModules as a prop. | ||
// See https://github.com/google/site-kit-wp/blob/c272c20eddcca61aae24c9812b6b11dbc15ec673/assets/js/googlesitekit/widgets/components/WidgetAreaRenderer.js#L171. | ||
moduleSlugs, | ||
} ), | ||
[ moduleSlugs ] | ||
); | ||
useWidgetStateEffect( widgetSlug, RecoverableModules, metadata ); | ||
|
||
return <RecoverableModules moduleSlugs={ moduleSlugs } { ...props } />; | ||
} | ||
|
||
WidgetRecoverableModules.propTypes = { | ||
widgetSlug: PropTypes.string.isRequired, | ||
...RecoverableModules.propTypes, | ||
}; |
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.