MrHertal / react-admin-json-view

JSON field and input for react-admin.
MIT License
51 stars 13 forks source link

Supported nested objects in field & input source with dotted notation #19

Open vaizki opened 1 year ago

vaizki commented 1 year ago

I have a nested object in my record, like this:

{
  id: "abcdef",
  info: {
    tree: {
       x: 1,
       y: 2
    }
  }
}

Now if I use the JSON view components and put source="info.tree" it doesn't work as the component looks for record[source]. The React Admin native fields and inputs use lodash to resolve nested location:

import get from 'lodash/get';
...
const value = get(record, source);

Could you incorporate this into the field and input?

vaizki commented 1 year ago

Just noticed that lodash/get was there before the RAv4 update release, so what was the reason for getting rid of lodash here?

fkowal commented 8 months ago

commented in the MR

const record = useRecordContext(props);

is a pattern that is used in react admin codebase

it's more powerful, it would allow <FunctionField render={(rec) => <JsonField source="newfield" record={{newfield: rec.x.y.z}} />>

so this is a key missing piece because JsonField doesn't support this (passing props to useRecordContext

fkowal commented 8 months ago

@MrHertal ping