-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add container level context fairground containers #12710
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import { decideCollectionBranding } from '../lib/branding'; | ||
import type { EditionId } from '../lib/edition'; | ||
import type { Branding } from '../types/branding'; | ||
import type { DCRCollectionType, FECollectionType } from '../types/front'; | ||
import type { | ||
DCRCollectionType, | ||
DCRContainerLevel, | ||
FECollectionType, | ||
FEContainerPalette, | ||
} from '../types/front'; | ||
import { decideContainerPalette } from './decideContainerPalette'; | ||
import { enhanceCards } from './enhanceCards'; | ||
import { enhanceTreats } from './enhanceTreats'; | ||
|
@@ -15,6 +20,16 @@ const FORBIDDEN_CONTAINERS = [ | |
|
||
const UNSUPPORTED_CONTAINERS = ['scrollable/feature', 'static/feature/2']; | ||
|
||
const FAIRGROUND_CONTAINERS = [ | ||
'scrollable/feature', | ||
'static/feature/2', | ||
'flexible/special', | ||
'flexible/general', | ||
'scrollable/small', | ||
'scrollable/medium', | ||
'static/medium/4', | ||
]; | ||
|
||
const PALETTE_STYLES_URI = | ||
'https://content.guardianapis.com/atom/interactive/interactives/2022/03/29/fronts-container-colours/default'; | ||
|
||
|
@@ -45,6 +60,19 @@ const findCollectionSuitableForFrontBranding = ( | |
return index; | ||
}; | ||
|
||
/** | ||
* The container levels are passed across on the config metadata object from frontend. | ||
* This is largely used for container palettes which is why the accepted type is `FEContainerPalette[]`. | ||
* The function will return the container level if it is found in the metadata. | ||
* */ | ||
const getContainerLevel = ( | ||
levels?: FEContainerPalette[], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, the level is included in the config meta from frontend. This is largely only used for container palette which is why the type here might seem strange. There are 3 options here:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for writing up these options! I think option 1 is fine for now with a view that we could improve to do 2 and/or 3 as a follow up improvement |
||
): DCRContainerLevel | undefined => { | ||
if (levels?.includes('Primary')) return 'Primary'; | ||
if (levels?.includes('Secondary')) return 'Secondary'; | ||
return undefined; | ||
}; | ||
|
||
export const enhanceCollections = ({ | ||
collections, | ||
editionId, | ||
|
@@ -92,6 +120,15 @@ export const enhanceCollections = ({ | |
}, | ||
); | ||
|
||
/** "Primary" or "Secondary" container level styling should only be applied to fairground containers | ||
* Ideally this logic would (and might) exist in the fronts tool. | ||
*/ | ||
const containerLevel = FAIRGROUND_CONTAINERS.includes(collectionType) | ||
? getContainerLevel( | ||
collection.config.metadata?.map((meta) => meta.type), | ||
) | ||
: undefined; | ||
|
||
return { | ||
id, | ||
displayName, | ||
|
@@ -131,6 +168,7 @@ export const enhanceCollections = ({ | |
}, | ||
canShowMore: hasMore && !collection.config.hideShowMore, | ||
targetedTerritory: collection.targetedTerritory, | ||
containerLevel, | ||
}; | ||
}); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree ideally these shouldn't need to be here - this should come from upstream data