chore: fixes bug with links always populating
This commit is contained in:
@@ -36,49 +36,16 @@ export const recurseRichText = ({
|
||||
}: RecurseRichTextArgs): void => {
|
||||
if (Array.isArray(children)) {
|
||||
(children as any[]).forEach((element) => {
|
||||
if ((element.type === 'relationship' || element.type === 'upload')
|
||||
&& element?.value?.id
|
||||
&& (depth && currentDepth <= depth)) {
|
||||
const collection = req.payload.collections[element?.relationTo];
|
||||
|
||||
if (collection) {
|
||||
promises.push(populate({
|
||||
req,
|
||||
id: element.value.id,
|
||||
data: element,
|
||||
key: 'value',
|
||||
overrideAccess,
|
||||
depth,
|
||||
currentDepth,
|
||||
field,
|
||||
collection,
|
||||
showHiddenFields,
|
||||
}));
|
||||
}
|
||||
|
||||
if (element.type === 'upload' && Array.isArray(field.admin?.upload?.collections?.[element?.relationTo]?.fields)) {
|
||||
recurseNestedFields({
|
||||
promises,
|
||||
data: element.fields || {},
|
||||
fields: field.admin.upload.collections[element.relationTo].fields,
|
||||
req,
|
||||
overrideAccess,
|
||||
depth,
|
||||
currentDepth,
|
||||
showHiddenFields,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (element.type === 'link') {
|
||||
if (element?.doc?.value && element?.doc?.relationTo) {
|
||||
const collection = req.payload.collections[element?.doc?.relationTo];
|
||||
if ((depth && currentDepth <= depth)) {
|
||||
if ((element.type === 'relationship' || element.type === 'upload')
|
||||
&& element?.value?.id) {
|
||||
const collection = req.payload.collections[element?.relationTo];
|
||||
|
||||
if (collection) {
|
||||
promises.push(populate({
|
||||
req,
|
||||
id: element.doc.value,
|
||||
data: element.doc,
|
||||
id: element.value.id,
|
||||
data: element,
|
||||
key: 'value',
|
||||
overrideAccess,
|
||||
depth,
|
||||
@@ -88,19 +55,53 @@ export const recurseRichText = ({
|
||||
showHiddenFields,
|
||||
}));
|
||||
}
|
||||
|
||||
if (element.type === 'upload' && Array.isArray(field.admin?.upload?.collections?.[element?.relationTo]?.fields)) {
|
||||
recurseNestedFields({
|
||||
promises,
|
||||
data: element.fields || {},
|
||||
fields: field.admin.upload.collections[element.relationTo].fields,
|
||||
req,
|
||||
overrideAccess,
|
||||
depth,
|
||||
currentDepth,
|
||||
showHiddenFields,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(field.admin?.link?.fields)) {
|
||||
recurseNestedFields({
|
||||
promises,
|
||||
data: element.fields || {},
|
||||
fields: field.admin?.link?.fields,
|
||||
req,
|
||||
overrideAccess,
|
||||
depth,
|
||||
currentDepth,
|
||||
showHiddenFields,
|
||||
});
|
||||
if (element.type === 'link') {
|
||||
if (element?.doc?.value && element?.doc?.relationTo) {
|
||||
const collection = req.payload.collections[element?.doc?.relationTo];
|
||||
|
||||
if (collection) {
|
||||
promises.push(populate({
|
||||
req,
|
||||
id: element.doc.value,
|
||||
data: element.doc,
|
||||
key: 'value',
|
||||
overrideAccess,
|
||||
depth,
|
||||
currentDepth,
|
||||
field,
|
||||
collection,
|
||||
showHiddenFields,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(field.admin?.link?.fields)) {
|
||||
recurseNestedFields({
|
||||
promises,
|
||||
data: element.fields || {},
|
||||
fields: field.admin?.link?.fields,
|
||||
req,
|
||||
overrideAccess,
|
||||
depth,
|
||||
currentDepth,
|
||||
showHiddenFields,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user