Skip to content

Commit

Permalink
Merge pull request #709 from dpc-sdp/bugfix/R20-1234-content-collecti…
Browse files Browse the repository at this point in the history
…on-results

[R20-1234] include current site ID in search filters
  • Loading branch information
dylankelly authored Jul 14, 2023
2 parents 0248ee0 + 2062908 commit 5df65a0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/ripple-tide-api/src/services/tide-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class TidePageApi extends TideApiBase {
...data
})
} else if (typeof componentMapping === 'function') {
const data = componentMapping.apply(this, [cmpData, pageData])
const data = componentMapping.apply(this, [cmpData, pageData, this])
mappedComponents.push({
uuid: cmpData.uuid || cmpData.id,
...data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ describe('contentCollectionMapping', () => {
values: ['landing_page', 'news']
},
{
type: 'all',
type: 'any',
field: 'field_topic',
values: [8941, 8940]
},
{
type: 'any',
field: 'field_node_site',
values: ['8888']
}
],
sortBy: [
Expand All @@ -48,6 +53,8 @@ describe('contentCollectionMapping', () => {
}
}

expect(contentCollectionMapping(rawData)).toEqual(result)
expect(contentCollectionMapping(rawData, {}, { site: '8888' })).toEqual(
result
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export interface ITideContentCollectionConfig {
}

const getContentCollectionFiltersFromConfig = (
config: ITideContentCollectionConfig
config: ITideContentCollectionConfig,
siteId?: string
): IContentCollectionFilter[] => {
const filters = []
if (config.internal?.contentTypes) {
Expand All @@ -61,20 +62,23 @@ const getContentCollectionFiltersFromConfig = (
}
if (config.internal?.contentFields) {
const contentFieldFilters = Object.keys(config.internal?.contentFields).map(
(field) => {
const type =
config.internal?.contentFields[field].operator === 'OR'
? 'any'
: 'all'
return {
type,
field,
values: config.internal?.contentFields[field].values
}
}
(field) => ({
field,
type: 'any',
values: config.internal?.contentFields[field].values
})
)
filters.push(...contentFieldFilters)
}

if (siteId) {
filters.push({
type: 'any',
field: 'field_node_site',
values: [siteId]
})
}

return filters
}

Expand All @@ -97,7 +101,9 @@ const getContentCollectionSortBy = (config) => {
}

export const contentCollectionMapping = (
field
field,
pageData,
TidePageApi
): TideDynamicPageComponent<IContentCollection> => {
return {
component: 'TideLandingPageContentCollection',
Expand All @@ -110,7 +116,8 @@ export const contentCollectionMapping = (
'callToAction'
]),
filters: getContentCollectionFiltersFromConfig(
field.field_content_collection_config
field.field_content_collection_config,
TidePageApi?.site
),
sortBy: getContentCollectionSortBy(field.field_content_collection_config),
perPage: getField(
Expand Down

0 comments on commit 5df65a0

Please sign in to comment.