-
Notifications
You must be signed in to change notification settings - Fork 903
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
Format sources properly on country panel using Intl.ListFormat
#4382
Format sources properly on country panel using Intl.ListFormat
#4382
Conversation
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.
Hmm this would require splitting and formatting on each render.
Perhaps I also miscommunicated in my last thread, when I said multiple items were depending on this value, I was referring to the entire infrastructure and DB, so we just can't change it to an array in all projects and the database.
I think that an arguably better solution would be to change this line here so we always treat source as an array of sources.
Then we can at least avoid splitting on each render.
Additionally maybe we'd want to use a memo for the formatted string, I can't recall the exact ratio for when a memo is worth it, but I believe we rerender the panel each time the graph/time is changed, while we don't actually need the sources to change
PS: I know the actual performance changes of this is not very high, but I think it's still worth thinking about
Oh, yeah it would be better to do it further upstream as you suggest, as for memo I can certainly add it but not sure if it will be worth it with the above change. I'll see if I can update the EDIT: Turning this into a draft in the meantime. |
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 ended up changing the removeDuplicateSources
function ever so slightly so it return a array instead of a string.
I couldn't find any other places where "data".source
was used so it should be safe.
@@ -101,16 +101,17 @@ function combineZoneData(zoneData, aggregate) { | |||
|
|||
function removeDuplicateSources(source) { | |||
if (!source) { | |||
return null; | |||
return undefined; |
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 change is needed so Intl.ListFormat don't fail.
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.
Looks great,
I am not sure in general how to handle the new keyword with intl stuff. We also use the new keyword elsewhere on each render so it's not exclusive here.
I am not sure if that could affect performance.
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.
Actually I just forgot, we have a file called formatting.js
I think it would be pretty cool if we moved this into a function called "formatDataSources" and placed it there
I'll try and move them later today. 👍🏼 |
I think we should treat Intl itself just like Math or Object but since the Intl objects consume configurations (settings) we could define those in a "settings" file/object of some kind. |
Yeah, specifically i am thinking that for each render we create a new instance of the intl object. This has some kind of instantiation cost associated to it. Anyways, that's probably not relevant for this PR |
I didn't have time to change anything today but I'll do it this weekend. However I think this will suffer the same fate as #4630 so I was thinking of just adding a fallback to display a simple array (like today) instead if |
Sounds good to me! :) |
@Kongkille should be good to go now! I created a formatting function and fixed the merge conflicts. |
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.
Great! I'll create a PR for fixing #4630 :)
Requested change has been fixed already :)
I just tried the "dismiss review" feature, but it's probably best to avoid it in future in case @Kongkille had some additional comments to the implementation of the requested change 😄 |
Maybe I should have held off on the merge then... 😅 |
This formats the sources on the country panel properly while also localizing the strings.
Reference: #4362