@vonaffenfels/contentful-teasermanager 1.2.19 → 1.2.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +55 -12
- package/package.json +2 -2
- package/src/components/Contentful/Dialog/LogicEditor.js +98 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vonaffenfels/contentful-teasermanager",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.22",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prepublish": "yarn run build",
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"contentful-resolve-response": "^1.9.2",
|
|
103
103
|
"webpack": "5.88.2"
|
|
104
104
|
},
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "1914d362b401e249ed1c116aef8e12d94311b4c7",
|
|
106
106
|
"publishConfig": {
|
|
107
107
|
"access": "public"
|
|
108
108
|
}
|
|
@@ -162,21 +162,28 @@ const LogicEditorInner = ({
|
|
|
162
162
|
if (!response?.items?.[0]) {
|
|
163
163
|
return [];
|
|
164
164
|
}
|
|
165
|
-
|
|
166
|
-
const references = await sdk.cma.entry.references({entryId: response.items[0].sys.id}, {include: 10});
|
|
167
|
-
const resolved = contentfulResolveResponse(references);
|
|
168
165
|
const allCategories = {};
|
|
169
166
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
167
|
+
try {
|
|
168
|
+
// Use different include levels based on portal to avoid multilingual content bloat
|
|
169
|
+
const includeLevel = portal === 'YACHT' ? 1 : 2;
|
|
170
|
+
const references = await sdk.cma.entry.references({entryId: response.items[0].sys.id, include: includeLevel});
|
|
171
|
+
const resolved = contentfulResolveResponse(references);
|
|
174
172
|
|
|
175
|
-
const
|
|
173
|
+
for (const category of resolved) {
|
|
174
|
+
if (!category?.fields?.children?.de) {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
176
177
|
|
|
177
|
-
|
|
178
|
-
|
|
178
|
+
const children = category.fields.children.de || [];
|
|
179
|
+
|
|
180
|
+
for (const child of children) {
|
|
181
|
+
await getAllTagsFromCategory(child, allCategories, null, portal, sdk);
|
|
182
|
+
}
|
|
179
183
|
}
|
|
184
|
+
} catch (e) {
|
|
185
|
+
console.error("Error getting categories and tags from references: ", e);
|
|
186
|
+
return [];
|
|
180
187
|
}
|
|
181
188
|
|
|
182
189
|
return Object.values(allCategories).filter((c) => c.tags.length > 0);
|
|
@@ -440,7 +447,7 @@ const LogicEditorInner = ({
|
|
|
440
447
|
</div>;
|
|
441
448
|
};
|
|
442
449
|
|
|
443
|
-
function getAllTagsFromCategory(categoryNode, allCategories = {}, parentCategoryTitle = null) {
|
|
450
|
+
async function getAllTagsFromCategory(categoryNode, allCategories = {}, parentCategoryTitle = null, portal = null, sdk = null) {
|
|
444
451
|
if (!categoryNode || !categoryNode.fields?.children) {
|
|
445
452
|
return allCategories;
|
|
446
453
|
}
|
|
@@ -455,16 +462,47 @@ function getAllTagsFromCategory(categoryNode, allCategories = {}, parentCategory
|
|
|
455
462
|
};
|
|
456
463
|
|
|
457
464
|
if (categoryNode?.fields?.tags?.de) {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
465
|
+
const tagRefs = categoryNode.fields.tags.de;
|
|
466
|
+
|
|
467
|
+
if (portal === 'YACHT') {
|
|
468
|
+
// For YACHT portal, fetch all tag titles at once for better performance
|
|
469
|
+
const tagIds = tagRefs.map(tag => tag.sys.id).filter(id => id);
|
|
470
|
+
|
|
471
|
+
if (tagIds.length > 0) {
|
|
472
|
+
try {
|
|
473
|
+
const tagPromises = tagIds.map(tagId =>
|
|
474
|
+
sdk.cma.entry.get({entryId: tagId}).catch(() => null),
|
|
475
|
+
);
|
|
476
|
+
const fetchedTags = await Promise.all(tagPromises);
|
|
477
|
+
|
|
478
|
+
fetchedTags.forEach((fetchedTag, index) => {
|
|
479
|
+
if (fetchedTag?.fields?.title?.de) {
|
|
480
|
+
const tagId = tagIds[index];
|
|
481
|
+
if (!allCategories[categoryNode.sys.id].tags.find((c) => c.id === tagId)) {
|
|
482
|
+
allCategories[categoryNode.sys.id].tags.push({
|
|
483
|
+
label: fetchedTag.fields.title.de,
|
|
484
|
+
id: tagId,
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
} catch (e) {
|
|
490
|
+
console.error("Error fetching tags for YACHT portal:", e);
|
|
491
|
+
}
|
|
461
492
|
}
|
|
493
|
+
} else {
|
|
494
|
+
// For non-YACHT portals, tags should have fields already included
|
|
495
|
+
for (const tag of tagRefs) {
|
|
496
|
+
if (!tag?.fields?.title) {
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
462
499
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
500
|
+
if (!allCategories[categoryNode.sys.id].tags.find((c) => c.id === tag.sys.id)) {
|
|
501
|
+
allCategories[categoryNode.sys.id].tags.push({
|
|
502
|
+
label: tag.fields.title.de,
|
|
503
|
+
id: tag.sys.id,
|
|
504
|
+
});
|
|
505
|
+
}
|
|
468
506
|
}
|
|
469
507
|
}
|
|
470
508
|
}
|
|
@@ -475,21 +513,52 @@ function getAllTagsFromCategory(categoryNode, allCategories = {}, parentCategory
|
|
|
475
513
|
}
|
|
476
514
|
|
|
477
515
|
if (child?.fields?.tags?.de) {
|
|
478
|
-
|
|
479
|
-
if (!allCategories[categoryNode.sys.id].tags.find((c) => c.id === tag.sys.id)) {
|
|
480
|
-
if (!tag?.fields?.title) {
|
|
481
|
-
continue;
|
|
482
|
-
}
|
|
516
|
+
const childTagRefs = child.fields.tags.de;
|
|
483
517
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
518
|
+
if (portal === 'YACHT') {
|
|
519
|
+
// For YACHT portal, fetch child tag titles
|
|
520
|
+
const childTagIds = childTagRefs.map(tag => tag.sys.id).filter(id => id);
|
|
521
|
+
|
|
522
|
+
if (childTagIds.length > 0) {
|
|
523
|
+
try {
|
|
524
|
+
const childTagPromises = childTagIds.map(tagId =>
|
|
525
|
+
sdk.cma.entry.get({entryId: tagId}).catch(() => null),
|
|
526
|
+
);
|
|
527
|
+
const fetchedChildTags = await Promise.all(childTagPromises);
|
|
528
|
+
|
|
529
|
+
fetchedChildTags.forEach((fetchedTag, index) => {
|
|
530
|
+
if (fetchedTag?.fields?.title?.de) {
|
|
531
|
+
const tagId = childTagIds[index];
|
|
532
|
+
if (!allCategories[categoryNode.sys.id].tags.find((c) => c.id === tagId)) {
|
|
533
|
+
allCategories[categoryNode.sys.id].tags.push({
|
|
534
|
+
label: fetchedTag.fields.title.de,
|
|
535
|
+
id: tagId,
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
} catch (e) {
|
|
541
|
+
console.error("Error fetching child tags for YACHT portal:", e);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
} else {
|
|
545
|
+
// For non-YACHT portals, child tags should have fields already included
|
|
546
|
+
for (const tag of childTagRefs) {
|
|
547
|
+
if (!allCategories[categoryNode.sys.id].tags.find((c) => c.id === tag.sys.id)) {
|
|
548
|
+
if (!tag?.fields?.title) {
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
allCategories[categoryNode.sys.id].tags.push({
|
|
553
|
+
label: tag.fields.title.de,
|
|
554
|
+
id: tag.sys.id,
|
|
555
|
+
});
|
|
556
|
+
}
|
|
488
557
|
}
|
|
489
558
|
}
|
|
490
559
|
}
|
|
491
560
|
|
|
492
|
-
getAllTagsFromCategory(child, allCategories, title);
|
|
561
|
+
await getAllTagsFromCategory(child, allCategories, title, portal, sdk);
|
|
493
562
|
}
|
|
494
563
|
|
|
495
564
|
allCategories[categoryNode.sys.id].tags = [...new Set(allCategories[categoryNode.sys.id].tags)];
|