Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Support API empty response on DELETE and DELETE_MANY actions #3441

Merged
merged 6 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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