-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'latest' into remove-dot-only-from-tests
- Loading branch information
Showing
7 changed files
with
1,814 additions
and
4 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
hindiRecommendations: '003_hindi_experiment', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/app/routes/cpsAsset/getInitialData/addExperimentPlaceholderBlocks/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.