Skip to content

Commit

Permalink
Merge pull request #4989 from google/followup/4908-gathering-data-fix-2
Browse files Browse the repository at this point in the history
Fix logic for gathering data states in WP dashboard widget
  • Loading branch information
felixarntz authored Mar 28, 2022
2 parents cb9539e + 2b781ef commit d407253
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 22 deletions.
5 changes: 1 addition & 4 deletions assets/js/components/wp-dashboard/WPDashboardClicks.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ const WPDashboardClicks = ( { WidgetReportZero, WidgetReportError } ) => {
);
}

if (
isZeroReport( data ) &&
( zeroDataStatesEnabled ? isGatheringData === false : isGatheringData )
) {
if ( ! zeroDataStatesEnabled && isGatheringData && isZeroReport( data ) ) {
return <WidgetReportZero moduleSlug="search-console" />;
}

Expand Down
5 changes: 1 addition & 4 deletions assets/js/components/wp-dashboard/WPDashboardImpressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ const WPDashboardImpressions = ( { WidgetReportZero, WidgetReportError } ) => {
);
}

if (
isZeroReport( data ) &&
( zeroDataStatesEnabled ? isGatheringData === false : isGatheringData )
) {
if ( ! zeroDataStatesEnabled && isGatheringData && isZeroReport( data ) ) {
return <WidgetReportZero moduleSlug="search-console" />;
}

Expand Down
18 changes: 12 additions & 6 deletions assets/js/components/wp-dashboard/WPDashboardPopularPages.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ import {
MODULES_ANALYTICS,
DATE_RANGE_OFFSET,
} from '../../modules/analytics/datastore/constants';
import { ZeroDataMessage } from '../../modules/analytics/components/common';
import { CORE_USER } from '../../googlesitekit/datastore/user/constants';
import PreviewTable from '../../components/PreviewTable';
import TableOverflowContainer from '../../components/TableOverflowContainer';
import ReportTable from '../ReportTable';
import DetailsPermaLinks from '../DetailsPermaLinks';
import { numFmt } from '../../util';
import { isFeatureEnabled } from '../../features';
import { isZeroReport } from '../../modules/analytics/util';
const { useSelect, useInViewSelect } = Data;

export default function WPDashboardPopularPages( props ) {
Expand Down Expand Up @@ -109,16 +111,19 @@ export default function WPDashboardPopularPages( props ) {
return <WidgetReportError moduleSlug="analytics" error={ error } />;
}

if ( isGatheringData && ! zeroDataStatesEnabled ) {
if (
! zeroDataStatesEnabled &&
isGatheringData &&
isZeroReport( report )
) {
return <WidgetReportZero moduleSlug="analytics" />;
}

// Skip rendering the table if there are no rows.
if ( ! report[ 0 ].data?.rows?.length ) {
return null;
// data.rows is not guaranteed to be set so we need a fallback.
let rows = [];
if ( report[ 0 ].data.rows ) {
rows = cloneDeep( report[ 0 ].data.rows );
}

const rows = cloneDeep( report[ 0 ].data.rows );
// Combine the titles from the pageTitles with the rows from the metrics report.
rows.forEach( ( row ) => {
const url = row.dimensions[ 0 ];
Expand All @@ -136,6 +141,7 @@ export default function WPDashboardPopularPages( props ) {
columns={ tableColumns }
limit={ 5 }
gatheringData={ isGatheringData }
zeroState={ ZeroDataMessage }
/>
</TableOverflowContainer>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ const WPDashboardSessionDuration = ( {
return <WidgetReportError moduleSlug="analytics" error={ error } />;
}

if (
isZeroReport( data ) &&
( zeroDataStatesEnabled ? isGatheringData === false : isGatheringData )
) {
if ( ! zeroDataStatesEnabled && isGatheringData && isZeroReport( data ) ) {
return <WidgetReportZero moduleSlug="analytics" />;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ const WPDashboardUniqueVisitors = ( {
return <WidgetReportError moduleSlug="analytics" error={ error } />;
}

if (
isZeroReport( data ) &&
( zeroDataStatesEnabled ? isGatheringData === false : isGatheringData )
) {
if ( ! zeroDataStatesEnabled && isGatheringData && isZeroReport( data ) ) {
return <WidgetReportZero moduleSlug="analytics" />;
}

Expand Down

0 comments on commit d407253

Please sign in to comment.