Skip to content
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

Merged
merged 4 commits into from
Sep 10, 2021
Merged

Formatter for printing categories #946

merged 4 commits into from
Sep 10, 2021

Conversation

yen-tt
Copy link
Contributor

@yen-tt yen-tt commented Sep 10, 2021

  • 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

- 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
@coveralls
Copy link

coveralls commented Sep 10, 2021

Coverage Status

Coverage increased (+0.1%) to 8.334% when pulling 4eb8759 on dev/category-formatter into e9ffd0c on develop.

Copy link
Collaborator

@tmeyer2115 tmeyer2115 left a 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 Show resolved Hide resolved
@yen-tt
Copy link
Contributor Author

yen-tt commented Sep 10, 2021

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.

Checked in with Rose, updated to return a single string!
Update: We are keeping it as a list of categories instead

static/js/formatters-internal.js Show resolved Hide resolved
}
return categoryIds.reduce((list, id) => {
const categoryNames = categoryIds.reduce((list, id) => {
const categoryEntry = categoryMap.find(category => category.id === id);
categoryEntry && list.push(categoryEntry.category);
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

categoryEntry ? list.push(categoryEntry.category) : console.error(`Unable to find category name for id ${id}.`);
return list;
}, []);
return categoryNames.join(', ');
Copy link
Contributor

@oshi97 oshi97 Sep 10, 2021

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)

Copy link
Contributor Author

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

@yen-tt yen-tt requested a review from oshi97 September 10, 2021 15:34
@yen-tt yen-tt merged commit 483ef1e into develop Sep 10, 2021
@yen-tt yen-tt deleted the dev/category-formatter branch September 10, 2021 15:56
@tmeyer2115 tmeyer2115 mentioned this pull request Sep 14, 2021
tmeyer2115 added a commit that referenced this pull request Sep 14, 2021
## 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants