-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
ref(dashboards): Fixes and refactoring for edit access selector button #80633
ref(dashboards): Fixes and refactoring for edit access selector button #80633
Conversation
Bundle ReportChanges will decrease total bundle size by 35.84kB (-0.11%) ⬇️. This is within the configured threshold ✅ Detailed changes
|
❌ 4 Tests Failed:
View the top 3 failed tests by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
}); | ||
|
||
menuOptions.push({ | ||
key: 'edit-widget', | ||
label: t('Edit Widget'), | ||
onAction: () => onEdit?.(), | ||
disabled: !hasEditAccess, |
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 also a button in the widget viewer (which opens up when you click the button next to the ...
context menu) that has an edit widget button. Could we also disable that? Doesn't need to be this PR.
if (isEqual(newSelectedValues, getSelectedOptions())) { | ||
setHasUnsavedChanges(false); | ||
} else { | ||
setHasUnsavedChanges(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.
Can we just pass isEqual(newSelectedValues, getSelectedOptions())
into disabled
on line 207? so disabed={!isCurrentUserDashboardOwner || isEqual(newSelectedValues, getSelectedOptions())}
, or you can just assign it to a variable instead of storing it in state like this
setHasUnsavedChanges(false); | ||
setSelectedOptions(getSelectedOptions()); |
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.
Do we need to set the selected options when the menu is closed? The state should be handled by the onSelectOptions
handler so opening and closing shouldn't have an effect on that
const currentUser = useUser(); | ||
const {teams: userTeams} = useUserTeams(); | ||
let hasEditAccess = true; | ||
if (organization.features.includes('dashboards-edit-access')) { | ||
hasEditAccess = checkUserHasEditAccess( | ||
currentUser, | ||
userTeams, | ||
organization, | ||
dashboardPermissions, | ||
dashboardCreator | ||
); | ||
} |
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.
Should we just pass around hasEditAccess
from above? It seems like a simpler change than checking this at multiple locations.
Also, an idea for a future clean up is that I think we could put this into a context to store edit access information and create a hook called useHasEditAccess
or something to avoid passing around the prop as much
#79833
Some fixes for the Edit Access dropdown button in Dashboards.
Save Changes
button inEditAccessSelector.tsx
so that it's enabled only when the changed selections are not the same as the existing permsEdit Widget
button there