woocommerce/plugins/woocommerce-admin/client/marketplace/components/discover/discover.tsx

88 lines
2.2 KiB
TypeScript
Raw Normal View History

/**
* External dependencies
*/
[wccom-17942] Only showing feedback snackbar when content of in-app marketplace has finished loading. Making sure snackbar is fixed position, so it's visible wherever you are on the page. - `ProductListContextProvider` provides `setIsLoading` function as well as `isLoading`. - `Discover` uses these values from context, instead of keeping a loading state in itself. - `FeedbackModal` calls `maybSetTimeout` when `isLoading` changes. If `isLoading` isn't truthy, and snackbar hasn't already rendered, it sets a timeout of 5 seconds to show it. - Removed wrapping <WooFooterItem> from around Footer component, so it's no longer a child of the WooCommerce Admin `.woocommerce-layout__footer` footer. - Removed the `position: relative` from `.woocommerce-layout__footer`. It needs to be `position: fixed`. - Added FooterContent component to Footer, to allow the layout we want. - Changed use of context. This now only has states for the selected tab and loading state. - We use this context in `Tabs` and `Content` to keep track of which tab is selected, and set the selected tab. - We also use it in `Discover` and `Extensions`, which both report loading state to the context. This allows us to use it to only render the snackbar when loading is complete. - Extensions: moved `productList` and `setProductList` and logic for getting product list from the context provider to a state in this component. We don't need to share the list of products in the context. - Renamed `ProductListContext`, `ProductListContextProvider` and `productListContextValue` to more generic `MarketplaceContext`, `MarketplaceContextProvider` and `marketplaceContextValue`. - Renamed a constant and created constants for API paths. - Only shows snackbar after content has loaded, and after a timeout. We set a date `marketplace_redesign_2023_last_shown_date` in local storage to ensure we only show one snackbar.
2023-08-23 15:49:36 +00:00
import { useContext, useEffect, useState } from '@wordpress/element';
import { recordEvent } from '@woocommerce/tracks';
/**
* Internal dependencies
*/
import ProductList from '../product-list/product-list';
import { fetchDiscoverPageData, ProductGroup } from '../../utils/functions';
import ProductLoader from '../product-loader/product-loader';
[wccom-17942] Only showing feedback snackbar when content of in-app marketplace has finished loading. Making sure snackbar is fixed position, so it's visible wherever you are on the page. - `ProductListContextProvider` provides `setIsLoading` function as well as `isLoading`. - `Discover` uses these values from context, instead of keeping a loading state in itself. - `FeedbackModal` calls `maybSetTimeout` when `isLoading` changes. If `isLoading` isn't truthy, and snackbar hasn't already rendered, it sets a timeout of 5 seconds to show it. - Removed wrapping <WooFooterItem> from around Footer component, so it's no longer a child of the WooCommerce Admin `.woocommerce-layout__footer` footer. - Removed the `position: relative` from `.woocommerce-layout__footer`. It needs to be `position: fixed`. - Added FooterContent component to Footer, to allow the layout we want. - Changed use of context. This now only has states for the selected tab and loading state. - We use this context in `Tabs` and `Content` to keep track of which tab is selected, and set the selected tab. - We also use it in `Discover` and `Extensions`, which both report loading state to the context. This allows us to use it to only render the snackbar when loading is complete. - Extensions: moved `productList` and `setProductList` and logic for getting product list from the context provider to a state in this component. We don't need to share the list of products in the context. - Renamed `ProductListContext`, `ProductListContextProvider` and `productListContextValue` to more generic `MarketplaceContext`, `MarketplaceContextProvider` and `marketplaceContextValue`. - Renamed a constant and created constants for API paths. - Only shows snackbar after content has loaded, and after a timeout. We set a date `marketplace_redesign_2023_last_shown_date` in local storage to ensure we only show one snackbar.
2023-08-23 15:49:36 +00:00
import { MarketplaceContext } from '../../contexts/marketplace-context';
import { ProductType } from '../product-list/types';
import './discover.scss';
Remove the ability to update Woo.com extensions not available in WP.org plugin directory (#44279) * Remove the hook for updating update_plugins transient with data fetched from Woo.com This prevents the WP core from updating Woo.com plugins. * Remove the hook for updating update_themes transient with data fetched from Woo.com This prevents the WP core from updating Woo.com themes. * Remove the class hand hooks used for updating the API response of WP.org with update URI's from Woo.com. * Add change log file. * Add update_plugins and themes transient update hooks back while removing the package from Woo.com extensions. When a Woo hosted plugin has an update, this will allow showing the update message but block the ability to update. * Adding a hook to modify the plugin update notification on plugins.php. When a Woo.com hosted plugin has an update available it will show a message to install Woo Marketplace plugin, if it's not installed. * Utility class for Woo Marketplace plugin. * Check wether the Woo marketplace plugin is already installed before modifying update notice. * Update docblocks. * Add status end point for wccom-site API. * Check the existence of marketplace plugin only after the plugins are loaded. * Add WP.org plugin api response updater back to core. * Function to identify if the market-place plugin is installed. * Update status API response with installation status. * Update the status variable push to store admin frontend with information about market-place plugin. * Styles for woo-connect-plugin component. * Component for displaying the message to install Woo Connect plugin based on the installation status. * Add Woo Connect plugin notice to my-subscriptions page. * Add Woo connect plugin message to discover page. * Add Woo Connect install/download urls to constants file. * Add a modal for asking the user to install Woo Connect plugin. * Update strings with constants. * Show the Woo Connect modal when user updating plugins without Woo Connect installed. * Show Woo Connect install notifications only when the site is connected. * Update plugin management page messaging. * Update notification on connect screen. * Update notifications on plugin management page. * Remove additional spacing in Plugin Install Notice and spacing in the discover page results and the notice. * Use notice component instead of Card. * Minor improvements to readability. * Add translation support for messages displayed on plugins.php. * Update woo connect plugin installation URL (#45127) * Ad functions for generating WooConnect plugin install URLs. * Make WooConnect install url to available to marketplace components. * Make WooConnect install url to available to marketplace components. * Link install buttons to install URL with access_token and secret. * Update Woo Update Manager download url. * Show admin notice to install Woo Update Manager on plugins.php. * Adding the view for admin notice for installing woo_update_manager. * Show woo update manager installation notice on WC admin pages and make the notice dissmisable. * Update the install url for Woo Update Manager by adding the product ID and introduce a filter to override the product ID. * Change the plugin name to Woo Update Manager. * Change the download url for woo update manager * Fix the margin below the Woo Update plugin install notice. * Rename Woo Connect to Woo Update Manager. * Rename wccom-site status endpoint response variables based on plugin name changes. * Update the plugin main file name for Woo Update Manager. * Updating the download URL. * Updating css class names and file names from `woo-connect-plugin` to `woo-update-manager`. * Change wooConnect variables to wooUpdateManager. * Rename WC_Helper_Plugin to WC_Woo_Update_Manager_Plugin and remove references to market place plugin. * Extract and reuse the logic for creating the signature. * Use WC built-in method to check if the current page is a WC page. * Add source parameter for installer. * Update text copies based on flows for in-app Woo Update Manager install message. * Update admin notice based on the flows. * Update connect store message. * Update the text based on the latest flow and show a different message when WUM is installed but not activated. * Use html text for install notice message. * Implement the bubble showing number of updates available on WooCommerce -> Extensions menu. Add one to available Woo.com updates if WUM is not installed or activated. * Update install url to new structure. * Update download url for WUM. * Add a method to get the id of the WUM. * Remove WUM from available to install list of extensions on my-subscriptions tab. * Remove the hard coded ID of the Woo Update Manager and use the slug to get the ID of the plugin based on update-check response. * Fixing the notice generated due to empty body. * Update CTA and image for the not connected screen. * Increasing the left margin of the install notice to match admin notices. * Add close button to modal with message to activate WUM. * Add install/activate notice to Browse and Themes tabs. * Add the view for showing admin notice for activating the plugin. * Update plugin name on install admin notice. * Show install or activate admin notice based on the context. * Update comment * Make the linked text shorter in plugin update message. * Generate a signed auto-install URL for woo hosted plugins without helper API (#45313) * Generate a signed auto-install URL for woo hosted plugins without helper API * Use product slug in auto-install URL instead of product id. * Update activate Woo Update Manager modal buttons. * Change install url from Woo Update Manager ID to slug. * Allow defining the menu title and page title separately for when adding menus and sub menus in WooCommerce Admin. * Set the page title separately for WooCommerce Extensions menu. * Fix the update count issue. * Update the download URL for Woo Update Manager. * Update the download link for WUM in admin notices. * Show WUM admin notices on WC Admin pages only when the site is connected. * Remove additional slash in plugin admin url. * Add wum-installed parameter to the connect URL (#45702) * Add wum-installed parameter to the connect URL * Send status of Woo Update Manager installation on connection init. * Revert "Add wum-installed parameter to the connect URL" This reverts commit 4c55038b0315370a800aa463ca391dbdae02bbf7. --------- Co-authored-by: Denis Dvali <denis.dvali@automattic.com> * Fix lint errors. * Fix lint error. * Fix lint errors. * Fix js lint issues. * Update Woo Update manager admin notice. --------- Co-authored-by: Muhammad Anas <anastts.pk@gmail.com> Co-authored-by: Denis Dvali <denis.dvali@automattic.com>
2024-03-20 14:02:23 +00:00
import PluginInstallNotice from '../woo-update-manager-plugin/plugin-install-notice';
export default function Discover(): JSX.Element | null {
const [ productGroups, setProductGroups ] = useState<
Array< ProductGroup >
>( [] );
[wccom-17942] Only showing feedback snackbar when content of in-app marketplace has finished loading. Making sure snackbar is fixed position, so it's visible wherever you are on the page. - `ProductListContextProvider` provides `setIsLoading` function as well as `isLoading`. - `Discover` uses these values from context, instead of keeping a loading state in itself. - `FeedbackModal` calls `maybSetTimeout` when `isLoading` changes. If `isLoading` isn't truthy, and snackbar hasn't already rendered, it sets a timeout of 5 seconds to show it. - Removed wrapping <WooFooterItem> from around Footer component, so it's no longer a child of the WooCommerce Admin `.woocommerce-layout__footer` footer. - Removed the `position: relative` from `.woocommerce-layout__footer`. It needs to be `position: fixed`. - Added FooterContent component to Footer, to allow the layout we want. - Changed use of context. This now only has states for the selected tab and loading state. - We use this context in `Tabs` and `Content` to keep track of which tab is selected, and set the selected tab. - We also use it in `Discover` and `Extensions`, which both report loading state to the context. This allows us to use it to only render the snackbar when loading is complete. - Extensions: moved `productList` and `setProductList` and logic for getting product list from the context provider to a state in this component. We don't need to share the list of products in the context. - Renamed `ProductListContext`, `ProductListContextProvider` and `productListContextValue` to more generic `MarketplaceContext`, `MarketplaceContextProvider` and `marketplaceContextValue`. - Renamed a constant and created constants for API paths. - Only shows snackbar after content has loaded, and after a timeout. We set a date `marketplace_redesign_2023_last_shown_date` in local storage to ensure we only show one snackbar.
2023-08-23 15:49:36 +00:00
const marketplaceContextValue = useContext( MarketplaceContext );
const { isLoading, setIsLoading } = marketplaceContextValue;
function recordTracksEvent( products: ProductGroup[] ) {
const product_ids = products
.flatMap( ( group ) => group.items )
.map( ( product ) => {
return product.id;
} );
recordEvent( 'marketplace_discover_viewed', {
view: 'discover',
product_ids,
} );
}
[wccom-17942] Only showing feedback snackbar when content of in-app marketplace has finished loading. Making sure snackbar is fixed position, so it's visible wherever you are on the page. - `ProductListContextProvider` provides `setIsLoading` function as well as `isLoading`. - `Discover` uses these values from context, instead of keeping a loading state in itself. - `FeedbackModal` calls `maybSetTimeout` when `isLoading` changes. If `isLoading` isn't truthy, and snackbar hasn't already rendered, it sets a timeout of 5 seconds to show it. - Removed wrapping <WooFooterItem> from around Footer component, so it's no longer a child of the WooCommerce Admin `.woocommerce-layout__footer` footer. - Removed the `position: relative` from `.woocommerce-layout__footer`. It needs to be `position: fixed`. - Added FooterContent component to Footer, to allow the layout we want. - Changed use of context. This now only has states for the selected tab and loading state. - We use this context in `Tabs` and `Content` to keep track of which tab is selected, and set the selected tab. - We also use it in `Discover` and `Extensions`, which both report loading state to the context. This allows us to use it to only render the snackbar when loading is complete. - Extensions: moved `productList` and `setProductList` and logic for getting product list from the context provider to a state in this component. We don't need to share the list of products in the context. - Renamed `ProductListContext`, `ProductListContextProvider` and `productListContextValue` to more generic `MarketplaceContext`, `MarketplaceContextProvider` and `marketplaceContextValue`. - Renamed a constant and created constants for API paths. - Only shows snackbar after content has loaded, and after a timeout. We set a date `marketplace_redesign_2023_last_shown_date` in local storage to ensure we only show one snackbar.
2023-08-23 15:49:36 +00:00
// Get the content for this screen
useEffect( () => {
setIsLoading( true );
fetchDiscoverPageData()
Marketplace Themes: Feature Branch (#40159) * Support for themes in in-app marketplace. Contains the changes from: https://github.com/woocommerce/woocommerce/pull/40247 https://github.com/woocommerce/woocommerce/pull/40272 https://github.com/woocommerce/woocommerce/pull/40302 https://github.com/woocommerce/woocommerce/pull/40303 https://github.com/woocommerce/woocommerce/pull/40333 https://github.com/woocommerce/woocommerce/pull/40368 https://github.com/woocommerce/woocommerce/pull/40375 https://github.com/woocommerce/woocommerce/pull/40375 https://github.com/woocommerce/woocommerce/pull/40389 * `.woocommerce-marketplace__discover`: changed `align-items` `flex-start` to `stretch` to properly display products on large and very large viewports. * Delete plugins/woocommerce/changelog/add-18026-marketplace-theme-cards Removing from feature branch before final review * Delete plugins/woocommerce/changelog/add-18027-themes-to-in-app-search Removing from feature branch before final review * Delete plugins/woocommerce/changelog/add-marketplace-theme-discover-section Removing from feature branch before final review * Delete plugins/woocommerce/changelog/update-in-app-multiple-category-filters Removing from feature branch before final review * Delete plugins/woocommerce/changelog/update-theme-no-result-style Removing from feature branch before final review * Add changefile(s) from automation for the following project(s): woocommerce --------- Co-authored-by: And Finally <andfinally@users.noreply.github.com> Co-authored-by: Dan Q <dan@danq.me> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Dan Q <danq@automattic.com>
2023-10-04 16:59:34 +00:00
.then(
( response: Array< ProductGroup > | { success: boolean } ) => {
if ( ! Array.isArray( response ) ) {
return [];
}
return response as Array< ProductGroup >;
}
)
.then( ( products: Array< ProductGroup > ) => {
setProductGroups( products );
recordTracksEvent( products );
} )
.finally( () => {
setIsLoading( false );
} );
}, [] );
if ( isLoading ) {
return (
<div className="woocommerce-marketplace__discover">
<ProductLoader
placeholderCount={ 9 }
type={ ProductType.extension }
/>
</div>
);
}
const groupsList = productGroups.flatMap( ( group ) => group );
return (
<div className="woocommerce-marketplace__discover">
Remove the ability to update Woo.com extensions not available in WP.org plugin directory (#44279) * Remove the hook for updating update_plugins transient with data fetched from Woo.com This prevents the WP core from updating Woo.com plugins. * Remove the hook for updating update_themes transient with data fetched from Woo.com This prevents the WP core from updating Woo.com themes. * Remove the class hand hooks used for updating the API response of WP.org with update URI's from Woo.com. * Add change log file. * Add update_plugins and themes transient update hooks back while removing the package from Woo.com extensions. When a Woo hosted plugin has an update, this will allow showing the update message but block the ability to update. * Adding a hook to modify the plugin update notification on plugins.php. When a Woo.com hosted plugin has an update available it will show a message to install Woo Marketplace plugin, if it's not installed. * Utility class for Woo Marketplace plugin. * Check wether the Woo marketplace plugin is already installed before modifying update notice. * Update docblocks. * Add status end point for wccom-site API. * Check the existence of marketplace plugin only after the plugins are loaded. * Add WP.org plugin api response updater back to core. * Function to identify if the market-place plugin is installed. * Update status API response with installation status. * Update the status variable push to store admin frontend with information about market-place plugin. * Styles for woo-connect-plugin component. * Component for displaying the message to install Woo Connect plugin based on the installation status. * Add Woo Connect plugin notice to my-subscriptions page. * Add Woo connect plugin message to discover page. * Add Woo Connect install/download urls to constants file. * Add a modal for asking the user to install Woo Connect plugin. * Update strings with constants. * Show the Woo Connect modal when user updating plugins without Woo Connect installed. * Show Woo Connect install notifications only when the site is connected. * Update plugin management page messaging. * Update notification on connect screen. * Update notifications on plugin management page. * Remove additional spacing in Plugin Install Notice and spacing in the discover page results and the notice. * Use notice component instead of Card. * Minor improvements to readability. * Add translation support for messages displayed on plugins.php. * Update woo connect plugin installation URL (#45127) * Ad functions for generating WooConnect plugin install URLs. * Make WooConnect install url to available to marketplace components. * Make WooConnect install url to available to marketplace components. * Link install buttons to install URL with access_token and secret. * Update Woo Update Manager download url. * Show admin notice to install Woo Update Manager on plugins.php. * Adding the view for admin notice for installing woo_update_manager. * Show woo update manager installation notice on WC admin pages and make the notice dissmisable. * Update the install url for Woo Update Manager by adding the product ID and introduce a filter to override the product ID. * Change the plugin name to Woo Update Manager. * Change the download url for woo update manager * Fix the margin below the Woo Update plugin install notice. * Rename Woo Connect to Woo Update Manager. * Rename wccom-site status endpoint response variables based on plugin name changes. * Update the plugin main file name for Woo Update Manager. * Updating the download URL. * Updating css class names and file names from `woo-connect-plugin` to `woo-update-manager`. * Change wooConnect variables to wooUpdateManager. * Rename WC_Helper_Plugin to WC_Woo_Update_Manager_Plugin and remove references to market place plugin. * Extract and reuse the logic for creating the signature. * Use WC built-in method to check if the current page is a WC page. * Add source parameter for installer. * Update text copies based on flows for in-app Woo Update Manager install message. * Update admin notice based on the flows. * Update connect store message. * Update the text based on the latest flow and show a different message when WUM is installed but not activated. * Use html text for install notice message. * Implement the bubble showing number of updates available on WooCommerce -> Extensions menu. Add one to available Woo.com updates if WUM is not installed or activated. * Update install url to new structure. * Update download url for WUM. * Add a method to get the id of the WUM. * Remove WUM from available to install list of extensions on my-subscriptions tab. * Remove the hard coded ID of the Woo Update Manager and use the slug to get the ID of the plugin based on update-check response. * Fixing the notice generated due to empty body. * Update CTA and image for the not connected screen. * Increasing the left margin of the install notice to match admin notices. * Add close button to modal with message to activate WUM. * Add install/activate notice to Browse and Themes tabs. * Add the view for showing admin notice for activating the plugin. * Update plugin name on install admin notice. * Show install or activate admin notice based on the context. * Update comment * Make the linked text shorter in plugin update message. * Generate a signed auto-install URL for woo hosted plugins without helper API (#45313) * Generate a signed auto-install URL for woo hosted plugins without helper API * Use product slug in auto-install URL instead of product id. * Update activate Woo Update Manager modal buttons. * Change install url from Woo Update Manager ID to slug. * Allow defining the menu title and page title separately for when adding menus and sub menus in WooCommerce Admin. * Set the page title separately for WooCommerce Extensions menu. * Fix the update count issue. * Update the download URL for Woo Update Manager. * Update the download link for WUM in admin notices. * Show WUM admin notices on WC Admin pages only when the site is connected. * Remove additional slash in plugin admin url. * Add wum-installed parameter to the connect URL (#45702) * Add wum-installed parameter to the connect URL * Send status of Woo Update Manager installation on connection init. * Revert "Add wum-installed parameter to the connect URL" This reverts commit 4c55038b0315370a800aa463ca391dbdae02bbf7. --------- Co-authored-by: Denis Dvali <denis.dvali@automattic.com> * Fix lint errors. * Fix lint error. * Fix lint errors. * Fix js lint issues. * Update Woo Update manager admin notice. --------- Co-authored-by: Muhammad Anas <anastts.pk@gmail.com> Co-authored-by: Denis Dvali <denis.dvali@automattic.com>
2024-03-20 14:02:23 +00:00
<PluginInstallNotice />
{ groupsList.map( ( groups ) => (
<ProductList
key={ groups.id }
productGroup={ groups.id }
title={ groups.title }
products={ groups.items }
groupURL={ groups.url }
Marketplace Themes: Feature Branch (#40159) * Support for themes in in-app marketplace. Contains the changes from: https://github.com/woocommerce/woocommerce/pull/40247 https://github.com/woocommerce/woocommerce/pull/40272 https://github.com/woocommerce/woocommerce/pull/40302 https://github.com/woocommerce/woocommerce/pull/40303 https://github.com/woocommerce/woocommerce/pull/40333 https://github.com/woocommerce/woocommerce/pull/40368 https://github.com/woocommerce/woocommerce/pull/40375 https://github.com/woocommerce/woocommerce/pull/40375 https://github.com/woocommerce/woocommerce/pull/40389 * `.woocommerce-marketplace__discover`: changed `align-items` `flex-start` to `stretch` to properly display products on large and very large viewports. * Delete plugins/woocommerce/changelog/add-18026-marketplace-theme-cards Removing from feature branch before final review * Delete plugins/woocommerce/changelog/add-18027-themes-to-in-app-search Removing from feature branch before final review * Delete plugins/woocommerce/changelog/add-marketplace-theme-discover-section Removing from feature branch before final review * Delete plugins/woocommerce/changelog/update-in-app-multiple-category-filters Removing from feature branch before final review * Delete plugins/woocommerce/changelog/update-theme-no-result-style Removing from feature branch before final review * Add changefile(s) from automation for the following project(s): woocommerce --------- Co-authored-by: And Finally <andfinally@users.noreply.github.com> Co-authored-by: Dan Q <dan@danq.me> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Dan Q <danq@automattic.com>
2023-10-04 16:59:34 +00:00
type={ groups.itemType }
/>
) ) }
</div>
);
}