-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue / 9489 Split Sell Products or Services Answers #9629
base: develop
Are you sure you want to change the base?
Issue / 9489 Split Sell Products or Services Answers #9629
Conversation
…swer descriptionsl.
…or user input edition to work within settings.
…Metrics to use new helper function, add return metrics for sell_products and sell_services purpose slugs.
…products_or_service value saved within user input settings.
Build files for fd4a7c7 are ready:
|
Size Change: -172 B (-0.01%) Total Size: 1.88 MB
ℹ️ View Unchanged
|
…ric for provide_services.
…e_services based tests.
…ug, and only persist state on Apply Changes CTA.
…89-split-sell-products-or-services-answers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @10upsimon almost there, left you few comments
…sell_products_or_service check in useEffect.
…thin useMount as opposed to useEffect.
…e different, and reset temporary stores accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @10upsimon LGTM
Not to MR reviewer - JS test is failing for flakiness with Audience modal tests, nothing related to this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @10upsimon. Left the initial feedback for you. Please, take a look.
@@ -20,6 +20,7 @@ | |||
* External dependencies | |||
*/ | |||
import PropTypes from 'prop-types'; | |||
import { useMount } from 'react-use'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know IB was written like this, but we should not change anything in the component because it should not contain business logic. All changes should be made in the UserInputPreview
component which should prepare proper data and pass it down to this component.
@@ -257,6 +257,7 @@ const baseSelectors = { | |||
* | |||
* @return {Array<string>|undefined} An array of Key Metric widget slugs, or undefined if the user input settings are not loaded. | |||
*/ | |||
/* eslint-disable complexity */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to refactor this selector to reduce its complexity instead of disabling the eslint rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eugene-manuilov I am going to challenge this one, as I feel we'd be satisfying an eslint rule but worsening the developer experience here, having to constantly check a function located elsewhere just to read (or add to) the list of metrics mapped to answers. This is a perfectly readable array, and I think we can keep the ignore rule. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@10upsimon, here are perfectly readable arrays in two new selectors:
getRegularKeyMetricsWidgetIDs: createRegistrySelector( ( select ) => () => {
const postTypes = select( CORE_SITE ).getPostTypes();
const hasProductPostType = postTypes.some(
( { slug } ) => slug === 'product'
);
return {
publish_blog: [
KM_ANALYTICS_RETURNING_VISITORS,
KM_ANALYTICS_NEW_VISITORS,
KM_ANALYTICS_TOP_TRAFFIC_SOURCE,
KM_ANALYTICS_ENGAGED_TRAFFIC_SOURCE,
],
publish_news: [
KM_ANALYTICS_PAGES_PER_VISIT,
KM_ANALYTICS_VISIT_LENGTH,
KM_ANALYTICS_VISITS_PER_VISITOR,
KM_ANALYTICS_MOST_ENGAGING_PAGES,
],
monetize_content: [
KM_ANALYTICS_POPULAR_CONTENT,
KM_ANALYTICS_ENGAGED_TRAFFIC_SOURCE,
KM_ANALYTICS_NEW_VISITORS,
KM_ANALYTICS_TOP_TRAFFIC_SOURCE,
],
sell_products_or_service: [
hasProductPostType
? KM_ANALYTICS_POPULAR_PRODUCTS
: KM_ANALYTICS_POPULAR_CONTENT,
KM_ANALYTICS_ENGAGED_TRAFFIC_SOURCE,
KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
KM_ANALYTICS_TOP_TRAFFIC_SOURCE,
],
sell_products: [
hasProductPostType
? KM_ANALYTICS_POPULAR_PRODUCTS
: KM_ANALYTICS_POPULAR_CONTENT,
KM_ANALYTICS_ENGAGED_TRAFFIC_SOURCE,
KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
KM_ANALYTICS_TOP_TRAFFIC_SOURCE,
],
provide_services: [
KM_ANALYTICS_TOP_TRAFFIC_SOURCE,
KM_ANALYTICS_ENGAGED_TRAFFIC_SOURCE,
KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
KM_ANALYTICS_POPULAR_CONTENT,
KM_ANALYTICS_TOP_RETURNING_VISITOR_PAGES,
],
share_portfolio: [
KM_ANALYTICS_NEW_VISITORS,
KM_ANALYTICS_TOP_TRAFFIC_SOURCE,
KM_ANALYTICS_ENGAGED_TRAFFIC_SOURCE,
KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
],
};
} ),
getConversionTailoredKeyMetricsWidgetIDs: createRegistrySelector(
( select ) => () => {
const postTypes = select( CORE_SITE ).getPostTypes();
const hasProductPostType = postTypes.some(
( { slug } ) => slug === 'product'
);
return {
publish_blog: [
KM_ANALYTICS_TOP_CATEGORIES,
KM_ANALYTICS_TOP_CONVERTING_TRAFFIC_SOURCE,
KM_ANALYTICS_TOP_RETURNING_VISITOR_PAGES,
KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
KM_ANALYTICS_TOP_RECENT_TRENDING_PAGES,
KM_ANALYTICS_TOP_TRAFFIC_SOURCE,
KM_ANALYTICS_TOP_PAGES_DRIVING_LEADS,
KM_ANALYTICS_TOP_TRAFFIC_SOURCE_DRIVING_LEADS,
],
publish_news: [
KM_ANALYTICS_ENGAGED_TRAFFIC_SOURCE,
KM_ANALYTICS_POPULAR_AUTHORS,
KM_ANALYTICS_TOP_CITIES,
KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
KM_ANALYTICS_TOP_RECENT_TRENDING_PAGES,
KM_ANALYTICS_TOP_TRAFFIC_SOURCE,
KM_ANALYTICS_TOP_PAGES_DRIVING_LEADS,
KM_ANALYTICS_TOP_TRAFFIC_SOURCE_DRIVING_LEADS,
],
monetize_content: [
KM_ANALYTICS_MOST_ENGAGING_PAGES,
KM_ANALYTICS_POPULAR_CONTENT,
KM_ANALYTICS_NEW_VISITORS,
KM_ANALYTICS_ADSENSE_TOP_EARNING_CONTENT,
KM_ANALYTICS_VISIT_LENGTH,
KM_ANALYTICS_VISITS_PER_VISITOR,
KM_ANALYTICS_ENGAGED_TRAFFIC_SOURCE,
KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
],
sell_products_or_service: [
hasProductPostType
? KM_ANALYTICS_POPULAR_PRODUCTS
: KM_ANALYTICS_POPULAR_CONTENT,
KM_ANALYTICS_TOP_CITIES_DRIVING_PURCHASES,
KM_ANALYTICS_TOP_DEVICE_DRIVING_PURCHASES,
KM_ANALYTICS_TOP_TRAFFIC_SOURCE_DRIVING_ADD_TO_CART,
KM_ANALYTICS_TOP_TRAFFIC_SOURCE_DRIVING_PURCHASES,
KM_ANALYTICS_ADSENSE_TOP_EARNING_CONTENT,
KM_ANALYTICS_TOP_CONVERTING_TRAFFIC_SOURCE,
KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
],
sell_products: [
hasProductPostType
? KM_ANALYTICS_POPULAR_PRODUCTS
: KM_ANALYTICS_POPULAR_CONTENT,
KM_ANALYTICS_TOP_CITIES_DRIVING_PURCHASES,
KM_ANALYTICS_TOP_DEVICE_DRIVING_PURCHASES,
KM_ANALYTICS_TOP_TRAFFIC_SOURCE_DRIVING_ADD_TO_CART,
KM_ANALYTICS_TOP_TRAFFIC_SOURCE_DRIVING_PURCHASES,
KM_ANALYTICS_ADSENSE_TOP_EARNING_CONTENT,
KM_ANALYTICS_TOP_CONVERTING_TRAFFIC_SOURCE,
KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
],
provide_services: [
KM_ANALYTICS_TOP_CITIES_DRIVING_LEADS,
KM_ANALYTICS_TOP_PAGES_DRIVING_LEADS,
KM_ANALYTICS_TOP_TRAFFIC_SOURCE_DRIVING_LEADS,
KM_ANALYTICS_TOP_TRAFFIC_SOURCE,
KM_ANALYTICS_ENGAGED_TRAFFIC_SOURCE,
KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
KM_ANALYTICS_POPULAR_CONTENT,
KM_ANALYTICS_TOP_RETURNING_VISITOR_PAGES,
],
share_portfolio: [
KM_ANALYTICS_TOP_CITIES_DRIVING_LEADS,
KM_ANALYTICS_TOP_CONVERTING_TRAFFIC_SOURCE,
KM_ANALYTICS_TOP_RETURNING_VISITOR_PAGES,
KM_ANALYTICS_POPULAR_AUTHORS,
KM_ANALYTICS_TOP_PAGES_DRIVING_LEADS,
KM_ANALYTICS_TOP_TRAFFIC_SOURCE_DRIVING_LEADS,
KM_ANALYTICS_POPULAR_CONTENT,
KM_SEARCH_CONSOLE_POPULAR_KEYWORDS,
],
};
}
),
Then the getAnswerBasedMetrics
selector becomes pretty simple:
getAnswerBasedMetrics: createRegistrySelector(
( select ) => ( state, purposeOverride ) => {
const userInputSettings =
select( CORE_USER ).getUserInputSettings();
if ( userInputSettings === undefined ) {
return undefined;
}
const purpose =
purposeOverride ?? userInputSettings?.purpose?.values?.[ 0 ];
const showConversionTailoredMetrics =
select( CORE_USER ).showConversionTailoredMetrics();
const widgetIDs = showConversionTailoredMetrics
? select( CORE_USER ).getRegularKeyMetricsWidgetIDs()
: select(
CORE_USER
).getConversionTailoredKeyMetricsWidgetIDs();
return widgetIDs[ purpose ] || [];
}
),
This is much easier to read and maintain without a need to disable the eslint rule.
@@ -164,7 +213,7 @@ export default function UserInputPreview( props ) { | |||
options={ USER_INPUT_ANSWERS_PURPOSE } | |||
loading={ loading } | |||
settingsView={ settingsView } | |||
onChange={ () => toggleIsModalOpen( true ) } | |||
onChange={ () => openModalIfMetricsChanged() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onChange={ () => openModalIfMetricsChanged() } | |
onChange={ openModalIfMetricsChanged } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@10upsimon, looks like you missed this one, right?
…utPreview component.
…proach within UserInputPreview.
…user data store partial.
…etConversionTailoredKeyMetricsWidgetIDs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @10upsimon. Almost looks good to me. Left two last comments.
checked: | ||
USER_INPUT_QUESTIONS_PURPOSE === slug && | ||
values.includes( 'sell_products_or_service' ) && | ||
'sell_products' === optionSlug | ||
? true | ||
: values.includes( optionSlug ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this change is not longer because we changed the selected value from sell_products_or_service
to sell_products
in the UserInputPreview
component, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @eugene-manuilov this has been resolved in the latest commit.
@@ -164,7 +213,7 @@ export default function UserInputPreview( props ) { | |||
options={ USER_INPUT_ANSWERS_PURPOSE } | |||
loading={ loading } | |||
settingsView={ settingsView } | |||
onChange={ () => toggleIsModalOpen( true ) } | |||
onChange={ () => openModalIfMetricsChanged() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@10upsimon, looks like you missed this one, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@10upsimon, there is a failing js test. Can you take a look?
Summary
Addresses issue:
Relevant technical choices
PR Author Checklist
Do not alter or remove anything below. The following sections will be managed by moderators only.
Code Reviewer Checklist
Merge Reviewer Checklist