AdHocFiltersVariable: Fixes issue updating hide state causing variable to be deactivated and preventing it from being shown again #679
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While troubleshooting the problem of clearing adhoc filters and setting hide: VariableHide.hideVariable and then adding filters and setting variable hide back to Variable.dontHide I discovered some fundamental issues with useState and AdHocFiltersVariable
Problem with useState.
Solution:
Problem with AdHocFiltersVariable
Example.
As you can see the other component subscribing to the variable state will get the first state change (with old filterExpression) as the last value. Could be fixed with updating filterExpresion inside a setTimeout but opted to update filterExpression inside an overridden setState function as this eliminates two state updates when updating filters.
Release notes
<SceneObject>.useState
will now cause the scene object to be activated (if it was not already). When the component that calls<sceneObject>.useState
unmounts it will deactivate the scene object if it was the last component to call useState on this instance.The same is not true for
<SceneObject>.subscribeToState
, this function still does not cause the source object to be activated.📦 Published PR as canary version:
4.4.2--canary.679.8556229462.0
✨ Test out this PR locally via:
npm install @grafana/scenes@4.4.2--canary.679.8556229462.0 # or yarn add @grafana/scenes@4.4.2--canary.679.8556229462.0