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

Confusing behavior when you add collection config without creating entry file #929

Closed
carrickjason opened this issue Dec 16, 2017 · 16 comments

Comments

@carrickjason
Copy link

- Do you want to request a feature or report a bug?
Both? Not sure if what is happening is desired behavior.

- What is the current behavior?
If you add a file entry to a collection in the config.yml file without adding the file at the specified path, The CMS simply shows 'No Entries' for that collection. If you remove that file config, the rest of your entries show up as they should.

- If the current behavior is a bug, please provide the steps to reproduce.
Add a file entry to a collection without adding the file in your fs.

- What is the expected behavior?
The docs are not clear that, in order to add an entry, you must also create the file yourself. I guess I assumed that it would because if you add an entry to a folder type collection, it adds/commits the file for you. On top of this, only seeing 'No Entries' under the collection in the CMS and not seeing anything in the browser console is confusing and made it difficult to debug.

- Please mention your CMS, node.js, and operating system version.
CMS version 1.0.1
Node version 9.2.1
OS: Mac OS High Sierra

I'm loving the CMS though and If I can provide any help on this, please let me know.

@tech4him1
Copy link
Contributor

tech4him1 commented Dec 16, 2017

cc/ @erquhart This looks like a regression in 1.0. If one of the files in a file collection does not actually exist in the repo, no files at all in the collection show up.

@erquhart
Copy link
Contributor

erquhart commented Dec 22, 2017

I checked, this goes back to 0.4.0 at least.

@carrickjason we would definitely take a PR for this!

@tech4him1
Copy link
Contributor

I think there a two separate bugs we need to think of this as here:

  1. No files in the collection show up if one is missing. This is definitely a high-priority bug.
  2. (After that is fixed,) If a file is missing, it is not shown in the collection. Creating the file would be an enhancement, still fairly high priority.

@tech4him1 tech4him1 removed the hot label Jan 21, 2018
@Swieckowski
Copy link
Contributor

I think I'd like to claim this. Thanks!

@erquhart
Copy link
Contributor

Awesome!

@tech4him1
Copy link
Contributor

I've looked into this a bit, but forgot to update the issue. The applicable code is:
https://github.com/netlify/netlify-cms/blob/756d562c6651b1634143f1f7d47ffc8119fe59bb/src/backends/github/implementation.js#L60-L83

I'm guessing when readFile returns a 404, and the Promise is rejected, it causes some rejection further up the call stack that prevents any of the files from showing up.

@tech4him1
Copy link
Contributor

Just brainstorming, I wonder if a good way to do that would just be to create a blank file immediately? Or we could just resolve to an empty string instead of rejecting (only if a 404). Either way, though, we would need to make sure this only happened during entriesByFiles calls, not with entriesByFolder.

@erquhart
Copy link
Contributor

erquhart commented Feb 1, 2018

Agreed, but we should notify the user at least with a toast or something, "Created blank file "_data/entry.json", especially since it's a deviation from current behavior. In the future (like beyond 2.0), I'd like to see this pulled into validation and some kind of prompt like "The files listed below are in your configuration, but don't exist in your repo. Would you like to create them now?". But again, that's futuristic :)

@tech4him1
Copy link
Contributor

@erquhart So, I see two ways to fix this, then:

  1. Only show files that actually exist in the repo.
  • This would still fix this issue, as it was causing all files to disappear.
  1. Create a new file if it's in the config.
  • I don't actually think this is really a deviation from our current behavior -- if the file is explicitly specified in the config, I'm assuming that it should be able to be filled out?
  • This could either be done at load time, or save time.

@erquhart
Copy link
Contributor

erquhart commented Feb 2, 2018

Not a deviation, I guess just a feature. I'd say load time only because the file may have been misspelled, so we should make it clear what happened.

@renestalder
Copy link
Contributor

renestalder commented Feb 21, 2018

I don't get it. I just tried to create a file collection. I used the example code from the documentation, but it only shows "No entries". Now, in your issue description you say, the file has to be created by the developer. No mention of that in the documentation. And it's also not clear whether an empty file is enough or whether it needs the container the data structure with empty values. Anyway, can't get file collections working.

@erquhart
Copy link
Contributor

erquhart commented Feb 23, 2018

@renestalder an empty file is enough if the format accepts an empty value as valid. e.g., a blank file is valid YAML, but not valid JSON, as JSON requires some kind of recognizable, non-empty value.

If all files in your configuration exist in your repo, and contain valid values for the file type, the collection will work.

@erquhart
Copy link
Contributor

Also, docs are now updated with this information, thanks for pointing out the gap.

@tech4him1
Copy link
Contributor

This has been partially fixed in #1093 -- if a file fails to load, all other entries in a collection will still work.

@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.

@stale stale bot added the status: stale label Oct 29, 2019
@erezrokah
Copy link
Contributor

closing as stale. Please comment if still relevant

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

6 participants