keystonejs/keystone-classic

Cloudinary fields not collapsing

Open

#4,526 创建于 2017年12月2日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)JavaScript (14,656 star) (2,288 fork)batch import
bughelp wanted

描述

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!

贡献者指南