import { Card } from '@automattic/components'; import { localize } from 'i18n-calypso'; import PropTypes from 'prop-types'; import { Component, Fragment } from 'react'; import { connect } from 'react-redux'; import QuerySiteSettings from 'calypso/components/data/query-site-settings'; import QuerySites from 'calypso/components/data/query-sites'; import { withLocalizedMoment } from 'calypso/components/localized-moment'; import Pagination from 'calypso/components/pagination'; import TileGrid from 'calypso/components/tile-grid'; import Tile from 'calypso/components/tile-grid/tile'; import useRewindableActivityLogQuery from 'calypso/data/activity-log/use-rewindable-activity-log-query'; import { applySiteOffset } from 'calypso/lib/site/timezone'; import ActivityLogItem from 'calypso/my-sites/activity/activity-log-item'; import StepWrapper from 'calypso/signup/step-wrapper'; import { submitSignupStep } from 'calypso/state/signup/progress/actions'; import { getSiteOption } from 'calypso/state/sites/selectors'; import './style.scss'; const PAGE_SIZE = 20; class ClonePointStep extends Component { static propTypes = { flowName: PropTypes.string, goToNextStep: PropTypes.func.isRequired, positionInFlow: PropTypes.number, stepName: PropTypes.string, signupDependencies: PropTypes.object, }; state = { showLog: false, currentPage: 1, }; selectCurrent = () => { this.props.submitSignupStep( { stepName: this.props.stepName }, { clonePoint: 0 } ); this.props.goToNextStep(); }; selectedPoint = ( activityTs ) => { this.props.submitSignupStep( { stepName: this.props.stepName }, { clonePoint: activityTs } ); this.props.goToNextStep(); }; selectPrevious = () => { this.setState( { showLog: true } ); }; applySiteOffset( date ) { const { timezone, gmtOffset } = this.props; return applySiteOffset( date, { timezone, gmtOffset } ); } changePage = ( pageNumber ) => { this.setState( { currentPage: pageNumber } ); window.scrollTo( 0, 0 ); }; renderActivityLog() { const { siteId, logs, moment, translate } = this.props; const actualPage = Math.max( 1, Math.min( this.state.currentPage, Math.ceil( logs.length / PAGE_SIZE ) ) ); const theseLogs = logs.slice( ( actualPage - 1 ) * PAGE_SIZE, actualPage * PAGE_SIZE ); const timePeriod = ( () => { const today = this.applySiteOffset( moment() ); let last = null; return ( { rewindId } ) => { const ts = this.applySiteOffset( moment( rewindId * 1000 ) ); if ( null === last || ! ts.isSame( last, 'day' ) ) { last = ts; return (