-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[FIX] Admin panel option is hidden after login #2867
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
Conversation
diegolmello
left a comment
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.
Left a few comments here and added a new task on ClickUp as blocking.
The issue is really on permissions fetch.
| if (nextState.isAdmin !== isAdmin) { | ||
| return true; | ||
| } | ||
| if (nextProps.state !== state && isSetAdminNeedCall === true) { |
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.
| } | ||
|
|
||
| componentDidUpdate() { | ||
| this.setIsAdmin(); |
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.
Not a good practice to call something on componentDidUpdate without testing in what cases it should run.
componentDidUpdate runs every time the component updates: when state changes, when props change or when the component is forced updated.
Even if shouldComponentUpdate returns false, this.setIsAdmin is being called.
Add a console.log at the start of setIsAdmin and you'll see how many times it's called.
| const isAdmin = permissionsFiltered.reduce((result, permission) => ( | ||
| result || permission.roles.some(r => roles.indexOf(r) !== -1)), | ||
| const isAdmin = permissionsFiltered.reduce((result, permission) => { | ||
| this.setState({ isSetAdminNeedCall: false }); |
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.
Not a good practice to change the state inside of an iteration.
It's going to set the state for every permissions on the list.
Even if sCU prevents the re-render to happen, you're calling unnecessary resources.
|
Closed in favour of #2914 |

Proposed changes
Fixing admin panel option hiding after login by adding componentDidUpdate function
Issue(s)
How to test or reproduce
Clickup task
Screenshots
Types of changes
Checklist
Further comments