keystonejs/keystone-classic

Cloudinary fields not collapsing

開放

#4,526 建立於 2017年12月2日

 (1 則留言) (0 個反應) (0 位負責人)JavaScript (2,288 個分叉)batch import
bughelp wanted

倉庫指標

星標
 (14,656 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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!

貢獻者指南