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

fix(utilities): exclude id properties from arrays #64

Merged
merged 1 commit into from
Jul 4, 2023

Conversation

thompsonsj
Copy link
Owner

  • Prevent fields with a name of id from identifying as a localized field.
  • Exclude arrays of empty objects from fields.json.

Details

getLocalizedFields supports top-level localized: true settings on fields that contain a group of fields. This support was added in #20.

Payload CMS adds text fields for the id in some cases: e.g. each item in an array will have it's own id. Here's an example doc with values in an array field:

{
  "id": "649da59a7a48bc576d04966f",
  "arrayField": [
    {
      "content": [
        {
          "children": [
            {
              "text": "Test content 1"
            }
          ]
        }
      ],
      "metaDescription": "Test meta description 1"
    },
    {
      "content": [
        {
          "children": [
            {
              "text": "Test content 2"
            }
          ]
        }
      ],
      "metaDescription": "Test meta description 2"
    }
  ],
  "createdAt": "2023-06-29T15:39:06.628Z",
  "updatedAt": "2023-07-03T10:32:43.988Z"
}

In this scenario, fields.json can end up containing id fields. In the above example, each array item only contains a richText field - which get sent to html files instead of fields.json.

{
  "arrayField": [
    {
      "id": "649cd20ebac7445191be36b0"
    },
    {
      "id": "649cd219bac7445191be36b1"
    }
  ]
}

Note that integration tests are written to test against this scenario. Providing fixtures to the unit tests in the utilities folder won't work because this situation only arises when a Payload CMS installation adds fields.

@thompsonsj thompsonsj merged commit 48390bb into main Jul 4, 2023
1 check passed
@thompsonsj thompsonsj mentioned this pull request Dec 15, 2023
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

Successfully merging this pull request may close these issues.

1 participant