Skip to content

feat(plugin-import-export): add custom toCSV function on fields #12533

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

Merged
merged 9 commits into from
Jun 9, 2025

Conversation

DanRibbens
Copy link
Contributor

@DanRibbens DanRibbens commented May 23, 2025

This makes it possible to add custom logic into how we map the document data into the CSV data on a field-by-field basis.

  • Allow custom data transformation to be added to `custom.['plugin-import-export'].toCSV inside the field config
  • Add type declaration to FieldCustom to improve types
  • Export with depth: 1

Example:

    {
      name: 'customRelationship',
      type: 'relationship',
      relationTo: 'users',
      custom: {
        'plugin-import-export': {
          toCSV: ({ value, columnName, row, siblingDoc, doc }) => {
            row[`${columnName}_id`] = value.id
            row[`${columnName}_email`] = value.email
          },
        },
      },
    },

@DanRibbens DanRibbens marked this pull request as ready for review June 9, 2025 14:20
@DanRibbens DanRibbens requested a review from r1tsuu June 9, 2025 14:20
…eld-transform

# Conflicts:
#	packages/plugin-import-export/src/export/createExport.ts
@DanRibbens DanRibbens merged commit 8f4c442 into main Jun 9, 2025
77 checks passed
@DanRibbens DanRibbens deleted the feat/import-export-field-transform branch June 9, 2025 17:53
@DanRibbens DanRibbens restored the feat/import-export-field-transform branch June 9, 2025 18:05
Copy link
Contributor

github-actions bot commented Jun 9, 2025

🚀 This is included in version v3.42.0

elliott-w pushed a commit to elliott-w/payload that referenced this pull request Jun 12, 2025
…oadcms#12533)

This makes it possible to add custom logic into how we map the document
data into the CSV data on a field-by-field basis.

- Allow custom data transformation to be added to
`custom.['plugin-import-export'].toCSV inside the field config
- Add type declaration to FieldCustom to improve types
- Export with `depth: 1`

Example:
```ts
    {
      name: 'customRelationship',
      type: 'relationship',
      relationTo: 'users',
      custom: {
        'plugin-import-export': {
          toCSV: ({ value, columnName, row, siblingDoc, doc }) => {
            row[`${columnName}_id`] = value.id
            row[`${columnName}_email`] = value.email
          },
        },
      },
    },
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants