-
Notifications
You must be signed in to change notification settings - Fork 45
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
Add GGD measurements #338
Add GGD measurements #338
Conversation
__html: replaceVariablesInText( | ||
text.percentage_ggd_positief_getest_getest_week_uitleg, | ||
{ | ||
percentage: `<span class="text-light-blue inline-kpi">${formatDecimal( | ||
percentageDataGGD?.percentage_infected_ggd | ||
)}%</span>`, | ||
totaal: `<span class="text-dark-blue inline-kpi">${formatDecimal( | ||
percentageDataGGD?.total_tested_ggd | ||
)}</span>`, |
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.
Indeed this looks very verbose in order to just replace a few values. I wouldn't know of a cleaner way to do this though, but this is something we might need to discuss and see if we can come up with a nicer solution. For now, it works, so let's leave it.
src/locale/nl.json
Outdated
"percentage_ggd_titel": "Aantal geteste personen via GGD", | ||
"percentage_ggd_datums": "Waarde van {{dateOfReport}}. Verkregen: {{dateOfInsertion}}. Wordt dagelijks bijgewerkt.", | ||
"percentage_ggd_bron": { | ||
"href": "https://coronadashboard.rijksoverheid.nl/#ggd", | ||
"text": "GGD" | ||
}, | ||
"percentage_ggd_toelichting": "Dit getal zegt iets over het totaal aantal personen dat via de GGD getest is, en hoeveel daarvan een positieve uitslag hadden. Let op dat de meeste testen via de GGD lopen, maar dit niet voor alle testen geldt. Daarom wijkt het absolute aantal positief geteste personen af van het aantal positief geteste personen door de GGD.", | ||
"percentage_ggd_totaal_getest_week_titel": "Aantal geteste personen via GGD", | ||
"percentage_ggd_totaal_getest_week_uitleg": "Aantal personen die in één week via de GGD getest zijn.", | ||
"percentage_ggd_positief_getest_week_titel": "Positief getest personen via GGD", | ||
"percentage_ggd_positief_getest_week_uitleg": "Aantal en percentage positief geteste personen die in één week via de GGD getest zijn.", | ||
"percentage_ggd_positief_getest_getest_week_uitleg": "dit is {{percentage}} van {{totaal}} geteste personen" |
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.
nit: Might be easier to put this all in one object, to keep them contained/namespaced.
@@ -1,4 +1,4 @@ | |||
import { useState } from 'react'; | |||
import { useState, Fragment } from 'react'; |
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.
No need for Fragment, you can use <>
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.
No, that's not possible for the way it is used.
…ashboard into feature/percentage-positive
|
||
const text: typeof siteText.positief_geteste_personen = | ||
siteText.positief_geteste_personen; | ||
|
||
const percentageGgdText: typeof siteText.positief_geteste_personen_ggd = |
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 looks weird. Using typeof on a value to extract a type, and then assigning the same value to the type. Typescript should infer the same time if you leave out the type definition @VWSCoronaDashboard4
Looks like it happened before in this file, so maybe that inspired 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.
This is legacy code, the typing is no longer necessary since the entire locale struct is typed in locale/index.ts.
So import siteText from 'locale';
already returns a fully typed object.
<> | ||
<ContentHeader | ||
category={'\u00A0'} | ||
title={percentageGgdText.titel} |
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.
There's a lot of percentageGgdText.
type of prefixes in this file. I would destructure it first.
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've adjusted this variable name, but destructing it first causes other troubles (and it's not consistent with our use of text.
in other pages)
src/utils/replaceKpisInText.ts
Outdated
*/ | ||
|
||
const replaceKpisInText = ( | ||
translation?: string | undefined | 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.
Why undefined and null? Also undefined is already implied by the ?
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.
In what situation would you want to call "replace in text" without passing an actual text? Similarly why would you call this to replace kpis in a string if you do not have any kpis? In other words, are you sure these function arguments need to be optional?
src/utils/replaceKpisInText.ts
Outdated
* - If no translation is given, an empty string will be returned. | ||
* | ||
* @param translation - Translation string with curly brackets for variables. | ||
* @param kpis - An object with keys representing kpi object containing a value and class name available for replacement. |
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.
These king of annotations are a little redundant. Typescript will tell you the shape of the kpis. So now you have to remember to update the comments whenever the code changes.
src/utils/replaceKpisInText.ts
Outdated
translation?: string | undefined | null, | ||
kpis?: Kpi[] | ||
): string => { | ||
const variables: { [key: string]: string | 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.
I don't see any code below that would make the result undefined. Looks like all iterations will produce a string.
…ashboard into feature/percentage-positive # Conflicts: # src/pages/landelijk/positief-geteste-mensen.tsx
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.
Please add tests for your new utility method.
Besides that, I think we should start thinking about different i18n and l10n solutions to make maintenance of this project a bit easier. I know bundle size is a concern, but still...
category={'\u00A0'} | ||
title={ggdText.titel} | ||
id="ggd" | ||
Icon={Fragment} |
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.
What's the theory behind this?
Is Icon a required prop and we just want to render nothing? Shouldn't we make Icon an optional prop?
I've never seen this pattern before and am curious about 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.
Now that I look at this again... I'll work on simplifying this! It's working around the problem that without the icon it messes up the spacing of the layout, which is a silly excuse.
src/utils/replaceKpisInText.ts
Outdated
* - If no translation is given, an empty string will be returned. | ||
*/ | ||
|
||
export function replaceKpisInText(translation: string, kpis: Kpi[]): string { |
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.
Can you add tests for this in Jest?
__html: replaceKpisInText( | ||
ggdText.positief_getest_getest_week_uitleg, | ||
[ | ||
{ | ||
name: 'numerator', | ||
value: formatNumber(ggdData?.infected_ggd), | ||
className: 'text-light-blue', | ||
}, | ||
{ | ||
name: 'denominator', | ||
value: formatNumber(ggdData?.total_tested_ggd), | ||
className: 'text-dark-blue', | ||
}, | ||
] | ||
), | ||
}} |
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 starting to get relatively complex.
Is there a way where we can rely on the ICU message format without adding too much bloat to the bundle?
We can take a look at react-intl
, or at a lower-level intl-messageformat
.
https://formatjs.io/docs/core-concepts/icu-syntax#plural-format
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.
Not sure if any of these packages would solve / improve any of the attached code. What specific part do you want to see to be simplified?
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.
It would make pluralization easier, and it would remove the need for our custom replacement methods.
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.
But we can take that off the table and put it on the tech debt backlog!
@VWSCoronaDashboard The -% would be a data issue, I've added an extra safeguard to prevent this from getting displayed. |
@@ -35,4 +42,7 @@ interface IContentHeaderProps { | |||
text: string; | |||
}; | |||
}; | |||
category?: string; | |||
Icon?: React.ComponentType; |
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.
👍
…ashboard into feature/percentage-positive # Conflicts: # src/pages/landelijk/positief-geteste-mensen.tsx
Summary & Motivation
Adds GGD measurements to the UI.
Detailed design
Most things are similar to the other tiles.
Is there any feedback on the way I render the KPI sentence around the percentage?
Drawbacks
n/a
Alternatives
n/a
Unresolved questions
n/a
Governance
https://github.com/minvws/nl-covid19-notification-app-coordination/blob/master/LICENSE.txt
and the contributor license agreement https://github.com/minvws/nl-covid19-notification-app-coordination/blob/master/CLA.md