Merge pull request #532 from outline/jori/collection-delete-fixes
Fixed collection deletion
This commit is contained in:
@ -29,6 +29,7 @@ type Options = {
|
|||||||
|
|
||||||
class DocumentsStore extends BaseStore {
|
class DocumentsStore extends BaseStore {
|
||||||
@observable recentlyViewedIds: Array<string> = [];
|
@observable recentlyViewedIds: Array<string> = [];
|
||||||
|
@observable recentlyEditedIds: Array<string> = [];
|
||||||
@observable data: Map<string, Document> = new ObservableMap([]);
|
@observable data: Map<string, Document> = new ObservableMap([]);
|
||||||
@observable isLoaded: boolean = false;
|
@observable isLoaded: boolean = false;
|
||||||
@observable isFetching: boolean = false;
|
@observable isFetching: boolean = false;
|
||||||
@ -41,17 +42,22 @@ class DocumentsStore extends BaseStore {
|
|||||||
|
|
||||||
@computed
|
@computed
|
||||||
get recentlyViewed(): Array<Document> {
|
get recentlyViewed(): Array<Document> {
|
||||||
return _.take(
|
const docs = [];
|
||||||
_.filter(this.data.values(), ({ id }) =>
|
this.recentlyViewedIds.forEach(id => {
|
||||||
this.recentlyViewedIds.includes(id)
|
const doc = this.getById(id);
|
||||||
),
|
if (doc) docs.push(doc);
|
||||||
5
|
});
|
||||||
);
|
return docs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
get recentlyEdited(): Document[] {
|
get recentlyEdited(): Document[] {
|
||||||
return _.take(_.orderBy(this.data.values(), 'updatedAt', 'desc'), 5);
|
const docs = [];
|
||||||
|
this.recentlyEditedIds.forEach(id => {
|
||||||
|
const doc = this.getById(id);
|
||||||
|
if (doc) docs.push(doc);
|
||||||
|
});
|
||||||
|
return docs;
|
||||||
}
|
}
|
||||||
|
|
||||||
recentlyEditedIn(documentIds: string[]): Document[] {
|
recentlyEditedIn(documentIds: string[]): Document[] {
|
||||||
@ -105,7 +111,12 @@ class DocumentsStore extends BaseStore {
|
|||||||
|
|
||||||
@action
|
@action
|
||||||
fetchRecentlyModified = async (options: ?PaginationParams): Promise<*> => {
|
fetchRecentlyModified = async (options: ?PaginationParams): Promise<*> => {
|
||||||
return await this.fetchAll('list', options);
|
const data = await this.fetchAll('list', options);
|
||||||
|
|
||||||
|
runInAction('DocumentsStore#fetchRecentlyModified', () => {
|
||||||
|
this.recentlyEditedIds = _.map(data, 'id');
|
||||||
|
});
|
||||||
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
@action
|
@action
|
||||||
@ -207,6 +218,16 @@ class DocumentsStore extends BaseStore {
|
|||||||
this.add(new Document(data));
|
this.add(new Document(data));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Re-fetch dashboard content so that we don't show deleted documents
|
||||||
|
this.on('collections.delete', () => {
|
||||||
|
this.fetchRecentlyModified();
|
||||||
|
this.fetchRecentlyViewed();
|
||||||
|
});
|
||||||
|
this.on('documents.delete', () => {
|
||||||
|
this.fetchRecentlyModified();
|
||||||
|
this.fetchRecentlyViewed();
|
||||||
|
});
|
||||||
|
|
||||||
autorunAsync('DocumentsStore.persists', () => {
|
autorunAsync('DocumentsStore.persists', () => {
|
||||||
if (this.data.size) {
|
if (this.data.size) {
|
||||||
this.cache.setItem(
|
this.cache.setItem(
|
||||||
|
@ -95,6 +95,14 @@ Collection.associate = models => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Collection.addHook('afterDestroy', async model => {
|
||||||
|
await Document.destroy({
|
||||||
|
where: {
|
||||||
|
atlasId: model.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Hooks
|
// Hooks
|
||||||
|
|
||||||
Collection.addHook('afterCreate', model =>
|
Collection.addHook('afterCreate', model =>
|
||||||
|
Reference in New Issue
Block a user