-
-
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
feat(core): Allow customising the collection list based on multiple fields #2140
Conversation
Preview proposed changes to the CMS demo site in the link below: Built with commit af645e9 |
Preview proposed changes to netlifycms.org in the link below: Built with commit 077a408 |
@devinea I like where this is going! List view customization is a long standing feature request, so thanks for picking this up! I have to say though, I find the concept of having three different options to displaying a text in the list view ( |
I like this feature. Great start! I agree, we should just check for an array and use it if it exists. and then have |
Thanks for this @devinea! See #2019 for previous discussion on how to address the underlying issue here. The current practice for constructing custom values in the configuration is to use template strings, as we do for the slug config, so we should probably go that route for this as well: https://www.netlifycms.org/docs/configuration-options/#slug This would allow us to use a familiar approach and just one config field to set it up. We could call the config key Your use case would then look like: - name: 'faq' # Used in routes, ie.: /admin/collections/:slug/edit
label: 'FAQ' # Used in the UI
folder: '_faqs'
summary: '{{version}} - {{title}}'
create: true # Allow users to create new documents in this collection
fields: # The fields each document in this collection have
- { label: 'Question', name: 'title', widget: 'string', tagname: 'h1' }
- { label: 'Answer', name: 'body', widget: 'markdown' }
- { label: 'Version', name: 'version', widget: 'string', default : '1.01' } Thoughts? |
Hey everyone, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this together @devinea and @MerlindlH!
function slugFormatter(collection, entryData, slugConfig) { | ||
const template = collection.get('slug') || '{{slug}}'; | ||
|
||
export function getIdentifier(entryData, collection) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a wrapper around selectIdentifier
, use that instead of exporting this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed, thanks :)
|
||
const summary = collection.get('summary'); | ||
if (summary) { | ||
title = compileSlug(summary, new Date(), getIdentifier(entryData, collection), entryData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The date replacements should be based off of fields in the entry, similar to what we do when creating a deploy preview URL: https://github.com/netlify/netlify-cms/blob/3cac3ef7796e89f8a3462b2dc06457fb4086cb29/packages/netlify-cms-core/src/backend.js#L242
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A problem could arise here if we do not have a date field in the entry.
We would like to use the compileSlug
function and "ignore" all date references in summary
(which compileSlug
currently doesn't allow, so we'd have to refactor it) or we could catch the raised exception and retry compileSlug
after removing all date template string from summary
@@ -128,7 +128,7 @@ export const selectInferedField = (collection, fieldName) => { | |||
const fields = collection.get('fields'); | |||
let field; | |||
|
|||
// If colllection has no fields or fieldName is not defined within inferables list, return null | |||
// If collection has no fields or fieldName is not defined within inferables list, return null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must have looked at this in annoyance a thousand times but never bothered to fix lol 👍👍
Pushed up a refactor, please test it in your setup and let me know if you run into any issues. It's rebased so you'll likely need to run |
export function extractTemplateVars(template) { | ||
const regexp = RegExp(templateVariablePattern, 'g'); | ||
return extractVars(template, regexp); | ||
const contentRegexp = RegExp(templateContentPattern, 'g'); | ||
return template.match(regexp).map(elem => elem.match(contentRegexp)[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brilliant!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, but I forgot to handle the case where there are no matches and the first match
-call returns null
instead of []
Apparently the search doesn't work anymore, I'm currently trying to figure out which change did crash it (update: fixed) |
Fantastic edits, thank you. Writing code when sleep deprived is never a good idea, not sure why I do it 🙄 Added a refactor and addressed the failing CI build. |
@MerlindlH everything looking good to your testing? We can merge and release in the next beta if so. |
I just checked it locally, fixed a small issue with searching a date and I think It's good to go (if the remote tests also go green, locally tests seemed fine) |
Sounds good - is one more commit coming for the date search fix you mentioned? Sent with GitHawk |
No, no more commits from my side (at least regarding the date search, that is fixed :) ) |
@MerlindlH @devinea this is currently published in the beta channel, you can use it at |
Awesome @erquhart @MerlindlH thanks |
Is this in the docs as of now, or should this thread be the general reference for now? Just curious because I don't see it, but I'm not sure if I'm overlooking it somewhere. |
@adamtaylor13 You can find this in the docs here: https://www.netlifycms.org/docs/configuration-options/#summary |
@tomrutgers DOH. I missed that somehow. Thanks! |
Summary
This allows customising the collection list display based on multiple fields rather than the
title
oridentifier_field
.Adding the following to the collection definition in the config.yml controls the feature.
full collection
Test plan
Here is a screenshot of the result.