Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor(site): replace UserContext with userXService #465

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

Merged
merged 48 commits into from
Mar 18, 2022

Conversation

presleyp
Copy link
Contributor

@presleyp presleyp commented Mar 16, 2022

  • replaces UserContext with XState
  • replaces checks for auth on every page with a wrapper component called in App
  • replaces rendering the nav on every page via that wrapper component
  • breaks Navbar and SignInPage/SignInForm into glue and visual components
  • adds command yarn typegen

Edit:

  • I did end up needing to wrap the XServices in a React Context for the mocks to work, but because they're static references, we can just have one Provider to rule them all and just access what we need.
  • Added MSW, wrote handlers to mock out some of our API calls, renamed mocks to entities because handlers are another kind of mock
  • Added NavbarView to Storybook
  • Rewrote Navbar unit test as NavbarView unit test
  • Adapted SignInForm integration test to SignInPage integration test - I had to part with the tests that check that you can sign in successfully and get redirected, because the redirect causes an infinite loop in at this level (where there's nothing new to render when you redirect). I started to write an e2e test for the case where you navigate to an auth-requiring page, get redirected to /login, log in, and get redirected back to that page, but the only one we can do without setting up a project first is /projects, which is already e2e tested. I'll make a ticket for doing this in the future, but for now I think we should get this code in.

@presleyp presleyp requested a review from a team as a code owner March 16, 2022 18:59
Copy link
Contributor

@greyscaled greyscaled left a comment

Choose a reason for hiding this comment

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

praise: I really like the pattern and removal of the user context. Very nice! I love how the projects components were greatly simplified (just red deltas) from a result of the pattern and separation of concerns.

I'm happy to ✅ this in the current state with satisfactory testing, then iterate - what are you plans @presleyp ?

@codecov
Copy link

codecov bot commented Mar 16, 2022

Codecov Report

Merging #465 (2be726b) into main (8fde3ed) will decrease coverage by 0.22%.
The diff coverage is 52.98%.

@@            Coverage Diff             @@
##             main     #465      +/-   ##
==========================================
- Coverage   68.12%   67.90%   -0.23%     
==========================================
  Files         158      164       +6     
  Lines        9271     9309      +38     
  Branches       79       85       +6     
==========================================
+ Hits         6316     6321       +5     
- Misses       2331     2360      +29     
- Partials      624      628       +4     
Flag Coverage Δ
unittest-go-macos-latest 62.39% <ø> (-0.17%) ⬇️
unittest-go-ubuntu-latest 67.33% <ø> (-0.27%) ⬇️
unittest-go-windows-2022 62.14% <ø> (+0.10%) ⬆️
unittest-js 63.63% <52.98%> (-0.64%) ⬇️
Impacted Files Coverage Δ
site/src/app.tsx 0.00% <0.00%> (ø)
site/src/components/Navbar/UserDropdown.tsx 86.95% <ø> (ø)
site/src/components/Navbar/index.tsx 0.00% <0.00%> (-100.00%) ⬇️
site/src/components/Page/AuthAndNav.tsx 0.00% <0.00%> (ø)
site/src/components/Page/RequireAuth.tsx 0.00% <0.00%> (ø)
site/src/components/Page/index.tsx 0.00% <0.00%> (ø)
site/src/components/User/UserAvatar.tsx 87.50% <ø> (ø)
site/src/components/User/UserProfileCard.tsx 75.00% <ø> (ø)
site/src/components/Workspace/Workspace.tsx 100.00% <ø> (ø)
site/src/forms/CreateProjectForm.tsx 95.45% <ø> (ø)
... and 25 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8fde3ed...2be726b. Read the comment docs.

@presleyp
Copy link
Contributor Author

Anyone know what this lint error means?

  0:0  error  Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: webpack.common.ts.
The file must be included in at least one of the projects provided```

@greyscaled
Copy link
Contributor

Anyone know what this lint error means?

  0:0  error  Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: webpack.common.ts.
The file must be included in at least one of the projects provided```

I'm about to push a fix

@greyscaled
Copy link
Contributor

@presleyp see #483 - I'm hoping this solves your woes. I found the same problems when I went to work on #472 with tests and storybook!

@greyscaled
Copy link
Contributor

@presleyp I merged #483 into your branch locally and ran everything. Tests pass, lint only fails because in this PR you need to fix two basic things:

  1. .eslintignore the typegen files
  2. The interface LoginResponse is in the types.ts file twice, probably from a merge conflict resolution. Just need to delete one of them.

greyscaled added a commit that referenced this pull request Mar 18, 2022
Summary:

This is a first step in porting over v1 AuditLog in a refactored/cleaned
up fashion. This isn't a direct port, since we do not yet have a
UserAvatar component.

Details:

- Port over UserCell from v1, sans UserAvatar impl
- Add tests and stories for UserCell

Notes:

We do not have a holistic solution for handling localization, but
starting from some kind of easy way that collects/resources strings will
make the migration significantly easier. It will also help out our
product copy owner, @khorne3 with maintenance. An RFC regarding this
might be necessitated.

Impact:

This change does not have any user-facing impact yet, because the
UserCell is not yet rendered in the product. This enables an incremental
approach to migrating in the FE of the Audit Log, which is still waiting
on the BE port.

Relations:

- This commit relates to #472, but does not finish it.
- This commit should not merge until after #465 and #483 because it's
based on them.
@presleyp presleyp self-assigned this Mar 18, 2022
@presleyp presleyp merged commit 22f820c into main Mar 18, 2022
@presleyp presleyp deleted the 435/presleyp/user-state branch March 18, 2022 18:07
greyscaled added a commit that referenced this pull request Mar 18, 2022
Summary:

This is a first step in porting over v1 AuditLog in a refactored/cleaned
up fashion. This isn't a direct port, since we do not yet have a
UserAvatar component.

Details:

- Port over UserCell from v1, sans UserAvatar impl
- Add tests and stories for UserCell

Notes:

We do not have a holistic solution for handling localization, but
starting from some kind of easy way that collects/resources strings will
make the migration significantly easier. It will also help out our
product copy owner, @khorne3 with maintenance. An RFC regarding this
might be necessitated.

Impact:

This change does not have any user-facing impact yet, because the
UserCell is not yet rendered in the product. This enables an incremental
approach to migrating in the FE of the Audit Log, which is still waiting
on the BE port.

Relations:

- This commit relates to #472, but does not finish it.
- This commit should not merge until after #465 and #483 because it's
based on them.
greyscaled pushed a commit that referenced this pull request Mar 23, 2022
Summary:

This is a first step in porting over v1 AuditLog in a refactored/cleaned
up fashion. The existing `UserCell` component was generalized for re-use
across various tables (AuditLog, Users, Orgs).

Details:

- Move UserCell to `components/Table/Cells`
- Add tests and stories for UserCell


Impact:

This unblocks future work in list views like the audit log, user management
panel and organizations management panel.

Relations:

- This commit relates to #472, but does not finish it.
- This commit should not merge until after #465 and #483 because it's
based on them.
@misskniss misskniss added this to the V2 Beta milestone May 15, 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.

4 participants