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

fix(banner-notification): type check error on docs template #6557

Merged
merged 4 commits into from
Jun 3, 2022

Conversation

Mousticke
Copy link
Contributor

Description

The boolean passed from docs template to banner notification component
has an issue when the variable passed is null. The interface of the
banner props has shouldShow declared as boolean or undefined. To prevent
each component to check against null to boolean, the check is made
internally inside the banner component and shouldShow is declared as
boolean or null or undefined.

Related Issue

Related to : #6392

the boolean passed from docs template to banner notification component
has an issue when the variable passed is null. The interface of the
banner props has shouldShow declared as boolean or undefined. To prevent
each component to check against null to boolean, the check is made
internally inside the banner component and shouldShow is declared as
boolean or null or undefined.
@gatsby-cloud
Copy link

gatsby-cloud bot commented Jun 3, 2022

Gatsby Cloud Build Report

ethereum-org-website-dev

🎉 Your build was successful! See the Deploy preview here.

Build Details

View the build logs here.

🕐 Build time: 19m

Performance

Lighthouse report

Metric Score
Performance 🔶 21
Accessibility 💚 91
Best Practices 💚 100
SEO 💚 92

🔗 View full report

Copy link
Member

@pettinarip pettinarip left a comment

Choose a reason for hiding this comment

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

Hey @Mousticke thanks for catching this issue. I don't think the problem is in the BannerNotification component.

BannerNotification is a UI dumb component, it is agnostic of the consumers logic or problems. The problem is on the consumer side, the consumer (template/docs.tsx in this case) should send the correct value (a boolean) to the component.

// template/docs.tsx
const isPageIncomplete = !!mdx.frontmatter.incomplete // force it to be a boolean

// now we are always sending a boolean to the component
<BannerNotification shouldShow={isPageIncomplete}>

So, if you agree, we should revert these changes and fix it in the docs.tsx template.

@Mousticke
Copy link
Contributor Author

@pettinarip It was my first attempt to do something like this

const isPageIncomplete = !!mdx.frontmatter.incomplete // force it to be a boolean

Here was my thought :
I realized that if another component imports the BannerNotificaton component and set the shouldShow value with another variable, then the type guard has to be made again and again. In this way, I was saying myself that I can factor inside the component itself. As you said, the BannerNotification is agnostic. So the props shouldShow (if provided) has to work with false,true, undefined and null values.

If you do not agree, let's revert and fix it in docs.tsx :)

@pettinarip
Copy link
Member

Thanks for sharing your thought @Mousticke.

The problem with checking null is that you are fixing a problem that is not a concern of the component. Is not its responsibility to check that. null is a different value type.
We are defining an interface to force the consumers to respect that. E.g. if the consumer sends an empty string, the component shouldn't have a check to account for that case. I don't like adding more logic to the component to fix the problems of the consumers.

@Mousticke
Copy link
Contributor Author

Mousticke commented Jun 3, 2022

@pettinarip Understood and It makes sense.
Let's revert :)

isPageIncomplete variable is truthy or falsy but the banner notification
component accept a boolean props. So we convert truthy or falsy to true
or false

Refs: ethereum#6392
@pettinarip
Copy link
Member

Thanks to you, for your comprehension and the time you put into this 💪🏼

@Mousticke Mousticke requested a review from pettinarip June 3, 2022 22:35
Copy link
Member

@pettinarip pettinarip left a comment

Choose a reason for hiding this comment

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

Thanks @Mousticke 🚀

@pettinarip pettinarip merged commit 34d483f into ethereum:dev Jun 3, 2022
@Mousticke Mousticke deleted the ts-fix-banner-notification branch June 3, 2022 23:16
@minimalsm minimalsm mentioned this pull request Jun 13, 2022
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.

2 participants