|
| 1 | +import { HostingFeatures, LogType } from '@automattic/api-core'; |
| 2 | +import { siteBySlugQuery } from '@automattic/api-queries'; |
| 3 | +import { DateRangePicker } from '@automattic/date-range-picker'; |
| 4 | +import { useSuspenseQuery } from '@tanstack/react-query'; |
| 5 | +import { createInterpolateElement } from '@wordpress/element'; |
| 6 | +import { __ } from '@wordpress/i18n'; |
| 7 | +import { useState } from 'react'; |
| 8 | +import { useDateRange } from '../../../app/hooks/use-date-range'; |
| 9 | +import { useSiteTimezoneWithJetpackFallback } from '../../../app/hooks/use-site-timezone'; |
| 10 | +import { useLocale } from '../../../app/locale'; |
| 11 | +import { agencySiteActivityRoute, agencySiteRoute } from '../../../app/router/agency'; |
| 12 | +import { Card, CardBody } from '../../../components/card'; |
| 13 | +import InlineSupportLink from '../../../components/inline-support-link'; |
| 14 | +import { PageHeader } from '../../../components/page-header'; |
| 15 | +import PageLayout from '../../../components/page-layout'; |
| 16 | +import SiteActivityLogsDataViews from '../../../sites/logs-activity/dataviews'; |
| 17 | +import { hasHostingFeature, hasPlanFeature } from '../../../utils/site-features'; |
| 18 | + |
| 19 | +export default function AgencySiteActivity() { |
| 20 | + const { siteSlug } = agencySiteRoute.useParams(); |
| 21 | + const { data: site } = useSuspenseQuery( siteBySlugQuery( siteSlug ) ); |
| 22 | + const { gmtOffset, timezoneString } = useSiteTimezoneWithJetpackFallback( site ); |
| 23 | + |
| 24 | + const locale = useLocale(); |
| 25 | + const searchParams = agencySiteActivityRoute.useSearch(); |
| 26 | + |
| 27 | + // Activity has no auto-refresh, but the shared DataViews props require this state. |
| 28 | + const [ autoRefresh, setAutoRefresh ] = useState( false ); |
| 29 | + const { dateRange, handleDateRangeChange } = useDateRange( { |
| 30 | + timezoneString, |
| 31 | + gmtOffset, |
| 32 | + autoRefresh, |
| 33 | + } ); |
| 34 | + const [ dateRangeVersion, setDateRangeVersion ] = useState( 0 ); |
| 35 | + |
| 36 | + const handleDateRangeChangeWrapper = ( next: { start: Date; end: Date } ) => { |
| 37 | + handleDateRangeChange( next ); |
| 38 | + setDateRangeVersion( ( v ) => v + 1 ); |
| 39 | + }; |
| 40 | + |
| 41 | + const hasActivityLogAccess = |
| 42 | + hasHostingFeature( site, HostingFeatures.ACTIVITY_LOG ) || |
| 43 | + hasPlanFeature( site, HostingFeatures.ACTIVITY_LOG ); |
| 44 | + |
| 45 | + return ( |
| 46 | + <PageLayout |
| 47 | + header={ |
| 48 | + <PageHeader |
| 49 | + title={ __( 'Activity' ) } |
| 50 | + description={ createInterpolateElement( |
| 51 | + __( 'View your site’s activity log. <learnMoreLink />' ), |
| 52 | + { |
| 53 | + learnMoreLink: <InlineSupportLink supportContext="site-monitoring-logs" />, |
| 54 | + } |
| 55 | + ) } |
| 56 | + actions={ |
| 57 | + <DateRangePicker |
| 58 | + start={ dateRange.start } |
| 59 | + end={ dateRange.end } |
| 60 | + gmtOffset={ gmtOffset } |
| 61 | + timezoneString={ timezoneString } |
| 62 | + locale={ locale } |
| 63 | + onChange={ handleDateRangeChangeWrapper } |
| 64 | + /> |
| 65 | + } |
| 66 | + /> |
| 67 | + } |
| 68 | + > |
| 69 | + <Card className="site-logs-card site-logs-card--activity"> |
| 70 | + <CardBody> |
| 71 | + { /* TODO(A4A-2917): the reused activity DataViews shows a primary "Manage backup" |
| 72 | + row action on rewindable entries that navigates to the dotcom |
| 73 | + siteBackupDetailRoute, which A4A doesn't register — it dead-ends until |
| 74 | + agency backups routes exist. Hide or re-point it once backups land. */ } |
| 75 | + <SiteActivityLogsDataViews |
| 76 | + logType={ LogType.ACTIVITY } |
| 77 | + dateRange={ dateRange } |
| 78 | + dateRangeVersion={ dateRangeVersion } |
| 79 | + autoRefresh={ autoRefresh } |
| 80 | + setAutoRefresh={ setAutoRefresh } |
| 81 | + gmtOffset={ gmtOffset } |
| 82 | + timezoneString={ timezoneString } |
| 83 | + site={ site } |
| 84 | + hasActivityLogsAccess={ hasActivityLogAccess } |
| 85 | + searchParams={ searchParams } |
| 86 | + /> |
| 87 | + </CardBody> |
| 88 | + </Card> |
| 89 | + </PageLayout> |
| 90 | + ); |
| 91 | +} |
0 commit comments