-
Notifications
You must be signed in to change notification settings - Fork 11.6k
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
QueryVariable: Default to first option when none is set #36521
Conversation
instanceState.current = { ...instanceState.options[0], selected: true }; | ||
instanceState.options = instanceState.options.map((option, index) => | ||
index === 0 ? instanceState.current : { ...option, selected: false } | ||
); | ||
return; |
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.
what happens if options are an empty array? will this crash?
Since this handler can be written mutably and immer will make it immutable. I think you first can just set all options to selected false except first and set instance.current = instance.options[0] ?
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.
Yeah, we need to add a check to make sure we have options.
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.
Looks good! Just need to add the check that @torkelo mentioned in his comment.
// If no value is set, default to the first avilable | ||
if (!current.value && instanceState.options.length) { | ||
instanceState.options.forEach((option, index) => { | ||
option.selected = !Boolean(index); |
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.
Quite enjoyed this fancy little trick 😎
What this PR does / why we need it:
To make sure that query variables do not break when the current dashboard is navigated to via an anchor tag.
Which issue(s) this PR fixes:
Fixes #35471
Special notes for your reviewer:
/d/${__dashboard.uid}