import { WIDE_BREAKPOINT } from '@automattic/viewport'; import { useBreakpoint } from '@automattic/viewport-react'; import { Button, DropdownMenu, Tooltip, FormToggle } from '@wordpress/components'; import { Icon, info } from '@wordpress/icons'; import { useTranslate } from 'i18n-calypso'; import { useScheduledUpdatesActivateMutation } from 'calypso/data/plugins/use-scheduled-updates-activate-mutation'; import { useUpdateScheduleQuery } from 'calypso/data/plugins/use-update-schedules-query'; import { Badge } from '../plugin-scheduled-updates-common/badge'; import { useDateTimeFormat } from '../plugin-scheduled-updates-common/hooks/use-date-time-format'; import { usePreparePluginsTooltipInfo } from '../plugin-scheduled-updates-common/hooks/use-prepare-plugins-tooltip-info'; import { usePrepareScheduleName } from '../plugin-scheduled-updates-common/hooks/use-prepare-schedule-name'; import { useIsEligibleForFeature } from './hooks/use-is-eligible-for-feature'; import { useSiteSlug } from './hooks/use-site-slug'; import { ellipsis } from './icons'; interface Props { onEditClick: ( id: string ) => void; onRemoveClick: ( id: string ) => void; onShowLogs: ( id: string ) => void; } export const ScheduleListTable = ( props: Props ) => { const siteSlug = useSiteSlug(); const translate = useTranslate(); const { isEligibleForFeature } = useIsEligibleForFeature(); const isWideScreen = useBreakpoint( WIDE_BREAKPOINT ); const { onEditClick, onRemoveClick, onShowLogs } = props; const { data: schedules = [] } = useUpdateScheduleQuery( siteSlug, isEligibleForFeature ); const { countInstalledPlugins, preparePluginsTooltipInfo } = usePreparePluginsTooltipInfo( siteSlug ); const { prepareScheduleName } = usePrepareScheduleName(); const { prepareDateTime } = useDateTimeFormat( siteSlug ); const { activateSchedule } = useScheduledUpdatesActivateMutation(); /** * NOTE: If you update the table structure, * make sure to update the ScheduleListCards component as well */ return ( { schedules.map( ( schedule ) => ( ) ) }
{ translate( 'Name' ) } { translate( 'Last update' ) } { translate( 'Next update' ) } { translate( 'Frequency' ) } { translate( 'Plugins' ) } { translate( 'Active' ) }
{ schedule.last_run_status && ( <> { ( schedule.last_run_timestamp || schedule.last_run_status === 'in-progress' ) && ( ) } ) } { ! schedule.last_run_status && ! schedule.last_run_timestamp && '-' } { prepareDateTime( schedule.timestamp ) } { { daily: translate( 'Daily' ), weekly: translate( 'Weekly' ), }[ schedule.schedule ] } { countInstalledPlugins( schedule.args ) } { schedule?.args && ( ) } activateSchedule( siteSlug, schedule.id, { active: e.target.checked } ) } /> onEditClick( schedule.id ), }, { title: translate( 'Logs' ), onClick: () => onShowLogs( schedule.id ), }, { title: translate( 'Remove' ), onClick: () => onRemoveClick( schedule.id ), }, ] } icon={ ellipsis } label={ translate( 'More' ) } />
); };