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
Dashboards: Fix 'Make Editable' button not working in Dashboard Settings #60306
Conversation
dashboard.meta.canMakeEditable = false; | ||
dashboard.meta.canEdit = true; | ||
dashboard.meta.canSave = true; | ||
// TODO add some kind of reload |
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.
Having a TODO here was so handy to know where to fix it! 😉
const [updateId, setUpdateId] = useState(0); | ||
useEffect(() => { | ||
dashboard.events.subscribe(DashboardMetaChangedEvent, () => setUpdateId((v) => v + 1)); | ||
}, [dashboard]); | ||
|
||
// updateId in deps so we can revaluate when dashboard is mutated | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
const pages = useMemo(() => getSettingsPages(dashboard), [dashboard, updateId]); |
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.
I'm not super in love with this change, but I felt like it was the most direct and easiest to understand of the possible solutions.
dashboard.meta
does get a new identity when it changes, so we could stick that in the useMemo props, but it would still fail exhaustive props, unless we pass that in seperately into getSettingsPages?
Definitely open to feedback on this!
public/app/features/dashboard/components/DashboardSettings/DashboardSettings.tsx
Outdated
Show resolved
Hide resolved
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.
was missing function call in the onClick callback, but otherwise looks good
3eed7d0
to
1849121
Compare
Actually, it worked. As in you could go back and the dashboard was editable. There was only no visible user feedback indicating clicking the button actually worked.. |
Yup. The state was being updated, but because we mutate the dashboard model, we need to force a re-render (or navigate away and back again) to see the changes. |
…ard Settings (grafana#60330) Dashboards: Fix 'Make Editable' button not working in Dashboard Settings (grafana#60306) * Dashboards: Fix 'Make Editable' button not working in Dashboard Settings * comment (cherry picked from commit 2586964) Co-authored-by: Josh Hunt <joshhunt@users.noreply.github.com>
What is this feature?
PR #52682 introduced a regression where the "Make Editable" button in Dashboard Settings for uneditable dashboards doesn't do anything.
This fixes that.
Why do we need this feature?
So people can edit their dashboards.
Who is this feature for?
Admins and editors of Grafana
Which issue(s) does this PR fix?:
Fixes #60305