Deleting a collection should detach associated drafts from it (#5082)

Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
Apoorv Mishra
2023-04-24 00:50:44 +05:30
committed by GitHub
parent 7250c0ed64
commit 86062f396d
39 changed files with 363 additions and 112 deletions

View File

@@ -175,7 +175,7 @@ class WebsocketProvider extends React.Component<Props> {
id: document.collectionId,
});
if (!existing) {
if (!existing && document.collectionId) {
event.collectionIds.push({
id: document.collectionId,
});
@@ -298,10 +298,14 @@ class WebsocketProvider extends React.Component<Props> {
action((event: WebsocketEntityDeletedEvent) => {
const collectionId = event.modelId;
const deletedAt = new Date().toISOString();
const deletedDocuments = documents.inCollection(collectionId);
deletedDocuments.forEach((doc) => {
doc.deletedAt = deletedAt;
if (!doc.publishedAt) {
// draft is to be detached from collection, not deleted
doc.collectionId = null;
} else {
doc.deletedAt = deletedAt;
}
policies.remove(doc.id);
});
documents.removeCollectionDocuments(collectionId);