decap-cms icon indicating copy to clipboard operation
decap-cms copied to clipboard

sortableFields should have default sorting options

Open fbnlsr opened this issue 4 years ago • 6 comments

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

Whenever I log into Netlify CMS, I have to always do the same operation so that the entries of a folder collection is displayed the way I'd like.

Describe the solution you'd like

I'd like if we could have an option in the sortableFields config so that we could specify a default order and display type. So for instance we could specify something like:

sortableFields:
  display: "grid"
  key: "commit_date"
  type: "desc"
  fields:
    - "commit_date"
    - "author"
    - "title"

fbnlsr avatar May 07 '20 12:05 fbnlsr

Thanks @fbnlsr, the sorting order and key should be persisted per collection, so you should only need to do it once (if that is not the case, can you please update to latest version and test again?).

The reason we didn't enabled a default sort is that it would require fetching all entries on initial load which can take some time (in large collections one might even reach the APIs limits).

Allowing to opt-in to it makes sense though.

The grid view not persisting is another issue unrelated to sorting.

erezrokah avatar May 07 '20 12:05 erezrokah

You're right, order and key are persisted. Grid view is not.

If we could still be able to enforce it via config.yml that'd be great still. :slightly_smiling_face:

fbnlsr avatar May 07 '20 13:05 fbnlsr

Just to make it clear - if a user manually sorts, that would override the config sort right?

erezrokah avatar May 07 '20 13:05 erezrokah

I feel it makes sense yes. The config could be used as a starting point or as an order suggestion, but it shouldn't come at the experience of the user's experience.

That is unless we could "freeze" it and make it impossible for the user to sort it again once it's been set in the config. We could imagine another optional key in the config that would make it so the sorting would be impossible. In that case, the fields parameter would be ignored. So for instance in the following example, since allow_sorting is present and set to false, fields are not shown:

sortableFields:
  display: "grid"
  key: "commit_date"
  type: "desc"
  allow_sorting: false
  fields:
    - "commit_date"
    - "author"
    - "title"

fbnlsr avatar May 07 '20 14:05 fbnlsr

I would like to work on this issue 😄

KancerEzeroglu avatar Nov 18 '20 11:11 KancerEzeroglu

For those who are wondering without official thing. You can find a localstorage entry called netlify-cms.entries.sort you can create this entry on local storage if there is none. With desired sorting. So when user logs in if there is none it will default to yours.

emre-eskimez avatar Jul 19 '22 09:07 emre-eskimez