refine
refine copied to clipboard
[FEAT] Custom ID for resources
Is your feature request related to a problem? Please describe.
Hi,
Most of my resources have their PKs not as "id", but as some other custom "x-id", like "resourceId". The Inferencer has a hard-coded assumption that the PK is "id", and so my resources aren't properly inference-d.
In most use-cases this is probably a non-issue because we can get the generated code and paste it to a specialized component and simply replace the "id" in this component. But my use-case is perhaps special, because I'm using the Inferencer generically and not taking the code it inferences; so I can't edit the code and use my custom ids instead of "id", i.e. I'm 100% relying on the Inferencer code.
Describe alternatives you've considered
The reason I'm raising this issue, albeit perhaps only supporting a special case, is that I believe the fix might be quite easy - passing a prop for the id, instead of using hard-coded value "id". Obviously there will be a default value "id", but if the prop is given then use it instead.
This will probably be helpful for most other use-cases where we simply want the Inferencer to work properl in dev environment.
Additional context
No response
Describe the thing to improve
As mentioned, I believe passing a prop for the Inferencer for PK would solve this issue.
Hello @YechiamTK
Thanks for the detailed issue!
We added this to our internal backlog.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
hey @omeraplak @BatuhanW ,
I tried to utilize meta to pass additional property like organizationId but it has it's limitations when it comes to the nested resources and it leads to additional lines of code and workarounds, like passing through the custom meta id on the Show & Edit pages.
So I would propose to customize the id property in the resource definition,
{
// It would be neat if we could customize the `id` property per resource.
// if no `id` was provided then we can use the existing - default `:id` behaviour
id: 'organizationId',
name: 'organizations',
list: '/organizations',
show: '/organizations/:organizationId',
edit: '/organizations/:organizationId/edit',
}
{
// same customization
id: 'memberId',
name: 'members',
list: '/members',
show: '/organizations/:organizationId/members/:memberId',
edit: '/organizations/:organizationId/members/:memberId',
}
Then we can utilize the existing hooks and component props without any workarounds as the property id is dynamic and defined by the config.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.