Skip to content

Commit

Permalink
Add a returnFailedResources option to semantic-data-provider
Browse files Browse the repository at this point in the history
  • Loading branch information
srosset81 committed Aug 27, 2021
1 parent 11aab5d commit 44cbaf3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions src/frontend/packages/semantic-data-provider/src/dataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const isType = (type, resource) => {
return Array.isArray(resourceType) ? resourceType.includes(type) : resourceType === type;
};

const dataProvider = ({ sparqlEndpoint, httpClient, resources, ontologies, jsonContext, uploadsContainerUri }) => {
const dataProvider = ({ sparqlEndpoint, httpClient, resources, ontologies, jsonContext, uploadsContainerUri, returnFailedResources = false }) => {
const uploadFile = async rawFile => {
if (!uploadsContainerUri) throw new Error('No uploadsContainerUri defined for the data provider');

Expand Down Expand Up @@ -252,12 +252,18 @@ const dataProvider = ({ sparqlEndpoint, httpClient, resources, ontologies, jsonC

try {
let { json } = await httpClient(id);
json.id = json.id || json['@id'];
json.id = id;
returnData.push(json);
} catch (e) {
// Do nothing if one resource fails to load
// Catch if one resource fails to load
// Otherwise no references will be show if only one is missing
// See https://github.com/marmelab/react-admin/issues/5190
if( returnFailedResources ) {
// Return only the ID of the resource
returnData.push({ id });
} else {
// Do nothing. The resource will not appear in the results.
}
}
}

Expand Down Expand Up @@ -311,15 +317,13 @@ const dataProvider = ({ sparqlEndpoint, httpClient, resources, ontologies, jsonC

return { data: params.data };
},

updateMany: (resourceId, params) => {
throw new Error('updateMany is not implemented yet');
},
delete: async (resourceId, params) => {
await httpClient(params.id, {
method: 'DELETE'
});

return { data: { id: params.id } };
},
deleteMany: (resourceId, params) => {
Expand Down

0 comments on commit 44cbaf3

Please sign in to comment.