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

Generated migration files swap field controls based on alpha order and field definition order #2171

Open
ecline123 opened this issue Jul 20, 2023 · 3 comments
Labels

Comments

@ecline123
Copy link

ecline123 commented Jul 20, 2023

Expected Behavior

When creating a migration script with:

contentful merge export

...or through the Merge app UI...

I expect the field controls for content type fields to match what was selected in the UI.

Actual Behavior

Field controls are assigned to fields in alphabetical order based on the order the fields were defined in. Running an incorrectly generated migration results in a broken content type.

function migrationFunction(migration, context) {
    const testType = migration.createContentType("testType");
    testType
        .displayField("cField")
        .name("TestType")
        .description("")

    const testTypeAField = testType.createField("aField");
    testTypeAField
        .name("A - Field")
        .type("Integer")
        .localized(false)
        .required(false)
        .validations([])
        .disabled(false)
        .omitted(false)

    const testTypeCField = testType.createField("cField");
    testTypeCField
        .name("C - Field")
        .type("Symbol")
        .localized(false)
        .required(false)
        .validations([])
        .disabled(false)
        .omitted(false)

    const testTypeBField = testType.createField("bField");
    testTypeBField
        .name("B - Field")
        .type("Date")
        .localized(false)
        .required(false)
        .validations([])
        .disabled(false)
        .omitted(false)
    testType.changeFieldControl("aField", "builtin", "numberEditor"    // aField is first alphabetically so correctly gets the numberEditor
    testType.changeFieldControl("cField", "builtin", "datePicker")   // cField is third alphabetically so incorrectly gets the datePicker from the third field defined (bField)
    testType.changeFieldControl("bField", "builtin", "singleLine")   // bField is second alphabetically so incorrectly gets the singleLine from the second field defined (cField)

}
module.exports = migrationFunction;

Possible Solution

Steps to Reproduce

  1. Create a model with field names that aren't alphabetical i.e. A - Field, C - Field, B - Field.
  2. Choose different field types for each field to demonstrate the issue
  3. Generate a migration script with contentful merge export
  4. See that the changeFieldControl function calls are incorrect.

Context

I'm new to the CLI but this doesn't give me much confidence in the tooling.

Environment

  • Language Version: v18.16.1
  • Package Manager Version: 9.5.1
  • Browser Version: n/a
  • Operating System: MacOS 13.4.1
  • Package Version: 2.6.30
@ruderngespra
Copy link
Contributor

Hey @ecline123, thanks for reporting this. I can confirm that this is a bug we are working on at the moment, will update you once this is fixed.

@ecline123
Copy link
Author

@ruderngespra Any progress on this?

@ruderngespra
Copy link
Contributor

@ecline123 Hey, hey, yes, we have now updated the related migration script creation logic. Could you let me know if you are still running into this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants