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

Typings or values incorrect for validations when running space generate migration command #95

Closed
ZwaarContrast opened this issue Nov 13, 2018 · 2 comments
Labels

Comments

@ZwaarContrast
Copy link

Expected Behavior

According to the typings of the assetImageDimensions field on IValidation the values for width.min, width.max, height.min and height.max are either are number or undefined.

Actual Behavior

When running the contentful space generate migration command, the generated values for the assetImageDimensions fields are can be null when you have not configured them in the UI:

screenshot 2018-11-13 10 35 58

Generated validations function:

.validations([
      {
        assetImageDimensions: {
          width: {
            min: 200,
            max: null
          },

          height: {
            min: null,
            max: null
          }
        }
      }
    ])

Possible Solution

Either adjust the typings if the behaviour of the command is correct, or adjust the functionality to not have null values but leave them out (undefined).

Adjust typings


export interface IValidation {
 ...
  /** Validates that an image asset is of a certain image dimension. */
  assetImageDimensions?: { width: { min?: number | null , max?: number | null }, height: { min?: number | null , max?: number | null } }
...
}

Or make sure the output is:

.validations([
      {
        assetImageDimensions: {
          width: {
            min: 200,
          },
        }
      }
    ])

Steps to Reproduce

  1. Create a contentType in the Contentful UI
  2. Add a field of type Media
  3. Add validation for Accept only specified image dimensions, only set a rule for width of atleast 200px
  4. Save content type
  5. Run command yarn run ts-node node_modules/.bin/contentful space generate migration -s XXX -e XXX -c XXX

Result:

module.exports = function(migration) {
  const test = migration
    .createContentType("test")
    .name("test")
    .description("");

  test
    .createField("test")
    .name("test")
    .type("Link")
    .localized(false)
    .required(false)
    .validations([
      {
        assetImageDimensions: {
          width: {
            min: 200,
            max: null
          },

          height: {
            min: null,
            max: null
          }
        }
      }
    ])
    .disabled(false)
    .omitted(false)
    .linkType("Asset");

  test.changeEditorInterface("test", "assetLinkEditor", {});
};
@Khaledgarbaya
Copy link
Contributor

Hi @ZwaarContrast,
Thanks for spotting that out we'll try to fix it asap. Meanwhile PRs are welcome if you want to take stab at it

@makinwab
Copy link
Contributor

makinwab commented Apr 2, 2020

Re: contentful/contentful-migration#312
I've routed this issue to the appropriate repo issues list and thus closing this.

@makinwab makinwab closed this as completed Apr 2, 2020
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

3 participants