Skip to content

Commit

Permalink
Merge branch 'latest' into remove-dot-only-from-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MuhammadAHussain authored Feb 22, 2022
2 parents 034d9ba + 31c9388 commit 5a8e845
Show file tree
Hide file tree
Showing 7 changed files with 1,814 additions and 4 deletions.
906 changes: 906 additions & 0 deletions data/hindi/cpsAssets/india-60426858.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/app/lib/config/optimizely/experimentIds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
hindiRecommendations: '003_hindi_experiment',
};
4 changes: 4 additions & 0 deletions src/app/lib/config/services/russian.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ export const service = {
title: 'Главная',
url: '/russian',
},
{
title: 'Украина',
url: '/russian/topics/cez0n29ggrdt',
},
{
title: 'Коронавирус',
url: '/russian/in-depth-51962199',
Expand Down
44 changes: 44 additions & 0 deletions src/app/pages/StoryPage/StoryPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import { RequestContext } from '#contexts/RequestContext';
import useToggle from '#hooks/useToggle';
import RelatedTopics from '#containers/RelatedTopics';
import NielsenAnalytics from '#containers/NielsenAnalytics';
import useOptimizelyVariation from '#hooks/useOptimizelyVariation';
import OPTIMIZELY_EXPERIMENT_IDS from '#lib/config/optimizely/experimentIds';
import categoryType from './categoryMap/index';
import cpsAssetPagePropTypes from '../../models/propTypes/cpsAssetPage';

Expand All @@ -71,6 +73,11 @@ const StoryPage = ({ pageData, mostReadEndpointOverride }) => {
lang,
showRelatedTopics,
} = useContext(ServiceContext);

const experimentVariation = useOptimizelyVariation(
OPTIMIZELY_EXPERIMENT_IDS.hindiRecommendations,
);

const { enabled: preloadLeadImageToggle } = useToggle('preloadLeadImage');
const title = path(['promo', 'headlines', 'headline'], pageData);
const shortHeadline = path(['promo', 'headlines', 'shortHeadline'], pageData);
Expand Down Expand Up @@ -204,6 +211,43 @@ const StoryPage = ({ pageData, mostReadEndpointOverride }) => {
<Disclaimer {...props} increasePaddingOnDesktop={false} />
),
podcastPromo: podcastPromoEnabled && InlinePodcastPromo,
experimentBlock: props => {
const { showForVariation, part } = props;
// Return 'control' variation if 'control' is returned from Optimizely or experiment is not enabled
if (
showForVariation === 'control' &&
(experimentVariation === 'control' || !experimentVariation)
) {
return (
<CpsRecommendations
{...props}
parentColumns={gridColsMain}
items={recommendationsInitialData}
/>
);
}

if (
showForVariation === 'variation_1' &&
experimentVariation === 'variation_1'
) {
if (part === 1) {
return <div>Recs with 2 items, first 2 recs</div>;
}
if (part === 2) {
return <div>Recs with 2 items, last 2 recs</div>;
}
}

if (
showForVariation === 'variation_3' &&
experimentVariation === 'variation_3'
) {
return <div>scrolling recs</div>;
}

return null;
},
};

const StyledTimestamp = styled(Timestamp)`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import path from 'ramda/src/path';
import splitAt from 'ramda/src/splitAt';
import { STORY_PAGE } from '#app/routes/utils/pageTypes';
import { getNthCpsParagraphIndex } from '../helpers';
import deepClone from '../../../utils/jsonClone';

const insertExperimentBlock = (experimentBlock, blocks, insertIndex) => {
const paragraphIndex = getNthCpsParagraphIndex(blocks, insertIndex);

if (!paragraphIndex) {
return blocks;
}

const parts = splitAt(paragraphIndex + 1, blocks);

return [...parts[0], { ...experimentBlock }, ...parts[1]];
};

const addExperimentPlaceholderBlocks = service => originalJson => {
const json = deepClone(originalJson);
const pageType = path(['metadata', 'type'], json);
const { allowAdvertising } = path(['metadata', 'options'], json);
let blocks = path(['content', 'model', 'blocks'], json);

if (pageType !== STORY_PAGE || !blocks || !allowAdvertising) {
return json;
}

/**
* Default recommendations for services outside of the experiment
*/

if (service !== 'hindi') {
const { assetUri } = path(['metadata', 'locators'], json);

const defaultRecommendationsBlock = {
type: 'wsoj',
model: {
type: 'recommendations',
path: `/api/recommend?recSys=2&limit=4&assetUri=${assetUri}`,
},
};

json.content.model.blocks = insertExperimentBlock(
defaultRecommendationsBlock,
blocks,
5,
);

return json;
}

/**
* For the Hindi service, we need to insert the experiment blocks into the pageData
*/

const experimentBlocks = [
// Control recs block
{
block: {
type: 'experimentBlock',
model: {
showForVariation: 'control',
},
},
insertIndex: 5,
},
// Split recs blocks
{
block: {
type: 'experimentBlock',
model: {
showForVariation: 'variation_1',
part: 1,
},
},
insertIndex: 5,
},
{
block: {
type: 'experimentBlock',
model: {
showForVariation: 'variation_1',
part: 2,
},
},
insertIndex: 10,
},
// Scrollable recs block
{
block: {
type: 'experimentBlock',
model: {
showForVariation: 'variation_3',
},
},
insertIndex: 5,
},
];

experimentBlocks.forEach(({ block, insertIndex }) => {
blocks = insertExperimentBlock(block, blocks, insertIndex);
});

json.content.model.blocks = blocks;

return json;
};

export default addExperimentPlaceholderBlocks;
Loading

0 comments on commit 5a8e845

Please sign in to comment.