-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,8 @@ class Sidebar extends Component { | |
| super(props); | ||
| this.state = { | ||
| showStatus: false, | ||
| isAdmin: false | ||
| isAdmin: false, | ||
| isSetAdminNeedCall: true | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -68,10 +69,11 @@ class Sidebar extends Component { | |
| } | ||
|
|
||
| shouldComponentUpdate(nextProps, nextState) { | ||
| const { showStatus, isAdmin } = this.state; | ||
| const { showStatus, isAdmin, isSetAdminNeedCall } = this.state; | ||
| const { | ||
| Site_Name, user, baseUrl, state, isMasterDetail, useRealName, theme | ||
| } = this.props; | ||
|
|
||
| // Drawer navigation state | ||
| if (state?.index !== nextProps.state?.index) { | ||
| return true; | ||
|
|
@@ -103,9 +105,16 @@ class Sidebar extends Component { | |
| if (nextState.isAdmin !== isAdmin) { | ||
| return true; | ||
| } | ||
| if (nextProps.state !== state && isSetAdminNeedCall === true) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| componentDidUpdate() { | ||
| this.setIsAdmin(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a good practice to call something on Even if |
||
| } | ||
|
|
||
| async setIsAdmin() { | ||
| const db = database.active; | ||
| const { user } = this.props; | ||
|
|
@@ -114,8 +123,11 @@ class Sidebar extends Component { | |
| if (roles) { | ||
| const permissionsCollection = db.collections.get('permissions'); | ||
| const permissionsFiltered = await permissionsCollection.query(Q.where('id', Q.oneOf(permissions))).fetch(); | ||
| 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 }); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a good practice to change the state inside of an iteration. |
||
| return ( | ||
| result || permission.roles.some(r => roles.indexOf(r) !== -1)); | ||
| }, | ||
| false); | ||
| this.setState({ isAdmin }); | ||
| } | ||
|
|
||
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.
As you can see at the beginning of the block,

statecomes fromreact-navigation(it's track current state of the navigation) and it's an object.nextProps.state !== stateis an object comparison, so it'll never be equal.