keystonejs/keystone-classic

Cloudinary fields not collapsing

Open

#4526 opened on Dec 2, 2017

View on GitHub
 (1 comment) (0 reactions) (0 assignees)JavaScript (14,656 stars) (2,288 forks)batch import
bughelp wanted

Description

Expected behavior

CloudinaryImage and CloudinaryImages file upload fields should be collapsed when collapse:true.

Actual/Current behavior

Fields are not collapsed.

Steps to reproduce the actual/current behavior

Flyer.add({
  date: { type: Types.Date, required: true, initial:true, index: true },
  store: { type: Types.Relationship, ref: 'Store', initial: true },
  image: { type: Types.CloudinaryImage, required: true, initial:true }
  image2: { type: Types.CloudinaryImage, collapse: true, initial:true },
});

Environment

Software Version
Keystone 4.0.0-beta.5
Node 6.11.0

Proposed Change

It looks like this issue is caused because the default props.value of these components are being set as an empty object in CloudinaryImage and an empty array in CloudinaryImages. This causes the shouldCollapse helper to return false because it sees the empty object and array as an existing value.

I suggest adding shouldCollapse helper functions to both the broken components that overwrite the default behaviour and instead check whether the fields are empty using the existing hasImage and hasFiles helpers.

☝️ Let me know if this sounds ok and I'll submit a PR!

Contributor guide