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

POC: Show Awesome Motive plugins when ref param is present #95307

Draft
wants to merge 16 commits into
base: trunk
Choose a base branch
from
Draft
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
19 changes: 18 additions & 1 deletion client/data/marketplace/search-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function generateApiQueryString( {
pageHandle,
pageSize,
locale,
slugs,
}: SearchParams ) {
const sort = 'score_default';

Expand Down Expand Up @@ -84,7 +85,11 @@ function generateApiQueryString( {
params.sort = 'plugin_modified';
break;
default:
params.filter = getFilterByCategory( category );
if ( Array.isArray( slugs ) && slugs.length ) {
params.filter = getFilterbySlugs( slugs || [] );
} else {
params.filter = getFilterByCategory( category );
}
params.sort = 'active_installs';
}
}
Expand Down Expand Up @@ -156,6 +161,18 @@ function getFilterbySlug( slug: string ): {
};
}

function getFilterbySlugs( slugs: string[] ): {
bool: {
should: { terms: object }[];
};
} {
return {
bool: {
should: [ { terms: { slug: slugs } } ],
},
};
}

function getFilterByCategory( category: string ): {
bool: object;
} {
Expand Down
2 changes: 2 additions & 0 deletions client/data/marketplace/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type PluginQueryOptions = {
locale: string;
tag?: string;
author?: string;
slugs?: string[];
};

export type Plugin = {
Expand Down Expand Up @@ -89,6 +90,7 @@ export type SearchParams = {
pageHandle: string | undefined;
pageSize: number;
locale: string;
slugs?: string[] | undefined;
};

export type ReinstallPluginsResponse = {
Expand Down
1 change: 1 addition & 0 deletions client/data/marketplace/use-es-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export const getESPluginsInfiniteQueryParams = (
pageHandle: pageParam + '',
pageSize,
locale: getWpLocaleBySlug( ( options.locale || locale ) as LanguageSlug ),
slugs: options.slugs,
} );
return { queryKey, queryFn, initialPageParam: 1 };
};
Expand Down
1 change: 1 addition & 0 deletions client/my-sites/plugins/categories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type Category = {
description?: string;
icon?: string;
separator?: boolean;
showOnlyActive?: boolean;
};

export type Plugin = {
Expand Down
10 changes: 10 additions & 0 deletions client/my-sites/plugins/categories/use-categories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const ALLOWED_CATEGORIES = [
'javascript',
'community',
'captcha',
'wpbeginner',
];

export const getCategories: () => Record< string, Category > = () => ( {
Expand Down Expand Up @@ -751,6 +752,15 @@ export const getCategories: () => Record< string, Category > = () => ( {
tags: [ 'captcha', 'invisible captcha', 'nocaptcha', 'CAPTCHA Code', 'anti-spam' ],
preview: [],
},
wpbeginner: {
menu: __( 'WPBeginner' ),
title: __( 'Must-have plugins from WPBeginner' ),
description: __( 'Add the best-loved plugins on WordPress.com' ),
slug: 'wpbeginner',
tags: [ 'wpbeginner', 'Awesome Motive' ],
preview: [],
showOnlyActive: true,
},
} );

/**
Expand Down
30 changes: 30 additions & 0 deletions client/my-sites/plugins/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,33 @@ export const ECOMMERCE_BUNDLED_PLUGINS = [
];

export const UNLISTED_PLUGINS = [ 'automated-db-schenker-shipping', 'wp-fusion-lite' ];

export const WPBEGINNER_PLUGINS = [
'optinmonster',
'wpforms-lite',
'google-analytics-for-wordpress',
'all-in-one-seo-pack',
'coming-soon',
'wp-mail-smtp',
'custom-facebook-feed',
'duplicator',
'insert-headers-and-footers',
'pushengage',
'searchwp-live-ajax-search',
'rafflepress',
'easy-digital-downloads',
'affiliatewp-checkout-referrals',
'stripe',
'sugar-calendar-lite',
'trustpulse-api',
'charitable',
'igotweb-wp-mp-links',
'uncanny-automator',
'pretty-link',
'formidable',
'woocommerce-wholesale-prices',
'advanced-coupons-for-woocommerce-free',
'thirstyaffiliates',
'uncanny-learndash-toolkit',
'nutrifox',
];
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { useCategories } from 'calypso/my-sites/plugins/categories/use-categorie
import PluginsBrowserList from 'calypso/my-sites/plugins/plugins-browser-list';
import { PluginsBrowserListVariant } from 'calypso/my-sites/plugins/plugins-browser-list/types';
import UpgradeNudge from 'calypso/my-sites/plugins/plugins-discovery-page/upgrade-nudge';
import { WPBEGINNER_PLUGINS } from '../constants';
import usePlugins from '../use-plugins';

const PluginsCategoryResultsPage = ( { category, siteSlug, sites } ) => {
const { plugins, isFetching, fetchNextPage, pagination } = usePlugins( {
category,
infinite: true,
slugs: category === 'wpbeginner' ? WPBEGINNER_PLUGINS : undefined,
} );

const categories = useCategories();
Expand Down
46 changes: 37 additions & 9 deletions client/my-sites/plugins/plugins-discovery-page/index.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useSelector } from 'react-redux';
import HostingActivateStatus from 'calypso/hosting/server-settings/hosting-activate-status';
import { getQueryArgs } from 'calypso/lib/query-args';
import { TrialAcknowledgeModal } from 'calypso/my-sites/plans/trials/trial-acknowledge/acknowlege-modal';
import { WithOnclickTrialRequest } from 'calypso/my-sites/plans/trials/trial-acknowledge/with-onclick-trial-request';
import { isCompatiblePlugin } from 'calypso/my-sites/plugins/plugin-compatibility';
import { isUserLoggedIn } from 'calypso/state/current-user/selectors';
import { WPBEGINNER_PLUGINS } from '../constants';
import EducationFooter from '../education-footer';
import CollectionListView from '../plugins-browser/collection-list-view';
import SingleListView, { SHORT_LIST_LENGTH } from '../plugins-browser/single-list-view';
Expand Down Expand Up @@ -47,6 +49,24 @@ export const PaidPluginsSection = ( props ) => {
/>
);
};
export const FeaturedWPBeginnerSection = ( props ) => {
const category = 'wpbeginner';

const { plugins, isFetching } = usePlugins( {
category,
infinite: true,
slugs: WPBEGINNER_PLUGINS,
} );

return (
<SingleListView
{ ...props }
category={ category }
plugins={ plugins }
isFetching={ isFetching }
/>
);
};

const FeaturedPluginsSection = ( props ) => {
return (
Expand Down Expand Up @@ -89,6 +109,7 @@ const PluginsDiscoveryPage = ( props ) => {
} );

const isLoggedIn = useSelector( isUserLoggedIn );
const isWPBeginnerSpecial = getQueryArgs()?.ref === 'wpbeginner-special-lp';

const {
isTrialAcknowledgeModalOpen,
Expand All @@ -112,15 +133,22 @@ const PluginsDiscoveryPage = ( props ) => {
/>
) }

<PaidPluginsSection { ...props } />
<CollectionListView category="monetization" { ...props } />
<EducationFooter />
{ ! isLoggedIn && <InPageCTASection /> }
<FeaturedPluginsSection
{ ...props }
pluginsByCategoryFeatured={ pluginsByCategoryFeatured }
isFetchingPluginsByCategoryFeatured={ isFetchingPluginsByCategoryFeatured }
/>
{ isWPBeginnerSpecial ? (
<FeaturedWPBeginnerSection { ...props } />
) : (
<>
<PaidPluginsSection { ...props } />
<CollectionListView category="monetization" { ...props } />
<EducationFooter />
{ ! isLoggedIn && <InPageCTASection /> }
<FeaturedPluginsSection
{ ...props }
pluginsByCategoryFeatured={ pluginsByCategoryFeatured }
isFetchingPluginsByCategoryFeatured={ isFetchingPluginsByCategoryFeatured }
/>
</>
) }

<CollectionListView category="business" { ...props } />
<PopularPluginsSection { ...props } pluginsByCategoryFeatured={ pluginsByCategoryFeatured } />
<CollectionListView category="ecommerce" { ...props } />
Expand Down
4 changes: 3 additions & 1 deletion client/my-sites/plugins/search-categories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ const SearchCategories: FC< {
const displayCategories = ALLOWED_CATEGORIES.filter(
( v ) => [ 'paid', 'popular', 'featured' ].indexOf( v ) < 0
);
const categories = Object.values( useCategories( displayCategories ) );
const categories = Object.values( useCategories( displayCategories ) ).filter(
( item ) => ! item.showOnlyActive || item.slug === category
);

// Update the search box with the value from the url everytime it changes
// This allows the component to be refilled with a keyword
Expand Down
3 changes: 3 additions & 0 deletions client/my-sites/plugins/use-plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ const usePlugins = ( {
search,
infinite = false,
locale = '',
slugs,
}: {
category: string;
search?: string;
infinite?: boolean;
locale?: string;
slugs?: string[];
} ) => {
let plugins = [];
let isFetching = false;
Expand All @@ -53,6 +55,7 @@ const usePlugins = ( {
category,
tag,
searchTerm: search,
slugs,
};

// This is triggered for searches OR any other category than paid, featured
Expand Down
Loading