Skip to content

Commit

Permalink
Activity Log: Get display rules from real API endpoint (#55542)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgawarecki authored Sep 6, 2021
1 parent 53f3ca4 commit c23f47c
Show file tree
Hide file tree
Showing 23 changed files with 207 additions and 183 deletions.
23 changes: 12 additions & 11 deletions client/components/activity-card-list/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import ActivityCard from 'calypso/components/activity-card';
import QueryActivityLogDisplayRules from 'calypso/components/data/query-activity-log-display-rules';
import QueryRewindCapabilities from 'calypso/components/data/query-rewind-capabilities';
import QueryRewindPolicies from 'calypso/components/data/query-rewind-policies';
import QueryRewindState from 'calypso/components/data/query-rewind-state';
import { withLocalizedMoment } from 'calypso/components/localized-moment';
import Pagination from 'calypso/components/pagination';
Expand All @@ -16,9 +16,9 @@ import { isActivityBackup } from 'calypso/lib/jetpack/backup-utils';
import Filterbar from 'calypso/my-sites/activity/filterbar';
import { updateFilter } from 'calypso/state/activity-log/actions';
import { getCurrentUserLocale } from 'calypso/state/current-user/selectors';
import getActivityLogDisplayRulesRequestStatus from 'calypso/state/selectors/get-activity-log-display-rules-request-status';
import getActivityLogVisibleDays from 'calypso/state/rewind/selectors/get-activity-log-visible-days';
import getRewindPoliciesRequestStatus from 'calypso/state/rewind/selectors/get-rewind-policies-request-status';
import getActivityLogFilter from 'calypso/state/selectors/get-activity-log-filter';
import getActivityLogVisibleDays from 'calypso/state/selectors/get-activity-log-visible-days';
import { getSelectedSiteId, getSelectedSiteSlug } from 'calypso/state/ui/selectors';
import VisibleDaysLimitUpsell from './visible-days-limit-upsell';

Expand Down Expand Up @@ -250,23 +250,24 @@ class ActivityCardList extends Component {
render() {
const {
displayRulesEnabled,
requestingDisplayRules,
displayRulesRequestError,
requestingRewindPolicies,
rewindPoliciesRequestError,
siteId,
logs,
} = this.props;

if ( displayRulesEnabled && displayRulesRequestError ) {
if ( displayRulesEnabled && rewindPoliciesRequestError ) {
return this.renderLoading();
}

return (
<>
{ displayRulesEnabled && <QueryActivityLogDisplayRules siteId={ siteId } /> }
{ displayRulesEnabled && <QueryRewindPolicies siteId={ siteId } /> }
<QueryRewindCapabilities siteId={ siteId } />
<QueryRewindState siteId={ siteId } />

{ ( ! logs || ( displayRulesEnabled && requestingDisplayRules ) ) && this.renderLoading() }
{ ( ! logs || ( displayRulesEnabled && requestingRewindPolicies ) ) &&
this.renderLoading() }
{ logs && this.renderData() }
</>
);
Expand All @@ -281,13 +282,13 @@ const mapStateToProps = ( state ) => {
const userLocale = getCurrentUserLocale( state );
const visibleDays = getActivityLogVisibleDays( state, siteId );

const displayRulesRequestStatus = getActivityLogDisplayRulesRequestStatus( state, siteId );
const rewindPoliciesRequestStatus = getRewindPoliciesRequestStatus( state, siteId );

return {
filter,
displayRulesEnabled: isEnabled( 'activity-log/display-rules' ),
requestingDisplayRules: displayRulesRequestStatus === 'pending',
displayRulesRequestError: displayRulesRequestStatus === 'failure',
requestingRewindPolicies: rewindPoliciesRequestStatus === 'pending',
rewindPoliciesRequestError: rewindPoliciesRequestStatus === 'failure',
visibleDays,
siteId,
siteSlug,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ActivityCard from 'calypso/components/activity-card';
import { preventWidows } from 'calypso/lib/formatting/prevent-widows';
import isJetpackCloud from 'calypso/lib/jetpack/is-jetpack-cloud';
import ActivityLogItem from 'calypso/my-sites/activity/activity-log-item';
import getActivityLogVisibleDays from 'calypso/state/selectors/get-activity-log-visible-days';
import getActivityLogVisibleDays from 'calypso/state/rewind/selectors/get-activity-log-visible-days';
import { getSelectedSiteId, getSelectedSiteSlug } from 'calypso/state/ui/selectors';
import { useTrackUpsellView, useTrackUpgradeClick } from './hooks';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { requestDisplayRules } from 'calypso/state/activity-log/display-rules/actions';
import isRequestingActivityLogDisplayRules from 'calypso/state/selectors/is-requesting-activity-log-display-rules';
import { requestPolicies } from 'calypso/state/rewind/policies/actions';
import isRequestingRewindPolicies from 'calypso/state/rewind/selectors/is-requesting-rewind-policies';
import type { AppState } from 'calypso/types';

const useRequestActivityLogDisplayRules = ( siteId: number ) => {
export const useRequestRewindPolicies = ( siteId: number ): void => {
const dispatch = useDispatch();
const requesting = useSelector( ( state: AppState ) =>
isRequestingActivityLogDisplayRules( state, siteId )
isRequestingRewindPolicies( state, siteId )
);

useEffect(
Expand All @@ -16,7 +16,7 @@ const useRequestActivityLogDisplayRules = ( siteId: number ) => {
return;
}

dispatch( requestDisplayRules( siteId ) );
dispatch( requestPolicies( siteId ) );
},

// `requesting` is technically a dependency but we exclude it here;
Expand All @@ -28,14 +28,14 @@ const useRequestActivityLogDisplayRules = ( siteId: number ) => {
};

// TODO: Remove this component once ActivityCardList can call hooks,
// then extract `useRequestActivityLogDisplayRules` into its own file
// then extract `useRequestRewindPolicies` into its own file
type OwnProps = {
siteId: number;
};

const QueryActivityLogDisplayRules: React.FC< OwnProps > = ( { siteId } ) => {
useRequestActivityLogDisplayRules( siteId );
const QueryRewindPolicies: React.FC< OwnProps > = ( { siteId } ) => {
useRequestRewindPolicies( siteId );
return null;
};

export default QueryActivityLogDisplayRules;
export default QueryRewindPolicies;
4 changes: 2 additions & 2 deletions client/components/jetpack/daily-backup-status/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Card } from '@automattic/components';
import PropTypes from 'prop-types';
import React, { useCallback, useEffect, useRef } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import QueryActivityLogDisplayRules from 'calypso/components/data/query-activity-log-display-rules';
import QueryRewindBackups from 'calypso/components/data/query-rewind-backups';
import QueryRewindPolicies from 'calypso/components/data/query-rewind-policies';
import { useLocalizedMoment } from 'calypso/components/localized-moment';
import { Interval, EVERY_SECOND } from 'calypso/lib/interval';
import {
Expand Down Expand Up @@ -138,7 +138,7 @@ const Wrapper = ( props ) => {
// to see if there's a backup currently in progress
return (
<Card className="daily-backup-status">
{ displayRulesEnabled && <QueryActivityLogDisplayRules siteId={ siteId } /> }
{ displayRulesEnabled && <QueryRewindPolicies siteId={ siteId } /> }
<QueryRewindBackups siteId={ siteId } />
<DailyBackupStatus { ...props } />
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Button from 'calypso/components/forms/form-button';
import isJetpackCloud from 'calypso/lib/jetpack/is-jetpack-cloud';
import { applySiteOffset } from 'calypso/lib/site/timezone';
import { recordTracksEvent } from 'calypso/state/analytics/actions/record';
import getActivityLogVisibleDays from 'calypso/state/selectors/get-activity-log-visible-days';
import getActivityLogVisibleDays from 'calypso/state/rewind/selectors/get-activity-log-visible-days';
import getSiteGmtOffset from 'calypso/state/selectors/get-site-gmt-offset';
import getSiteTimezoneValue from 'calypso/state/selectors/get-site-timezone-value';
import { getSelectedSiteId, getSelectedSiteSlug } from 'calypso/state/ui/selectors';
Expand Down
14 changes: 8 additions & 6 deletions client/my-sites/activity/activity-log/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import { connect } from 'react-redux';
import TimeMismatchWarning from 'calypso/blocks/time-mismatch-warning';
import VisibleDaysLimitUpsell from 'calypso/components/activity-card-list/visible-days-limit-upsell';
import DocumentHead from 'calypso/components/data/document-head';
import QueryActivityLogDisplayRules from 'calypso/components/data/query-activity-log-display-rules';
import QueryJetpackPlugins from 'calypso/components/data/query-jetpack-plugins';
import QueryRewindBackupStatus from 'calypso/components/data/query-rewind-backup-status';
import QueryRewindBackups from 'calypso/components/data/query-rewind-backups';
import QueryRewindPolicies from 'calypso/components/data/query-rewind-policies';
import QueryRewindState from 'calypso/components/data/query-rewind-state';
import QuerySitePurchases from 'calypso/components/data/query-site-purchases';
import QuerySiteSettings from 'calypso/components/data/query-site-settings'; // For site time offset
Expand Down Expand Up @@ -47,9 +47,9 @@ import {
siteHasBackupProductPurchase,
siteHasScanProductPurchase,
} from 'calypso/state/purchases/selectors';
import getActivityLogDisplayRulesRequestStatus from 'calypso/state/selectors/get-activity-log-display-rules-request-status';
import getActivityLogVisibleDays from 'calypso/state/rewind/selectors/get-activity-log-visible-days';
import getRewindPoliciesRequestStatus from 'calypso/state/rewind/selectors/get-rewind-policies-request-status';
import getActivityLogFilter from 'calypso/state/selectors/get-activity-log-filter';
import getActivityLogVisibleDays from 'calypso/state/selectors/get-activity-log-visible-days';
import getBackupProgress from 'calypso/state/selectors/get-backup-progress';
import getRequestedBackup from 'calypso/state/selectors/get-requested-backup';
import getRequestedRewind from 'calypso/state/selectors/get-requested-rewind';
Expand Down Expand Up @@ -548,7 +548,9 @@ class ActivityLog extends Component {
<QuerySitePurchases siteId={ siteId } />
<PageViewTracker path="/activity-log/:site" title="Activity" />
<DocumentHead title={ translate( 'Activity' ) } />
{ siteId && <QueryActivityLogDisplayRules siteId={ siteId } /> }
{ siteId && isEnabled( 'activity-log/display-rules' ) && (
<QueryRewindPolicies siteId={ siteId } />
) }
{ siteId && <QueryRewindState siteId={ siteId } /> }
{ siteId && <QueryJetpackPlugins siteIds={ [ siteId ] } /> }
{ siteId && <TimeMismatchWarning siteId={ siteId } settingsUrl={ siteSettingsUrl } /> }
Expand Down Expand Up @@ -585,7 +587,7 @@ export default connect(

const displayRulesEnabled = isEnabled( 'activity-log/display-rules' );
const displayRulesLoaded = displayRulesEnabled
? getActivityLogDisplayRulesRequestStatus( state, siteId ) === 'success'
? getRewindPoliciesRequestStatus( state, siteId ) === 'success'
: true;
const visibleDays = displayRulesEnabled
? getActivityLogVisibleDays( state, siteId )
Expand Down Expand Up @@ -615,7 +617,7 @@ export default connect(
: allLogEntries;

const allLogsVisible = displayRulesEnabled
? visibleLogEntries.length < allLogEntries.length
? visibleLogEntries.length === allLogEntries.length
: false;

return {
Expand Down
2 changes: 1 addition & 1 deletion client/my-sites/backup/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { applySiteOffset } from 'calypso/lib/site/timezone';
import { getRequestActivityLogsId, requestActivityLogs } from 'calypso/state/data-getters';
import { getHttpData } from 'calypso/state/data-layer/http-data';
import { requestRewindCapabilities } from 'calypso/state/rewind/capabilities/actions';
import getActivityLogVisibleDays from 'calypso/state/selectors/get-activity-log-visible-days';
import getActivityLogVisibleDays from 'calypso/state/rewind/selectors/get-activity-log-visible-days';
import getRewindCapabilities from 'calypso/state/selectors/get-rewind-capabilities';
import getSiteGmtOffset from 'calypso/state/selectors/get-site-gmt-offset';
import getSiteTimezoneValue from 'calypso/state/selectors/get-site-timezone-value';
Expand Down
10 changes: 4 additions & 6 deletions client/state/action-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ export const ACTIVE_PROMOTIONS_RECEIVE = 'ACTIVE_PROMOTIONS_RECEIVE';
export const ACTIVE_PROMOTIONS_REQUEST = 'ACTIVE_PROMOTIONS_REQUEST';
export const ACTIVE_PROMOTIONS_REQUEST_FAILURE = 'ACTIVE_PROMOTIONS_REQUEST_FAILURE';
export const ACTIVE_PROMOTIONS_REQUEST_SUCCESS = 'ACTIVE_PROMOTIONS_REQUEST_SUCCESS';
export const ACTIVITY_LOG_DISPLAY_RULES_REQUEST = 'ACTIVITY_LOG_DISPLAY_RULES_REQUEST';
export const ACTIVITY_LOG_DISPLAY_RULES_REQUEST_FAILURE =
'ACTIVITY_LOG_DISPLAY_RULES_REQUEST_FAILURE';
export const ACTIVITY_LOG_DISPLAY_RULES_REQUEST_SUCCESS =
'ACTIVITY_LOG_DISPLAY_RULES_REQUEST_SUCCESS';
export const ACTIVITY_LOG_DISPLAY_RULES_SET = 'ACTIVITY_LOG_DISPLAY_RULES_SET';
export const ACTIVITY_LOG_FILTER_SET = 'ACTIVITY_LOG_FILTER_SET';
export const ACTIVITY_LOG_FILTER_UPDATE = 'ACTIVITY_LOG_FILTER_UPDATE';
export const ADMIN_MENU_RECEIVE = 'ADMIN_MENU_RECEIVE';
Expand Down Expand Up @@ -840,6 +834,10 @@ export const REWIND_CLONE = 'REWIND_CLONE';
export const REWIND_DEACTIVATE_FAILURE = 'REWIND_DEACTIVATE_FAILURE';
export const REWIND_DEACTIVATE_REQUEST = 'REWIND_DEACTIVATE_REQUEST';
export const REWIND_DEACTIVATE_SUCCESS = 'REWIND_DEACTIVATE_SUCCESS';
export const REWIND_POLICIES_REQUEST = 'REWIND_POLICIES_REQUEST';
export const REWIND_POLICIES_REQUEST_FAILURE = 'REWIND_POLICIES_REQUEST_FAILURE';
export const REWIND_POLICIES_REQUEST_SUCCESS = 'REWIND_POLICIES_REQUEST_SUCCESS';
export const REWIND_POLICIES_SET = 'REWIND_POLICIES_SET';
export const REWIND_RESTORE = 'REWIND_RESTORE';
export const REWIND_RESTORE_DISMISS = 'REWIND_RESTORE_DISMISS';
export const REWIND_RESTORE_DISMISS_PROGRESS = 'REWIND_RESTORE_DISMISS_PROGRESS';
Expand Down
2 changes: 0 additions & 2 deletions client/state/activity-log/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ import 'calypso/state/data-layer/wpcom/sites/rewind/downloads';
import 'calypso/state/data-layer/wpcom/sites/rewind/restores';
import 'calypso/state/activity-log/init';

export * from './display-rules/actions';

/**
* Turn the 'rewind' feature on for a site.
*
Expand Down
29 changes: 0 additions & 29 deletions client/state/activity-log/display-rules/actions.ts

This file was deleted.

41 changes: 0 additions & 41 deletions client/state/activity-log/display-rules/reducer.ts

This file was deleted.

2 changes: 0 additions & 2 deletions client/state/activity-log/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ACTIVITY_LOG_FILTER_SET, ACTIVITY_LOG_FILTER_UPDATE } from 'calypso/sta
import { combineReducers, keyedReducer } from 'calypso/state/utils';
import { activationRequesting } from './activation/reducer';
import { backupRequest, backupProgress } from './backup/reducer';
import displayRules from './display-rules/reducer';
import { restoreProgress, restoreRequest } from './restore/reducer';

export const emptyFilter = {
Expand All @@ -26,7 +25,6 @@ export const filterState = ( state = emptyFilter, { type, filter } ) => {
const combinedReducer = combineReducers( {
activationRequesting,
filter: keyedReducer( 'siteId', filterState ),
displayRules,
restoreProgress,
restoreRequest,
backupProgress,
Expand Down

This file was deleted.

Loading

0 comments on commit c23f47c

Please sign in to comment.