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

Nested field access in name #595

Open
robinvdvleuten opened this issue Sep 12, 2017 · 9 comments
Open

Nested field access in name #595

robinvdvleuten opened this issue Sep 12, 2017 · 9 comments

Comments

@robinvdvleuten
Copy link

It would be very nice to have the possibility to have nested fields access in field names.

Currently when I am configuring a nested field like this;

files:
      - file: 'site/content/_index.md'
        name: sections
        label: 'Sections'
        fields:
          - name: about
            label: 'About'
            widget: object
            fields:
              - { name: title, label: 'Title', widget: string }
              - { name: body, label: 'Body', widget: markdown }

It gives me the following;

-section-----
|--about----|
|----title--|
|----body---|
-------------

But if would be nice if I can just do this;

files:
      - file: 'site/content/_index.md'
        name: about
        label: 'About'
        fields:
         - { name: 'about.title', label: 'Title', widget: string }
         - { name: 'about.body', label: 'Body', widget: markdown }

And having this output;

-about-------
|--title----|
|--body-----|
-------------
@erquhart
Copy link
Contributor

erquhart commented Dec 8, 2017

Providing more control over the data model makes sense, agreed. Just need to figure out how the api should work, I think we can do better than dot notation (but maybe not?).

@01ivr3
Copy link

01ivr3 commented Mar 15, 2018

If I understand this correctly, adding this feature could help clean up the editor experience quite a lot.

Say I have the following front matter on some Hugo pages.

menu:
  main:
    weight: '1'

Setting this one integer value per page will determine both the sort order and whether the page is included in Hugo's built-in nav system. Hugo will take care of the rest using the page title as the default label for each entry and auto-generating the relative links.

Now someone please correct me if I am wrong, but to make this one field editable in NetlifyCMS, I believe I need something like the following in config.yml:

- label: "Menu"
  name: "menu"
  widget: "object"
  fields:
    - label: "Main"
      name: "main"
      widget: "object"
      fields:
        - {label: "Weight", name: "weight", widget: "number"}

This will yield a three layer deep nested object UI in NetlifyCMS to edit one single field, which will also look about as hideous as it sounds.

@randallmlough
Copy link

+1 for this issue. Not being able to nest fields is a big UI / UX issue in my opinion.

@erquhart
Copy link
Contributor

erquhart commented Apr 26, 2018

Man, just had to get a simple value nested a couple levels deep for the docs site and yeah, this is pretty silly.

screen shot 2018-04-26 at 7 48 09 pm

@robinvdvleuten
Copy link
Author

And it should be quite easy to implement with a library like https://github.com/developit/dlv or https://github.com/robinvdvleuten/shvl.

@erquhart
Copy link
Contributor

We're already including Lodash, so I'd expect we go with _.toPath. The challenge is in the details, e.g. collisions and validation.

@randallmlough
Copy link

@erquhart is this something we could have a fix for in 2.0? I know the status of this is "accepted"and I saw there's a some open projects to rework the API, but didn't see something that explicitly mentions this type of functionality.

@erquhart
Copy link
Contributor

If someone wants to take it on, we're open to a PR. We'd need to map when writing and also reverse map when reading, and ensure graceful handling of collisions. That said, I'd say this is ready for development.

@stale
Copy link

stale bot commented Oct 29, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants