Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme Tiers: Use the Theme Filters Store #89651

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion client/state/themes/action-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const THEME_STOP_ACTIVATION_SYNC = 'THEME_STOP_ACTIVATION_SYNC';
export const THEME_SHOW_ATOMIC_TRANSFER_DIALOG = 'THEME_SHOW_ATOMIC_TRANSFER_DIALOG';
export const THEME_ACCEPT_ATOMIC_TRANSFER_DIALOG = 'THEME_ACCEPT_ATOMIC_TRANSFER_DIALOG';
export const THEME_DISMISS_ATOMIC_TRANSFER_DIALOG = 'THEME_DISMISS_ATOMIC_TRANSFER_DIALOG';
export const THEME_TIERS_UPDATE = 'THEME_TIERS_UPDATE';
export const THEME_TRANSFER_INITIATE_FAILURE = 'THEME_TRANSFER_INITIATE_FAILURE';
export const THEME_TRANSFER_INITIATE_PROGRESS = 'THEME_TRANSFER_INITIATE_PROGRESS';
export const THEME_TRANSFER_INITIATE_REQUEST = 'THEME_TRANSFER_INITIATE_REQUEST';
Expand Down
1 change: 0 additions & 1 deletion client/state/themes/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,3 @@ export { tryAndCustomizeTheme } from 'calypso/state/themes/actions/try-and-custo
export { uploadTheme } from 'calypso/state/themes/actions/upload-theme';
export { updateThemes } from 'calypso/state/themes/actions/theme-update';
export { upsellCardDisplayed } from 'calypso/state/themes/actions/upsell-card-displayed';
export { updateThemeTiers } from 'calypso/state/themes/actions/theme-tiers';
4 changes: 1 addition & 3 deletions client/state/themes/actions/request-themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import isSiteAutomatedTransfer from 'calypso/state/selectors/is-site-automated-t
import { isJetpackSite } from 'calypso/state/sites/selectors';
import { THEMES_REQUEST, THEMES_REQUEST_FAILURE } from 'calypso/state/themes/action-types';
import { receiveThemes } from 'calypso/state/themes/actions/receive-themes';
import { updateThemeTiers } from 'calypso/state/themes/actions/theme-tiers';
import { prependThemeFilterKeys } from 'calypso/state/themes/selectors';
import {
normalizeJetpackTheme,
Expand Down Expand Up @@ -80,13 +79,12 @@ export function requestThemes( siteId, query = {}, locale ) {
// WP.org returns an `info` object containing a `results` number, so we destructure that
// and use it as default value for `found`.
return request()
.then( ( { themes: rawThemes, info: { results } = {}, found = results, tiers = {} } ) => {
.then( ( { themes: rawThemes, info: { results } = {}, found = results } ) => {
let themes;
if ( siteId === 'wporg' ) {
themes = map( rawThemes, normalizeWporgTheme );
} else if ( siteId === 'wpcom' ) {
themes = map( rawThemes, normalizeWpcomTheme );
dispatch( updateThemeTiers( tiers ) );
} else if ( isAtomic || isJetpack ) {
// Jetpack or Atomic Site
themes = map( rawThemes, normalizeJetpackTheme );
Expand Down
4 changes: 0 additions & 4 deletions client/state/themes/actions/theme-tiers.js

This file was deleted.

5 changes: 0 additions & 5 deletions client/state/themes/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import {
THEMES_LOADING_CART,
THEME_START_ACTIVATION_SYNC,
THEME_STOP_ACTIVATION_SYNC,
THEME_TIERS_UPDATE,
} from 'calypso/state/themes/action-types';
import { combineReducers, withSchemaValidation, withPersistence } from 'calypso/state/utils';
import {
Expand Down Expand Up @@ -699,9 +698,6 @@ export const themeHasAtomicTransferDialog = ( state = null, action ) => {
return state;
};

export const themeTiers = ( state = {}, action ) =>
THEME_TIERS_UPDATE === action.type ? action.tiers : state;

const combinedReducer = combineReducers( {
queries,
queryRequests,
Expand Down Expand Up @@ -729,7 +725,6 @@ const combinedReducer = combineReducers( {
startActivationSync,
themeHasAtomicTransferDialog,
livePreview,
themeTiers,
} );
const themesReducer = withStorageKey( 'themes', combinedReducer );

Expand Down
2 changes: 1 addition & 1 deletion client/state/themes/selectors/get-theme-tiers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'calypso/state/themes/init';

export function getThemeTiers( state ) {
return state?.themes?.themeTiers || {};
return state?.themes?.themeFilters?.tier || {};
}
17 changes: 0 additions & 17 deletions client/state/themes/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
THEME_TRANSFER_INITIATE_SUCCESS,
THEME_TRANSFER_STATUS_FAILURE,
THEME_TRANSFER_STATUS_RECEIVE,
THEME_TIERS_UPDATE,
THEMES_REQUEST,
THEMES_REQUEST_SUCCESS,
THEMES_REQUEST_FAILURE,
Expand Down Expand Up @@ -61,7 +60,6 @@ import {
addExternalManagedThemeToCart,
livePreview,
redirectToLivePreview,
updateThemeTiers,
} from '../actions';
import { themesUpdated } from '../actions/theme-update';

Expand Down Expand Up @@ -1758,19 +1756,4 @@ describe( 'actions', () => {
} );
} );
} );

describe( '#updateThemeTiers()', () => {
test( 'without a tiers param, should return an action with an empty object tiers property', () => {
expect( updateThemeTiers() ).toEqual( {
type: THEME_TIERS_UPDATE,
tiers: {},
} );
} );
test( 'with a tiers param, should return an action with a tiers property containing the same value', () => {
expect( updateThemeTiers( { free: {} } ) ).toEqual( {
type: THEME_TIERS_UPDATE,
tiers: { free: {} },
} );
} );
} );
} );
13 changes: 0 additions & 13 deletions client/state/themes/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
RECOMMENDED_THEMES_SUCCESS,
RECOMMENDED_THEMES_FAIL,
THEMES_LOADING_CART,
THEME_TIERS_UPDATE,
} from 'calypso/state/themes/action-types';
import { serialize, deserialize } from 'calypso/state/utils';
import reducer, {
Expand All @@ -38,7 +37,6 @@ import reducer, {
completedActivationRequests,
recommendedThemes,
isLoadingCart,
themeTiers,
} from '../reducer';

const twentysixteen = {
Expand Down Expand Up @@ -1044,15 +1042,4 @@ describe( 'reducer', () => {
expect( state ).toBe( true );
} );
} );

describe( '#themeTiers', () => {
test( 'should be an empty object by default', () => {
const state = themeTiers( undefined, {} );
expect( state ).toEqual( {} );
} );
test( 'should be the tiers object if provided', () => {
const state = themeTiers( undefined, { type: THEME_TIERS_UPDATE, tiers: { free: {} } } );
expect( state ).toEqual( { free: {} } );
} );
} );
} );
16 changes: 8 additions & 8 deletions client/state/themes/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3429,23 +3429,23 @@ describe( '#getThemeTiers', () => {
expect( themeTiers ).toEqual( {} );
} );
test( 'should return the tier object if it exists', () => {
const themeTiers = getThemeTiers( { themes: { themeTiers: { free: {} } } } );
const themeTiers = getThemeTiers( { themes: { themeFilters: { tier: { free: {} } } } } );
expect( themeTiers ).toEqual( { free: {} } );
} );
} );
describe( '#getThemeTier', () => {
const state = { themes: { themeTiers: { free: { foo: 'bar' } } } };
test( 'should return an empty object if the state is empty', () => {
const themeTiers = getThemeTier( {}, 'free' );
expect( themeTiers ).toEqual( {} );
const themeTier = getThemeTier( {}, 'free' );
expect( themeTier ).toEqual( {} );
} );
const state = { themes: { themeFilters: { tier: { free: { foo: 'bar' } } } } };
test( 'should return an empty object if the tier is empty', () => {
const themeTiers = getThemeTier( state, null );
expect( themeTiers ).toEqual( {} );
const themeTier = getThemeTier( state, null );
expect( themeTier ).toEqual( {} );
} );
test( 'should return the tier object if it exists', () => {
const themeTiers = getThemeTier( state, 'free' );
expect( themeTiers ).toEqual( { foo: 'bar' } );
const themeTier = getThemeTier( state, 'free' );
expect( themeTier ).toEqual( { foo: 'bar' } );
} );
} );
describe( '#getThemeTierForTheme', () => {
Expand Down
Loading