Fix regression where store age is 0 while isResolving for the option is returning false (https://github.com/woocommerce/woocommerce-admin/pull/5858)

Co-authored-by: Rebecca Scott <me@becdetat.com>
This commit is contained in:
Bec Scott 2020-12-10 17:26:31 +10:00 committed by GitHub
parent 13a738558c
commit 88b64b6980
1 changed files with 15 additions and 4 deletions

View File

@ -178,6 +178,19 @@ CustomerEffortScoreTracks.propTypes = {
createNotice: PropTypes.func, createNotice: PropTypes.func,
}; };
function getStoreAgeInWeeks( adminInstallTimestamp ) {
if ( adminInstallTimestamp === 0 ) {
return null;
}
// Date.now() is ms since Unix epoch, adminInstallTimestamp is in
// seconds since Unix epoch.
const storeAgeInMs = Date.now() - adminInstallTimestamp * 1000;
const storeAgeInWeeks = Math.round( storeAgeInMs / WEEK );
return storeAgeInWeeks;
}
export default compose( export default compose(
withSelect( ( select ) => { withSelect( ( select ) => {
const { getOption, isResolving } = select( OPTIONS_STORE_NAME ); const { getOption, isResolving } = select( OPTIONS_STORE_NAME );
@ -187,10 +200,7 @@ export default compose(
const adminInstallTimestamp = const adminInstallTimestamp =
getOption( ADMIN_INSTALL_TIMESTAMP_OPTION_NAME ) || 0; getOption( ADMIN_INSTALL_TIMESTAMP_OPTION_NAME ) || 0;
// Date.now() is ms since Unix epoch, adminInstallTimestamp is in const storeAgeInWeeks = getStoreAgeInWeeks( adminInstallTimestamp );
// seconds since Unix epoch.
const storeAgeInMs = Date.now() - adminInstallTimestamp * 1000;
const storeAgeInWeeks = Math.round( storeAgeInMs / WEEK );
const allowTrackingOption = const allowTrackingOption =
getOption( ALLOW_TRACKING_OPTION_NAME ) || 'no'; getOption( ALLOW_TRACKING_OPTION_NAME ) || 'no';
@ -198,6 +208,7 @@ export default compose(
const resolving = const resolving =
isResolving( 'getOption', [ SHOWN_FOR_ACTIONS_OPTION_NAME ] ) || isResolving( 'getOption', [ SHOWN_FOR_ACTIONS_OPTION_NAME ] ) ||
storeAgeInWeeks === null ||
isResolving( 'getOption', [ isResolving( 'getOption', [
ADMIN_INSTALL_TIMESTAMP_OPTION_NAME, ADMIN_INSTALL_TIMESTAMP_OPTION_NAME,
] ) || ] ) ||