Skip to content
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

Inject record data into transformRows callback #68

Open
freddyseubertnio opened this issue Jul 9, 2021 · 0 comments
Open

Inject record data into transformRows callback #68

freddyseubertnio opened this issue Jul 9, 2021 · 0 comments

Comments

@freddyseubertnio
Copy link

Hi there!

I have a Show component for a 'Parent' resource and I want to import a CSV which contains entries of a 'Child' resource. Now I need to reference the currently displayed Parent ID in a field for every imported Child.
I understand that I can add static information in the transformRows callback but how can I possibly inject the currently displayed Parent record into the function?

Thank you in advance for any solution or hint in the right direction!

const configuration: ImportConfig = {
  // ...
  transformRows: (csvRows) => {
    let rows = [];
    csvRows.map((row) => {
      row.parent_id = parent.id; // this is where I need the injected data
      rows.push(row);
    });
    return rows;
  },
  // ...
}

export const ParentShow = (props) => (
    <Show {...props}>
        <TabbedShowLayout>
            <Tab label="Parent Details">
                <TextField source="parentdetail1" />
                <TextField source="parentdetail2" />
            </Tab>
            <Tab label="Children" path="children">
                <ImportButton {...props} {...configuration} />
                <ReferenceManyField reference="children" target="parent_id">
                    <Datagrid>
                        <TextField source="childdetail" />
                    </Datagrid>
                </ReferenceManyField>
            </Tab>
        </TabbedShowLayout>
    </Show>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant