Skip to content

Commit

Permalink
Stats: Fix possible undefined value (#95601)
Browse files Browse the repository at this point in the history
* fix possible empty events

* possibly undefined value

* Apply suggestions from code review

* use a default value for possibly not found selected period

* use empty array as default data to avoid undefined value

* use empty array as default data to avoid undefined value

* current_usage could be undefined
  • Loading branch information
kangzj authored Oct 23, 2024
1 parent e5a8595 commit 1be5b08
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export default function OdysseyQuerySitePurchases( { siteId }: { siteId: number
reduxDispatch( {
type: PURCHASES_SITE_FETCH_COMPLETED,
siteId,
purchases,
purchases: purchases ?? [],
} );
}
}, [ purchases, isFetching, reduxDispatch, hasOtherErrors, siteId, purchasesFromMyJetpack ] );
Expand Down
3 changes: 2 additions & 1 deletion client/my-sites/stats/stats-module/all-time-nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ export const StatsModuleSummaryLinks = ( props ) => {
];

const numberDays = get( query, 'num', '0' );
const selected = find( options, { value: numberDays } );
let selected = find( options, { value: numberDays } );
selected = selected || options[ 0 ];

const tabs = (
<SegmentedControl
Expand Down
2 changes: 1 addition & 1 deletion client/my-sites/stats/stats-notices/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const NewStatsNotices = ( { siteId, isOdysseyStats, statsPurchaseSuccess }: Stat
const hasSignificantViews = !! ( views && views >= SIGNIFICANT_VIEWS_AMOUNT );

const { data } = usePlanUsageQuery( siteId );
const currentUsage = data?.current_usage.views_count || 0;
const currentUsage = data?.current_usage?.views_count || 0;
const tierLimit = data?.views_limit || null;
const isNearLimit = tierLimit ? currentUsage / tierLimit >= 0.9 : false;
const isOverLimit = tierLimit ? currentUsage / tierLimit >= 1 : false;
Expand Down

0 comments on commit 1be5b08

Please sign in to comment.