import { WIDE_BREAKPOINT } from '@automattic/viewport'; import { useBreakpoint } from '@automattic/viewport-react'; import { Button, Tooltip, FormToggle } from '@wordpress/components'; import { chevronDown, chevronRight, Icon, info } from '@wordpress/icons'; import { useTranslate } from 'i18n-calypso'; import { useState } from 'react'; import { useDateTimeFormat } from 'calypso/blocks/plugin-scheduled-updates-common/hooks/use-date-time-format'; import { usePrepareMultisitePluginsTooltipInfo } from 'calypso/blocks/plugin-scheduled-updates-common/hooks/use-prepare-plugins-tooltip-info'; import { usePrepareScheduleName } from 'calypso/blocks/plugin-scheduled-updates-common/hooks/use-prepare-schedule-name'; import { usePrepareSitesTooltipInfo } from 'calypso/blocks/plugins-scheduled-updates-multisite/hooks/use-prepare-sites-tooltip-info'; import { ScheduleListLastRunStatus } from 'calypso/blocks/plugins-scheduled-updates-multisite/schedule-list-last-run-status'; import { useScheduledUpdatesActivateBatchMutation } from 'calypso/data/plugins/use-scheduled-updates-activate-batch-mutation'; import { SiteSlug } from 'calypso/types'; import { ScheduleListTableRowMenu } from './schedule-list-table-row-menu'; import type { MultisiteSchedulesUpdates, ScheduleUpdates, } from 'calypso/data/plugins/use-update-schedules-query'; type Props = { schedule: MultisiteSchedulesUpdates; onEditClick: ( id: string ) => void; onRemoveClick: ( id: string ) => void; onLogsClick: ( id: string, siteSlug: SiteSlug ) => void; }; export const ScheduleListTableRow = ( props: Props ) => { const { schedule, onEditClick, onLogsClick } = props; const isWideScreen = useBreakpoint( WIDE_BREAKPOINT ); const { prepareSitesTooltipInfo } = usePrepareSitesTooltipInfo(); const { prepareScheduleName } = usePrepareScheduleName(); const { prepareDateTime } = useDateTimeFormat(); const { preparePluginsTooltipInfo, countInstalledPlugins } = usePrepareMultisitePluginsTooltipInfo( schedule.sites.map( ( site ) => site.ID ) ); const translate = useTranslate(); const [ isExpanded, setIsExpanded ] = useState( false ); const { activateSchedule } = useScheduledUpdatesActivateBatchMutation(); const batchActiveState = schedule.sites.some( ( site ) => site.active ); return ( <> { schedule.sites.length }{ ' ' } { prepareDateTime( schedule.timestamp, ! isWideScreen ? 'M d,' : undefined ) } { { daily: translate( 'Daily' ), weekly: translate( 'Weekly' ), }[ schedule.schedule ] } { countInstalledPlugins( schedule.args ) }{ ' ' } { activateSchedule( schedule.sites.map( ( site ) => ( { id: site.ID, slug: site.slug } ) ), schedule.schedule_id, { active: e.target.checked } ); } } /> { isExpanded && schedule.sites.map( ( site ) => ( { site.title } activateSchedule( [ { id: site.ID, slug: site.slug } ], schedule.schedule_id, { active: e.target.checked, } ) } /> ) ) } ); };