Skip to content

feat(client): ts-migrate client/src/utils - #42666

Merged
ojeytonwilliams merged 28 commits into
freeCodeCamp:mainfrom
awu43:feat/ts-migrate-client-src-utils
Jul 12, 2021
Merged

ojeytonwilliams merged 28 commits into
freeCodeCamp:mainfrom
awu43:feat/ts-migrate-client-src-utils

Conversation

@awu43

@awu43 awu43 commented Jun 29, 2021 •

Copy link
Copy Markdown
Contributor

Checklist:

  • I have read freeCodeCamp's contribution guidelines.
  • My pull request has a descriptive title (not a vague title like Update index.md)
  • My pull request targets the main branch of freeCodeCamp.
  • I have tested these changes either locally on my machine, or GitPod.

Refers #42256

Files:

/client/src/utils/ajax.js
/client/src/utils/algolia-locale-setup.js
/client/src/utils/curriculum-helpers.test.js
/client/src/utils/format.js
/client/src/utils/format.test.js
/client/src/utils/get-words.js
/client/src/utils/handled-error.js
/client/src/utils/handled-error.test.js
/client/src/utils/index.js
/client/src/utils/reallyWeirdErrorMessage.js
/client/src/utils/report-error.js
/client/src/utils/reportedErrorMessage.js
/client/src/utils/scriptLoaders.js
/client/src/utils/standardErrorMessage.js
/client/src/utils/to-learn-path.js

Issues:

  • Take the types in ajax.ts with a grain of salt. While I've done my best to follow the breadcrumbs to deduce the proper types, there was some guesswork involved.

@gitpod-io

gitpod-io Bot commented Jun 29, 2021

Copy link
Copy Markdown

@awu43
awu43 changed the base branch from main to next June 29, 2021 06:36
@github-actions github-actions Bot added the platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. label Jun 29, 2021
@awu43

awu43 commented Jun 29, 2021

Copy link
Copy Markdown
Contributor Author

Hey @ojeytonwilliams, I just started migrated my latest batch of files and I'm having some trouble figuring out what the requests in ajax.ts are sending/receiving. Could I get some guidance on this?

@raisedadead
raisedadead deleted the branch freeCodeCamp:main June 30, 2021 15:51
@raisedadead raisedadead reopened this Jun 30, 2021
@raisedadead
raisedadead changed the base branch from next to main June 30, 2021 15:58
@raisedadead raisedadead reopened this Jun 30, 2021

@raisedadead raisedadead left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We have landed the next branch into main, and I have rebased and retargeted your pull request. Please make sure to sync with your local before you continue to make any further changes.

If you need assistance with that, let us know in the contributors chat, or here.

@raisedadead

This comment has been minimized.

@awu43

This comment has been minimized.

@raisedadead

This comment has been minimized.

@awu43

This comment has been minimized.

@raisedadead

This comment has been minimized.

@awu43

awu43 commented Jul 1, 2021

Copy link
Copy Markdown
Contributor Author

Looks like everything's synced properly on my end. While I have your ear, could I get some help on migrating ajax.ts? I'm having some difficulty figuring out what types the requests in that file are actually sending/receiving.

@ojeytonwilliams

Copy link
Copy Markdown
Contributor

Hey @awu43, sorry for the delay getting back to you.

I'm having some trouble figuring out what the requests in ajax.ts are sending/receiving. Could I get some guidance on this?

Unfortunately it's quite complicated since each call fetches a different type of data. They should all be JSON objects, but they will all have different shapes. To figure it out, you can look at the part of the api that handles that endpoint and it should call res.json on an object. That object is what we should expect on the client side.

For example, getSessionUser is handled here:

.map(({ user, sessionMeta }) => ({
user: {
[user.username]: {
...pick(user, userPropsForSession),
isEmailVerified: !!user.emailVerified,
isGithub: !!user.githubProfile,
isLinkedIn: !!user.linkedin,
isTwitter: !!user.twitter,
isWebsite: !!user.website,
...normaliseUserFields(user),
joinDate: user.id.getTimestamp()
}
},
sessionMeta,
result: user.username
}))
).subscribe(user => res.json(user), next);

So we expect to receive an object with the keys user, sessionMeta and result.

I hope that clarifies a touch and wasn't just telling you what you already know!

@awu43

awu43 commented Jul 3, 2021

Copy link
Copy Markdown
Contributor Author

No worries @ojeytonwilliams, I'm sure everybody was busy trying to unfreeze things. Your advice has definitely helped and after poking around in api-server I've worked out the rest of the types.

@ShaunSHamilton ShaunSHamilton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As mentioned, there needs to be a good reason to assert the type with as - only when the compiler cannot infer the type. As it stands, the assertion is giving the incorrect type.

Comment thread client/src/utils/ajax.ts Resolved
Comment thread client/src/utils/ajax.ts Resolved
Comment thread client/src/utils/ajax.ts Resolved

@ojeytonwilliams ojeytonwilliams left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @awu43 as I've been looking into this, I've come to realise that most of the error code is legacy and can be removed. Once we've done that all the Axios stuff should go away again.

Since this is kind of out of scope for this PR, don't worry about it, I'll handle it after merging.

However, in order to do that, could you revert the migration of client/src/utils/format.js? Unfortunately this is used by the curriculum and the curriculum is not able to handle TypeScript yet. I'd rather not pull on that particular thread until we have to!

@awu43

awu43 commented Jul 6, 2021

Copy link
Copy Markdown
Contributor Author

However, in order to do that, could you revert the migration of client/src/utils/format.js? Unfortunately this is used by the curriculum and the curriculum is not able to handle TypeScript yet. I'd rather not pull on that particular thread until we have to!

That would explain how I broke the imports without renaming it. It's been done.

Comment thread client/src/utils/ajax.ts Resolved
Comment thread client/src/utils/ajax.ts Resolved
Comment thread client/src/utils/ajax.ts Resolved
Comment thread client/src/utils/ajax.ts Resolved
Comment thread client/src/utils/script-loaders.ts Resolved
Comment thread client/src/utils/script-loaders.ts Resolved
ojeytonwilliams
ojeytonwilliams previously approved these changes Jul 8, 2021

@ojeytonwilliams ojeytonwilliams left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome job @awu43! LGTM 👍

@awu43
awu43 requested a review from ShaunSHamilton July 9, 2021 16:52
ShaunSHamilton
ShaunSHamilton previously approved these changes Jul 11, 2021

@ShaunSHamilton ShaunSHamilton left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This LGTM 👍 . Thank you, for making those changes. Just pending the merge conflicts being resolved, when you get a chance, else one of us can do it.

@awu43
awu43 dismissed stale reviews from ShaunSHamilton and ojeytonwilliams via caf4102 July 11, 2021 18:17

@raisedadead raisedadead left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ojeytonwilliams can you confirm we are going to need axios in the client and there is no way around it..

@raisedadead raisedadead added the status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. label Jul 12, 2021

@ojeytonwilliams ojeytonwilliams left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@raisedadead it's all good, axios is only used in tests and doesn't make its way into any bundles:
image

@ojeytonwilliams
ojeytonwilliams merged commit e1d8f4b into freeCodeCamp:main Jul 12, 2021
@ojeytonwilliams

Copy link
Copy Markdown
Contributor

@awu43 Thanks again for this excellent PR 💯

moT01 added a commit to moT01/freeCodeCamp that referenced this pull request Jul 13, 2021
@awu43
awu43 deleted the feat/ts-migrate-client-src-utils branch July 16, 2021 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants