Skip to content

Commit

Permalink
Merge pull request #3441 from marmelab/avoid-error-messages-when-empt…
Browse files Browse the repository at this point in the history
…y-response

[RFR] Support API empty response on DELETE and DELETE_MANY actions
  • Loading branch information
fzaninotto authored Aug 21, 2019
2 parents 80fb03d + 29d1670 commit 853c807
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions docs/DataProviders.md
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ Request Type | Response format
`CREATE` | `{ data: {Record} }`
`UPDATE` | `{ data: {Record} }`
`UPDATE_MANY` | `{ data: {mixed[]} }` The ids which have been updated
`DELETE` | `{ data: {Record} }`
`DELETE_MANY` | `{ data: {mixed[]} }` The ids which have been deleted
`DELETE` | `{ data: {Record|null} }` The record that has been deleted (optional)
`DELETE_MANY` | `{ data: {mixed[]} }` The ids of the deleted records (optional)
`GET_MANY` | `{ data: {Record[]} }`
`GET_MANY_REFERENCE` | `{ data: {Record[]}, total: {int} }`

Expand Down Expand Up @@ -678,6 +678,8 @@ export default (type, resource, params) => {
};
case CREATE:
return { data: { ...params.data, id: json.id } };
case DELETE_MANY:
return { data: json || [] };
default:
return { data: json };
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/dataFetchActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const UPDATE_MANY = 'UPDATE_MANY';
export const DELETE = 'DELETE';
export const DELETE_MANY = 'DELETE_MANY';

export const fetchActionsWithRecordResponse = [GET_ONE, CREATE, UPDATE, DELETE];
export const fetchActionsWithRecordResponse = [GET_ONE, CREATE, UPDATE];
export const fetchActionsWithArrayOfIdentifiedRecordsResponse = [
GET_LIST,
GET_MANY,
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-core/src/sideEffect/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ function validateResponseFormat(
fetchActionsWithArrayOfIdentifiedRecordsResponse.includes(type) &&
Array.isArray(response.data) &&
response.data.length > 0 &&
!response.data[0].hasOwnProperty('id')
response.data.some(d => !d.hasOwnProperty('id'))
) {
logger(
`The response to '${type}' must be like { data : [{ id: 123, ...}, ...] }, but the received data items do not have an 'id' key. The dataProvider is probably wrong for '${type}'`
`The response to '${type}' must be like { data : [{ id: 123, ...}, ...] }, but at least one received data item do not have an 'id' key. The dataProvider is probably wrong for '${type}'`
);
throw new Error('ra.notification.data_provider_error');
}
Expand Down
2 changes: 2 additions & 0 deletions packages/ra-data-json-server/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ export default (apiUrl, httpClient = fetchUtils.fetchJson) => {
};
case CREATE:
return { data: { ...params.data, id: json.id } };
case DELETE_MANY:
return { data: json || [] };
default:
return { data: json };
}
Expand Down
3 changes: 3 additions & 0 deletions packages/ra-data-simple-rest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ export default (apiUrl, httpClient = fetchUtils.fetchJson) => {
};
case CREATE:
return { data: { ...params.data, id: json.id } };
case DELETE_MANY: {
return { data: json || [] };
}
default:
return { data: json };
}
Expand Down

0 comments on commit 853c807

Please sign in to comment.