site-kit-wp: Module settings view shows errors even after successfully saving settings

Bug Description

When I successfully submitted settings, the settings preview screen keeps showing errors that had been shown during editing settings. We should reset errors for a module when settings have been saved or changes have been canceled.

Steps to reproduce

  1. Go to the Google Analytics console and create a new account.
  2. Activate the Analytics module and connect the newly created account.
  3. Go to the settings page and make sure you see your selection on the settings preview screen.
  4. Go to the Google Analytics console again and delete the newly created account.
  5. Go back to the settings page and click on the “Edit” settings button.
  6. When the settings edit form loads, you should see errors on the form because it can’t find the deleted account (see screenshot below)
  7. Select another account, property, and profile and submit changes.
  8. Now you should see the settings preview screen, but errors from the settings edit form don’t disappear.

Screenshots

sitekit 10uplabs com_wp-admin_admin php_page=googlesitekit-settings


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • Module store errors should be cleared after successfully saving settings
  • Secondarily, module stores should not show duplicate error messages

Implementation Brief

Prevent duplicate error messages by filtering getErrors calls

const existingErrorMessages = [];

	return errors
		.filter( ( error ) => {
			if (
				! error?.message ||
				existingErrorMessages.includes( error.message )
			) {
				return false;
			}

			existingErrorMessages.push( error.message );

			return true;
		} )
		// Include other map methods in original file here…
  • Clear all modules/analytics errors when selecting a new account. (See: 407e36905d4b21e80eb552e45ec32195857f9851) as well as when the settings screen is closed or the new settings are submitted.

Test Coverage

  • N/A

Visual Regression Changes

  • N/A

QA Brief

  1. Go to the Google Analytics console and create a new account.
  2. Activate the Analytics module and connect the newly created account.
  3. Go to the settings page and make sure you see your selection on the settings preview screen.
  4. Go to the Google Analytics console again and delete the newly created account.
  5. Go back to the settings page and click on the “Edit” settings button.
  6. When the settings edit form loads, you should see an error on the form because it can’t find the deleted account. You shoud only see
  7. Select another account, property, and profile and submit changes.
  8. Now you should see the settings preview screen, but errors from the settings edit form don’t disappear.

Changelog entry

  • Don’t show duplicate errors when loading deleted Analytics accounts in the settings.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 16 (1 by maintainers)

Most upvoted comments

QA Update: ✅

Verified:

  • When you connect Analytics from an account created in the GA console, the correct details appear in settings. When you then delete the account in GA console, and go back to settings, an error appears. The account, property and view fields are empty. As per screenshot below.

image

  • When new details were selected, and you add that account, no errors reappear on the screen when it reloads in the settings overview or when editing.

image

There is an issue that a red border remains the Analytics settings but chatting with Arafat, this needs to be a separate issue.

I’ve made a note to create a new ticket for this.

Selecting a new account doesn’t clear the fetch errors though, that’s part of the issue here—I think it’s because the errors are for various profiles/properties/etc.

When the account is selected not all errors are cleared and that’s why the message is still there… the only reliable solution I could find was to clear all errors.

Filter errors with the exact same error message from the getErrors selector by adding:

@tofumatt let’s better not change the results of the getErrors selector and filter out duplicate errors in the StoreErrorNotices component.

Clear all modules/analytics errors when selecting a new account.

We need to clear all module errors when we either close settings or before submitting the settings form.