[v11.0.x] DashboardScene: Fixes issues with relative time range in panel edit #87026
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.
Backport a4bb4c8 from #86862
Fixes #86420 '
This one was very hard to solve, tried so many different ways that all ended up with some dead end.
The original problem was the "Table view" toggle in panel edit, this switching the rendering of the visualization from the main VizPanel to a temporary table view. But for this temporary table VizPanel to get the data we moved the SceneQueryRunner from VizPanelManager.state.panel to VizPanelManager level (so that it's children all get the data). We could of course clone the main VizPanel SceneQueryRunner to this temporary table VizPanel but this disconnects the queries tab from the table view as the queries tab is subscribing to the main viz scene query runner (and we want changes to queries to reflect in the table view).
But moving SceneQueryRunner to VizPanelManager level left the time range on the main VizPanel level, so the SceneQueryRunner did not get local panel time range. I tried moving the time range also to VizPanelManager level but then we do not get any rendering of the local time range in the panel chrome header (Which only happens when VizPanel render detects $timeRange on it's local level).
Ok, lets revert back to SceneQueryRunner living on the main VizPanel level (same as time range), so back to square one. How to switch to Table view and maintain the same SceneQueryRunner between main viz and queries tab? Well, we could break the rule of reusing the same SceneObject instance, when we switch to TableView I use the same instance of the SceneQueryRunner as the main VizPanel.
One last issue, the SceneQueryRunner is deactivated because it's attached to the main VizPanel and this is not rendered when the table view is rendered, when deactivated it clears all subscriptions so the queries tab which is subscribing to it via
useState()
no longer get's any updates after this.To fix this I make sure the queries tab calls the queryRunner activate function (which increments the refCount for main viz SceneQueryRunner so that it does not deactivate during the transition from main VizPane and Table VizPanel).
I know, messy, complex, don't like it, but best I can come up with for now.