decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.94k stars 3.04k forks source link

Add an hidden property to collections #3618

Closed magomimmo closed 4 years ago

magomimmo commented 4 years ago

Is your feature request related to a problem? Please describe.

Anytime you configure a files collection, a corresponding panel is added to the NetlifyCMS view of collections. As a consequence the Collections View of the CMS quickly become polluted of Collections not meant to be edited (e.g. Read Only) by the Editor and used as fields in other collections.

Describe the solution you'd like

Add a boolean hidden property to collections as we already have the same hidden property for fields in such a way that the read-only collections do not pollute the editor view of the collections

Describe alternatives you've considered

I have no alternative solution at the moment

Additional context

When you are migrating a db based CMS to NetlifyCMS, it always happens that you need to make reference to what is known as lookup table in db parlance. Most of the time those lookup tables are readable only by the content editor (e.g. countries, states, cities, etc.). By making files collection (or folder collection as well) hidden-able, we reach a more clean view of collections for the editor.

hanneskuettner commented 4 years ago

Chipping in here since I like the idea and have a similar problem.

Do you just want to hide the collection in the UI and someone with the right URL could still edit a collection or should editing in general be prevented?

magomimmo commented 4 years ago

Hi @hanneskuettner, I think that the editing of the collection should be prevented in general.

erezrokah commented 4 years ago

Just to make sure I understand - the use case here is hiding a file collection that is only meant to be used in a relation widget? File collections are not read only as you can edit the content of the entries (you can't add new ones).

magomimmo commented 4 years ago

Yes, my use case is that one.

erezrokah commented 4 years ago

Thanks for clarifying, just in case someone would be interested in contributing, I think https://github.com/netlify/netlify-cms/blob/72b26f4435b428f79805920566678627e60fffaa/packages/netlify-cms-core/src/components/Collection/Sidebar.js#L108 is a good place to start.

shashank-bairy commented 4 years ago

@magomimmo I would like to work on this issue. This is my first time on netlify-cms and it would be really helpful if anyone could guide me on how to resolve this issue. Thanks.

erezrokah commented 4 years ago

Hi @BA1RY, thank you for the initiative. This will require adding a hidden flag on the collection and filtering it in the UI here: https://github.com/netlify/netlify-cms/blob/72b26f4435b428f79805920566678627e60fffaa/packages/netlify-cms-core/src/components/Collection/Sidebar.js#L136 You'll probably need to add the flag to our config schema here: https://github.com/netlify/netlify-cms/blob/b151bdfd7311472eaa1861e9fc17546a3658a083/packages/netlify-cms-core/src/constants/configSchema.js#L120 and update the docs here: https://github.com/netlify/netlify-cms/blob/b151bdfd7311472eaa1861e9fc17546a3658a083/website/content/docs/configuration-options.md#collections Please see https://github.com/netlify/netlify-cms/blob/b151bdfd7311472eaa1861e9fc17546a3658a083/CONTRIBUTING.md as well.

shashank-bairy commented 4 years ago

@erezrokah Thanks a lot. Will do.

magomimmo commented 4 years ago

Hi all, IMHO opinion we should start by defining more precisely the requirement of this feature. My feature requested emerged in the context of the evaluation of NetlifyCMS as the target of a database intensive web application. Any db model has relationships between tables and a few number of the relations targets are known as lookup tables. Some of these lookup tables are "closed" meaning that they are not intended to be updated by the CMS user (add new or update records).

Those kind of lookup tables can be mapped as JSON file in the data folder and a file collections is a natural NetlifyCMS concept to be used to describe them.

json file sample:

{
  "places": [
    {
      "id": "000002",
      "name": "Bergamo (BG)"
    },
    {
      "id": "000003",
      "name": "Milano (MI)"
    },
    {
      "id": "000004",
      "name": "Lurano (BG)"
    },
    {
      "id": "000005",
      "name": "Roma (RM)"
    },
    {
      "id": "000006",
      "name": "Salerno (SA)"
    },
    {
      "id": "000007",
      "name": "Napoli (NA)"
    },
    {
      "id": "000008",
      "name": "Quarna Sotto (VC)"
    },
    {
      "id": "000009",
      "name": "Verona (VR)"
    }
  ]
}

Now, imagine that I have a people folder collection like the following:

collections:

  # People
  - name: 'people'
    ...
    folder: 'content/people'
    fields:
      ...
      # Place
      - label: 'Place'
        name: 'place'
        widget: 'ncw-file-relation'
        collection: 'lookups'
        file: 'places'
        target_field: 'places'
        id_field: 'id'
        display_fields: 'name'

NOTE: I'm using ncw-file-relation because the standard relation widget does not work with a file collection as a target

Following is the files collection definition:

  # Lookup tables
  - name: 'lookups'
    label: 'Lookup Tables'
    files:
      - label: 'Places'
        name: 'places'
        file: 'data/places.json'
        fields:
          - label: 'Places'
            name: 'places'
            allow_add: false
            widget: 'list'
            fields:
              - label: 'Name'
                name: 'name'
                widget: 'string'
              - label: 'ID'
                name: 'id'
                widget: 'string'

Now suppose to have a lot of these kind of file collections not intended to be edited by the CMS user, and that few of them have thousand of recorded items.

You don't want to pollute the CMS UI with useless File Collections, like places non intended to be shown to the CSM User. She does only want to choose the right place to be set in the people collection.

We already have a create option for folder collection, but I don't mind if we want to have a new one (.e.g hidden), to be used in the context of files collections.

But all these trouble is useless if we do not have a standard relation widget able to target file collections as above.

That to say that I would first fix the relation widget is such a way that it could target file collections, then I would introduce a boolean create option to the file-collections in such a way that the developer can choose if that collection is editable by the CMS user or not.

Am I wrong in the above reasoning?

erezrokah commented 4 years ago

That to say that I would first fix the relation widget is such a way that it could target file collections

Completely agree on that.

I think targeting file collections works, just not a specific file https://github.com/netlify/netlify-cms/issues/800#issuecomment-487197188 but will have to test more to see it behaves in a way that makes sense.

magomimmo commented 4 years ago

I think targeting file collections works, just not a specific file #800 (comment) but will have to test more to see it behaves in a way that makes sense.

I'll take a look an let you know.

magomimmo commented 4 years ago

I think targeting file collections works, just not a specific file #800 (comment) but will have to test more to see it behaves in a way that makes sense.

I'll take a look an let you know.

Hum....I would prefer much more to target a specific file in a files collection, as the author of the comment himself said.

erezrokah commented 4 years ago

Hum....I would prefer much more to target a specific file in a files collection, as the author of the comment himself said.

I agree - it makes much more sense

shashank-bairy commented 4 years ago

@magomimmo @erezrokah so how shall I proceed?

erezrokah commented 4 years ago

I think hiding a collection has value and should be simple to implement regardless of the relation widget issue, so I would say just go for it and we can fix the relation widget in an unrelated PR. @magomimmo sounds good?

magomimmo commented 4 years ago

sounds good! Go on, please.

shashank-bairy commented 4 years ago

@magomimmo @erezrokah Is the hidden property true or false by default? I'm updating it in the docs

magomimmo commented 4 years ago

@BA1RY I would say false, to conform to the hidden option for fields. @erezrokah ?

erezrokah commented 4 years ago

false by default like @magomimmo said

shashank-bairy commented 4 years ago

@magomimmo @erezrokah I've made a PR. Please check it. Thank you.

magomimmo commented 4 years ago

Great @BA1RY ! we're now in the @erezrokah hands. Have a good night!