Document Archive (#921)

* WIP: Archive

* WIP

* Finishing up archive endpoints

* WIP

* Update docs

* Flow

* Stash

* Add toast message confirmations

* Redirect handling, fixed publishhing info for archived docs

* Redirect to collection instead of home, remove unused pub info

* Account for deleted parent

* Trash -> Archive
Allow reading of archived docs

* Dont overload deletedAt

* Fixes

* 💚

* ParentDocumentId wipe for unarchived sub docs

* Fix: CMD+S exits editing
Fix: Duplicate user name on published but unedited docs

* Improve jank on paginated lists

* Prevent editing when archived

* 💚
Separate lint / flow steps
This commit is contained in:
Tom Moor
2019-04-06 16:20:27 -07:00
committed by GitHub
parent 76957865bb
commit 642c11ff7d
39 changed files with 811 additions and 311 deletions

View File

@@ -20,7 +20,12 @@ export default class DocumentsStore extends BaseStore<Document> {
}
@computed
get recentlyViewed(): * {
get all(): Document[] {
return filter(this.orderedData, d => !d.archivedAt && !d.deletedAt);
}
@computed
get recentlyViewed(): Document[] {
return orderBy(
compact(this.recentlyViewedIds.map(id => this.data.get(id))),
'updatedAt',
@@ -29,16 +34,13 @@ export default class DocumentsStore extends BaseStore<Document> {
}
@computed
get recentlyUpdated(): * {
return orderBy(Array.from(this.data.values()), 'updatedAt', 'desc');
get recentlyUpdated(): Document[] {
return orderBy(this.all, 'updatedAt', 'desc');
}
createdByUser(userId: string): * {
return orderBy(
filter(
Array.from(this.data.values()),
document => document.createdBy.id === userId
),
filter(this.all, d => d.createdBy.id === userId),
'updatedAt',
'desc'
);
@@ -53,7 +55,7 @@ export default class DocumentsStore extends BaseStore<Document> {
publishedInCollection(collectionId: string): Document[] {
return filter(
Array.from(this.data.values()),
this.all,
document =>
document.collectionId === collectionId && !!document.publishedAt
);
@@ -93,7 +95,15 @@ export default class DocumentsStore extends BaseStore<Document> {
@computed
get starred(): Document[] {
return filter(this.orderedData, d => d.starred);
return filter(this.all, d => d.starred);
}
@computed
get archived(): Document[] {
return filter(
orderBy(this.orderedData, 'archivedAt', 'desc'),
d => d.archivedAt
);
}
@computed
@@ -104,7 +114,7 @@ export default class DocumentsStore extends BaseStore<Document> {
@computed
get drafts(): Document[] {
return filter(
orderBy(Array.from(this.data.values()), 'updatedAt', 'desc'),
orderBy(this.all, 'updatedAt', 'desc'),
doc => !doc.publishedAt
);
}
@@ -137,6 +147,11 @@ export default class DocumentsStore extends BaseStore<Document> {
}
};
@action
fetchArchived = async (options: ?PaginationParams): Promise<*> => {
return this.fetchNamedPage('archived', options);
};
@action
fetchRecentlyUpdated = async (options: ?PaginationParams): Promise<*> => {
return this.fetchNamedPage('list', options);
@@ -331,15 +346,32 @@ export default class DocumentsStore extends BaseStore<Document> {
}
@action
restore = async (document: Document, revision: Revision) => {
archive = async (document: Document) => {
const res = await client.post('/documents.archive', {
id: document.id,
});
runInAction('Document#archive', () => {
invariant(res && res.data, 'Data should be available');
document.updateFromJson(res.data);
});
const collection = this.getCollectionForDocument(document);
if (collection) collection.refresh();
};
@action
restore = async (document: Document, revision?: Revision) => {
const res = await client.post('/documents.restore', {
id: document.id,
revisionId: revision.id,
revisionId: revision ? revision.id : undefined,
});
runInAction('Document#restore', () => {
invariant(res && res.data, 'Data should be available');
document.updateFromJson(res.data);
});
const collection = this.getCollectionForDocument(document);
if (collection) collection.refresh();
};
pin = (document: Document) => {
@@ -359,7 +391,7 @@ export default class DocumentsStore extends BaseStore<Document> {
};
getByUrl = (url: string = ''): ?Document => {
return find(Array.from(this.data.values()), doc => url.endsWith(doc.urlId));
return find(this.orderedData, doc => url.endsWith(doc.urlId));
};
getCollectionForDocument(document: Document) {

View File

@@ -40,7 +40,7 @@ class UiStore {
setActiveDocument = (document: Document): void => {
this.activeDocumentId = document.id;
if (document.publishedAt) {
if (document.publishedAt && !document.isArchived && !document.isDeleted) {
this.activeCollectionId = document.collectionId;
}
};