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

Bulk Plugin Management: Use list view for small viewports #98551

Merged
merged 4 commits into from
Jan 21, 2025
Merged
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
9 changes: 7 additions & 2 deletions client/my-sites/plugins/plugin-activate-toggle/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,18 @@
}

.plugin-row-formatter__toggle {
.plugin-autoupdate-toggle {
.components-flex.components-h-stack {
flex-direction: row-reverse;
.plugin-action__label {
@include break-xlarge() {
@include break-large() {
// We don't want to use display: none here, because it will hide the popover icon
// that might contain useful details about why the action is disabled.
font-size: 0;
}
}
}
.plugin-autoupdate-toggle {
.plugin-action__label {
.plugin-action__disabled-info {
color: var(--studio-gray-40);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { isDesktop, subscribeIsDesktop } from '@automattic/viewport';
import { filterSortAndPaginate } from '@wordpress/dataviews';
import { useTranslate } from 'i18n-calypso';
import { useMemo, useState, useCallback } from 'react';
import { initialDataViewsState } from 'calypso/a8c-for-agencies/components/items-dashboard/constants';
import { useMemo, useState, useCallback, useEffect } from 'react';
import {
DATAVIEWS_LIST,
DATAVIEWS_TABLE,
initialDataViewsState,
} from 'calypso/a8c-for-agencies/components/items-dashboard/constants';
import { DataViewsState } from 'calypso/a8c-for-agencies/components/items-dashboard/items-dataviews/interfaces';
import QueryUserPurchases from 'calypso/components/data/query-user-purchases';
import { DataViews } from 'calypso/components/dataviews';
Expand Down Expand Up @@ -31,8 +36,10 @@ interface Props {
export default function SitesWithInstalledPluginsList( { sites, plugin, isWpCom }: Props ) {
const translate = useTranslate();
const dispatch = useDispatch();
const isDesktopView = isDesktop();
const shouldUseListView = ! isDesktopView;

const compareBooleans =
const compareBooleans = useCallback(
( fieldName: keyof PluginSite ) => ( a: SiteDetails, b: SiteDetails, direction: string ) => {
const aValue = plugin.sites[ a.ID ][ fieldName ];
const bValue = plugin.sites[ b.ID ][ fieldName ];
Expand All @@ -43,7 +50,9 @@ export default function SitesWithInstalledPluginsList( { sites, plugin, isWpCom
return aValue ? 1 : -1;
}
return aValue ? -1 : 1;
};
},
[ plugin ]
);

const renderActions = useCallback(
( site: SiteDetails ) => {
Expand Down Expand Up @@ -155,19 +164,41 @@ export default function SitesWithInstalledPluginsList( { sites, plugin, isWpCom
enableSorting: false,
},
],
[ translate, plugin, sites.length, dispatch, renderActions ]
[ translate, compareBooleans, plugin, sites.length, dispatch, renderActions ]
);

const [ dataViewsState, setDataViewsState ] = useState< DataViewsState >( () => ( {
...initialDataViewsState,
type: shouldUseListView ? DATAVIEWS_LIST : DATAVIEWS_TABLE,
fields: [ 'domain', 'activate', 'autoupdate', 'update', 'actions' ],
items: sites,
layout: {
primaryField: 'domain',
},
} ) );

const sitesWithSecondarySites = useSelector( ( state ) =>
getSitesWithSecondarySites( state, sites )
);

useEffect( () => {
// Sets the correct fields when route changes or viewport changes
setDataViewsState( ( dVwState ) => ( {
...dVwState,
type: shouldUseListView ? DATAVIEWS_LIST : DATAVIEWS_TABLE,
} ) );

// Subscribe to viewport changes
const unsubscribe = subscribeIsDesktop( ( matches ) => {
const shouldUseListView = ! matches;
setDataViewsState( ( dVwState ) => ( {
...dVwState,
type: shouldUseListView ? DATAVIEWS_LIST : DATAVIEWS_TABLE,
} ) );
} );

return () => unsubscribe();
}, [ plugin.slug, shouldUseListView ] );

if ( ! sitesWithSecondarySites?.length ) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,31 @@
td:first-child .dataviews-view-table__cell-content-wrapper > span {
flex-grow: 1;

.plugin-row-formatter__overlay {
display: none;
}
}

td:last-child .dataviews-view-table__cell-content-wrapper {
justify-content: flex-end;
}
}

.plugin-row-formatter__overlay {
display: none;
}

.dataviews-view-list {
// Hiding this here because in this version the mediaField is not hiddable
// https://github.com/WordPress/gutenberg/tree/d59faffa3d270dbc7716f653b4cdab6020812658/packages/dataviews#properties-of-layout
// In future versions, a showMedia property can be used
.dataviews-view-list__media-wrapper {
background-color: transparent;
display: none;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can be revisited once the latest version of the @wordpress/dataviews component is deployed as part of #96470 because in the latest version there is a showMedia property: https://developer.wordpress.org/block-editor/reference-guides/packages/packages-dataviews/#properties

}
.dataviews-view-list__field-wrapper {
width: 100%;
.dataviews-view-list__field:last-child {
margin-left: auto;
order: 0;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ export default function PluginRowFormatter( {
<div className="plugin-row-formatter__toggle">
<PluginActivateToggle
isJetpackCloud
hideLabel={ ! isSmallScreen }
plugin={ pluginOnSite }
site={ selectedSite }
disabled={ !! item?.isSelectable }
Expand All @@ -225,7 +224,6 @@ export default function PluginRowFormatter( {
<div className="plugin-row-formatter__toggle">
<PluginAutoupdateToggle
plugin={ pluginOnSite }
hideLabel
site={ selectedSite }
wporg={ !! item.wporg }
isMarketplaceProduct={ isFromMarketplace }
Expand Down
5 changes: 3 additions & 2 deletions client/my-sites/plugins/plugins-dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { PluginActionName, PluginActions, Site } from '../hooks/types';
import { withShowPluginActionDialog } from '../hooks/use-show-plugin-action-dialog';
import PluginAvailableOnSitesList from '../plugin-management-v2/plugin-details-v2/plugin-available-on-sites-list';
import SitesWithInstalledPluginsList from '../plugin-management-v2/plugin-details-v2/sites-with-installed-plugin-list';
import { PluginComponentProps } from '../plugin-management-v2/types';
import PluginsListDataViews from '../plugins-list/plugins-list-dataviews';
import type { SiteDetails } from '@automattic/data-stores';
import type { Plugin } from 'calypso/state/plugins/installed/types';
Expand Down Expand Up @@ -115,8 +116,8 @@ const PluginsDashboard = ( {
const productsList = useSelector( ( state ) => getProductsList( state ) );
const { data: dotComPlugins }: { data: Plugin[] | undefined } = useWPCOMPluginsList( 'all' );
const allPlugins = useSelector( ( state ) =>
getPlugins( state, siteIds, 'all' ).map( ( plugin: Plugin ) => {
let dotComPluginData: Plugin | undefined;
getPlugins( state, siteIds, 'all' ).map( ( plugin: PluginComponentProps ) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using PluginComponentProps as a type as it contains the isMarketplaceProduct property and it does not need to be added to the Plugin type below.

let dotComPluginData: PluginComponentProps | undefined;
if ( dotComPlugins ) {
dotComPluginData = dotComPlugins.find(
( dotComPlugin ) => dotComPlugin.slug === plugin.slug
Expand Down
1 change: 0 additions & 1 deletion client/state/plugins/installed/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export type Plugin = {
wporg?: boolean;
status?: Array< number >;
allStatuses?: Array< CurrentSiteStatus >;
isMarketplaceProduct?: boolean;
};

export type PluginSite = {
Expand Down
Loading