Skip to content

Commit

Permalink
s/supplemental/supplementary/g
Browse files Browse the repository at this point in the history
  • Loading branch information
sd2k committed May 24, 2024
1 parent b0bd8a5 commit 374bda5
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 41 deletions.
8 changes: 4 additions & 4 deletions packages/scenes/src/components/SceneTimeRangeCompare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -38,7 +38,7 @@ export const DEFAULT_COMPARE_OPTIONS = [

export class SceneTimeRangeCompare
extends SceneObjectBase<SceneTimeRangeCompareState>
implements SupplementalRequestProvider<SceneTimeRangeCompareState> {
implements SupplementaryRequestProvider<SceneTimeRangeCompareState> {

static Component = SceneTimeRangeCompareRenderer;
protected _urlSync = new SceneObjectUrlSyncConfig(this, { keys: ['compareWith'] });
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/scenes/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
33 changes: 17 additions & 16 deletions packages/scenes/src/querying/SceneQueryRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand All @@ -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 () => {
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -2275,24 +2276,24 @@ class CustomDataSource extends RuntimeDataSource {
}
}

interface TestSupplementalRequestProviderState extends SceneObjectState {
interface TestSupplementaryRequestProviderState extends SceneObjectState {
foo: number;
}

class TestSupplementalRequestProvider extends SceneObjectBase<TestSupplementalRequestProviderState> implements SupplementalRequestProvider<{}> {
class TestSupplementaryRequestProvider extends SceneObjectBase<TestSupplementaryRequestProviderState> implements SupplementaryRequestProvider<{}> {
private _shouldRerun: boolean;

public constructor(state: { foo: number; }, shouldRerun: boolean) {
super(state);
this._shouldRerun = shouldRerun;
}

public getSupplementalRequests(): SupplementalRequest[] {
public getSupplementaryRequests(): SupplementaryRequest[] {
return [{
req: {
targets: [
// @ts-expect-error
{ refId: 'Supplemental', foo: this.state.foo },
{ refId: 'Supplementary', foo: this.state.foo },
],
}
}];
Expand Down
22 changes: 11 additions & 11 deletions packages/scenes/src/querying/SceneQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { writeSceneLog } from '../utils/writeSceneLog';
import { VariableValueRecorder } from '../variables/VariableValueRecorder';
import { emptyPanelData } from '../core/SceneDataNode';
import { getClosest } from '../core/sceneGraph/utils';
import { isSupplementalRequestProvider, ProcessorFunc, SupplementalRequestProvider } from './SupplementalRequestProvider';
import { isSupplementaryRequestProvider, ProcessorFunc, SupplementaryRequestProvider } from './SupplementaryRequestProvider';
import { passthroughProcessor, extraRequestProcessingOperator } from './extraRequestProcessingOperator';
import { filterAnnotations } from './layers/annotations/filterAnnotations';
import { getEnrichedDataRequest } from './getEnrichedDataRequest';
Expand Down Expand Up @@ -110,9 +110,9 @@ export class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> 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) => {
Expand Down Expand Up @@ -421,7 +421,7 @@ export class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> 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);
Expand Down Expand Up @@ -534,14 +534,14 @@ export class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> 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);
Expand Down Expand Up @@ -590,21 +590,21 @@ export class SceneQueryRunner extends SceneObjectBase<QueryRunnerState> 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<SupplementalRequestProvider<any>> {
private getClosestSupplementaryRequestProviders(): Array<SupplementaryRequestProvider<any>> {
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);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand All @@ -20,19 +20,19 @@ 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
// to any transformations or visualizations.
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<T extends SceneObjectState> extends SceneObjectBase<T> {
// Get any supplemental requests and their required processors.
getSupplementalRequests(request: DataQueryRequest): SupplementalRequest[];
export interface SupplementaryRequestProvider<T extends SceneObjectState> extends SceneObjectBase<T> {
// 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
Expand All @@ -41,6 +41,6 @@ export interface SupplementalRequestProvider<T extends SceneObjectState> extends
shouldRerun(prev: T, next: T): boolean;
}

export function isSupplementalRequestProvider(obj: any): obj is SupplementalRequestProvider<any> {
return typeof obj === 'object' && 'getSupplementalRequests' in obj;
export function isSupplementaryRequestProvider(obj: any): obj is SupplementaryRequestProvider<any> {
return typeof obj === 'object' && 'getSupplementaryRequests' in obj;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 374bda5

Please sign in to comment.