import { Card } from '@automattic/components'; import { times } from 'lodash'; import PropTypes from 'prop-types'; import { useSelector } from 'react-redux'; import AsyncLoad from 'calypso/components/async-load'; import Spotlight from 'calypso/components/spotlight'; import { getMessagePathForJITM } from 'calypso/lib/route'; import PluginBrowserItem from 'calypso/my-sites/plugins/plugins-browser-item'; import { PluginsBrowserElementVariant } from 'calypso/my-sites/plugins/plugins-browser-item/types'; import PluginsResultsHeader from 'calypso/my-sites/plugins/plugins-results-header'; import getCurrentRoute from 'calypso/state/selectors/get-current-route'; import { PluginsBrowserListVariant } from './types'; import './style.scss'; const DEFAULT_PLACEHOLDER_NUMBER = 6; const PluginsBrowserList = ( { plugins, variant = PluginsBrowserListVariant.Fixed, title, subtitle, resultCount, extended, showPlaceholders, site, currentSites, listName, listType, browseAllLink, size, search, noHeader = false, } ) => { const extendedVariant = extended ? PluginsBrowserElementVariant.Extended : PluginsBrowserElementVariant.Compact; const renderPluginsViewList = () => { const pluginsViewsList = plugins.map( ( plugin, n ) => { // Needs a beter fix but something is leaking empty objects into this list. if ( ! plugin?.slug ) { return null; } return ( ); } ); if ( size ) { return pluginsViewsList.slice( 0, size ); } return pluginsViewsList; }; const renderPlaceholdersViews = () => { return times( size || DEFAULT_PLACEHOLDER_NUMBER, ( i ) => ( ) ); }; const renderViews = () => { if ( ! plugins.length ) { return renderPlaceholdersViews(); } switch ( variant ) { case PluginsBrowserListVariant.InfiniteScroll: if ( showPlaceholders ) { return renderPluginsViewList().concat( renderPlaceholdersViews() ); } return renderPluginsViewList(); case PluginsBrowserListVariant.Paginated: if ( showPlaceholders ) { return renderPlaceholdersViews(); } return renderPluginsViewList(); case PluginsBrowserListVariant.Fixed: default: return renderPluginsViewList(); } }; const SpotlightPlaceholder = ( {} } titleText="This is the default placeholder rendered in Calypso" ctaText="Click me" /> ); // Get the message path for the current route. This is needed to be able to display JITMs const currentRoute = useSelector( getCurrentRoute ); const sectionJitmPath = getMessagePathForJITM( currentRoute ); return (
{ ! noHeader && ( title || subtitle || resultCount || browseAllLink ) && ( ) } { listName === 'paid' && ( ) } { listType === 'search' && ( ) } { listType === 'browse' && ( ) } { renderViews() }
); }; PluginsBrowserList.propTypes = { plugins: PropTypes.array.isRequired, variant: PropTypes.oneOf( Object.values( PluginsBrowserListVariant ) ).isRequired, extended: PropTypes.bool, }; export default PluginsBrowserList;