-
Notifications
You must be signed in to change notification settings - Fork 5
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
Formatter for printing categories #946
Conversation
- add a formatter getCategoryNames that will return a list of category names based on the list of category ids and HH supplied map of id to display name J=SLAP-823 TEST=auto add jest test and see that it passed sucessfully
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 think it could be worth asking Rose if this formatter should output a list of strings, as they outline in the DocMD, or if it should output a single string. In the card, they composed this formatter with the joinList
one. I'm wondering if they will want that to happen automatically inside this Formatter
. If there's another use-case for a list of category names, unconcatted, then we would not want to add that additional step in this new formatter.
|
static/js/formatters-internal.js
Outdated
} | ||
return categoryIds.reduce((list, id) => { | ||
const categoryNames = categoryIds.reduce((list, id) => { | ||
const categoryEntry = categoryMap.find(category => category.id === id); | ||
categoryEntry && list.push(categoryEntry.category); |
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.
Maybe if there's not a corresponding category entry, we display a console.error
?
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.
Updated!
static/js/formatters-internal.js
Outdated
categoryEntry ? list.push(categoryEntry.category) : console.error(`Unable to find category name for id ${id}.`); | ||
return list; | ||
}, []); | ||
return categoryNames.join(', '); |
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.
are they going to ask for the last element to be separated with an "and" instead of a comma?
like would they ever want
"category 1, category2, and category3"
(I hope not because i18n would be annoying with 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.
good point. Talked to Rose, I will revert this to return an array of category instead, and it will be up to the user to customize it with join list formatter or manipulate the list however they want
## Version 1.24.0 ### Features - A new formatter was added that prints the list of categories applied to an entity. (#946) - Added a new localized price range formatter. (#943) ### Enhancements - Google's text highlighting was added to the "View Details" link on the `document-search` Direct Answer card. Note that the highlighting is only applied when the user's browser is Chrome. (#945) - The Open Status translations are no longer hard-coded in `static` JS files. Instead, they are sourced from the Theme's .PO files. This means they can be overridden in custom .PO files. ### Bugfixes - Styling was added to the `prominent-image` and `prominent-video` cards to ensure that images and videos, respectively, are the same size. (#941, #950)
J=SLAP-823
TEST=auto
add jest test and see that it passed sucessfully