Skip to content
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

Stats: Enable tab switching for unsupported fields of hourly views #97163

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions client/my-sites/stats/stats-chart-tabs/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import clsx from 'clsx';
import { localize } from 'i18n-calypso';
import { localize, translate } from 'i18n-calypso';
import { flowRight } from 'lodash';
import moment from 'moment';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -151,7 +151,16 @@ class StatModuleChartTabs extends Component {

<StatsModulePlaceholder className="is-chart" isLoading={ isActiveTabLoading } />
<Chart barClick={ this.props.barClick } data={ chartData } minBarWidth={ 35 }>
<StatsEmptyState />
<StatsEmptyState
headingText={
selectedPeriod === 'hour' ? translate( 'No hourly data available' ) : null
}
infoText={
selectedPeriod === 'hour'
? translate( 'Try selecting a different time frame.' )
: null
}
/>
</Chart>
<StatTabs
data={ this.props.counts }
Expand Down
6 changes: 3 additions & 3 deletions client/my-sites/stats/stats-tabs/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class StatsTabs extends Component {
} else {
data?.map( ( day ) =>
tabs.map( ( tab ) => {
if ( isFinite( day[ tab.attr ] ) ) {
// Exclude non-numeric values, e.g., NULL from unsupported stats fields.
if ( Number.isFinite( day[ tab.attr ] ) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isFinite( null ) === true
Number.isFinite( null ) === false

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm that's why we love JavaScript right? 🥲

if ( ! ( tab.attr in activeData ) ) {
activeData[ tab.attr ] = 0;
}
Expand Down Expand Up @@ -68,7 +69,6 @@ class StatsTabs extends Component {
};

statsTabs = tabs.map( ( tab ) => {
const hasTrend = trendData?.[ tab.attr ] >= 0 && trendData[ tab.attr ] !== null;
const hasData = activeData?.[ tab.attr ] >= 0 && activeData[ tab.attr ] !== null;
const value = hasData ? activeData[ tab.attr ] : null;
const previousValue =
Expand All @@ -81,7 +81,7 @@ class StatsTabs extends Component {
label: tab.label,
loading: ! hasData,
selected: selectedTab === tab.attr,
tabClick: hasTrend ? switchTab : undefined,
tabClick: switchTab,
value,
previousValue,
format: tab.format,
Expand Down
2 changes: 1 addition & 1 deletion client/state/data-layer/wpcom/sites/stats/visits/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const fetch = ( action ) => {
unit: period,
date: adjustedDate,
quantity,
stat_fields: 'views',
stat_fields: statFields,
},
},
action
Expand Down
3 changes: 2 additions & 1 deletion client/state/data-layer/wpcom/sites/stats/visits/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export default {
items: {
type: 'array',
items: {
type: [ 'integer', 'string', 'array' ],
// Valid for NULL from unsupported stats fields in hourly data
type: [ 'integer', 'string', 'array', null ],
},
},
},
Expand Down
Loading