Skip to content

Inject record data into transformRows callback #68

Description

@freddyseubertnio

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>
);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions