mirror of
https://github.com/outline/outline.git
synced 2026-12-01 01:14:11 +03:00
fix: Prevent duplicate personal document in sidebar on first create (#14107)
This commit is contained in:
1 parent
0514c5ba4f
commit
6df3fa18d3
3 files changed
+25
-4
No files matched your search
@@ -20,4 +20,23 @@ describe("Collection model", () => {
|
||||
const shared = stores.collections.add({ id: "789", name: "Design" });
|
||||
expect(shared.displayName).toBe("Design");
|
||||
});
|
||||
|
||||
it("should not add a document that is already in the collection", () => {
|
||||
const collection = stores.collections.add({
|
||||
id: "abc",
|
||||
name: "Personal",
|
||||
sort: { field: "title", direction: "asc" },
|
||||
documents: [],
|
||||
});
|
||||
const document = stores.documents.add({
|
||||
id: "doc-1",
|
||||
title: "Doc",
|
||||
url: "/doc/doc-1",
|
||||
collectionId: collection.id,
|
||||
});
|
||||
|
||||
collection.addDocument(document);
|
||||
collection.addDocument(document);
|
||||
expect(collection.documents?.map((node) => node.id)).toEqual(["doc-1"]);
|
||||
});
|
||||
});
|
||||
@@ -344,14 +344,15 @@ export default class Collection extends ParanoidModel {
|
||||
|
||||
/**
|
||||
* Adds the document identified by the given id to the collection in
|
||||
* memory. Does not add the document to the database or store.
|
||||
* memory, if it is not already present. Does not add the document to the
|
||||
* database or store.
|
||||
*
|
||||
* @param document The document to add.
|
||||
* @param parentDocumentId The id of the document to add the new document to.
|
||||
*/
|
||||
@action
|
||||
addDocument(document: Document, parentDocumentId?: string) {
|
||||
if (!this.documents) {
|
||||
if (!this.documents || this.childrenByDocumentId.has(document.id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -128,14 +128,15 @@ export default abstract class NavigableModel extends Model {
|
||||
|
||||
/**
|
||||
* Adds the document identified by the given id to the model in
|
||||
* memory. Does not add the document to the database or store.
|
||||
* memory, if it is not already present. Does not add the document to the
|
||||
* database or store.
|
||||
*
|
||||
* @param document The document to add.
|
||||
* @param parentDocumentId The id of the document to add the new document to.
|
||||
*/
|
||||
@action
|
||||
addDocument(document: Document, parentDocumentId: string) {
|
||||
if (!this.documents || !document || !parentDocumentId?.trim()) {
|
||||
if (!this.documents || this.childrenByDocumentId.has(document.id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user