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

Add GGD measurements #338

Merged
merged 12 commits into from
Sep 25, 2020
Merged

Conversation

VWSCoronaDashboard4
Copy link
Contributor

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

Comment on lines 242 to 250
__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>`,
Copy link
Contributor

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.

Comment on lines 141 to 152
"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"
Copy link
Contributor

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';
Copy link
Contributor

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 <>

Copy link
Contributor Author

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.

@VWSCoronaDashboard4 VWSCoronaDashboard4 added the Hold This should not be merged (yet) label Sep 17, 2020

const text: typeof siteText.positief_geteste_personen =
siteText.positief_geteste_personen;

const percentageGgdText: typeof siteText.positief_geteste_personen_ggd =
Copy link
Contributor

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...

Copy link
Contributor

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}
Copy link
Contributor

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.

Copy link
Contributor Author

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)

*/

const replaceKpisInText = (
translation?: string | undefined | null,
Copy link
Contributor

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 ?

Copy link
Contributor

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?

* - 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.
Copy link
Contributor

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.

translation?: string | undefined | null,
kpis?: Kpi[]
): string => {
const variables: { [key: string]: string | undefined } = {};
Copy link
Contributor

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.

@VWSCoronaDashboard4 VWSCoronaDashboard4 removed the Hold This should not be merged (yet) label Sep 25, 2020
@VWSCoronaDashboard
Copy link
Contributor

In this situation I would prefer a different message

image

would be better as:

"Geen van de GGD testen was positief"

Copy link
Contributor

@VWSCoronaDashboard VWSCoronaDashboard left a 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}
Copy link
Contributor

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.

Copy link
Contributor Author

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.

* - If no translation is given, an empty string will be returned.
*/

export function replaceKpisInText(translation: string, kpis: Kpi[]): string {
Copy link
Contributor

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?

Comment on lines +240 to +255
__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',
},
]
),
}}
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor

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!

@VWSCoronaDashboard4
Copy link
Contributor Author

@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;
Copy link
Contributor

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
@VWSCoronaDashboard4 VWSCoronaDashboard4 merged commit 0d953b1 into develop Sep 25, 2020
@VWSCoronaDashboard4 VWSCoronaDashboard4 deleted the feature/percentage-positive branch September 25, 2020 13:28
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.

None yet

4 participants