-
Notifications
You must be signed in to change notification settings - Fork 4
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
Question: what hook determines the data that is sent to resource data a list? #151
Comments
OK, I see the problem here. The List Item is controlled by the ResourceListItem component. This component has a transform function apparently, so only some of the resource data is displayed, based on the hard coded transform function in the actual app elements code. I suggest you allow an additional data type prop that allows you to pass in additional data you want to be displayed as part of the ResourceListItem, because the tranform function doesn't always give the data that is needed. I know we can just create a new ListeItem component, but that's a bit more work. It would be easier if the ResourceListItem accepted some additional data that is not transformed. Maybe allow the ability to pass in an additional component into the ResourceListItem, which can then display the additional data. |
Hi @osseonews, I believe what you are trying to achieve would be possibile with the existing components. The The orders app is the only one that leverages the metrics api (and not our core api) to fetch the list of orders, for performance reasons. What I see is not clear from the developer point of view is that is not possible to set both When you specify a What you can do now is to get rid of the Mainly you will need to revert to the state where the app was before using the metrics api. A reference can still be found here: https://github.com/commercelayer/app-orders/pull/146/files Let me know if this gets too complicate or it's still doable. |
@gciotola Thanks. Actually, after messing around a bit with the code, we ended up doing the exact same thing as you suggested. The metricsquery is what really threw us off and when we deleted it, we noticed that you can't use that and query at the same time. But, if you get rid of the metricsquery you also need to fix the filter in the search for order. Thanks for the reference to the old repo, that was helpful in fixing some outstanding issues we had. BTW, what's the benefit of using ResourceList alone over the FilteredList? From what I can tell the Resource list has built in transformers and they are not necessarily the data we actually need in most instances. So we are busy changing the ResourceList to FitleredLists when we need to customize things. |
They are exactly the same component.
If you do not have a search bar and the filters page ( To clarify the standard usage of const { ResourceList } = useResourceList({
type: 'orders',
query: {
fields: ['number', 'market'],
filters: {
status_eq: 'placed'
},
pageSize: 25,
sort: [...],
include: ['market']
}
})
)
return (
<ResourceList
title='My orders list'
ItemTemplate={(props) => <div>order number {props.resource?.number} </div> }
/>
) But if you don't want to build the So finally, to answer the following:
Imagine you want to list the orders of a specific customer, for a specific market, with placed status (fixed list, not dinamically filtrable by the user). You can simply do: const { ResourceList } = useResourceList({
type: 'orders',
query: {
filters: {
status_eq: 'placed',
markets_id_in: ['xxxx'],
customer_id_eq: 'zzzzz'
},
pageSize: 25
}
})
)
return (
<ResourceList
title='My orders list'
ItemTemplate={(props) => <div>order number {props.resource?.number} </div> }
/>
) |
Right but when you use ResourceList the component has a built in transform and it only returns the data that is hard coded into the ResourceList component. Basically, it seems like a quick way to create a list from a resource. That's at least how we see the results. But you can't customize the display of the list at all, to include additional data etc. So when we want to customize the list, we have been using FilteredList. Is that the correct approach? |
For example, take a look at your code in the customers app. CustomerList component uses FilteredList to display the data, while CustomerOrders component uses ResourceList. |
No, that's not correct. The transformation function is only used when metrics api is used (so when If you look at the example above, I am using const { ResourceList } = useResourceList({
type: 'orders',
query: {
filters: {
// optional filters
},
include: ['customer', 'payment_method'],
pageSize: 25
}
})
)
return (
<ResourceList
title='My orders list'
ItemTemplate={(props) =>
// props.resource is now a single `order` because the `useResourceList` has been initialized with `type: orders`
<div className="single-list-item">
<ul>
<li>order number {props.resource?.number}</li>
<li>placed at {props.resource?.placed_at}</li>
<li>from customer {props.resource?.customer?.email}</li>
<li>payed by {props.resource?. payment_method?.name}</li>
</ul>
</div>
}
/>
) You can do whatever you want with |
metricsQuery: Oh ok, that's what confused us. Because we were on the orders app. now i understand. But, based on what you wrote, why in the Customers App, do you use Filtered List in CustomerList component instead of ResourceList? |
Ah ok. I think I am finally understanding this and when to use what. Thanks! |
Ok, so I've been confusing things. Our issue is with the ResourceListItem component. This has a built in transformer, so if you pass data to it from ResourceList or FilterList, you can't get all the data you want and you need to create a separate component. This is a bit annoying, if I'm understanding this correctly. Why does ResourceListItem have built in transformers? |
That's right. But it's just a pre-made component, you can build your custom list item component to be used in Not all apps have a prebuilt |
We are struggling to figure out where the data comes from for any resource on a List page. So for example in OrderList.tsx in the orders app, you have the FilteredList component, which sends the data to the ListItemOrder template. But the data provided thru the ListItemOrder is a resource prop. Where does the data come from for the resource? It's only has certain information from the order, but we wanted to display additional information on the list. We thought we can do that by adding a query to the FilteredList, like below, but none of that information shows up in the resource for the list. So how do we get additional data in the list? The only optio we saw that worked was to just call a useOrdersDetails hook for every single item in the list, but this seems like a wasteful query and we will hit the API a significant amount of time for each item in the list. But how can we do it otherwise? Which hook controls the data that is sent back to the list?
The text was updated successfully, but these errors were encountered: