Skip to content

Commit

Permalink
VACMS-16099: Update logic to account for Beneficiary Tags change to a…
Browse files Browse the repository at this point in the history
… multi select (#1821)

* update logic to account for tags change from obj to array

---------

Co-authored-by: Chris Kim <[email protected]>
Co-authored-by: Daniel Sasser <[email protected]>
  • Loading branch information
3 people authored Dec 11, 2023
1 parent b8ed521 commit d74c83c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
17 changes: 13 additions & 4 deletions src/site/filters/liquid.js
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,19 @@ module.exports = function registerFilters() {
categoryLabel: 'Topics',
}));

const audiences = [
fieldAudienceBeneficiares?.entity,
fieldNonBeneficiares?.entity,
]
let beneficiaresAudiences = [];
if (
fieldAudienceBeneficiares &&
!Array.isArray(fieldAudienceBeneficiares)
) {
beneficiaresAudiences = [fieldAudienceBeneficiares?.entity];
} else if (fieldAudienceBeneficiares) {
beneficiaresAudiences = fieldAudienceBeneficiares.map(
audience => audience?.entity,
);
}

const audiences = [fieldNonBeneficiares?.entity, ...beneficiaresAudiences]
.filter(tag => !!tag)
.map(audience => ({
...audience,
Expand Down
10 changes: 6 additions & 4 deletions src/site/filters/liquid.unit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,11 +935,13 @@ describe('getTagsList', () => {
},
},
],
fieldAudienceBeneficiares: {
entity: {
name: 'C. Example',
fieldAudienceBeneficiares: [
{
entity: {
name: 'C. Example',
},
},
},
],
fieldNonBeneficiares: {
entity: {
name: 'D. Example',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ function groupByTags(allArticles) {
const terms = [...fieldTopics];

if (fieldAudienceBeneficiares) {
terms.push(fieldAudienceBeneficiares);
if (!Array.isArray(fieldAudienceBeneficiares)) {
terms.push({ ...fieldAudienceBeneficiares });
} else {
fieldAudienceBeneficiares.forEach(tag => {
terms.push(tag);
});
}
}

if (fieldNonBeneficiares) {
Expand Down

0 comments on commit d74c83c

Please sign in to comment.