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

WP-104: phantom entry in ViewTab when user removed #884

Merged
merged 6 commits into from
Nov 14, 2023

Conversation

van-go
Copy link
Contributor

@van-go van-go commented Oct 10, 2023

Overview

When a user was selected in the View Team tab, then the same user was removed in the Manage Team tab, when you clicked back to View Team, that user's info was still here, even if they were removed.

Related

Changes

Added a conditional statement to reset the AllocationContactCard back to it's default state where it displays "Click on a user’s name to view their allocation usage." when the tab is switched back to View Team from Manage Team.

Testing

Find a Allocation that your are PI or manager on (you'll need to see the Manage Team tab)

  1. In the View Team tab, select a user
  2. Click on Manage Team
  3. From the Manage Team tab, remove the previously selected user.
  4. Click on View Team
  5. Notice that the previously selected user info is not there. Instead it should display "Click on a user’s name to view their allocation usage."

UI

Screen.Recording.2023-10-10.at.1.24.49.PM.mov

Notes

@codecov
Copy link

codecov bot commented Oct 10, 2023

Codecov Report

Merging #884 (ada19e6) into main (5e6be96) will increase coverage by 6.34%.
The diff coverage is 60.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #884      +/-   ##
==========================================
+ Coverage   63.41%   69.75%   +6.34%     
==========================================
  Files         432      224     -208     
  Lines       12388     6256    -6132     
  Branches     2579     1877     -702     
==========================================
- Hits         7856     4364    -3492     
+ Misses       4322     1814    -2508     
+ Partials      210       78     -132     
Flag Coverage Δ
javascript 69.75% <60.00%> (-0.01%) ⬇️
unittests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...ocationsTeamViewModal/AllocationsTeamViewModal.jsx 65.15% <60.00%> (-0.43%) ⬇️

... and 208 files with indirect coverage changes

@chandra-tacc
Copy link
Collaborator

@van-go
I cannot test this because of my role, trying to write unit test.
The side-effect of this is selection is never preserved when moving between tabs. Is that what we want ?
Also, there is a lint error.

@chandra-tacc chandra-tacc changed the title wp-104: phantom entry n ViewTab when user removed WP-104: phantom entry in ViewTab when user removed Oct 17, 2023
@van-go
Copy link
Contributor Author

van-go commented Oct 19, 2023

@chandra-tacc I thought about the fact that the selection is not preserved when moving between tabs, but I don't think it's a real concern. At least it's not as big of a concern as showing a removed user. But, if there's a different approach you suggest, I'll look into implementing it. Also, I'll look at and fix the linting issue.

@chandra-tacc
Copy link
Collaborator

@chandra-tacc I thought about the fact that the selection is not preserved when moving between tabs, but I don't think it's a real concern. At least it's not as big of a concern as showing a removed user. But, if there's a different approach you suggest, I'll look into implementing it. Also, I'll look at and fix the linting issue.

@van-go - This definitely will fix the bug. I'm not sure about stats on usage, if deletion of user is common vs other non-deletion related tasks.

If we want to preserve selection, one way to do that is check if the selected user exists in the list.

(untested):

const selectedCardExists = card && !isLoading && projectId in teams && teams[projectId].some(user => user.username === card.username);
if (!selectedCardExists) setCard(null);

Also, is there is a trick to test this locally without being a PI like role?
I started unit test, but it is going to take longer

Copy link
Collaborator

@chandra-tacc chandra-tacc left a comment

Choose a reason for hiding this comment

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

comments added here: #884 (comment)

Copy link
Collaborator

@chandra-tacc chandra-tacc left a comment

Choose a reason for hiding this comment

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

Thanks for adjusting to the user scenario. The test case works, but the code needs adjustment. I shared the details in the code comments.

Comment on lines 86 to 93

let selectedUser = useState(null);
if (removingUserOperation) {
selectedUser = removingUserOperation.username;
}
if (card && card.username === selectedUser) {
setCard(null);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The useState usage is incorrect. It should be

const [selectedUser, setSelectedUser] = useState(null);

Otherwise selectedUser is a tuple of [null, setter].
When it is set in line 89, it simply overrides the value with username.

A reason all of this is still working is because in line 88, if condition is checking an object removingUserOperation, who value in cases where user is not removed will be

{
   "loading": false,
   "error": false,
   "username": ""
}

So, for all non-deletion scenarios, selectedUser is always empty string.
And in line 91, the condition fails and setCard(null) will not execute.

In delete user scenario:

  • removingUserOperation will be
{
    "loading": false,
    "error": false,
    "username": "foobar"
}

selectedUser will be "foobar"
line 91 check passes
and setCard is null.

The test cases work, but the code needs cleanup:
line 87, useState is not needed, just initialize to null
line 88, check should be checking if removingUserOperation && removingUserOperation.username is not empty.
Rest of the code will work as is.

Copy link
Collaborator

@chandra-tacc chandra-tacc left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for adjustments.

@chandra-tacc chandra-tacc merged commit 4d006aa into main Nov 14, 2023
5 of 6 checks passed
@chandra-tacc chandra-tacc deleted the bug/wp-104-view-team-tab branch November 14, 2023 16:03
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.

3 participants