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

feat(RandomContributor): Migrate Component #5378

Conversation

Harkunwar
Copy link
Contributor

Description

Migrates RandomContributor from nodejs.dev

Related Issues

#5193

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run npx turbo lint to ensure the code follows the style guide. And run npx turbo lint:fix to fix the style errors if necessary.
  • I have run npx turbo format to ensure the code follows the style guide.
  • I have run npx turbo test to check if all tests are passing, and/or npx turbo test:snapshot to update snapshots if I created and/or updated React Components.
  • I've covered new added functionality with unit tests if necessary.

Harkunwar and others added 9 commits May 5, 2023 10:09
Co-authored-by: Manish Kumar ⛄ <[email protected]>
Co-authored-by: Wai.Tung <[email protected]>
Co-authored-by: Shanmughapriyan S <[email protected]>
Co-authored-by: Michael Esteban <[email protected]>
Co-authored-by: Claudio Wunder <[email protected]>
Co-authored-by: Teja Sai Sandeep Reddy Konala <[email protected]>
Co-authored-by: Claudio Wunder <[email protected]>
Co-authored-by: vasanth9 <cheepurupalli.vasanthkumar.com>
Co-authored-by: Aymen Naghmouchi <[email protected]>
Co-authored-by: Teja Sai Sandeep Reddy Konala <[email protected]>
Co-authored-by: Augustin Mauroy <[email protected]>
Co-authored-by: Guilherme Araújo <[email protected]>
Co-authored-by: Augustin Mauroy <[email protected]>
Co-authored-by: HinataKah0 <[email protected]>
Co-authored-by: Olaleye Blessing <[email protected]>
Co-authored-by: ktssr <[email protected]>
Co-authored-by: vasanthkumar <[email protected]>
Co-authored-by: Floran Hachez <[email protected]>
Co-authored-by: Jatin <[email protected]>
fixed styleling misconfig and fixed storybooks (nodejs#5281)
fix storybook styles, imports, typescript config and dependencies (nodejs#5319
fix(package.json) Lint command is missing slashes (nodejs#5321
fix storybook local development mode (nodejs#5335)
fix(i18n): translation key (nodejs#5347)
… method (nodejs#5369)

Add clarity to step 4 based on clone method

Signed-off-by: Vessy Shestorkina <[email protected]>
* Migrate JsonLink component

Signed-off-by: Vessy Shestorkina <[email protected]>

* Add storybook snap and robot icon

Signed-off-by: Vessy Shestorkina <[email protected]>

* Remove IconContext provider

Signed-off-by: Vessy Shestorkina <[email protected]>

---------

Signed-off-by: Vessy Shestorkina <[email protected]>
Signed-off-by: Claudio Wunder <[email protected]>
Co-authored-by: Claudio Wunder <[email protected]>
…s#5376)

* refactor(useDownloadLink): Move useDetectOs to useDownloadLink

* refactor(useDownloadLink): rename file

* refactor(useDownloadLink): rename file

* Apply suggestions from code review

Signed-off-by: Claudio Wunder <[email protected]>

* refactor(useDownloadLink): undo deleted file

---------

Signed-off-by: Claudio Wunder <[email protected]>
Co-authored-by: Claudio Wunder <[email protected]>
@vercel
Copy link

vercel bot commented May 15, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nodejs-org ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 15, 2023 5:03am
nodejs-org-stories ✅ Ready (Inspect) Visit Preview May 15, 2023 5:03am

@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories May 15, 2023 04:34 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories May 15, 2023 04:40 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org May 15, 2023 04:42 Inactive
@Harkunwar Harkunwar requested review from ovflowd and shanpriyan May 15, 2023 04:42
@Harkunwar Harkunwar marked this pull request as ready for review May 15, 2023 04:42
@vercel vercel bot temporarily deployed to Preview – nodejs-org May 15, 2023 05:02 Inactive
@vercel vercel bot temporarily deployed to Preview – nodejs-org-stories May 15, 2023 05:03 Inactive
Copy link
Member

@ovflowd ovflowd left a comment

Choose a reason for hiding this comment

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

Hey, @Harkunwar I super appreciate for taking the migration of that component :)

I left a lot of comments, just to raise the bar of the quality of the PR. Regardless, thank you so much for working on this!

@@ -0,0 +1,27 @@
.random-contributor {
Copy link
Member

Choose a reason for hiding this comment

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

We usually use camelCase classnames

max-width: 400px;
padding: var(--space-12);

@media (max-width: 900px) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we somewhere added a mixin for the 900px max-wdith

parameters: {
moduleMock: {
mock: () => {
const mock = createMock(hooks, 'useNodeJsContributorsApi');
Copy link
Member

Choose a reason for hiding this comment

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

Can we call the hook useFetchNodeContributor?


return (
<div ref={ref} className={styles.randomContributor}>
{!contributor && isVisible && <AnimatedPlaceholder />}
Copy link
Member

Choose a reason for hiding this comment

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

We can leave the animated placeholder even when it's not visible, to reduce layout shift.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
{!contributor && isVisible && <AnimatedPlaceholder />}
{contributor || <AnimatedPlaceholder />}

import { useOnScreen } from '../../../hooks/useOnScreen';
import { useNodeJsContributorsApi } from '../../../hooks/useNodeJsContributorsApi';

const DefaultImageSize = 75;
Copy link
Member

Choose a reason for hiding this comment

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

Constants are usually uppercase

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const DefaultImageSize = 75;
const DEFAULT_IMAGE_SIZE = 75;

Copy link
Member

Choose a reason for hiding this comment

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

This whole test feels overcomplicated imho, feels like we're testing things that do not need to be tested. But I'm not sure. This has a chance to become a flaky test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I don't think it's easy to test this one since we're basically mocking everything.

page: number;
};

export type ContributorApiResponse = {
Copy link
Member

Choose a reason for hiding this comment

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

We don't need a type that covers the full JSON response, we can simply just leave what we want.

It is indeed a partial type that wouldn't reflect 100% on the extent of the object, but I rather doing that than keeping a bunch of types that have no value for me.

import { NodeJSContributorsApiKey } from '../constants/swr';

const LIMIT_CONTRIBUTORS = 5;
const CONTRIBUTORS_API_URI = `https://api.github.com/repos/nodejs/node/contributors?per_page=${LIMIT_CONTRIBUTORS}`;
Copy link
Member

Choose a reason for hiding this comment

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

I feel we could have a dedicated constants file for all these sorts of constants, including API URL constants as we had on nodejs.dev

Copy link
Member

Choose a reason for hiding this comment

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

(To have a single point for all constants, which makes it easier to find)

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, but I have a single word for this Hook. Megazord.

It is doing way way many things. A React Hook should never be this much convoluted and complicated.

  • It is breaking the single responsibility pattern
  • It mixes all sort of design patterns making it confusing
  • It's convoluted and big
  • Hard to heard
  • Newcomer unfriendly

Let's, please simplify the logic, document what is possible to be documented, outsource actual utilities such as link parsing and etc, to somewhere (we want to be able to reuse these bits of code as much as possible in different places), and keep the Hook real and simple

@@ -68,6 +68,7 @@
"@storybook/addon-interactions": "^7.0.8",
"@storybook/addon-links": "^7.0.8",
"@storybook/blocks": "^7.0.8",
"@storybook/jest": "^0.1.0",
Copy link
Member

Choose a reason for hiding this comment

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

How often is this module maintained?

I'm worried that we're needlessly more and more adding packages to our website. I think, for now, it's okay, but let's keep this in mind. We don't want to have too many packages accidentally by the end of the day...

Let's keep this on mind!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This module seems to be actively maintained. The last version about a month old.

@Harkunwar
Copy link
Contributor Author

Thanks for the reviews @ovflowd . I tried migrating with minimal modifications to the original code. I'll address all the issues and bring it up to better standards.

@ovflowd
Copy link
Member

ovflowd commented May 15, 2023

Thank you, @Harkunwar! 🙇

@AugustinMauroy
Copy link
Member

We should put on home component ?

@ovflowd ovflowd force-pushed the major/website-redesign branch from cb8c95e to 9243764 Compare May 24, 2023 13:33
@ovflowd ovflowd requested a review from a team as a code owner May 24, 2023 13:33
@ovflowd ovflowd deleted the branch nodejs:major/website-redesign May 24, 2023 13:37
@ovflowd ovflowd closed this May 24, 2023
@ovflowd
Copy link
Member

ovflowd commented May 24, 2023

FYI: We deleted the major/website-redesign branch to simplify our release and rollout process. Please feel free to recreate this PR or reopen it with the main branch as a target.

Thank you, and we apologise for the inconvenience!

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