/**
 * StoreErrorNotices component.
 *
 * Site Kit by Google, Copyright 2020 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';

/**
 * Internal dependencies
 */
import Data from 'googlesitekit-data';
import { isPermissionScopeError } from '../util/errors';
import ErrorNotice from './ErrorNotice';
const { useSelect } = Data;

function StoreErrorNotices( { moduleSlug, storeName, shouldDisplayError } ) {
	const errors = useSelect( ( select ) => select( storeName ).getErrors() );

	if ( Array.isArray( errors ) && errors.length > 0 ) {
		const errorNotices = errors.map( ( error, key ) => {
			// Do not display if no error, or if the error is for missing scopes.
			if ( ! error || isPermissionScopeError( error ) || ! shouldDisplayError( error ) ) {
				return null;
			}

			return <ErrorNotice
				moduleSlug={ moduleSlug }
				error={ error }
				shouldDisplayError={ shouldDisplayError }
				key={ key }
			/>;
		} );

		return errorNotices;
	}

	return null;
}

StoreErrorNotices.propTypes = {
	moduleSlug: PropTypes.string,
	storeName: PropTypes.string.isRequired,
	shouldDisplayError: PropTypes.func,
};

StoreErrorNotices.defaultProps = {
	moduleSlug: '',
	shouldDisplayError: () => true,
};

export default StoreErrorNotices;

@@ -791,65 +791,8 @@
 a';%0A
-import %7B isPermissionScopeError %7D from '../util/errors';%0A
 impo
@@ -857,16 +857,31 @@
  Data;%0A%0A
+export default 
 function
@@ -1032,84 +1032,14 @@
 ;%0A%0A%09
-if ( Array.isArray( errors ) && errors.length %3E 0 ) %7B%0A%09%09const errorNotices =
+return
  err
@@ -1069,218 +1069,59 @@
  =%3E 
-%7B%0A%09%09%09// Do not display if no error, or if the error is for missing scopes.%0A%09%09%09if ( ! error %7C%7C isPermissionScopeError( error ) %7C%7C ! shouldDisplayError( error ) ) %7B%0A%09%09%09%09return null;%0A%09%09%09%7D%0A%0A%09%09%09return %3CErrorNotice%0A%09
+(%0A%09%09%3CErrorNotice%0A%09%09%09key=%7B key %7D%0A%09%09%09error=%7B error %7D%0A
 %09%09%09m
@@ -1149,29 +1149,8 @@
 g %7D%0A
-%09%09%09%09error=%7B error %7D%0A%09
 %09%09%09s
@@ -1194,78 +1194,17 @@
 r %7D%0A
-%09%09%09%09key=%7B key %7D%0A%09
 %09%09/%3E
-;
 %0A%09
-%09%7D );%0A%0A%09%09return errorNotices;%0A%09%7D%0A%0A%09return null
+) )
 ;%0A%7D%0A
@@ -1240,39 +1240,8 @@
 = %7B%0A
-%09moduleSlug: PropTypes.string,%0A
 %09sto
@@ -1318,131 +1318,38 @@
 nc,%0A
-%7D;%0A%0AStoreErrorNotices.defaultProps = %7B%0A%09moduleSlug: '',%0A%09shouldDisplayError: () =%3E true,%0A%7D;%0A%0Aexport default StoreErrorNotices
+%09moduleSlug: PropTypes.string,%0A%7D
 ;%0A

Simplify StoreErrorNotices.