diff --git a/packages/scenes/src/components/SceneTimeRangeCompare.tsx b/packages/scenes/src/components/SceneTimeRangeCompare.tsx index 1e7c6083d..580577378 100644 --- a/packages/scenes/src/components/SceneTimeRangeCompare.tsx +++ b/packages/scenes/src/components/SceneTimeRangeCompare.tsx @@ -6,7 +6,7 @@ import { sceneGraph } from '../core/sceneGraph'; import { SceneObjectBase } from '../core/SceneObjectBase'; import { SceneComponentProps, SceneObjectState, SceneObjectUrlValues } from '../core/types'; import { DataQueryExtended } from '../querying/SceneQueryRunner'; -import { SupplementalRequest, ProcessorFunc, SupplementalRequestProvider } from '../querying/SupplementalRequestProvider'; +import { SupplementaryRequest, ProcessorFunc, SupplementaryRequestProvider } from '../querying/SupplementaryRequestProvider'; import { SceneObjectUrlSyncConfig } from '../services/SceneObjectUrlSyncConfig'; import { getCompareSeriesRefId } from '../utils/getCompareSeriesRefId'; import { parseUrlParam } from '../utils/parseUrlParam'; @@ -38,7 +38,7 @@ export const DEFAULT_COMPARE_OPTIONS = [ export class SceneTimeRangeCompare extends SceneObjectBase - implements SupplementalRequestProvider { + implements SupplementaryRequestProvider { static Component = SceneTimeRangeCompareRenderer; protected _urlSync = new SceneObjectUrlSyncConfig(this, { keys: ['compareWith'] }); @@ -95,8 +95,8 @@ export class SceneTimeRangeCompare }; // Get a time shifted request to compare with the primary request. - public getSupplementalRequests(request: DataQueryRequest): SupplementalRequest[] { - const extraRequests: SupplementalRequest[] = []; + public getSupplementaryRequests(request: DataQueryRequest): SupplementaryRequest[] { + const extraRequests: SupplementaryRequest[] = []; const compareRange = this.getCompareTimeRange(request.range); if (!compareRange) { return extraRequests; diff --git a/packages/scenes/src/index.ts b/packages/scenes/src/index.ts index 882338d6a..2f2e550e4 100644 --- a/packages/scenes/src/index.ts +++ b/packages/scenes/src/index.ts @@ -28,7 +28,7 @@ export { SceneTimeRange } from './core/SceneTimeRange'; export { SceneTimeZoneOverride } from './core/SceneTimeZoneOverride'; export { SceneQueryRunner, type QueryRunnerState } from './querying/SceneQueryRunner'; -export { type SupplementalRequest, type SupplementalRequestProvider, type ProcessorFunc } from './querying/SupplementalRequestProvider'; +export { type SupplementaryRequest, type SupplementaryRequestProvider, type ProcessorFunc } from './querying/SupplementaryRequestProvider'; export { SceneDataLayerSet, SceneDataLayerSetBase } from './querying/SceneDataLayerSet'; export { SceneDataLayerBase } from './querying/layers/SceneDataLayerBase'; export { SceneDataLayerControls } from './querying/layers/SceneDataLayerControls'; diff --git a/packages/scenes/src/querying/SceneQueryRunner.test.ts b/packages/scenes/src/querying/SceneQueryRunner.test.ts index eac233543..993128f30 100644 --- a/packages/scenes/src/querying/SceneQueryRunner.test.ts +++ b/packages/scenes/src/querying/SceneQueryRunner.test.ts @@ -34,7 +34,8 @@ import { SceneQueryController, SceneQueryStateControllerState } from '../behavio import { activateFullSceneTree } from '../utils/test/activateFullSceneTree'; import { SceneDeactivationHandler, SceneObjectState } from '../core/types'; import { LocalValueVariable } from '../variables/variants/LocalValueVariable'; -import { SceneObjectBase, SupplementalRequest, SupplementalRequestProvider } from '..'; +import { SceneObjectBase } from '../core/SceneObjectBase'; +import { SupplementaryRequest, SupplementaryRequestProvider } from './SupplementaryRequestProvider'; const getDataSourceMock = jest.fn().mockReturnValue({ uid: 'test-uid', @@ -1093,7 +1094,7 @@ describe('SceneQueryRunner', () => { const queryRunner = new SceneQueryRunner({ queries: [{ refId: 'A' }], }); - const provider = new TestSupplementalRequestProvider({ foo: 1 }, true); + const provider = new TestSupplementaryRequestProvider({ foo: 1 }, true); const scene = new EmbeddedScene({ $timeRange: timeRange, $data: queryRunner, @@ -1108,10 +1109,10 @@ describe('SceneQueryRunner', () => { expect(runRequestMock.mock.calls.length).toEqual(2); let runRequestCall = runRequestMock.mock.calls[0]; - let supplementalRunRequestCall = runRequestMock.mock.calls[1]; + let supplementaryRunRequestCall = runRequestMock.mock.calls[1]; expect(runRequestCall[1].targets[0].refId).toEqual('A'); - expect(supplementalRunRequestCall[1].targets[0].refId).toEqual('Supplemental'); - expect(supplementalRunRequestCall[1].targets[0].foo).toEqual(1); + expect(supplementaryRunRequestCall[1].targets[0].refId).toEqual('Supplementary'); + expect(supplementaryRunRequestCall[1].targets[0].foo).toEqual(1); // change the state of the provider, which will trigger the activation // handler to run the supplementary request again. @@ -1120,10 +1121,10 @@ describe('SceneQueryRunner', () => { expect(runRequestMock.mock.calls.length).toEqual(4); runRequestCall = runRequestMock.mock.calls[2]; - supplementalRunRequestCall = runRequestMock.mock.calls[3]; + supplementaryRunRequestCall = runRequestMock.mock.calls[3]; expect(runRequestCall[1].targets[0].refId).toEqual('A'); - expect(supplementalRunRequestCall[1].targets[0].refId).toEqual('Supplemental'); - expect(supplementalRunRequestCall[1].targets[0].foo).toEqual(2); + expect(supplementaryRunRequestCall[1].targets[0].refId).toEqual('Supplementary'); + expect(supplementaryRunRequestCall[1].targets[0].foo).toEqual(2); }); test('should not rerun supplementary requests when providers say not to', async () => { @@ -1135,7 +1136,7 @@ describe('SceneQueryRunner', () => { const queryRunner = new SceneQueryRunner({ queries: [{ refId: 'A' }], }); - const provider = new TestSupplementalRequestProvider({ foo: 1 }, false); + const provider = new TestSupplementaryRequestProvider({ foo: 1 }, false); const scene = new EmbeddedScene({ $timeRange: timeRange, $data: queryRunner, @@ -1150,10 +1151,10 @@ describe('SceneQueryRunner', () => { expect(runRequestMock.mock.calls.length).toEqual(2); let runRequestCall = runRequestMock.mock.calls[0]; - let supplementalRunRequestCall = runRequestMock.mock.calls[1]; + let supplementaryRunRequestCall = runRequestMock.mock.calls[1]; expect(runRequestCall[1].targets[0].refId).toEqual('A'); - expect(supplementalRunRequestCall[1].targets[0].refId).toEqual('Supplemental'); - expect(supplementalRunRequestCall[1].targets[0].foo).toEqual(1); + expect(supplementaryRunRequestCall[1].targets[0].refId).toEqual('Supplementary'); + expect(supplementaryRunRequestCall[1].targets[0].foo).toEqual(1); // change the state of the provider, which will trigger the activation // handler to run the supplementary request again. The provider will @@ -2275,11 +2276,11 @@ class CustomDataSource extends RuntimeDataSource { } } -interface TestSupplementalRequestProviderState extends SceneObjectState { +interface TestSupplementaryRequestProviderState extends SceneObjectState { foo: number; } -class TestSupplementalRequestProvider extends SceneObjectBase implements SupplementalRequestProvider<{}> { +class TestSupplementaryRequestProvider extends SceneObjectBase implements SupplementaryRequestProvider<{}> { private _shouldRerun: boolean; public constructor(state: { foo: number; }, shouldRerun: boolean) { @@ -2287,12 +2288,12 @@ class TestSupplementalRequestProvider extends SceneObjectBase implemen private _onActivate() { const timeRange = sceneGraph.getTimeRange(this); - // Add subscriptions to any supplemental providers so that they rerun queries + // Add subscriptions to any supplementary providers so that they rerun queries // when their state changes and they should rerun. - const providers = this.getClosestSupplementalRequestProviders(); + const providers = this.getClosestSupplementaryRequestProviders(); for (const provider of providers) { this._subs.add( provider.subscribeToState((n, p) => { @@ -421,7 +421,7 @@ export class SceneQueryRunner extends SceneObjectBase implemen const secondaryStreams = secondaries.map((r) => runRequest(ds, r)); // Create the rxjs operator which will combine the primary and secondary responses // by calling the correct processor functions provided by the - // supplemental request providers. + // supplementary request providers. const op = extraRequestProcessingOperator(processors); // Combine the primary and secondary streams into a single stream, and apply the operator. stream = forkJoin([stream, ...secondaryStreams]).pipe(op); @@ -534,14 +534,14 @@ export class SceneQueryRunner extends SceneObjectBase implemen request.interval = norm.interval; request.intervalMs = norm.intervalMs; - // If there are any supplemental request providers, we need to add a new request for each + // If there are any supplementary request providers, we need to add a new request for each // and map the request's ID to the processor function given by the provider, to ensure that // the processor is called with the correct response data. const primaryTimeRange = timeRange.state.value; let secondaryRequests: DataQueryRequest[] = []; let secondaryProcessors = new Map(); - for (const provider of this.getClosestSupplementalRequestProviders() ?? []) { - for (const { req, processor } of provider.getSupplementalRequests(request)) { + for (const provider of this.getClosestSupplementaryRequestProviders() ?? []) { + for (const { req, processor } of provider.getSupplementaryRequests(request)) { const requestId = getNextRequestId(); secondaryRequests.push({ ...req, requestId }) secondaryProcessors.set(requestId, processor ?? passthroughProcessor); @@ -590,21 +590,21 @@ export class SceneQueryRunner extends SceneObjectBase implemen } /** - * Walk up the scene graph and find any SupplementalRequestProviders. + * Walk up the scene graph and find any SupplementaryRequestProviders. * * This will return an array of the closest provider of each type. */ - private getClosestSupplementalRequestProviders(): Array> { + private getClosestSupplementaryRequestProviders(): Array> { const found = new Map(); if (!this.parent) { return []; } getClosest(this.parent, (s) => { - if (isSupplementalRequestProvider(s) && !found.has(s.constructor.name)) { + if (isSupplementaryRequestProvider(s) && !found.has(s.constructor.name)) { found.set(s.constructor.name, s); } s.forEachChild((child) => { - if (isSupplementalRequestProvider(child) && !found.has(child.constructor.name)) { + if (isSupplementaryRequestProvider(child) && !found.has(child.constructor.name)) { found.set(child.constructor.name, child); } }); diff --git a/packages/scenes/src/querying/SupplementalRequestProvider.ts b/packages/scenes/src/querying/SupplementaryRequestProvider.ts similarity index 72% rename from packages/scenes/src/querying/SupplementalRequestProvider.ts rename to packages/scenes/src/querying/SupplementaryRequestProvider.ts index e4511b034..9e6213180 100644 --- a/packages/scenes/src/querying/SupplementalRequestProvider.ts +++ b/packages/scenes/src/querying/SupplementaryRequestProvider.ts @@ -7,7 +7,7 @@ import { SceneObjectState } from "../core/types"; // to any extra requests. // // A processor function should accept two arguments: the data returned by the -// _primary_ query, and the data returned by the `SupplementalRequestProvider`'s +// _primary_ query, and the data returned by the `SupplementaryRequestProvider`'s // _secondary_ query. It should return a new `PanelData` representing the processed output. // It should _not_ modify the primary PanelData. // @@ -20,7 +20,7 @@ export type ProcessorFunc = (primary: PanelData, secondary: PanelData) => PanelD // An extra request that should be run by a query runner, and an optional // processor that should be called with the response data. -export interface SupplementalRequest { +export interface SupplementaryRequest { // The extra request to add. req: DataQueryRequest; // An optional function used to process the data before passing it @@ -28,11 +28,11 @@ export interface SupplementalRequest { processor?: ProcessorFunc; } -// Indicates that this type wants to add supplemental requests, along with +// Indicates that this type wants to add supplementary requests, along with // optional processing functions, to a query runner. -export interface SupplementalRequestProvider extends SceneObjectBase { - // Get any supplemental requests and their required processors. - getSupplementalRequests(request: DataQueryRequest): SupplementalRequest[]; +export interface SupplementaryRequestProvider extends SceneObjectBase { + // Get any supplementary requests and their required processors. + getSupplementaryRequests(request: DataQueryRequest): SupplementaryRequest[]; // Determine whether a query should be rerun. // // When the provider's state changes this function will be passed both the previous and the @@ -41,6 +41,6 @@ export interface SupplementalRequestProvider extends shouldRerun(prev: T, next: T): boolean; } -export function isSupplementalRequestProvider(obj: any): obj is SupplementalRequestProvider { - return typeof obj === 'object' && 'getSupplementalRequests' in obj; +export function isSupplementaryRequestProvider(obj: any): obj is SupplementaryRequestProvider { + return typeof obj === 'object' && 'getSupplementaryRequests' in obj; } diff --git a/packages/scenes/src/querying/extraRequestProcessingOperator.ts b/packages/scenes/src/querying/extraRequestProcessingOperator.ts index 3cba18565..b015f10b0 100644 --- a/packages/scenes/src/querying/extraRequestProcessingOperator.ts +++ b/packages/scenes/src/querying/extraRequestProcessingOperator.ts @@ -1,6 +1,6 @@ import { PanelData } from '@grafana/data'; import { map, Observable } from 'rxjs'; -import { ProcessorFunc } from './SupplementalRequestProvider'; +import { ProcessorFunc } from './SupplementaryRequestProvider'; // Passthrough processor for use with ExtraRequests. export const passthroughProcessor: ProcessorFunc = (_, secondary) => secondary;