Skip to content

Commit

Permalink
Find first RequestAdder of each type, rather than stopping when first…
Browse files Browse the repository at this point in the history
… of any is found
  • Loading branch information
sd2k committed Apr 24, 2024
1 parent 44d9c5c commit 4a45604
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/scenes/src/components/SceneTimeRangeCompare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const DEFAULT_COMPARE_OPTIONS = [
export class SceneTimeRangeCompare
extends SceneObjectBase<SceneTimeRangeCompareState>
implements SceneRequestAdder<SceneTimeRangeCompareState> {

static Component = SceneTimeRangeCompareRenderer;
protected _urlSync = new SceneObjectUrlSyncConfig(this, { keys: ['compareWith'] });

Expand Down
30 changes: 16 additions & 14 deletions packages/scenes/src/querying/SceneQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> implemen
private _onActivate() {
const timeRange = sceneGraph.getTimeRange(this);
const adders = this.getClosestRequestAdders();
for (const adder of adders) {
for (const adder of adders.values()) {
this._subs.add(
adder.subscribeToState((n, p) => {
if (adder.shouldRerun(p, n)) {
Expand Down Expand Up @@ -515,7 +515,7 @@ export class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> implemen
const primaryTimeRange = timeRange.state.value;
let secondaryRequests: DataQueryRequest[] = [];
let secondaryTransformations = new Map();
for (const adder of this.getClosestRequestAdders() ?? []) {
for (const adder of this.getClosestRequestAdders().values() ?? []) {
for (const { req, transform } of adder.getExtraRequests(request)) {
const requestId = getNextRequestId();
secondaryRequests.push({ ...req, requestId })
Expand Down Expand Up @@ -567,25 +567,27 @@ export class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> implemen
/**
* Walk up the scene graph and find any request adders.
*
* Will stop as soon as at least one adder has been found at any level
* of the graph. This might need to change in future.
* This will return a map from id to the closest adder for each id.
*/
private getClosestRequestAdders(): Array<SceneRequestAdder<any>> {
private getClosestRequestAdders(): Map<string, SceneRequestAdder<any>> {
const found = new Map();
if (!this.parent) {
return [];
return new Map();
}
return getClosest(this.parent, (s) => {
const found: Array<SceneRequestAdder<any>> = [];
if (isRequestAdder(s)) {
found.push(s);
getClosest(this.parent, (s) => {
if (isRequestAdder(s) && !found.has(s.constructor.name)) {
found.set(s.constructor.name, s);
}
s.forEachChild((child) => {
if (isRequestAdder(child)) {
found.push(child);
if (isRequestAdder(child) && !found.has(child.constructor.name)) {
found.set(child.constructor.name, child);
}
});
return found.length > 0 ? found : null;
}) ?? [];
// Always return null so that the search continues to the top of
// the scene graph.
return null;
});
return found;
}

/**
Expand Down

0 comments on commit 4a45604

Please sign in to comment.