Skip to content
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

VACMS-16099: Update logic to account for Beneficiary Tags change to a multi select #1821

Merged
merged 11 commits into from
Dec 11, 2023
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
Loading