Skip to content

Commit

Permalink
A4A: Sites Dashboard - Update and adds some improvements to the route…
Browse files Browse the repository at this point in the history
…s code (#88800)

* constants.js rename by constants.ts

* Remove the A4A_SITES_DASHBOARD_DEFAULT_FEATURE constant

* Add the missing key prop to NavITem

* Move out the component the filtersMap constant

* setSelectedSiteFeature method should accept undefined

* Improve the Jetpack Preview Pane. Set Boost as the default selected tab

* Move the Activity Preview Pane code to its own folder with the style.scss file

* Add the missing siteId prop to the ActivityCardList

We were getting a Warning in the console.
  • Loading branch information
cleacos authored Mar 25, 2024
1 parent 91e777d commit 7e62f53
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 77 deletions.
2 changes: 0 additions & 2 deletions client/a8c-for-agencies/sections/sites/constants.js

This file was deleted.

1 change: 1 addition & 0 deletions client/a8c-for-agencies/sections/sites/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const A4A_SITES_DASHBOARD_DEFAULT_CATEGORY = 'overview';
3 changes: 1 addition & 2 deletions client/a8c-for-agencies/sections/sites/controller.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Context, type Callback } from '@automattic/calypso-router';
import { setAllSitesSelected } from 'calypso/state/ui/actions';
import SitesSidebar from '../../components/sidebar-menu/sites';
import { A4A_SITES_DASHBOARD_DEFAULT_FEATURE } from './constants';
import SitesDashboard from './sites-dashboard';
import { SitesDashboardProvider } from './sites-dashboard-provider';

function configureSitesContext( isFavorites: boolean, context: Context ) {
const category = context.params.category;
const siteUrl = context.params.siteUrl;
const siteFeature = context.params.feature || A4A_SITES_DASHBOARD_DEFAULT_FEATURE;
const siteFeature = context.params.feature;
const hideListingInitialState = !! siteUrl;

const { s: search, page: contextPage, issue_types, sort_field, sort_direction } = context.query;
Expand Down
39 changes: 13 additions & 26 deletions client/a8c-for-agencies/sections/sites/sites-dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import page from '@automattic/calypso-router';
import { isWithinBreakpoint } from '@automattic/viewport';
import classNames from 'classnames';
import { translate } from 'i18n-calypso';
import React, { useContext, useEffect, useState, useMemo, useCallback } from 'react';
import React, { useContext, useEffect, useState, useCallback } from 'react';
import Layout from 'calypso/a8c-for-agencies/components/layout';
import LayoutColumn from 'calypso/a8c-for-agencies/components/layout/column';
import LayoutHeader, {
Expand Down Expand Up @@ -32,15 +32,22 @@ import { checkIfJetpackSiteGotDisconnected } from 'calypso/state/jetpack-agency-
import useProductsQuery from 'calypso/state/partner-portal/licenses/hooks/use-products-query';
import { getIsPartnerOAuthTokenLoaded } from 'calypso/state/partner-portal/partner/selectors';
import { setSelectedSiteId } from 'calypso/state/ui/actions';
import {
A4A_SITES_DASHBOARD_DEFAULT_CATEGORY,
A4A_SITES_DASHBOARD_DEFAULT_FEATURE,
} from '../constants';
import { A4A_SITES_DASHBOARD_DEFAULT_CATEGORY } from '../constants';
import SitesDashboardContext from '../sites-dashboard-context';
import SiteNotifications from '../sites-notifications';

import './style.scss';

const filtersMap: AgencyDashboardFilterMap[] = [
{ filterType: 'all_issues', ref: 1 },
{ filterType: 'backup_failed', ref: 2 },
{ filterType: 'backup_warning', ref: 3 },
{ filterType: 'threats_found', ref: 4 },
{ filterType: 'site_disconnected', ref: 5 },
{ filterType: 'site_down', ref: 6 },
{ filterType: 'plugin_updates', ref: 7 },
];

export default function SitesDashboard() {
useQueryJetpackPartnerPortalPartner();
const jetpackSiteDisconnected = useSelector( checkIfJetpackSiteGotDisconnected );
Expand All @@ -54,19 +61,6 @@ export default function SitesDashboard() {
setSelectedCategory: setCategory,
} = useContext( SitesDashboardContext );

const filtersMap = useMemo< AgencyDashboardFilterMap[] >(
() => [
{ filterType: 'all_issues', ref: 1 },
{ filterType: 'backup_failed', ref: 2 },
{ filterType: 'backup_warning', ref: 3 },
{ filterType: 'threats_found', ref: 4 },
{ filterType: 'site_disconnected', ref: 5 },
{ filterType: 'site_down', ref: 6 },
{ filterType: 'plugin_updates', ref: 7 },
],
[]
);

const isLargeScreen = isWithinBreakpoint( '>960px' );
const { data: products } = useProductsQuery();
const isPartnerOAuthTokenLoaded = useSelector( getIsPartnerOAuthTokenLoaded );
Expand Down Expand Up @@ -147,12 +141,7 @@ export default function SitesDashboard() {
// We need a category in the URL if we have a selected site
if ( sitesViewState.selectedSite && ! category ) {
setCategory( A4A_SITES_DASHBOARD_DEFAULT_CATEGORY );
} else if (
category &&
sitesViewState.selectedSite &&
selectedSiteFeature &&
selectedSiteFeature !== A4A_SITES_DASHBOARD_DEFAULT_FEATURE // If the selected feature is the default one, we can leave the url a little cleaner.
) {
} else if ( category && sitesViewState.selectedSite && selectedSiteFeature ) {
page.replace(
`/sites/${ category }/${ sitesViewState.selectedSite.url }/${ selectedSiteFeature }`
);
Expand All @@ -173,8 +162,6 @@ export default function SitesDashboard() {
const closeSitePreviewPane = useCallback( () => {
if ( sitesViewState.selectedSite ) {
setSitesViewState( { ...sitesViewState, type: 'table', selectedSite: undefined } );
// We reset the feature to its default upon closing, instead of setting it to undefined. This way, when users switch sites while a site is selected, the feature remains consistent.
setSelectedSiteFeature( A4A_SITES_DASHBOARD_DEFAULT_FEATURE );
}
}, [ sitesViewState, setSelectedSiteFeature ] );

Expand Down
2 changes: 1 addition & 1 deletion client/a8c-for-agencies/sections/sites/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface SitesDashboardContextInterface {
setSelectedSiteUrl: ( siteUrl: string ) => void;

selectedSiteFeature?: string;
setSelectedSiteFeature: ( siteFeature: string ) => void;
setSelectedSiteFeature: ( siteFeature: string | undefined ) => void;

hideListing?: boolean;
setHideListing: ( hideListing: boolean ) => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import ActivityLogV2 from 'calypso/my-sites/activity/activity-log-v2';
import SitePreviewPaneContent from '../../site-preview-pane/site-preview-pane-content';

import 'calypso/my-sites/activity/activity-log-v2/style.scss';
import './style.scss';

export function JetpackActivityPreview() {
return (
<SitePreviewPaneContent>
<ActivityLogV2 />
</SitePreviewPaneContent>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.activity-log-v2 {
text-align: left;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { useTranslate } from 'i18n-calypso';
import React, { useCallback, useContext, useEffect, useMemo } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import SitesDashboardContext from 'calypso/a8c-for-agencies/sections/sites/sites-dashboard-context';
import { setSelectedSiteId } from 'calypso/state/ui/actions';
import { getSelectedSiteId } from 'calypso/state/ui/selectors';
import { useJetpackAgencyDashboardRecordTrackEvent } from '../../hooks';
import SitePreviewPane, { createFeaturePreview } from '../site-preview-pane';
import { SitePreviewPaneProps } from '../site-preview-pane/types';
import { JetpackActivityPreview } from './jetpack-activity';
import { JetpackActivityPreview } from './activity';
import { JetpackBackupPreview } from './jetpack-backup';
import { JetpackBoostPreview } from './jetpack-boost';
import { JetpackMonitorPreview } from './jetpack-monitor';
Expand All @@ -25,15 +22,6 @@ export function JetpackPreviewPane( {
const translate = useTranslate();
const recordEvent = useJetpackAgencyDashboardRecordTrackEvent( [ site ], ! isSmallScreen );

const dispatch = useDispatch();
const selectedSiteId = useSelector( getSelectedSiteId );

useEffect( () => {
if ( site ) {
dispatch( setSelectedSiteId( site.blog_id ) );
}
}, [ dispatch, site ] );

const trackEvent = useCallback(
( eventName: string ) => {
recordEvent( eventName );
Expand All @@ -43,14 +31,23 @@ export function JetpackPreviewPane( {

const { selectedSiteFeature, setSelectedSiteFeature } = useContext( SitesDashboardContext );

useEffect( () => {
if ( selectedSiteFeature === undefined ) {
setSelectedSiteFeature( 'jetpack_boost' );
}
return () => {
setSelectedSiteFeature( undefined );
};
}, [] );

// Jetpack features: Boost, Backup, Monitor, Stats
const features = useMemo(
() => [
createFeaturePreview(
'jetpack_boost',
'Boost',
true,
selectedSiteFeature,
selectedSiteFeature ?? 'jetpack_boost',
setSelectedSiteFeature,
<JetpackBoostPreview site={ site } trackEvent={ trackEvent } hasError={ hasError } />
),
Expand Down Expand Up @@ -106,18 +103,10 @@ export function JetpackPreviewPane( {
true,
selectedSiteFeature,
setSelectedSiteFeature,
<JetpackActivityPreview isLoading={ ! selectedSiteId } />
<JetpackActivityPreview />
),
],
[
selectedSiteFeature,
setSelectedSiteFeature,
site,
trackEvent,
hasError,
translate,
selectedSiteId,
]
[ selectedSiteFeature, setSelectedSiteFeature, site, trackEvent, hasError, translate ]
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export default function SitePreviewPane( {
return null;
}
return (
<NavItem selected={ featureTab.selected } onClick={ featureTab.onClick }>
<NavItem
key={ featureTab.key }
selected={ featureTab.selected }
onClick={ featureTab.onClick }
>
{ featureTab.label }
</NavItem>
);
Expand Down
7 changes: 6 additions & 1 deletion client/my-sites/activity/activity-log-v2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ const ActivityLogV2: FunctionComponent = () => {
/>
) }
<div className="activity-log-v2__content">
<ActivityCardList logs={ logs } pageSize={ 10 } showFilter={ siteHasFullActivityLog } />
<ActivityCardList
logs={ logs }
pageSize={ 10 }
showFilter={ siteHasFullActivityLog }
siteId={ siteId }
/>
</div>
</Main>
);
Expand Down

0 comments on commit 7e62f53

Please sign in to comment.