Skip to content

Commit

Permalink
Add chevron to interstitial for mobile view (#41554)
Browse files Browse the repository at this point in the history
* Add redbubble and notice when paid plan is missing plugin(s).

* Add activate-multiple-plugins endpoint & logic.

* Delay last-backup-failed red-bubble until 30 min after purchase. Also fix $not_shown_products.

* Refactor how we derive shown_products & not_shown_products.

* Cleanup & add GlobalNotice after successfull activation/installation.

* Remove single product endpoints from mj REST_Products.

* Update unowned section to list

* changelog

* Remove filter
:

* Remove print statement

* Add missing text domain package"

* Update lockfile

* Fix package versions

* Add chevron to interstitial for mobile view

* Add mobile chevron tracks event click

* Add changelog

* Add accidentally removed function

* Remove chevron padding and fix rebase issue

---------

Co-authored-by: Bryan Elliott <[email protected]>
  • Loading branch information
CodeyGuyDylan and elliottprogrammer authored Feb 7, 2025
1 parent a7b2490 commit 50eb9aa
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { useViewportMatch } from '@wordpress/compose';
import { DataViews, filterSortAndPaginate } from '@wordpress/dataviews';
import { __ } from '@wordpress/i18n';
import { Icon, chevronRight } from '@wordpress/icons';
import { useCallback, useState, useMemo } from 'react';
import { useNavigate } from 'react-router-dom';
import { useAllProducts } from '../../data/products/use-all-products';
import useAnalytics from '../../hooks/use-analytics';
import ActionButton from '../action-button';
import {
PRODUCT_TABLE_TITLE,
Expand Down Expand Up @@ -30,7 +34,7 @@ import type {
Operator,
Option,
} from '@wordpress/dataviews';
import type { FC } from 'react';
import type { FC, MouseEvent } from 'react';

import './style.scss';

Expand Down Expand Up @@ -100,6 +104,9 @@ const ProductsTableView: FC< ProductsTableViewProps > = ( { products } ) => {
}, [] );
const isItemClickable = useCallback( () => false, [] );
const allProductData = useAllProducts();
const isMobileViewport: boolean = useViewportMatch( 'medium', '<' );
const navigate = useNavigate();
const { recordEvent } = useAnalytics();

const baseView: ViewList = {
sort: {
Expand Down Expand Up @@ -127,6 +134,15 @@ const ProductsTableView: FC< ProductsTableViewProps > = ( { products } ) => {
[ products, allProductData ]
);

const navigateToInterstitial = useCallback(
( slug: string ) => ( event: MouseEvent< HTMLButtonElement > ) => {
event.preventDefault();
recordEvent( `jetpack_myjetpack_product_list_item_${ slug }_learnmore_mobile_click` );
navigate( `add-${ slug }` );
},
[ navigate, recordEvent ]
);

const fields = useMemo( () => {
return [
{
Expand Down Expand Up @@ -177,8 +193,8 @@ const ProductsTableView: FC< ProductsTableViewProps > = ( { products } ) => {
enableHiding: false,
render( { item }: { item: ProductData } ) {
const { product } = item;
const Icon = PRODUCT_ICONS[ product.slug ];
return <Icon />;
const ProductIcon = PRODUCT_ICONS[ product.slug ];
return <ProductIcon />;
},
},
{
Expand All @@ -193,15 +209,32 @@ const ProductsTableView: FC< ProductsTableViewProps > = ( { products } ) => {
const { product } = item;
const { slug } = product;

return <ActionButton slug={ slug } tracksIdentifier="product_list_item" />;
if ( isMobileViewport ) {
return (
<button
onClick={ navigateToInterstitial( slug ) }
className="product-list-item-chevron"
>
<Icon icon={ chevronRight } size={ 24 } />
</button>
);
}

return (
<ActionButton
className="product-list-item-cta"
slug={ slug }
tracksIdentifier="product_list_item"
/>
);
},
},
];
// Having this re-calculate on every change of "categories" was causing unnecessary re-renders
// and a 'jumping' of the CTA buttons. Having categories as a dependency here is unnecessary
// and leaving it out doesn't cause the values to be incorrect.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [] );
}, [ isMobileViewport, navigateToInterstitial ] );

const [ view, setView ] = useState< View >( {
type: 'list',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ div.dataviews-wrapper {

.dataviews-view-list__fields {
justify-content: space-between;
flex-wrap: nowrap;
}

&:not(.is-selected).is-hovered,
Expand Down Expand Up @@ -97,4 +98,16 @@ div.dataviews-filters__summary-chip-container div.dataviews-filters__summary-chi
div.dataviews-filters__summary-chip-container div.dataviews-filters__summary-chip.has-values:hover,
div.dataviews-filters__summary-chip-container button.dataviews-filters__summary-chip-remove.has-values:hover {
background-color: var(--tag-color);
}
}

button.product-list-item-chevron {
display: flex;
align-items: center;
justify-content: center;
padding: 0;

cursor: pointer;
background: transparent;
border: none;
outline-color: var(--jp-green-40);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Add mobile CTA to DataViews table

0 comments on commit 50eb9aa

Please sign in to comment.