-
Notifications
You must be signed in to change notification settings - Fork 20
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
MultiValueVariable: Fix issue where url update would not take options into account #870
Conversation
query: 'A : 1,B : 2', | ||
}); | ||
|
||
await variable.urlSync?.updateFromUrl({ ['var-test']: 'B' }); |
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.
url should not have the text / display value, it has the the value part I think
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.
This is the scenario where the issue stemmed from. In the old arch you can set the key/text/display value and it will use it's correct value, but the URL shows the key. So we need something like this for backwards comp.
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 think this is likely a good solution, hm... wonder how it works in the old arch, maybe it works because URL sync happens so late, after variable has been fully initiated and options fetched/built
@@ -419,6 +419,23 @@ export class MultiValueUrlSyncHandler<TState extends MultiValueVariableState = M | |||
this._sceneObject.skipNextValidation = true; | |||
} | |||
|
|||
if (!this._sceneObject.state.options || !this._sceneObject.state.options.length) { | |||
const options = await lastValueFrom(this._sceneObject.getValueOptions({})); |
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.
could this lead to double queries being issued for QueryVariables ?
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.
Yes, it will :/ once here and once on activation itself
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.
that will not do :(
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.
the variable will be validated later (when SceneVariableSet calls validateAndUpdate), can't we do this lookup at that point?
@mdvictor not sure I understand the issue, looked again, I thought it was related to setting the correct key in the select after a full page reload, b but see now that it's about setting the variable to the display value via URL. Both the new and old variable system sets the variable value via url using the value not the text representation |
wonder where/why they have urls with the text representation, grafana only generates URLs with the value |
@mdvictor so the problem is this if statement here: https://github.com/grafana/scenes/blob/main/packages/scenes/src/variables/variants/MultiValueVariable.ts#L196 that code there makes sure you can add a custom value (enter anything) in the select, that value get's set in the URL and if you reload the page we need to preserve that custom value even if it's not among the options returned by the query (or specified in the variable csv string). We might be able to modify that logic a bit and ignore the if statement if current value === stateUpdate.text like this
|
Closing this in favor of #874 |
I don't know hey that happened either
Thank you! Indeed that fixes the problem, I've opened a new PR with these changes and closed this one |
This PR fixes an issue where in a variable with key-value pairs(esc), setting the key in the url param would not update to it's value but instead create a new custom option with the key as a value.
Before:
Screen.Recording.2024-08-14.at.11.38.59.mov
After:
Screen.Recording.2024-08-14.at.11.39.41.mov