-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Update Collection View #3270
Update Collection View #3270
Conversation
Release EnvironmentsThis Environment is provided by Release, learn more! 🔧Environment Status : https://app.release.com/public/Processing%20Foundation/env-5a8e51661b |
user != null && | ||
user.username && | ||
typeof user.username !== 'undefined' && | ||
collection?.owner?.username === user.username; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is definitely room to clean this up further.
The user != null
check is unnecessary because user
is state.user
which is always an object even when there is no one logged in.
You are now passing username
as a prop, which is the username of the collection owner, so you can use that instead of collection?.owner?.username
. Using username
has a few advantages, including that it won't be undefined
while the collection is fetching so you get an accurate boolean during loading.
Additionally, username
is never undefined
. So there is no possibility that username === user.username
when there is no logged in user (and user.username
is undefined
). So you don't need to explicitly check that there is a user.username
. If username === user.username
is true
then there is a user logged in who is the the owner of this collection. If it is false
then either there is no user logged in or the logged in user is not the owner.
So you can write const isOwner = () => username === user.username
and it will have the same effect.
When I converted this component I wrote it as:
const currentUsername = useSelector((state) => state.user.username);
const isOwner = username === currentUsername;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it's important to use descriptive variable names like currentUsername
and ownerUsername
to avoid bugs like the one that you fixed here.
I know that I can be rude sometimes but I think you can understand my frustrations. Because I already converted this component over a year ago and it was cleanly written and did not have that sort of mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching these, there's probably still a lot of other areas this component could be improved here!
Since I wasn't able to get through all of your work and made some changes to these files that differed from yours, I do get your frustrations on how it probably feels like this could've been preventable. Although it'll be a lot of work since I didn't keep up with the PRs from back then, if you'd like to, we can get still try to get them in. I could be wrong, but I think most of them could probably be merged with some minimal changes except for a few (like the Common Table Components and the CodeMirror one, esp since it's part of the fellowship). I was also planning to upgrade the Node.js minor version in the near future, which I think might conflict with this one.
This is a bit of a tangent and definitely depends on the context, but I also personally feel that it's okay for code to end up a little messy and have mistakes sometimes! While I do think it's important to try not to make them, I don't want to view them negatively because I feel like they're a really normal part of any process, and in most cases, can usually be fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wanted to add that I meant the latter more as a point of conversation, rather than disagreeing!
Fixes #3269
Changes:
username
as a prop toCollection
component, which was previously not accessibleisOwner
, which was previously returningundefined
instead of a booleanremoveFromCollection
action directly intoCollectionItemRow
I have verified that this pull request:
npm run lint
)npm run test
)develop
branch.Fixes #123