-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Feature: edit data files with a list/array at root level #531
Comments
Thanks for opening this - it's definitely something folks have needed. I think the most straightforward approach would be to accept a boolean This probably conflicts with #468 as well, where I believe we're outmoding the list widget in favor of a "repeatable" flag for all fields, in which case any "repeatable" field could have a "root" field (but still only one field defined if there's a root). Would you be up for taking a swing at this? |
Unfortunately I'm super busy with university. :( |
No problem! I'm sure someone will take it on. |
I would be happy to implement this - currently it is not possible to use Any pointers on where to look in the code to get started? I'm pretty new to netlify. |
I have solved this on the gatsby side with a custom yaml transformer. I would still like to support it here for maximum flexibility :) |
Forget the boolean thing I said before, we should apply the
Here's the list widget using # list field config using `fields`
- name: my-list
label: My List
widget: list
fields: [{ name: title, label: title, widget: string }]
# output:
# list: [{ title: 'a title' }, { title: 'another title' }] Here's the same widget config using # list field config using `field`
- name: my-list
label: My List
widget: list
field: [{ name: title, label: title, widget: string }]
# output
# list: ['a title', 'another title']
Note: this is a proposal, doesn't actually work! - name: posts
label: Posts
file: data/list.json # this only makes sense for file collections
field: [{ name: name, label: Name, widget: string }]
# output
['item', 'another item'] The UI and certain config options (like I can't think of any downsides or issues with this approach, personally. Thoughts? |
Are there any updates regarding the proposals mentioned above? This is a deal-breaker for Gatsby users, please see #1282. |
@kripod I believe this is a feature the CMS should support, Until then, it is NOT a deal-breaker for Gatsby users when it is still able to map to a structure the CMS does support at the moment. |
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. |
This is still happening. |
I've just patched this locally in
Not as clever as the approach mentioned above - but if you think of it as normalising files to always be a map instead of sometimes passing arrays around then it feels a bit less hacky. |
No fix on this since 2017? )= |
Hi @cyonder, we try to get to the most up voted features first. You can see the sorted list here https://github.com/netlify/netlify-cms/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc. |
I just tried to see if I could get the ball rolling on this issue.
Doing edits / adding new content would be similar to above but in reversed order. But the assumptions of content being in separate files made it very complicated straight away but maybe my idea was overly complicated? Would love to get some help / discussion with main contributors to the project. <3 |
Hi @reimertz, thanks for pushing this forward. Another option is our #contributing channel on Slack https://www.netlifycms.org/chat. |
Hi everyone, any update on this ? |
Hi @vnourdin this would make a great contribution to the CMS if anyone would like to pick it up |
Just to said this is also an issue for @nuxt/content with array at the root level of a json. Like here. |
+1 would love to see support for .json files with array at root level to mimic a MongoDB collection |
would love to see support for this |
Still needed :) |
NEEEEED |
Need it.... |
Here is a workaround: CMS.registerCustomFormat('flat-json', 'json', {
fromFile: text => {
const body = JSON.parse(text) as Record<string, Record<string, string>>;
// Now we want to transform this object into a flat object with a 'key' field
const value = { items: Object.entries(body).reduce((acc, [key, value] : [
string,
Record<string, string>
]) => {
acc.push({ key, ...value });
return acc;
}, [] as Record<string, string>[]) };
return value;
},
toFile: (value : { items: Record<string, string>[] }) => {
const body = value.items.reduce((acc, { key, ...rest }) => {
acc[key] = rest;
return acc;
}, {} as Record<string, Record<string, string>>);
return JSON.stringify(body, null, 2);
}
}); - name: 'redirects-collection'
label: 'Redirects'
format: 'flat-json'
files:
- label: 'All Redirects'
file: 'sigpwny.com/src/redirects.json'
name: 'redirects'
fields:
- {label: 'Links', name: 'items', widget: 'list', fields: [
# must be named 'key' for our custom formatter to work
{label: 'From', name: 'key', widget: 'string', hint: 'Example: "/qrcode"'},
{label: 'To', name: 'destination', widget: 'string', hint: 'Example: "myurl.com/foo"'},
{label: 'Status Code', name: 'status', widget: 'hidden', default: 302}
]} If you have a folder collection, you need a title field, and then your |
- Do you want to request a feature or report a bug?
Feature
- What is the current behavior?
it seems to be impossible to create data files with a list at root level:
The current work-around is to use
However, this may require a change of the template that may be part of libraries (jekyll theme gems).
- What is the expected behavior?
I can just create lists also on root level.
The text was updated successfully, but these errors were encountered: