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-authors: toggle the "authors" module when there is only one to be displayed #97079

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
isRequestingSiteStatsForQuery,
getSiteStatsNormalizedData,
} from 'calypso/state/stats/lists/selectors';
import { getModuleToggles } from 'calypso/state/stats/module-toggles/selectors';
import { getSelectedSiteId } from 'calypso/state/ui/selectors';
import EmptyModuleCard from '../../../components/empty-module-card/empty-module-card';
import { SUPPORT_URL, JETPACK_SUPPORT_URL_TRAFFIC } from '../../../const';
Expand Down Expand Up @@ -45,6 +46,14 @@ const StatAuthors: React.FC< StatsDefaultModuleProps > = ( {
getSiteStatsNormalizedData( state, siteId, statType, query )
) as [ id: number, label: string ];

// toggle the module if it's going to show just a single author
const isSingleAuthor = data?.length === 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm afraid even if there is only one author in the response, but it wouldn't necessarily mean the site only has one author.

Copy link
Member Author

Choose a reason for hiding this comment

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

What condition should I use instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

There's a useUsersQuery that can take a author_only: 1 option which may be able to get a list of authors on the site that you can check the size of.

Copy link
Contributor

Choose a reason for hiding this comment

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

I left a comment in the issue:

#80534 (comment)


useSelector( ( state ) => {
const pageModuleToggles = getModuleToggles( state, siteId, [ 'traffic' ] );
pageModuleToggles.authors = ! isSingleAuthor;
} );

return (
<>
{ ! shouldGateStatsModule && siteId && statType && (
Expand Down
Loading