-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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(netlify-cms-widget-list): allow 'summary' field #3616
feat(netlify-cms-widget-list): allow 'summary' field #3616
Conversation
const fallbackLabel = itemType.get('label'); | ||
const summaryTemplate = itemType.get('summary'); | ||
return summaryTemplate | ||
? compileStringTemplate(summaryTemplate, null, '', item) |
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.
We'll want to handle Date in an item's content here. Also we may want to pass in the type's label, so user can do i.e {{type.label}} | {{name}}
instead of manually copying the label into the string template
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.
You can add additional templates by modifying the item data, e.g.
item = item.set('label', itemType.get('label'))
Then {{label}}
should work.
See: https://github.com/netlify/netlify-cms/blob/f88c83b97a18d9094240b688739d8b2909f19b0c/packages/netlify-cms-core/src/lib/formatters.ts#L125
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.
If you have an existing label
field you should be able to access it via fields.label
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 @erezrokah, that's neat!
Could we extend this to also allow a |
Yeah, I think a "fallback" to the summary entry on the list declaration itself makes sense and covers all the bases. |
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.
@d4rekanguok thanks for putting this up.
I'm good with this approach. Is there anything we can do on our side?
@erezrokah I don't think so, requiring
Perhaps adding I'm a bit occupied at the moment, would you be able to step in and continue this PR @djMax? |
FYI, |
let labelReturn = label | ||
if (summary) { | ||
const data = item.set('label', label) | ||
labelReturn = stringTemplate.compileStringTemplate(summary, null, '', data) |
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.
@erezrokah It looks like in a string template, slug
and date-related keys are hard-coded in:
When I tried using {{fields.label}}
, it returns the same value as {{label}}
. Should I pass in type's label
under a different name/map?
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 {{fields.*}}
format is useful when you want to avoid collision with built in tags, for example let's say you want to reference a field named slug
(see note here https://www.netlifycms.org/docs/configuration-options/#slug).
When referencing a field I would say it is safer to always use {{fields.fieldName}}
to avoid possible future collisions (for example we recently added built in filename
and extension
template tags)
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.
Hi @erezrokah, thank you for further explaining about the field.
format. I think I might be missing something, let me walk through this issue I have in my head:
Say I have an item
Map with { label: 'One' }
The following code will replace label
with item.getIn(['label'])
, returning 'Type: One'
.
compileStringTemplate("Type: {{label}}", null, null, item) // "Type: One"
I can override this label
field by adding a new field to item
, and now the following code should return Type: Two
:
item = item.set('label', 'Two')
compileStringTemplate("Type: {{label}}", null, null, item) // "Type: Two"
This works!
Now here's the part I'm confused about. The following code should replace fields.label
with the original label
in item
& return Type: One
.
compileStringTemplate("Type: {{fields.label}}", null, null, item) // "Type: Two"
This doesn't work.
Looking at the code of getExplicitFieldReplacement
which handles keys with fields.
prefix, it removes fields.
prefix and use data.getIn(keyToPathArray(fieldName))
to access the value of the label
.
Looking at the code of compileStringTemplate
, if a field is not a date-related key (year
, month
, day
, etc), doesn't start with fields.
, or is not slug
, it will access the value of the key via data.getIn(keyToPathArray(key), '')
.
Because of this, compileStringTemplate
does exact the same for fields.label
and label
in stringTemplate:
let data = Map({ label: 'One' })
data = item.set('label', 'Two')
labelReturn = stringTemplate.compileStringTemplate('{{fields.label}} | {{label}}', null, '', data)
I see no special handling for filename
and extension
either, so I'm lost on understanding how it works. Do I have to do something special so the original data is preserved? Thank you!
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.
Sorry for not being clear enough. At the moment {{label}}
{{fields.label}}
have the same result, but we might want to have a built in label
with special meaning in the future (like date
and slug
). If we do decide to make label
a built in template var it would break behaviour for existing users that use {{label}}
without the fields
prefix and we would need to apply backwards compatibility code for that. To avoid doing so in the widget as well using fields.label
is safer.
As for filename
and extension
, they are added when relevant here https://github.com/netlify/netlify-cms/blob/1c7ef1c457612242257d96af53a57c1460e45b31/packages/netlify-cms-core/src/lib/formatters.ts#L206
For example, adding those templates when evaluating the slug doesn't make any sense since the filename is based on the slug.
Hi @jozsi, we recently added |
100c3d3
to
731b167
Compare
@d4rekanguok, I hope you don't mind, but I rebased the branch and added support for |
Dear @erezrokah, I am on latest. If you are referring to the string template support, I tried it, no luck. But it might be related to #3739 so I am not going to pollute this issue further, sorry! |
@erezrokah Super neat, thank you for taking this over & taking it all the way (allowing summary field for regular lists) 👍! Also thank you for the collaborator invitation, I'm honored to be a part of this project. |
Long overdue on the invitation 😄 |
Was I removed as a maintainer @erezrokah @erquhart ? |
A while ago maintainers without two-factor where removed, you might have been a victim. |
I have 2FA, that's not the case here. |
Hey @talves - yes, we try to keep our access current. If you're thinking of getting involved again that would be awesome! I'll send your collaborator invite now. |
This really disappoints me after all the contributions I did. Although I have had limited time, there was no reason to remove my access, since I was and always have been a trusted maintainer. I am not surprised, but I think it warranted an email first. 😢 |
@talves that's a really good point, sending an email would have made a lot of sense. I reached out on Gitter a few times, but that definitely isn't the same thing. So sorry I didn't do a better job communicating here. Please understand this in no way reflects a lack of respect for all of the work you've done personally - I cleared out all of our user access from contributors with more than 6 months of no activity. I'll certainly handle this kind of action better in the future. |
Agreed, a big thank you from me too @d4rekanguok, as I didn't end up doing any real work on this one, but reap all the benefits! |
Hi folks! This PR is a WIP, in collaboration with @djMax
Summary
Fixes #3713
In the list widget's control, when an item is collapsed, only its type name is displayed. This makes it difficult for editors to understand the content of a list at a glance. This issue is more pronounced when editing a large list with many items of the same type.
This PR explores adding a
summary
field to each list's type, allow each item to display a summary based on its content, in the same fashion as a folder collection.- label: 'Typed List' name: 'typed_list' widget: 'list' types: - label: 'Type 1 Object' name: 'type_1_object' + summary: 'Type 1 | {{string}}' widget: 'object' fields: - { label: 'String', name: 'string', widget: 'string' } - { label: 'Boolean', name: 'boolean', widget: 'boolean' } - { label: 'Text', name: 'text', widget: 'text' }
We'd love to get feedback on this! We've also consider adding a
summary
field for the list widget itself that can be applied to all types.Test plan
[TBA]