Currently, after selecting the metrics manually, and then going to the settings and switching to tailored metrics by going through the user input, the initially selected metrics will remain selected, instead of the tailored metrics overriding them.
We should fix the pre-existing behaviour so when user goes through user input, manual selection should be reset/set to undefined, and tailored metrics should be shown.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Going through the user input questionnaire should result in tailored metrics being shown in the key metrics widget area on the dashboard regardless if user made previous manual selection or not
Implementation Brief
[x] In Google\Site_Kit\Core\Dismissals\REST_Key_Metrics_Controller::get_rest_routes
Add new endpoint core/user/data/reset-key-metrics-selection with CREATABLE method
It doesn't need to receive any arguments
In the callback, update/reset the widgetSlugs setting to be an empty array, eq $this->settings->merge( array( 'widgetSlugs' => array() ) )
And return final settings in the response
[x] In assets/js/googlesitekit/datastore/user/key-metrics.js
Add new fetch store, say fetchResetKeyMetricsSelectionStore to invoke the new REST endpoint
You can use fetchSaveKeyMetricsSettingsStore as a starting point, as reducerCallback would be the same
Add new resetKeyMetricsSelection action, which will invoke new fetch store mentioned above
[x] In assets/js/components/user-input/UserInputQuestionnaire.js
Update submitChanges callback
Within if ( ! response.error ) conditional check, reset the manual selection by dispatching the new resetKeyMetricsSelection action
You can wrap this in conditional check if getUserPickedMetrics selector from CORE_USER store has any metrics saved, to dispatch the action, so it is not sending the request on every save, but only when it needs to override the manual selection
Test Coverage
Update tests/phpunit/integration/Core/Key_Metrics/REST_Key_Metrics_ControllerTest.php to include new endpoint
Add basic test coverage for resetKeyMetricsSelection action and fix any failing JS test due to the new request that needs to be mocked/or prevented
QA Brief
Set up a new instance of Site Kit
When the Key Metrics Setup CTA Banner displays, choose the option to select metrics yourself
Pick 3 metrics, and note them
Next, navigate to Site Kit > Settings > Admin
Within the Key Metrics settings section, action the subtle CTA banner and answer the user input questions, saving in the end
Validate that the user input preview is now present in the Key Metrics settings area
Finally, and most importantly, validate that the Key Metric Widgets showing on the main dashboard have changed to tailored metrics based on the user input questionnaire you just answered, and are no longer the 3 manually selected ones as initially chosen
Changelog entry
Ensure tailored metrics override previous metrics when switching from manually-selected metrics.
Verified that Going through the user input questionnaire result in tailored metrics being shown in the key metrics widget area on the dashboard regardless if user made previous manual selection or not.
Verified that changing purpose in user input questionnaire changes the tailored metrics on dashboard as per selected purpose.
Feature Description
Currently, after selecting the metrics manually, and then going to the settings and switching to tailored metrics by going through the user input, the initially selected metrics will remain selected, instead of the tailored metrics overriding them.
We should fix the pre-existing behaviour so when user goes through user input, manual selection should be reset/set to undefined, and tailored metrics should be shown.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation Brief
Google\Site_Kit\Core\Dismissals\REST_Key_Metrics_Controller::get_rest_routes
core/user/data/reset-key-metrics-selection
withCREATABLE
methodwidgetSlugs
setting to be an empty array, eq$this->settings->merge( array( 'widgetSlugs' => array() ) )
assets/js/googlesitekit/datastore/user/key-metrics.js
fetchResetKeyMetricsSelectionStore
to invoke the new REST endpointfetchSaveKeyMetricsSettingsStore
as a starting point, asreducerCallback
would be the sameresetKeyMetricsSelection
action, which will invoke new fetch store mentioned aboveassets/js/components/user-input/UserInputQuestionnaire.js
submitChanges
callbackif ( ! response.error )
conditional check, reset the manual selection by dispatching the newresetKeyMetricsSelection
actiongetUserPickedMetrics
selector fromCORE_USER
store has any metrics saved, to dispatch the action, so it is not sending the request on every save, but only when it needs to override the manual selectionTest Coverage
tests/phpunit/integration/Core/Key_Metrics/REST_Key_Metrics_ControllerTest.php
to include new endpointresetKeyMetricsSelection
action and fix any failing JS test due to the new request that needs to be mocked/or preventedQA Brief
Changelog entry