Skip to content

Commit

Permalink
Refresh list on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
m4theushw authored and akshah123 committed Feb 14, 2020
1 parent b3ae237 commit fec5755
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
26 changes: 26 additions & 0 deletions cypress/integration/edit.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import createPageFactory from '../support/CreatePage';
import editPageFactory from '../support/EditPage';
import listPageFactory from '../support/ListPage';

describe('Edit Page', () => {
const EditPostPage = editPageFactory('/#/posts/5');
const CreatePostPage = createPageFactory('/#/posts/create');
const EditCommentPage = editPageFactory('/#/comments/5');
const ListPagePosts = listPageFactory('/#/posts');

describe('Title', () => {
it('should show the correct title in the appBar', () => {
Expand Down Expand Up @@ -176,4 +178,28 @@ describe('Edit Page', () => {
expect(el).to.have.value('')
);
});

it('should refresh the list when the update fails', () => {
ListPagePosts.navigate();
ListPagePosts.nextPage(); // Ensure the record is visible in the table

EditPostPage.navigate();
EditPostPage.setInputValue('input', 'title', 'f00bar');
EditPostPage.submit();

cy.get(ListPagePosts.elements.recordRows)
.eq(2)
.should(el => expect(el).to.contain('f00bar'));

cy.get('div[role="alertdialog"]');
cy.wait(4000); // Wait for the undo notification to disappear

cy.get('div[role="alertdialog"]').should(el =>
expect(el).to.have.text('this title cannot be used')
);

cy.get(ListPagePosts.elements.recordRows)
.eq(2)
.should(el => expect(el).to.contain('Sed quo et et fugiat modi'));
});
});
7 changes: 7 additions & 0 deletions examples/simple/src/dataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ const sometimesFailsDataProvider = new Proxy(uploadCapableDataProvider, {
// if (name === 'delete' && resource === 'posts') {
// return Promise.reject(new Error('deletion error'));
// }
if (
resource === 'posts' &&
params.data &&
params.data.title === 'f00bar'
) {
return Promise.reject(new Error('this title cannot be used'));
}
return uploadCapableDataProvider[name](resource, params);
},
});
Expand Down
10 changes: 7 additions & 3 deletions packages/ra-core/src/controller/useEditController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,22 @@ const useEditController = (props: EditProps): EditControllerProps => {
},
onFailure: onFailure
? onFailure
: error =>
: error => {
notify(
typeof error === 'string'
? error
: error.message ||
'ra.notification.http_error',
'warning'
),
);
if (undoable) {
refresh();
}
},
undoable,
}
),
[basePath, notify, redirect, undoable, update, successMessage]
[update, undoable, notify, successMessage, redirect, basePath, refresh]
);

return {
Expand Down

0 comments on commit fec5755

Please sign in to comment.