Skip to content

Commit

Permalink
avoid adding same subjects twice (#4448)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaskikutis authored Mar 5, 2024
1 parent 1ca979b commit b21223d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion scripts/apps/authoring/media/MediaCopyMetadataDirective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ function getMediaMetadata(metadata: Partial<IArticle>, fields): Partial<IArticle
} else if (metadata[field.field] != null) {
output[field.field] = metadata[field.field];
} else if (field.cv != null && metadata.subject?.length > 0) {
const values = metadata.subject.filter((subj) => subj.scheme === field.field);
const alreadyAddedSubjectQcodes = new Set((output.subject ?? []).map(({qcode}) => qcode));
const values = metadata.subject.filter(
(subj) => subj.scheme === field.field && alreadyAddedSubjectQcodes.has(subj.qcode) !== true,
);

if (values.length) {
output.subject = output.subject ? output.subject.concat(values) : values;
Expand Down

0 comments on commit b21223d

Please sign in to comment.