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

Skip to content

feat: Add suspend user action #1275

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 7 commits into from
May 4, 2022
Merged

feat: Add suspend user action #1275

merged 7 commits into from
May 4, 2022

Conversation

BrunoQuaresma
Copy link
Collaborator

Closes #738

@BrunoQuaresma BrunoQuaresma self-assigned this May 3, 2022
@BrunoQuaresma BrunoQuaresma requested review from presleyp and a team as code owners May 3, 2022 15:58
@@ -19,20 +25,42 @@ export const UsersPage: React.FC = () => {
usersSend("GET_USERS")
}, [usersSend])

if (usersState.matches("error")) {
return <ErrorSummary error={getUsersError} />
Copy link
Collaborator Author

@BrunoQuaresma BrunoQuaresma May 3, 2022

Choose a reason for hiding this comment

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

I moved this to be inside of UsersPage, so the getUsersError does not block the UI(not showing the table) for the other non-blocking errors like the suspendUserError.

Copy link
Contributor

Choose a reason for hiding this comment

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

My idea for that was to not go to the error state for non-blocking errors. This may work fine too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, I didn't understand. Without removing this statement, any error will remove the user table from the screen and show the error summary.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm suggesting that every error gets assigned to context so that we can display error messages, but that only blocking errors put the page in the error finite state. I see that state as meaning "the page is unusable."

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ahh I see it, good to know!

// Passing API.getUsers directly does not invoke the function properly
// when it is mocked. This happen in the UsersPage tests inside of the
// "shows a success message and refresh the page" test case.
getUsers: () => API.getUsers(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Idk why this is happening, but I guess jest lost the reference when it is passed directly. 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

What happened? I've seen some weird behavior in tests so this might be a clue :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No idea, but I would guess when you pass it directly, Jest lost the reference. Maybe I should open an issue in the jest repo, but I'm not sure if it is a problem on their side on something in the XState engine... 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ahh, I saw some of the errors that you were having last week, but they were related to some components trying to access some theme variables without being rendered inside of a ThemeProvider component.

@@ -58,6 +58,7 @@
"@storybook/addon-essentials": "6.4.22",
"@storybook/addon-links": "6.4.22",
"@storybook/react": "6.4.22",
"@testing-library/jest-dom": "5.16.4",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This adds some helpful test matchers!

@codecov
Copy link

codecov bot commented May 3, 2022

Codecov Report

Merging #1275 (5a43eac) into main (34b91fd) will increase coverage by 0.01%.
The diff coverage is 73.52%.

@@            Coverage Diff             @@
##             main    #1275      +/-   ##
==========================================
+ Coverage   66.10%   66.11%   +0.01%     
==========================================
  Files         281      277       -4     
  Lines       18400    18224     -176     
  Branches      216      220       +4     
==========================================
- Hits        12163    12049     -114     
+ Misses       4974     4931      -43     
+ Partials     1263     1244      -19     
Flag Coverage Δ
unittest-go-macos-latest 53.62% <ø> (+0.10%) ⬆️
unittest-go-postgres- 65.03% <ø> (-0.01%) ⬇️
unittest-go-ubuntu-latest 56.01% <ø> (+0.10%) ⬆️
unittest-go-windows-2022 ?
unittest-js 71.61% <73.52%> (+0.61%) ⬆️
Impacted Files Coverage Δ
site/src/testHelpers/index.tsx 94.44% <ø> (ø)
site/src/api/index.ts 67.74% <50.00%> (-1.75%) ⬇️
site/src/components/GlobalSnackbar/utils.ts 73.68% <50.00%> (-2.79%) ⬇️
site/src/pages/UsersPage/UsersPage.tsx 79.16% <66.66%> (+4.16%) ⬆️
site/src/xServices/users/usersXService.ts 79.16% <80.00%> (-0.84%) ⬇️
site/src/pages/UsersPage/UsersPageView.tsx 92.85% <85.71%> (-7.15%) ⬇️
site/src/components/UsersTable/UsersTable.tsx 100.00% <100.00%> (ø)
cli/configssh.go 62.04% <0.00%> (-6.57%) ⬇️
pty/ptytest/ptytest.go 86.95% <0.00%> (-4.35%) ⬇️
cli/templateinit.go 58.62% <0.00%> (-3.45%) ⬇️
... and 19 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 34b91fd...5a43eac. Read the comment docs.

@BrunoQuaresma BrunoQuaresma requested a review from presleyp May 3, 2022 19:01
@@ -108,6 +156,9 @@ export const usersMachine = createMachine(
assignGetUsersError: assign({
getUsersError: (_, event) => event.data,
}),
assignUserIdToSuspend: assign({
userIdToSuspend: (_, event) => event.userId,
}),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also clear this user afterwards?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

An issue with clearing this right after is the text will blink/disappear before the modal gets completely closed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, the next thing I would try is clearing the user on exiting or entering a state to see if that avoids the flash, but if it doesn't work we can just leave it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What potential problems do you see with keeping it? On exiting, the flash happens. On entering there is no need because a new user will be assigned.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking on entering idle. It's not creating a problem now, but I thought there was potential to create a bug down the line because when you're not mid-suspend, you wouldn't expect to have a user to suspend in state. Sounds like it's more trouble than it's worth right now though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, the issue with making that on entering the idle state is because it "breaks" the modal during the close transition. The text disappears before it gets fully closed.

error={getUsersError}
/>

<ConfirmDialog
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 so clean, love it

Copy link
Contributor

@presleyp presleyp left a comment

Choose a reason for hiding this comment

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

I don't think there's a need to move the error check from the page to the view now that the suspend error goes to idle, but I'm fine with it either way. Looks great!

@BrunoQuaresma BrunoQuaresma enabled auto-merge (squash) May 4, 2022 15:58
auto-merge was automatically disabled May 4, 2022 16:02

Pull request was closed

@BrunoQuaresma BrunoQuaresma reopened this May 4, 2022
@BrunoQuaresma BrunoQuaresma enabled auto-merge (squash) May 4, 2022 16:03
@BrunoQuaresma BrunoQuaresma merged commit f911c8a into main May 4, 2022
@BrunoQuaresma BrunoQuaresma deleted the bq/738/suspend-user branch May 4, 2022 16:10
@misskniss misskniss added this to the V2 Beta milestone May 15, 2022
kylecarbs pushed a commit that referenced this pull request Jun 10, 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.

Frontend User Delete
3 participants