-
Notifications
You must be signed in to change notification settings - Fork 339
Implement error notice infrastructure in admin settings and email reports subscription panel #11860
Copy link
Copy link
Closed
Labels
P0High priorityHigh priorityTeam SIssues for Squad 1Issues for Squad 1Type: EnhancementImprovement of an existing featureImprovement of an existing feature
Description
Feature Description
Implement these notice variants PUE Errors - UX copy in the user email reports subscription panel for admins only
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- When all emails in the last batch have failed to send an Error Notice should be displayed in the Admin Settings within the Email reports section as well as in the email reports User settings side panel.
- The notices should be displayed when logged in as an Admin user only - view only users should not see this notice.
- Notices should only appear after all three send attempts for a batch fail and they should clear once a subsequent batch succeeds.
Implementation Brief
-
Update
includes/Core/Email_Reporting/REST_Email_Reporting_Controller.php- Add new
READABLEroute:core/site/data/email-reporting-failure- Compute data from
Email_Log_Batch_Query(latest batch where all logs aregsk_email_failedafterMAX_ATTEMPTS) andMETA_ERROR_DETAILSto extract the category (wp_errorcode). Clear it when a later batch has anygsk_email_sent.
- Compute data from
- Consider a central config (e.g.,
includes/Core/Email_Reporting/Error_Notices_Map.php) keyed by the error reason codes already logged (network_error,permissions_revoked,property_deleted,server_error,scheduler_error,sending_error,other_error), and mapped to their copy and CTA, etc, something like how we handle AdSense server notifications (assets/js/hooks/useAdSenseNotifications.js).Error_Notices_Mapcan expose one method to append content and other details within switch statement like we do inGoogle\Site_Kit\Core\Authentication\Clients\OAuth_Client_Base::get_error_message()
- Add new
-
Datastore updates in
assets/js/googlesitekit/datastore/site/email-reporting.js- Add selector/resolver
getEmailReportingFailure()returning eitherundefined(loading),null(no terminal failure), or an object like{ category: 'network_error', isTerminal: true, batchID, lastUpdated }. If we do error data mapping on the backend viaError_Notices_Mapinclude the content, CTA, etc to the response as well.- Resolver should invoke the new fetch store eq.
fetchGetEmailReportingFailureStorethat reads a new REST endpointcore/site/data/email-reporting-failure.
- Resolver should invoke the new fetch store eq.
- Optionally add a companion selector
hasEmailReportingFailure()returning a boolean whenisTerminal && category.
- Add selector/resolver
-
Add
assets/js/components/email-reporting/notices/EmailBatchErrorNotice.js- Use
useSelect( CORE_SITE ).getEmailReportingFailure()and! viewOnlyto gate rendering. - Reuse an existing notice component pattern (e.g., structure of
AnalyticsDisconnectedNoticeor any banner inassets/js/components/email-reporting/UserSettingsSelectionPanel/Notices.js) as the starting point: a heading + body + optional CTAs. - Map
categoryto copy/links via the PUE config, and render only whenfailure && failure.isTerminal - Keep it contained to
assets/js/components/email-reporting/UserSettingsSelectionPanel/Notices.jsso other panels stay unaffected.
- Use
-
Ensure the notice resets/clears when a batch succeeds (or no terminal failure is present).
Test Coverage
- Update
tests/phpunit/integration/Core/User/REST_Email_Reporting_ControllerTest.php - Update
assets/js/googlesitekit/datastore/site/email-reporting.test.jsto include coverage for new resolver/selector
QA Brief
- Copy-paste and run the following SQL into your site's database that mocks the logs generated after emails are sent.
SQL with all emails FAILED
SET NAMES utf8mb4;
-- Insert posts and capture their IDs
INSERT INTO `wp_posts` (`post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES
(1, NOW(), NOW(), '', 'f1a73c27-4481-4e0b-bc98-b90eb2cbe76b', '', 'gsk_email_failed', 'closed', 'closed', '', 'f1a73c27-4481-4e0b-bc98-b90eb2cbe76b', '', '', NOW(), NOW(), '', 0, 'https://sitekitssl.10uplabs.com/?post_type=gsk_email_log&p=116', 0, 'gsk_email_log', '', 0),
(2, NOW(), NOW(), '', 'f1a73c27-4481-4e0b-bc98-b90eb2cbe76b', '', 'gsk_email_failed', 'closed', 'closed', '', 'f1a73c27-4481-4e0b-bc98-b90eb2cbe76b-2', '', '', NOW(), NOW(), '', 0, 'https://sitekitssl.10uplabs.com/?post_type=gsk_email_log&p=117', 0, 'gsk_email_log', '', 0),
(3, NOW(), NOW(), '', 'f1a73c27-4481-4e0b-bc98-b90eb2cbe76b', '', 'gsk_email_failed', 'closed', 'closed', '', 'f1a73c27-4481-4e0b-bc98-b90eb2cbe76b-3', '', '', NOW(), NOW(), '', 0, 'https://sitekitssl.10uplabs.com/?post_type=gsk_email_log&p=118', 0, 'gsk_email_log', '', 0);
-- Get the auto-generated IDs for reference
SET @post_id_1 = LAST_INSERT_ID();
SET @post_id_2 = @post_id_1 + 1;
SET @post_id_3 = @post_id_1 + 2;
-- Insert postmeta using the captured IDs
INSERT INTO `wp_postmeta` (`post_id`, `meta_key`, `meta_value`) VALUES
(@post_id_1, '_batch_id', 'f1a73c27-4481-4e0b-bc98-b90eb2cbe76b'),
(@post_id_1, '_report_frequency', 'monthly'),
(@post_id_1, '_report_reference_dates', '{\"startDate\":1766361600,\"sendDate\":1768953600,\"compareStartDate\":1763769600,\"compareEndDate\":1766275200}'),
(@post_id_1, '_send_attempts', '3'),
(@post_id_1, '_error_details', '{\"errors\":{\"email_report_section_build_failed\":[\"title must be a non-empty string\"]},\"error_data\":[]}'),
(@post_id_2, '_batch_id', 'f1a73c27-4481-4e0b-bc98-b90eb2cbe76b'),
(@post_id_2, '_report_frequency', 'monthly'),
(@post_id_2, '_report_reference_dates', '{\"startDate\":1766361600,\"sendDate\":1768953600,\"compareStartDate\":1763769600,\"compareEndDate\":1766275200}'),
(@post_id_2, '_send_attempts', '3'),
(@post_id_2, '_error_details', '{\"errors\":{\"email_report_section_build_failed\":[\"title must be a non-empty string\"]},\"error_data\":[]}'),
(@post_id_3, '_batch_id', 'f1a73c27-4481-4e0b-bc98-b90eb2cbe76b'),
(@post_id_3, '_report_frequency', 'monthly'),
(@post_id_3, '_report_reference_dates', '{\"startDate\":1766361600,\"sendDate\":1768953600,\"compareStartDate\":1763769600,\"compareEndDate\":1766275200}'),
(@post_id_3, '_send_attempts', '3'),
(@post_id_3, '_error_details', '{\"errors\":{\"email_report_no_data\":[\"No email report data available.\"]},\"error_data\":[]}');
- Download this development version of the tester plugin (in case the latest has still not got all Email Reporting features). Within "Email reporting", toggle the "Show Email Log Post Type". Save settings and refresh the page (your WP Admin). Then go to the "SK Email Logs" post link in the WP Admin Menu. This will show you all the email logs. Ensure there are 3 new records there that have been inserted by the SQL query above. All of them have "Failed" with errors.
- Now in the plugin, enable email reporting and test the side panel and admin settings. There should be an error message displayed in both places when email reporting is enabled. And no error should be displayed when it is disabled. Also test that only admins see the error message and it is not visible to view only users who open the side panel.
- Now simulate a simple run of new emails using these bug bash instructions. Check that emails were sent correctly after about 1 minute and the errors in both areas should automatically clear. If you aren't able to send emails, run the following SQL that will mock a new email batch where one email was successful and two the failed. In this case, since not all emails have failed, there should be no error displayed.
SQL with 2/3 emails FAILED
SET NAMES utf8mb4;
-- Insert posts and capture their IDs
INSERT INTO `wp_posts` (`post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES
(1, NOW(), NOW(), '', 'f1a73c27-4481-4e0b-bc98-b90eb2cbe76c', '', 'gsk_email_sent', 'closed', 'closed', '', 'f1a73c27-4481-4e0b-bc98-b90eb2cbe76c', '', '', NOW(), NOW(), '', 0, 'https://sitekitssl.10uplabs.com/?post_type=gsk_email_log&p=116', 0, 'gsk_email_log', '', 0),
(2, NOW(), NOW(), '', 'f1a73c27-4481-4e0b-bc98-b90eb2cbe76c', '', 'gsk_email_failed', 'closed', 'closed', '', 'f1a73c27-4481-4e0b-bc98-b90eb2cbe76c-2', '', '', NOW(), NOW(), '', 0, 'https://sitekitssl.10uplabs.com/?post_type=gsk_email_log&p=117', 0, 'gsk_email_log', '', 0),
(3, NOW(), NOW(), '', 'f1a73c27-4481-4e0b-bc98-b90eb2cbe76c', '', 'gsk_email_failed', 'closed', 'closed', '', 'f1a73c27-4481-4e0b-bc98-b90eb2cbe76c-3', '', '', NOW(), NOW(), '', 0, 'https://sitekitssl.10uplabs.com/?post_type=gsk_email_log&p=118', 0, 'gsk_email_log', '', 0);
-- Get the auto-generated IDs for reference
SET @post_id_1 = LAST_INSERT_ID();
SET @post_id_2 = @post_id_1 + 1;
SET @post_id_3 = @post_id_1 + 2;
-- Insert postmeta using the captured IDs
INSERT INTO `wp_postmeta` (`post_id`, `meta_key`, `meta_value`) VALUES
(@post_id_1, '_batch_id', 'f1a73c27-4481-4e0b-bc98-b90eb2cbe76c'),
(@post_id_1, '_report_frequency', 'monthly'),
(@post_id_1, '_report_reference_dates', '{\"startDate\":1766361600,\"sendDate\":1768953600,\"compareStartDate\":1763769600,\"compareEndDate\":1766275200}'),
(@post_id_1, '_send_attempts', '1'),
(@post_id_2, '_batch_id', 'f1a73c27-4481-4e0b-bc98-b90eb2cbe76c'),
(@post_id_2, '_report_frequency', 'monthly'),
(@post_id_2, '_report_reference_dates', '{\"startDate\":1766361600,\"sendDate\":1768953600,\"compareStartDate\":1763769600,\"compareEndDate\":1766275200}'),
(@post_id_2, '_send_attempts', '3'),
(@post_id_2, '_error_details', '{\"errors\":{\"email_report_section_build_failed\":[\"title must be a non-empty string\"]},\"error_data\":[]}'),
(@post_id_3, '_batch_id', 'f1a73c27-4481-4e0b-bc98-b90eb2cbe76c'),
(@post_id_3, '_report_frequency', 'monthly'),
(@post_id_3, '_report_reference_dates', '{\"startDate\":1766361600,\"sendDate\":1768953600,\"compareStartDate\":1763769600,\"compareEndDate\":1766275200}'),
(@post_id_3, '_send_attempts', '3'),
(@post_id_3, '_error_details', '{\"errors\":{\"email_report_no_data\":[\"No email report data available.\"]},\"error_data\":[]}');
Changelog entry
- Implement error notice infrastructure in admin settings and email reports subscription panel.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P0High priorityHigh priorityTeam SIssues for Squad 1Issues for Squad 1Type: EnhancementImprovement of an existing featureImprovement of an existing feature