Remove legacy error notifications infrastructure in favor of store-based one
See original GitHub issueThe storeErrorNotifications
feature flag should be removed and the logic behind it should become the new default, more specifically the only version available.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Part 1: Replace generic errors legacy infrastructure
- The principal usage of
showErrorNotification
should be replaced with a datastore-driven alternative, using thecore/site
store:- It should receive actions
setInternalServerError( error )
andclearInternalServerError()
and a selectorgetInternalServerError()
, all of which behave similarly to their*AuthError
counterparts in thecore/user
store. - The usages of
showErrorNotification
that handle errors after a failed module activation (which is basically almost all usages of that function in total) should usesetInternalServerError
instead (also see next bullet point for context on how to replace the notifications themselves). - A new
InternalServerError
component should be implemented inassets/js/components/notifications/
which should display the error notification forgetInternalServerError
(inspired by logic in theAuthError
component), with similar appearance (e.g. title, format etc.) that the notifications from the current usages ofshowErrorNotification
have. That component should then be included in theErrorNotifications
component, on top of the two other components.
- It should receive actions
- The
showErrorNotification
function and its remaining usages should be completely removed.- The now unused
GenericError
component should also be removed.
- The now unused
Part 2: Remove legacy error notifications infrastructure
- The
storeErrorNotifications
feature flag should be removed and what’s currently behind it should become the new way to display error notifications. - The legacy
ErrorNotification
component (sometimes referred to asLegacyErrorNotifications
) should no longer be used. - The
googlesitekit.ErrorNotification
filter and all of its usages should be removed, e.g.:- the legacy
ErrorNotification
- the relevant logic in the legacy
handleWPError
function and inassets/js/components/legacy-notifications/index.js
- the legacy
Implementation Brief
Numbering here matches numbering on AC. Refer to AC first
Part 1
1 .i. Create a new datastore assets/js/googlesitekit/data/site/errors.js
. Copy relevant actions and selectors from assets/js/googlesitekit/datastore/user/authentication.js
but change names and constants (and ignore all the code for storing authentication state. This datastore is much larger)
1 .ii. Follow AC. Some existing calls to showErrorNotification
have a second argument e.g.
showErrorNotification( GenericError, {
id: 'activate-module-error',
title: __( 'Internal Server Error', 'google-site-kit' ),
description: error.message,
format: 'small',
type: 'win-error',
} );
and another call passes in an instantiated Notification component showErrorNotification( InvalidCredentialsWarning );
The id
, title
, description
, learnMoreURL
, and learnMoreLabel
change
So copying AuthError
we’d want these passed in error.data
-
iii. Follow IB. Copy like
AuthError
but pass in the keys above to the inner `Notification component. -
i. Follow AC
“The usages of showErrorNotification that handle errors after a failed module activation (which is basically almost all usages of that function in total)”
The only other usage of showErrorNotification
in assets/js/components/legacy-notifications/data-error.js
is to be deleted
Part 2
-
Remove
storeErrorNotifications
fromfeature-flags.json
-
Remove any usage of this
storeErrorNotifications
flag from codebase. Not many uses. InHeader.js
make the component behind the flag always visible. Tests should still pass where previously this was set. -
Remove <LegacyErrorNotification/> from
Header.js
(double-check no more instances) -
Do as per AC
Test Coverage
- Create a
assets/js/googlesitekit/data/site/errors.test.js
, copying relevant tests fromassets/js/googlesitekit/data/site/authentication.test.js
- Currently
assets/js/util/test/showErrorNotification.js
contains tests forshowErrorNotification
. Check thatsetInternalServerError
,clearInternalServerError
andgetInternalServerError
cause corresponding changes inInternalServerError
(displayed, not displayed, displays correct message)
Visual Regression Changes
- Changes not expected
QA Brief
- Check the new
datastore/site/errors
store has been created with the following:- action:
setInternalServerError
- action:
clearInternalServerError
- selector:
getInternalServerError
- action:
- Check that all instances of
showErrorNotification
have been replaced with dispatches tosetInternalServerError
- Check the
storeErrorNotifications
flag has been removed fromfeature-flags.json
and from everywhere in the codebase - Check the
LegacyErrorNotification
component has been removed fromHeader.js
and everywhere else in the codebase - Check that js tests pass
Changelog entry
- N/A
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (13 by maintainers)
@eugene-manuilov @aaemnnosttv Please do not merge this until
develop
is open towards the 1.38.0 release, since we want to time this to go out together with #1997, #2077, and #2258.@Hazlitte that’s definitely a typo on my behalf 😄 Apologies. Put any more questions in here!