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

@@ -645,7 +645,11 @@ export default class DocumentsStore extends BaseStore<Document> {
@action
removeCollectionDocuments(collectionId: string) {
const documents = this.inCollection(collectionId);
// drafts are to be detached from collection rather than deleted, hence excluded here
const documents = filter(
this.inCollection(collectionId),
(d) => !!d.publishedAt
);
const documentIds = documents.map((doc) => doc.id);
documentIds.forEach((id) => this.remove(id));
}
@@ -795,6 +799,8 @@ export default class DocumentsStore extends BaseStore<Document> {
find(this.orderedData, (doc) => url.endsWith(doc.urlId));
getCollectionForDocument(document: Document) {
return this.rootStore.collections.data.get(document.collectionId);
return document.collectionId
? this.rootStore.collections.get(document.collectionId)
: undefined;
}
}