How to create Multiple resource based on permanent filter?
How to create multiple resources from the same API endpoint but the difference is each resource has a different permanent filter?
filters.permanent property when defining your resources. This allows you to create different resources from the same API endpoint, each with its own permanent filter. Here's how you can approach this:<Refine> component, each with a unique name.useTable, useSimpleList, etc.) and set the filters.permanent property with the desired filter.useTable hook:useTable hook with a different permanent filter. The filters.permanent property ensures that these filters are always applied and cannot be changed by the user.<Refine> component:permanent filter is unchangeable and will always be applied, unlike initial filters which can be modified by the user.warehouse_listing, so I want to have 2 list pages, the first one will shows only data with pending status, and the other one is for the 'done' statuswarehouse_listing resource, one for pending status and another for done status, using the same API endpoint but with different permanent filters. Here's how you can achieve this using refine:useTable hook with a permanent filter:``
This approach allows you to have two separate list pages for pending and done warehouse listings, using the same API endpoint but with different permanent filters. The filters.permanent` property ensures that these filters are always applied and cannot be changed by the user useTable filters.permanent (https://refine.dev/docs/ui-integrations/ant-design/hooks/use-table/#filterspermanent).warehouse_listing resource name.``
This approach ensures that:
1. The permanent filters are only applied to the list pages.
2. The edit, create, and show pages will use the same warehouse_listing resource without any permanent filters.
By moving the filter logic into the list components, we isolate the filtering behavior to just the list pages. The edit, create, and show pages will function as before, using the common warehouse_listing resource without any permanent filters applied.
This solution allows you to have separate list views for pending and done statuses while maintaining a single, unfiltered resource for other CRUD operations. The permanent filters will only be active in the useTable` hook calls within the list components useTable filters.permanent (https://refine.dev/docs/ui-integrations/ant-design/hooks/use-table/#filterspermanent).filters.permanentfilters.permanentfilters.permanent<Refine><Refine>useTableuseTableuseTableuseTableuseSimpleListpermanentwarehouse_listingwarehouse_listingwarehouse_listing{
name: "warehouse_listing",
list: "/warehouse_listing",
create: "/warehouse_listing/create",
edit: "/warehouse_listing/edit/:id",
show: "/warehouse_listing/show/:id",
meta: {
canDelete: true,
label: "Pending Warehouse Listing",
parent: "warehouse_module",
},
},
{
name: "warehouse_listing",
list: "/warehouse_listing",
create: "/warehouse_listing/create",
edit: "/warehouse_listing/edit/:id",
show: "/warehouse_listing/show/:id",
meta: {
canDelete: true,
label: "Done Warehouse Listing",
parent: "warehouse_module",
},
},3. Finally, update your resource definitions to use these new components:``
This approach allows you to have two separate list pages for pending and done warehouse listings, using the same API endpoint but with different permanent filters. The ``
This approach ensures that:
1. The permanent filters are only applied to the list pages.
2. The edit, create, and show pages will use the same resource without any permanent filters.
By moving the filter logic into the list components, we isolate the filtering behavior to just the list pages. The edit, create, and show pages will function as before, using the common resource without any permanent filters applied.
This solution allows you to have separate list views for pending and done statuses while maintaining a single, unfiltered resource for other CRUD operations. The permanent filters will only be active in the // Resource 1: Products with material "Cotton"
const CottonProducts = () => {
const { tableProps } = useTable({
filters: {
permanent: [
{
field: "material",
operator: "eq",
value: "Cotton",
},
],
},
});
// Render your table here
};
// Resource 2: Products with material "Bronze"
const BronzeProducts = () => {
const { tableProps } = useTable({
filters: {
permanent: [
{
field: "material",
operator: "eq",
value: "Bronze",
},
],
},
});
// Render your table here
};<Refine
resources={[
{
name: "cotton-products",
list: CottonProducts,
// other CRUD components...
},
{
name: "bronze-products",
list: BronzeProducts,
// other CRUD components...
},
]}
// other Refine configurations...
/>{
name: "pending_warehouse_listing",
list: "/warehouse_listing/pending",
create: "/warehouse_listing/create",
edit: "/warehouse_listing/edit/:id",
show: "/warehouse_listing/show/:id",
meta: {
canDelete: true,
label: "Pending Warehouse Listing",
parent: "warehouse_module",
},
},
{
name: "done_warehouse_listing",
list: "/warehouse_listing/done",
create: "/warehouse_listing/create",
edit: "/warehouse_listing/edit/:id",
show: "/warehouse_listing/show/:id",
meta: {
canDelete: true,
label: "Done Warehouse Listing",
parent: "warehouse_module",
},
},{
name: "warehouse_listing",
list: PendingWarehouseList,
create: "/warehouse_listing/create",
edit: "/warehouse_listing/edit/:id",
show: "/warehouse_listing/show/:id",
meta: {
canDelete: true,
label: "Pending Warehouse Listing",
parent: "warehouse_module",
},
},
{
name: "warehouse_listing",
list: DoneWarehouseList,
create: "/warehouse_listing/create",
edit: "/warehouse_listing/edit/:id",
show: "/warehouse_listing/show/:id",
meta: {
canDelete: true,
label: "Done Warehouse Listing",
parent: "warehouse_module",
},
}