-
Notifications
You must be signed in to change notification settings - Fork 31
feat: (sceneQueryRunner) - allow manual timerange override, pass props to useQueryRunner #1098
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,8 @@ export interface QueryRunnerState extends SceneObjectState { | |
dataLayerFilter?: DataLayerFilter; | ||
// Private runtime state | ||
_hasFetchedData?: boolean; | ||
// Optional timeRange to use instead of sceneGraph timeRange | ||
timeRange?: SceneTimeRangeLike; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure this makes sense, all scene objects can already have local time range via $timeRange |
||
} | ||
|
||
export interface DataQueryExtended extends DataQuery { | ||
|
@@ -140,9 +142,14 @@ export class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> implemen | |
this.addActivationHandler(() => this._onActivate()); | ||
} | ||
|
||
private getTimeRange(): SceneTimeRangeLike { | ||
// If timeRange is provided in state, use that, otherwise fall back to sceneGraph | ||
return this.state.timeRange ?? sceneGraph.getTimeRange(this); | ||
} | ||
|
||
private _onActivate() { | ||
if (this.isQueryModeAuto()) { | ||
const timeRange = sceneGraph.getTimeRange(this); | ||
const timeRange = this.getTimeRange(); | ||
const scopesBridge = sceneGraph.getScopesBridge(this); | ||
|
||
// Add subscriptions to any extra providers so that they rerun queries | ||
|
@@ -188,7 +195,7 @@ export class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> implemen | |
} | ||
|
||
private _onLayersReceived(results: Iterable<SceneDataProviderResult>) { | ||
const timeRange = sceneGraph.getTimeRange(this); | ||
const timeRange = this.getTimeRange(); | ||
const { dataLayerFilter } = this.state; | ||
|
||
let annotations: DataFrame[] = []; | ||
|
@@ -312,7 +319,7 @@ export class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> implemen | |
} | ||
|
||
private _isDataTimeRangeStale(data: PanelData) { | ||
const timeRange = sceneGraph.getTimeRange(this); | ||
const timeRange = this.getTimeRange(); | ||
|
||
const stateTimeRange = timeRange.state.value; | ||
const dataTimeRange = data.timeRange; | ||
|
@@ -390,13 +397,17 @@ export class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> implemen | |
this._scopesSubBridge = scopesBridge; | ||
|
||
this._scopesSub = scopesBridge.subscribeToValue(() => { | ||
this.runWithTimeRangeAndScopes(sceneGraph.getTimeRange(this), scopesBridge); | ||
this.runWithTimeRangeAndScopes(this.getTimeRange(), scopesBridge); | ||
}); | ||
} | ||
|
||
private subscribeToTimeRangeChanges(timeRange: SceneTimeRangeLike) { | ||
// Only subscribe to time range changes if we're not using a prop | ||
if (this.state.timeRange) { | ||
return; | ||
} | ||
|
||
if (this._timeSubRange === timeRange) { | ||
// Nothing to do, already subscribed | ||
return; | ||
} | ||
|
||
|
@@ -411,7 +422,7 @@ export class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> implemen | |
} | ||
|
||
public runQueries() { | ||
const timeRange = sceneGraph.getTimeRange(this); | ||
const timeRange = this.getTimeRange(); | ||
const scopesBridge = sceneGraph.getScopesBridge(this); | ||
if (this.isQueryModeAuto()) { | ||
this.subscribeToTimeRangeChanges(timeRange); | ||
|
Oops, something went wrong.
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.
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.