Skip to content

Conversation

@kresnaputra
Copy link
Contributor

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

  • Bugfix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves a current function)
  • New feature (non-breaking change which adds functionality)
  • Documentation update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have added necessary documentation (if applicable)
  • Any dependent changes have been merged and published in downstream modules

Further comments

@kresnaputra kresnaputra self-assigned this Feb 4, 2021
Copy link
Member

@diegolmello diegolmello left a 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) {
Copy link
Member

Choose a reason for hiding this comment

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

As you can see at the beginning of the block, state comes from react-navigation (it's track current state of the navigation) and it's an object.
nextProps.state !== state is an object comparison, so it'll never be equal.
image

}

componentDidUpdate() {
this.setIsAdmin();
Copy link
Member

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 });
Copy link
Member

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.

@diegolmello
Copy link
Member

Closed in favour of #2914

@diegolmello diegolmello deleted the fix.admin-panel-hidden branch February 22, 2021 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants