From 8ff191c84d2a9ae86289f0c855f5f1a3b0603497 Mon Sep 17 00:00:00 2001 From: okmttdhr Date: Mon, 25 Nov 2024 13:45:34 +0900 Subject: [PATCH] Hide Overview action in the list view --- .../components/sites-dataviews/actions.tsx | 63 ++++++++++--------- .../components/sites-dataviews/index.tsx | 6 +- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/client/sites/components/sites-dataviews/actions.tsx b/client/sites/components/sites-dataviews/actions.tsx index d6b5c859ffefe..9581c150a6690 100644 --- a/client/sites/components/sites-dataviews/actions.tsx +++ b/client/sites/components/sites-dataviews/actions.tsx @@ -34,12 +34,14 @@ import type { Action } from '@wordpress/dataviews'; export function useActions( { openSitePreviewPane, selectedItem, + viewType, }: { openSitePreviewPane?: ( site: SiteExcerptData, source: 'site_field' | 'action' | 'list_row_click' | 'environment_switcher' ) => void; selectedItem?: SiteExcerptData | null; + viewType: 'list' | 'table'; } ): Action< SiteExcerptData >[] { const { __ } = useI18n(); const dispatch = useReduxDispatch(); @@ -98,36 +100,37 @@ export function useActions( { return useMemo( () => [ - { - id: 'site-overview', - isPrimary: true, - label: __( 'Overview' ), - icon: drawerLeft, - callback: ( sites ) => { - const site = sites[ 0 ]; - const adminUrl = site.options?.admin_url ?? ''; - const isAdmin = capabilities[ site.ID ]?.manage_options; - if ( - isAdmin && - ! isP2Site( site ) && - ! isNotAtomicJetpack( site ) && - ! isDisconnectedJetpackAndNotAtomic( site ) - ) { - openSitePreviewPane && openSitePreviewPane( site, 'action' ); - } else { - navigate( adminUrl ); - } - }, - isEligible: ( site ) => { - if ( site.ID === selectedItem?.ID ) { - return false; - } - if ( site.is_deleted ) { - return false; - } - return true; - }, - }, + ...( viewType !== 'list' + ? [ + { + id: 'site-overview', + isPrimary: true, + label: __( 'Overview' ), + icon: drawerLeft, + callback: ( sites: SiteExcerptData[] ) => { + const site = sites[ 0 ]; + const adminUrl = site.options?.admin_url ?? ''; + const isAdmin = capabilities[ site.ID ]?.manage_options; + if ( + isAdmin && + ! isP2Site( site ) && + ! isNotAtomicJetpack( site ) && + ! isDisconnectedJetpackAndNotAtomic( site ) + ) { + openSitePreviewPane && openSitePreviewPane( site, 'action' ); + } else { + navigate( adminUrl ); + } + }, + isEligible: ( site: SiteExcerptData ) => { + if ( site.is_deleted ) { + return false; + } + return true; + }, + }, + ] + : [] ), { id: 'open-site', isPrimary: true, diff --git a/client/sites/components/sites-dataviews/index.tsx b/client/sites/components/sites-dataviews/index.tsx index 6bebaa232ce6f..0e3e945c14949 100644 --- a/client/sites/components/sites-dataviews/index.tsx +++ b/client/sites/components/sites-dataviews/index.tsx @@ -184,7 +184,11 @@ const DotcomSitesDataViews = ( { [ __, openSitePreviewPane, userId, siteStatusGroups ] ); - const actions = useActions( { openSitePreviewPane, selectedItem } ); + const actions = useActions( { + openSitePreviewPane, + selectedItem, + viewType: dataViewsState.type, + } ); return (