refine icon indicating copy to clipboard operation
refine copied to clipboard

[FEAT] Custom ID for resources

Open YechiamW3 opened this issue 2 years ago • 5 comments

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.

YechiamW3 avatar Jan 29 '23 17:01 YechiamW3

Hello @YechiamTK

Thanks for the detailed issue!

We added this to our internal backlog.

BatuhanW avatar Feb 24 '23 11:02 BatuhanW

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.

stale[bot] avatar May 13 '23 07:05 stale[bot]

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.

stale[bot] avatar Aug 19 '23 13:08 stale[bot]

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.

stale[bot] avatar Jan 20 '24 10:01 stale[bot]

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.

rners01 avatar Mar 19 '24 14:03 rners01

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.

stale[bot] avatar May 27 '24 11:05 stale[bot]