decaporg / decaporg/decap-cms

fieldsMetaData empty

Open
#4,819 1 comment 0 reactions 0 assignees View on GitHub
area: extensions/preview-templates area: extensions/widgets area: extensions/widgets/relation type: bug
Dominant language
JavaScript
Stars
19.4k
Forks
3.1k
Avg merge
1d 14h
Merged PRs (30d)
9

Description

**Describe the bug**
fieldsMetaData attribute is empty on registerPreviewTemplate() handler.

**To Reproduce**
register own PreviewTemplate and print out the incoming data.

```
CMS.registerPreviewTemplate('blog', BlogPostPreview)

const BlogPostPreview = (data) => {

console.log(data);
const {entry, widgetFor, getAsset, fieldsMetaData} = data;
...
}

```

**Expected behavior**
fieldsMetaData with data about the collection and more importantly about the "relation" collections. Thats the reason why i need it.

**Screenshots**
Bildschirmfoto 2021-01-09 um 14 15 32

**Applicable Versions:**
netlify-cms-app 2.14.10
netlify-cms-core 2.36.9
together with latest Gatsby.

**CMS configuration**
```
backend:
name: github
repo: logemann/okaycloudweb2
branch: main

local_backend: true

logo_url: https://okaycloud.de/static/okaycloud_logo-f77199ecfa7a21de8ce142f51ab6009f.svg
site_url: https://okaycloud.de
display_url: https://okaycloud.de
locale: 'de'
media_folder: static/images
public_folder: /images
slug:
encoding: "ascii"
clean_accents: true

collections:
- name: authors
label: Authors
folder: src/pages/blog/_authors/
extension: .md
media_folder: ''
public_folder: ''
format: frontmatter
create: true
fields:
- { label: Name, name: name, widget: string }
- { label: Title, name: title, widget: string }
- { label: Email, name: email, widget: string }
- { label: Shortbio, name: shortbio, widget: text }
- { label: Image, name: authorimage, widget: image }
- { label: "Template Key", name: "templateKey", widget: "hidden", default: "author" }

- name: "blog"
label: "Blog"
folder: "src/pages/blog"
create: true
slug: "{{title}}"
media_folder: ''
public_folder: ''
path: '{{year}}-{{month}}-{{day}}/{{title}}/index'
fields:
- { label: "Template Key", name: "templateKey", widget: "hidden", default: "single-blog-post" }
- { label: "Title", name: "title", widget: "string" }
- { label: "Author", name: "author", widget: "relation", collection: "authors", value_field: "email", display_fields: [ "name" ], search_fields: [ "name", "email" ] }
- { label: "Publish Date", name: "date", widget: "datetime", date_format: 'DD.MM.YYYY', time_format: "HH:mm U\\hr" }
- { label: "Description", name: "description", widget: "text" }
- { label: "Featured Post", name: "featuredpost", widget: "boolean", required: false }
- { label: "Featured Image (AR 1,0)", name: "featuredimage", widget: image }
- { label: "Social Media Image (AR 2,0)", name: "socialmediaimage", widget: image }
- { label: "Body", name: "body", widget: "markdown" }
- {
label: "Tags", name: "tags", widget: "select",
options: [ "Daimler", "BMW", "Fiat", "VW", "Porsche", "Bankrecht", "Kapitalmarktrecht", "Versicherungsrecht",
"Handelsrecht", "Gesellschaftsrecht", "Video", "Podcast" ],
multiple: true, max: 3 }
- {
label: "Category", name: "category", widget: "select",
options: [ "General", "Websites / SEO", "Cloud Infrastructure", "Software Development" ],
multiple: false }

```

**Additional context**

As written. For preview reason i need the authors image, which is stored in the "relation" collection. The only way to get those related attributes is via fieldsMetaData according to Docs.

One more note to the docs at https://www.netlifycms.org/docs/customization/ . I appreciate the specific section about MetaData but the example is pretty non-selfexplaining cause no one knows the data model behind this example. I mean, the obfuscation resulting by using Immutable.js is ok as long as the docs make it clear what kind of object "data" is in data.author. To me this snippet wouldnt even work because of that phantom "data" object.

Then in the document its written: "react_component: A React component that renders the collection data. Six props will be passed to your component during render:"

But with fieldsMetaData object, its 7 isnt it? Its not mentioned there as a bullet point.

I think tons of issues could be prevented by having proper API docs.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.