Fixes bug in loader when a relationship is empty
This commit is contained in:
@@ -36,8 +36,9 @@ export function DocumentLoader({
|
|||||||
relationships: doc.expand?.relationships_via_primary || [],
|
relationships: doc.expand?.relationships_via_primary || [],
|
||||||
relatedDocuments:
|
relatedDocuments:
|
||||||
doc.expand?.relationships_via_primary?.flatMap(
|
doc.expand?.relationships_via_primary?.flatMap(
|
||||||
(r: RecordModel) => r.expand?.secondary,
|
// Note: If there are no entries in the expanded secondaries there just won't be an entry instead of an empty list.
|
||||||
) || [],
|
(r: RecordModel) => r.expand?.secondary ?? [],
|
||||||
|
) ?? [],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -150,13 +150,20 @@ export function reducer(
|
|||||||
action.doc.id,
|
action.doc.id,
|
||||||
setDocument(state, action.doc),
|
setDocument(state, action.doc),
|
||||||
);
|
);
|
||||||
|
|
||||||
const updatedRelationshipsState = action.relationships.reduce(
|
const updatedRelationshipsState = action.relationships.reduce(
|
||||||
setRelationship.bind(null, action.doc.id),
|
setRelationship.bind(null, action.doc.id),
|
||||||
updatedDocumentState,
|
updatedDocumentState,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const emptyRemainingRelationships = setAllRelationshipsEmpty(
|
||||||
|
action.doc.id,
|
||||||
|
updatedRelationshipsState,
|
||||||
|
);
|
||||||
|
|
||||||
return action.relatedDocuments.reduce(
|
return action.relatedDocuments.reduce(
|
||||||
setDocument,
|
setDocument,
|
||||||
updatedRelationshipsState,
|
emptyRemainingRelationships,
|
||||||
);
|
);
|
||||||
case "removeDocument":
|
case "removeDocument":
|
||||||
return removeDocument(action.docId, state);
|
return removeDocument(action.docId, state);
|
||||||
|
|||||||
Reference in New Issue
Block a user