Edit collection (#173)
* Collection edit modal * Add icon * 💚 * Oh look, some specs * Delete collection * Remove from collection * Handle error responses Protect against deleting last collection * Fix key * 💚 * Keyboard navigate documents list * Add missing database constraints
This commit is contained in:
@ -67,9 +67,11 @@ class Collection extends BaseModel {
|
||||
description: this.description,
|
||||
});
|
||||
}
|
||||
invariant(res && res.data, 'Data should be available');
|
||||
this.updateData(res.data);
|
||||
this.hasPendingChanges = false;
|
||||
runInAction('Collection#save', () => {
|
||||
invariant(res && res.data, 'Data should be available');
|
||||
this.updateData(res.data);
|
||||
this.hasPendingChanges = false;
|
||||
});
|
||||
} catch (e) {
|
||||
this.errors.add('Collection failed saving');
|
||||
return false;
|
||||
@ -80,6 +82,17 @@ class Collection extends BaseModel {
|
||||
return true;
|
||||
};
|
||||
|
||||
@action delete = async () => {
|
||||
try {
|
||||
const res = await client.post('/collections.delete', { id: this.id });
|
||||
invariant(res && res.data, 'Data should be available');
|
||||
const { data } = res;
|
||||
return data.success;
|
||||
} catch (e) {
|
||||
this.errors.add('Collection failed to delete');
|
||||
}
|
||||
};
|
||||
|
||||
updateData(data: Object = {}) {
|
||||
this.data = data;
|
||||
extendObservable(this, data);
|
||||
|
Reference in New Issue
Block a user