I have a list of resources, which I understood that must be the entities for which we have the CRUD operations:
The problem is that inside the entity page I want to use 2 tabs (components), one for the list of the entity and one for a list of aggregated data based on the entity. The problem is with the second, because I was required to write a custom graphql query, but both components use the same source (first list).
<ProtectedResource
name={RESOURCES.Product}
list={Product.homepage}
icon={StarHalfIcon}
options={{ label: translate('Products') }}
/>
Products.js is a hook which returns this:
<TabbedForm redirect={`/${RESOURCES.Product}`}>
<FormTab label={translate('Lines')}>
<ReferenceManyField reference={RESOURCES.Product} target="" label="" fullWidth {...paginationProps('id')}>
<ProductsList {...props} />
</ReferenceManyField>
</FormTab>
<FormTab label={translate('Aggregated Lines')} path="/aggregates">
<ReferenceManyField reference={RESOURCES.Product} target="" label="" fullWidth {...paginationProps('id')}>
<ProductAggregatesList {...props} />
</ReferenceManyField>
</FormTab>
</TabbedForm>
In reality, should hit 2 queries: getAllProducts and getAggregatedProducts. Based on fetchType and resource, I can rewrite the query which I want to execute (in frontend), but I can not catch the data and send to the specific component.
if (fetchType === GET_MANY_REFERENCE && resource === RESOURCES.Product)
return getAggregatedProducts(resource, params);
And GET_LIST fetch type will be used for first tab.
If I create another resource, for AggregatedProducts, there will throw an error because AggregatedProducts is not known in backend's schema.