@grafana/scenes 6.26.2--canary.1173.16026799419.0 → 6.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/dist/esm/components/VizPanel/VizPanel.js +0 -15
- package/dist/esm/components/VizPanel/VizPanel.js.map +1 -1
- package/dist/esm/components/VizPanel/VizPanelRenderer.js +1 -1
- package/dist/esm/components/VizPanel/VizPanelRenderer.js.map +1 -1
- package/dist/esm/variables/variants/MultiValueVariable.js +10 -3
- package/dist/esm/variables/variants/MultiValueVariable.js.map +1 -1
- package/dist/esm/variables/variants/query/QueryVariable.js +14 -2
- package/dist/esm/variables/variants/query/QueryVariable.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +271 -265
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
@@ -1062,7 +1062,7 @@ declare abstract class MultiValueVariable<TState extends MultiValueVariableState
|
|
1062
1062
|
* This function can intercept and make sure those values are preserved.
|
1063
1063
|
*/
|
1064
1064
|
protected interceptStateUpdateAfterValidation(stateUpdate: Partial<MultiValueVariableState>): void;
|
1065
|
-
getValue(): VariableValue;
|
1065
|
+
getValue(fieldPath?: string): VariableValue;
|
1066
1066
|
getValueText(): string;
|
1067
1067
|
hasAllValue(): boolean;
|
1068
1068
|
getDefaultMultiState(options: VariableValueOption[]): {
|
@@ -1166,6 +1166,8 @@ interface QueryVariableState extends MultiValueVariableState {
|
|
1166
1166
|
regex: string;
|
1167
1167
|
refresh: VariableRefresh$1;
|
1168
1168
|
sort: VariableSort;
|
1169
|
+
staticOptions?: VariableValueOption[];
|
1170
|
+
staticOptionsOrder?: 'before' | 'after' | 'sorted';
|
1169
1171
|
/** @internal Only for use inside core dashboards */
|
1170
1172
|
definition?: string;
|
1171
1173
|
}
|
package/dist/index.js
CHANGED
@@ -1835,14 +1835,21 @@ class MultiValueVariable extends SceneObjectBase {
|
|
1835
1835
|
}
|
1836
1836
|
this.skipNextValidation = false;
|
1837
1837
|
}
|
1838
|
-
getValue() {
|
1838
|
+
getValue(fieldPath) {
|
1839
|
+
let value = this.state.value;
|
1839
1840
|
if (this.hasAllValue()) {
|
1840
1841
|
if (this.state.allValue) {
|
1841
1842
|
return new CustomAllValue(this.state.allValue, this);
|
1842
1843
|
}
|
1843
|
-
|
1844
|
+
value = this.state.options.map((x) => x.value);
|
1844
1845
|
}
|
1845
|
-
|
1846
|
+
if (fieldPath != null && Array.isArray(value)) {
|
1847
|
+
const index = parseInt(fieldPath, 10);
|
1848
|
+
if (!isNaN(index) && index >= 0 && index < value.length) {
|
1849
|
+
return value[index];
|
1850
|
+
}
|
1851
|
+
}
|
1852
|
+
return value;
|
1846
1853
|
}
|
1847
1854
|
getValueText() {
|
1848
1855
|
if (this.hasAllValue()) {
|
@@ -7354,7 +7361,19 @@ class QueryVariable extends MultiValueVariable {
|
|
7354
7361
|
if (this.state.regex) {
|
7355
7362
|
regex = sceneGraph.interpolate(this, this.state.regex, void 0, "regex");
|
7356
7363
|
}
|
7357
|
-
|
7364
|
+
let options = metricNamesToVariableValues(regex, this.state.sort, values);
|
7365
|
+
if (this.state.staticOptions) {
|
7366
|
+
const customOptions = this.state.staticOptions;
|
7367
|
+
options = options.filter((option) => !customOptions.find((custom) => custom.value === option.value));
|
7368
|
+
if (this.state.staticOptionsOrder === "after") {
|
7369
|
+
options.push(...customOptions);
|
7370
|
+
} else if (this.state.staticOptionsOrder === "sorted") {
|
7371
|
+
options = sortVariableValues(options.concat(customOptions), this.state.sort);
|
7372
|
+
} else {
|
7373
|
+
options.unshift(...customOptions);
|
7374
|
+
}
|
7375
|
+
}
|
7376
|
+
return rxjs.of(options);
|
7358
7377
|
}),
|
7359
7378
|
rxjs.catchError((error) => {
|
7360
7379
|
if (error.cancelled) {
|
@@ -8095,7 +8114,7 @@ function VizPanelRenderer({ model }) {
|
|
8095
8114
|
timeZone,
|
8096
8115
|
options,
|
8097
8116
|
fieldConfig,
|
8098
|
-
transparent:
|
8117
|
+
transparent: displayMode === "transparent",
|
8099
8118
|
width: innerWidth,
|
8100
8119
|
height: innerHeight,
|
8101
8120
|
renderCounter: _renderCounter,
|
@@ -8378,253 +8397,6 @@ const createProperty = (color) => {
|
|
8378
8397
|
};
|
8379
8398
|
};
|
8380
8399
|
|
8381
|
-
class SceneDataLayerSetBase extends SceneObjectBase {
|
8382
|
-
constructor() {
|
8383
|
-
super(...arguments);
|
8384
|
-
/** Mark it as a data layer */
|
8385
|
-
this.isDataLayer = true;
|
8386
|
-
/**
|
8387
|
-
* Subject to emit results to.
|
8388
|
-
*/
|
8389
|
-
this._results = new rxjs.ReplaySubject(1);
|
8390
|
-
this._dataLayersMerger = new DataLayersMerger();
|
8391
|
-
}
|
8392
|
-
subscribeToAllLayers(layers) {
|
8393
|
-
if (layers.length > 0) {
|
8394
|
-
this.querySub = this._dataLayersMerger.getMergedStream(layers).subscribe(this._onLayerUpdateReceived.bind(this));
|
8395
|
-
} else {
|
8396
|
-
this._results.next({ origin: this, data: emptyPanelData });
|
8397
|
-
this.setStateHelper({ data: emptyPanelData });
|
8398
|
-
}
|
8399
|
-
}
|
8400
|
-
_onLayerUpdateReceived(results) {
|
8401
|
-
var _a;
|
8402
|
-
let series = [];
|
8403
|
-
for (const result of results) {
|
8404
|
-
if ((_a = result.data) == null ? void 0 : _a.series) {
|
8405
|
-
series = series.concat(result.data.series);
|
8406
|
-
}
|
8407
|
-
}
|
8408
|
-
const combinedData = { ...emptyPanelData, series };
|
8409
|
-
this._results.next({ origin: this, data: combinedData });
|
8410
|
-
this.setStateHelper({ data: combinedData });
|
8411
|
-
}
|
8412
|
-
getResultsStream() {
|
8413
|
-
return this._results;
|
8414
|
-
}
|
8415
|
-
cancelQuery() {
|
8416
|
-
var _a;
|
8417
|
-
(_a = this.querySub) == null ? void 0 : _a.unsubscribe();
|
8418
|
-
}
|
8419
|
-
/**
|
8420
|
-
* This helper function is to counter the contravariance of setState
|
8421
|
-
*/
|
8422
|
-
setStateHelper(state) {
|
8423
|
-
setBaseClassState(this, state);
|
8424
|
-
}
|
8425
|
-
}
|
8426
|
-
class SceneDataLayerSet extends SceneDataLayerSetBase {
|
8427
|
-
constructor(state) {
|
8428
|
-
var _a, _b;
|
8429
|
-
super({
|
8430
|
-
name: (_a = state.name) != null ? _a : "Data layers",
|
8431
|
-
layers: (_b = state.layers) != null ? _b : []
|
8432
|
-
});
|
8433
|
-
this.addActivationHandler(() => this._onActivate());
|
8434
|
-
}
|
8435
|
-
_onActivate() {
|
8436
|
-
this._subs.add(
|
8437
|
-
this.subscribeToState((newState, oldState) => {
|
8438
|
-
var _a;
|
8439
|
-
if (newState.layers !== oldState.layers) {
|
8440
|
-
(_a = this.querySub) == null ? void 0 : _a.unsubscribe();
|
8441
|
-
this.subscribeToAllLayers(newState.layers);
|
8442
|
-
}
|
8443
|
-
})
|
8444
|
-
);
|
8445
|
-
this.subscribeToAllLayers(this.state.layers);
|
8446
|
-
return () => {
|
8447
|
-
var _a;
|
8448
|
-
(_a = this.querySub) == null ? void 0 : _a.unsubscribe();
|
8449
|
-
};
|
8450
|
-
}
|
8451
|
-
}
|
8452
|
-
SceneDataLayerSet.Component = ({ model }) => {
|
8453
|
-
const { layers } = model.useState();
|
8454
|
-
return /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, layers.map((layer) => /* @__PURE__ */ React__default.default.createElement(layer.Component, { model: layer, key: layer.state.key })));
|
8455
|
-
};
|
8456
|
-
|
8457
|
-
class SceneDataTransformer extends SceneObjectBase {
|
8458
|
-
constructor(state) {
|
8459
|
-
super(state);
|
8460
|
-
this._results = new rxjs.ReplaySubject(1);
|
8461
|
-
/**
|
8462
|
-
* Scan transformations for variable usage and re-process transforms when a variable values change
|
8463
|
-
*/
|
8464
|
-
this._variableDependency = new VariableDependencyConfig(
|
8465
|
-
this,
|
8466
|
-
{
|
8467
|
-
statePaths: ["transformations"],
|
8468
|
-
onReferencedVariableValueChanged: () => this.reprocessTransformations()
|
8469
|
-
}
|
8470
|
-
);
|
8471
|
-
this.addActivationHandler(() => this.activationHandler());
|
8472
|
-
}
|
8473
|
-
activationHandler() {
|
8474
|
-
const sourceData = this.getSourceData();
|
8475
|
-
this._subs.add(sourceData.subscribeToState((state) => this.transform(state.data)));
|
8476
|
-
if (sourceData.state.data) {
|
8477
|
-
this.transform(sourceData.state.data);
|
8478
|
-
}
|
8479
|
-
return () => {
|
8480
|
-
if (this._transformSub) {
|
8481
|
-
this._transformSub.unsubscribe();
|
8482
|
-
}
|
8483
|
-
};
|
8484
|
-
}
|
8485
|
-
getSourceData() {
|
8486
|
-
if (this.state.$data) {
|
8487
|
-
if (this.state.$data instanceof SceneDataLayerSet) {
|
8488
|
-
throw new Error("SceneDataLayerSet can not be used as data provider for SceneDataTransformer.");
|
8489
|
-
}
|
8490
|
-
return this.state.$data;
|
8491
|
-
}
|
8492
|
-
if (!this.parent || !this.parent.parent) {
|
8493
|
-
throw new Error("SceneDataTransformer must either have $data set on it or have a parent.parent with $data");
|
8494
|
-
}
|
8495
|
-
return sceneGraph.getData(this.parent.parent);
|
8496
|
-
}
|
8497
|
-
setContainerWidth(width) {
|
8498
|
-
if (this.state.$data && this.state.$data.setContainerWidth) {
|
8499
|
-
this.state.$data.setContainerWidth(width);
|
8500
|
-
}
|
8501
|
-
}
|
8502
|
-
isDataReadyToDisplay() {
|
8503
|
-
const dataObject = this.getSourceData();
|
8504
|
-
if (dataObject.isDataReadyToDisplay) {
|
8505
|
-
return dataObject.isDataReadyToDisplay();
|
8506
|
-
}
|
8507
|
-
return true;
|
8508
|
-
}
|
8509
|
-
reprocessTransformations() {
|
8510
|
-
this.transform(this.getSourceData().state.data, true);
|
8511
|
-
}
|
8512
|
-
cancelQuery() {
|
8513
|
-
var _a, _b;
|
8514
|
-
(_b = (_a = this.getSourceData()).cancelQuery) == null ? void 0 : _b.call(_a);
|
8515
|
-
}
|
8516
|
-
getResultsStream() {
|
8517
|
-
return this._results;
|
8518
|
-
}
|
8519
|
-
clone(withState) {
|
8520
|
-
const clone = super.clone(withState);
|
8521
|
-
if (this._prevDataFromSource) {
|
8522
|
-
clone["_prevDataFromSource"] = this._prevDataFromSource;
|
8523
|
-
}
|
8524
|
-
return clone;
|
8525
|
-
}
|
8526
|
-
haveAlreadyTransformedData(data) {
|
8527
|
-
if (!this._prevDataFromSource) {
|
8528
|
-
return false;
|
8529
|
-
}
|
8530
|
-
if (data === this._prevDataFromSource) {
|
8531
|
-
return true;
|
8532
|
-
}
|
8533
|
-
const { series, annotations } = this._prevDataFromSource;
|
8534
|
-
if (data.series === series && data.annotations === annotations) {
|
8535
|
-
if (this.state.data && data.state !== this.state.data.state) {
|
8536
|
-
this.setState({ data: { ...this.state.data, state: data.state } });
|
8537
|
-
}
|
8538
|
-
return true;
|
8539
|
-
}
|
8540
|
-
return false;
|
8541
|
-
}
|
8542
|
-
transform(data$1, force = false) {
|
8543
|
-
var _a;
|
8544
|
-
if (this.state.transformations.length === 0 || !data$1) {
|
8545
|
-
this._prevDataFromSource = data$1;
|
8546
|
-
this.setState({ data: data$1 });
|
8547
|
-
if (data$1) {
|
8548
|
-
this._results.next({ origin: this, data: data$1 });
|
8549
|
-
}
|
8550
|
-
return;
|
8551
|
-
}
|
8552
|
-
if (!force && this.haveAlreadyTransformedData(data$1)) {
|
8553
|
-
return;
|
8554
|
-
}
|
8555
|
-
let interpolatedTransformations = this._interpolateVariablesInTransformationConfigs(data$1);
|
8556
|
-
const seriesTransformations = interpolatedTransformations.filter((transformation) => {
|
8557
|
-
if ("options" in transformation || "topic" in transformation) {
|
8558
|
-
return transformation.topic == null || transformation.topic === data.DataTopic.Series;
|
8559
|
-
}
|
8560
|
-
return true;
|
8561
|
-
}).map((transformation) => "operator" in transformation ? transformation.operator : transformation);
|
8562
|
-
const annotationsTransformations = interpolatedTransformations.filter((transformation) => {
|
8563
|
-
if ("options" in transformation || "topic" in transformation) {
|
8564
|
-
return transformation.topic === data.DataTopic.Annotations;
|
8565
|
-
}
|
8566
|
-
return false;
|
8567
|
-
}).map((transformation) => "operator" in transformation ? transformation.operator : transformation);
|
8568
|
-
if (this._transformSub) {
|
8569
|
-
this._transformSub.unsubscribe();
|
8570
|
-
}
|
8571
|
-
const ctx = {
|
8572
|
-
interpolate: (value) => {
|
8573
|
-
var _a2;
|
8574
|
-
return sceneGraph.interpolate(this, value, (_a2 = data$1.request) == null ? void 0 : _a2.scopedVars);
|
8575
|
-
}
|
8576
|
-
};
|
8577
|
-
let streams = [data.transformDataFrame(seriesTransformations, data$1.series, ctx)];
|
8578
|
-
if (data$1.annotations && data$1.annotations.length > 0 && annotationsTransformations.length > 0) {
|
8579
|
-
streams.push(data.transformDataFrame(annotationsTransformations, (_a = data$1.annotations) != null ? _a : []));
|
8580
|
-
}
|
8581
|
-
this._transformSub = rxjs.forkJoin(streams).pipe(
|
8582
|
-
rxjs.map((values) => {
|
8583
|
-
const transformedSeries = values[0];
|
8584
|
-
const transformedAnnotations = values[1];
|
8585
|
-
return {
|
8586
|
-
...data$1,
|
8587
|
-
series: transformedSeries,
|
8588
|
-
annotations: transformedAnnotations != null ? transformedAnnotations : data$1.annotations
|
8589
|
-
};
|
8590
|
-
}),
|
8591
|
-
rxjs.catchError((err) => {
|
8592
|
-
var _a2;
|
8593
|
-
console.error("Error transforming data: ", err);
|
8594
|
-
const sourceErr = ((_a2 = this.getSourceData().state.data) == null ? void 0 : _a2.errors) || [];
|
8595
|
-
const transformationError = runtime.toDataQueryError(err);
|
8596
|
-
transformationError.message = `Error transforming data: ${transformationError.message}`;
|
8597
|
-
const result = {
|
8598
|
-
...data$1,
|
8599
|
-
state: data.LoadingState.Error,
|
8600
|
-
// Combine transformation error with upstream errors
|
8601
|
-
errors: [...sourceErr, transformationError]
|
8602
|
-
};
|
8603
|
-
return rxjs.of(result);
|
8604
|
-
})
|
8605
|
-
).subscribe((transformedData) => {
|
8606
|
-
this.setState({ data: transformedData });
|
8607
|
-
this._results.next({ origin: this, data: transformedData });
|
8608
|
-
this._prevDataFromSource = data$1;
|
8609
|
-
});
|
8610
|
-
}
|
8611
|
-
_interpolateVariablesInTransformationConfigs(data) {
|
8612
|
-
var _a;
|
8613
|
-
const transformations = this.state.transformations;
|
8614
|
-
if (this._variableDependency.getNames().size === 0) {
|
8615
|
-
return transformations;
|
8616
|
-
}
|
8617
|
-
const onlyObjects = transformations.every((t) => typeof t === "object");
|
8618
|
-
if (onlyObjects) {
|
8619
|
-
return JSON.parse(sceneGraph.interpolate(this, JSON.stringify(transformations), (_a = data.request) == null ? void 0 : _a.scopedVars));
|
8620
|
-
}
|
8621
|
-
return transformations.map((t) => {
|
8622
|
-
var _a2;
|
8623
|
-
return typeof t === "object" ? JSON.parse(sceneGraph.interpolate(this, JSON.stringify(t), (_a2 = data.request) == null ? void 0 : _a2.scopedVars)) : t;
|
8624
|
-
});
|
8625
|
-
}
|
8626
|
-
}
|
8627
|
-
|
8628
8400
|
class VizPanel extends SceneObjectBase {
|
8629
8401
|
constructor(state) {
|
8630
8402
|
var _a;
|
@@ -8863,18 +8635,6 @@ class VizPanel extends SceneObjectBase {
|
|
8863
8635
|
if (plugin.onPanelMigration && currentVersion !== pluginVersion && !isAfterPluginChange) {
|
8864
8636
|
panel.options = await plugin.onPanelMigration(panel);
|
8865
8637
|
}
|
8866
|
-
let $data = this.state.$data;
|
8867
|
-
if (panel.transformations && $data) {
|
8868
|
-
if ($data instanceof SceneDataTransformer) {
|
8869
|
-
$data.setState({ transformations: panel.transformations });
|
8870
|
-
} else if ($data instanceof SceneQueryRunner) {
|
8871
|
-
$data.clearParent();
|
8872
|
-
$data = new SceneDataTransformer({
|
8873
|
-
transformations: panel.transformations,
|
8874
|
-
$data
|
8875
|
-
});
|
8876
|
-
}
|
8877
|
-
}
|
8878
8638
|
const withDefaults = data.getPanelOptionsWithDefaults({
|
8879
8639
|
plugin,
|
8880
8640
|
currentOptions: panel.options,
|
@@ -8883,7 +8643,6 @@ class VizPanel extends SceneObjectBase {
|
|
8883
8643
|
});
|
8884
8644
|
this._plugin = plugin;
|
8885
8645
|
this.setState({
|
8886
|
-
$data,
|
8887
8646
|
options: withDefaults.options,
|
8888
8647
|
fieldConfig: withDefaults.fieldConfig,
|
8889
8648
|
pluginVersion: currentVersion,
|
@@ -9783,6 +9542,253 @@ class DataProviderProxy extends SceneObjectBase {
|
|
9783
9542
|
}
|
9784
9543
|
}
|
9785
9544
|
|
9545
|
+
class SceneDataLayerSetBase extends SceneObjectBase {
|
9546
|
+
constructor() {
|
9547
|
+
super(...arguments);
|
9548
|
+
/** Mark it as a data layer */
|
9549
|
+
this.isDataLayer = true;
|
9550
|
+
/**
|
9551
|
+
* Subject to emit results to.
|
9552
|
+
*/
|
9553
|
+
this._results = new rxjs.ReplaySubject(1);
|
9554
|
+
this._dataLayersMerger = new DataLayersMerger();
|
9555
|
+
}
|
9556
|
+
subscribeToAllLayers(layers) {
|
9557
|
+
if (layers.length > 0) {
|
9558
|
+
this.querySub = this._dataLayersMerger.getMergedStream(layers).subscribe(this._onLayerUpdateReceived.bind(this));
|
9559
|
+
} else {
|
9560
|
+
this._results.next({ origin: this, data: emptyPanelData });
|
9561
|
+
this.setStateHelper({ data: emptyPanelData });
|
9562
|
+
}
|
9563
|
+
}
|
9564
|
+
_onLayerUpdateReceived(results) {
|
9565
|
+
var _a;
|
9566
|
+
let series = [];
|
9567
|
+
for (const result of results) {
|
9568
|
+
if ((_a = result.data) == null ? void 0 : _a.series) {
|
9569
|
+
series = series.concat(result.data.series);
|
9570
|
+
}
|
9571
|
+
}
|
9572
|
+
const combinedData = { ...emptyPanelData, series };
|
9573
|
+
this._results.next({ origin: this, data: combinedData });
|
9574
|
+
this.setStateHelper({ data: combinedData });
|
9575
|
+
}
|
9576
|
+
getResultsStream() {
|
9577
|
+
return this._results;
|
9578
|
+
}
|
9579
|
+
cancelQuery() {
|
9580
|
+
var _a;
|
9581
|
+
(_a = this.querySub) == null ? void 0 : _a.unsubscribe();
|
9582
|
+
}
|
9583
|
+
/**
|
9584
|
+
* This helper function is to counter the contravariance of setState
|
9585
|
+
*/
|
9586
|
+
setStateHelper(state) {
|
9587
|
+
setBaseClassState(this, state);
|
9588
|
+
}
|
9589
|
+
}
|
9590
|
+
class SceneDataLayerSet extends SceneDataLayerSetBase {
|
9591
|
+
constructor(state) {
|
9592
|
+
var _a, _b;
|
9593
|
+
super({
|
9594
|
+
name: (_a = state.name) != null ? _a : "Data layers",
|
9595
|
+
layers: (_b = state.layers) != null ? _b : []
|
9596
|
+
});
|
9597
|
+
this.addActivationHandler(() => this._onActivate());
|
9598
|
+
}
|
9599
|
+
_onActivate() {
|
9600
|
+
this._subs.add(
|
9601
|
+
this.subscribeToState((newState, oldState) => {
|
9602
|
+
var _a;
|
9603
|
+
if (newState.layers !== oldState.layers) {
|
9604
|
+
(_a = this.querySub) == null ? void 0 : _a.unsubscribe();
|
9605
|
+
this.subscribeToAllLayers(newState.layers);
|
9606
|
+
}
|
9607
|
+
})
|
9608
|
+
);
|
9609
|
+
this.subscribeToAllLayers(this.state.layers);
|
9610
|
+
return () => {
|
9611
|
+
var _a;
|
9612
|
+
(_a = this.querySub) == null ? void 0 : _a.unsubscribe();
|
9613
|
+
};
|
9614
|
+
}
|
9615
|
+
}
|
9616
|
+
SceneDataLayerSet.Component = ({ model }) => {
|
9617
|
+
const { layers } = model.useState();
|
9618
|
+
return /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, layers.map((layer) => /* @__PURE__ */ React__default.default.createElement(layer.Component, { model: layer, key: layer.state.key })));
|
9619
|
+
};
|
9620
|
+
|
9621
|
+
class SceneDataTransformer extends SceneObjectBase {
|
9622
|
+
constructor(state) {
|
9623
|
+
super(state);
|
9624
|
+
this._results = new rxjs.ReplaySubject(1);
|
9625
|
+
/**
|
9626
|
+
* Scan transformations for variable usage and re-process transforms when a variable values change
|
9627
|
+
*/
|
9628
|
+
this._variableDependency = new VariableDependencyConfig(
|
9629
|
+
this,
|
9630
|
+
{
|
9631
|
+
statePaths: ["transformations"],
|
9632
|
+
onReferencedVariableValueChanged: () => this.reprocessTransformations()
|
9633
|
+
}
|
9634
|
+
);
|
9635
|
+
this.addActivationHandler(() => this.activationHandler());
|
9636
|
+
}
|
9637
|
+
activationHandler() {
|
9638
|
+
const sourceData = this.getSourceData();
|
9639
|
+
this._subs.add(sourceData.subscribeToState((state) => this.transform(state.data)));
|
9640
|
+
if (sourceData.state.data) {
|
9641
|
+
this.transform(sourceData.state.data);
|
9642
|
+
}
|
9643
|
+
return () => {
|
9644
|
+
if (this._transformSub) {
|
9645
|
+
this._transformSub.unsubscribe();
|
9646
|
+
}
|
9647
|
+
};
|
9648
|
+
}
|
9649
|
+
getSourceData() {
|
9650
|
+
if (this.state.$data) {
|
9651
|
+
if (this.state.$data instanceof SceneDataLayerSet) {
|
9652
|
+
throw new Error("SceneDataLayerSet can not be used as data provider for SceneDataTransformer.");
|
9653
|
+
}
|
9654
|
+
return this.state.$data;
|
9655
|
+
}
|
9656
|
+
if (!this.parent || !this.parent.parent) {
|
9657
|
+
throw new Error("SceneDataTransformer must either have $data set on it or have a parent.parent with $data");
|
9658
|
+
}
|
9659
|
+
return sceneGraph.getData(this.parent.parent);
|
9660
|
+
}
|
9661
|
+
setContainerWidth(width) {
|
9662
|
+
if (this.state.$data && this.state.$data.setContainerWidth) {
|
9663
|
+
this.state.$data.setContainerWidth(width);
|
9664
|
+
}
|
9665
|
+
}
|
9666
|
+
isDataReadyToDisplay() {
|
9667
|
+
const dataObject = this.getSourceData();
|
9668
|
+
if (dataObject.isDataReadyToDisplay) {
|
9669
|
+
return dataObject.isDataReadyToDisplay();
|
9670
|
+
}
|
9671
|
+
return true;
|
9672
|
+
}
|
9673
|
+
reprocessTransformations() {
|
9674
|
+
this.transform(this.getSourceData().state.data, true);
|
9675
|
+
}
|
9676
|
+
cancelQuery() {
|
9677
|
+
var _a, _b;
|
9678
|
+
(_b = (_a = this.getSourceData()).cancelQuery) == null ? void 0 : _b.call(_a);
|
9679
|
+
}
|
9680
|
+
getResultsStream() {
|
9681
|
+
return this._results;
|
9682
|
+
}
|
9683
|
+
clone(withState) {
|
9684
|
+
const clone = super.clone(withState);
|
9685
|
+
if (this._prevDataFromSource) {
|
9686
|
+
clone["_prevDataFromSource"] = this._prevDataFromSource;
|
9687
|
+
}
|
9688
|
+
return clone;
|
9689
|
+
}
|
9690
|
+
haveAlreadyTransformedData(data) {
|
9691
|
+
if (!this._prevDataFromSource) {
|
9692
|
+
return false;
|
9693
|
+
}
|
9694
|
+
if (data === this._prevDataFromSource) {
|
9695
|
+
return true;
|
9696
|
+
}
|
9697
|
+
const { series, annotations } = this._prevDataFromSource;
|
9698
|
+
if (data.series === series && data.annotations === annotations) {
|
9699
|
+
if (this.state.data && data.state !== this.state.data.state) {
|
9700
|
+
this.setState({ data: { ...this.state.data, state: data.state } });
|
9701
|
+
}
|
9702
|
+
return true;
|
9703
|
+
}
|
9704
|
+
return false;
|
9705
|
+
}
|
9706
|
+
transform(data$1, force = false) {
|
9707
|
+
var _a;
|
9708
|
+
if (this.state.transformations.length === 0 || !data$1) {
|
9709
|
+
this._prevDataFromSource = data$1;
|
9710
|
+
this.setState({ data: data$1 });
|
9711
|
+
if (data$1) {
|
9712
|
+
this._results.next({ origin: this, data: data$1 });
|
9713
|
+
}
|
9714
|
+
return;
|
9715
|
+
}
|
9716
|
+
if (!force && this.haveAlreadyTransformedData(data$1)) {
|
9717
|
+
return;
|
9718
|
+
}
|
9719
|
+
let interpolatedTransformations = this._interpolateVariablesInTransformationConfigs(data$1);
|
9720
|
+
const seriesTransformations = interpolatedTransformations.filter((transformation) => {
|
9721
|
+
if ("options" in transformation || "topic" in transformation) {
|
9722
|
+
return transformation.topic == null || transformation.topic === data.DataTopic.Series;
|
9723
|
+
}
|
9724
|
+
return true;
|
9725
|
+
}).map((transformation) => "operator" in transformation ? transformation.operator : transformation);
|
9726
|
+
const annotationsTransformations = interpolatedTransformations.filter((transformation) => {
|
9727
|
+
if ("options" in transformation || "topic" in transformation) {
|
9728
|
+
return transformation.topic === data.DataTopic.Annotations;
|
9729
|
+
}
|
9730
|
+
return false;
|
9731
|
+
}).map((transformation) => "operator" in transformation ? transformation.operator : transformation);
|
9732
|
+
if (this._transformSub) {
|
9733
|
+
this._transformSub.unsubscribe();
|
9734
|
+
}
|
9735
|
+
const ctx = {
|
9736
|
+
interpolate: (value) => {
|
9737
|
+
var _a2;
|
9738
|
+
return sceneGraph.interpolate(this, value, (_a2 = data$1.request) == null ? void 0 : _a2.scopedVars);
|
9739
|
+
}
|
9740
|
+
};
|
9741
|
+
let streams = [data.transformDataFrame(seriesTransformations, data$1.series, ctx)];
|
9742
|
+
if (data$1.annotations && data$1.annotations.length > 0 && annotationsTransformations.length > 0) {
|
9743
|
+
streams.push(data.transformDataFrame(annotationsTransformations, (_a = data$1.annotations) != null ? _a : []));
|
9744
|
+
}
|
9745
|
+
this._transformSub = rxjs.forkJoin(streams).pipe(
|
9746
|
+
rxjs.map((values) => {
|
9747
|
+
const transformedSeries = values[0];
|
9748
|
+
const transformedAnnotations = values[1];
|
9749
|
+
return {
|
9750
|
+
...data$1,
|
9751
|
+
series: transformedSeries,
|
9752
|
+
annotations: transformedAnnotations != null ? transformedAnnotations : data$1.annotations
|
9753
|
+
};
|
9754
|
+
}),
|
9755
|
+
rxjs.catchError((err) => {
|
9756
|
+
var _a2;
|
9757
|
+
console.error("Error transforming data: ", err);
|
9758
|
+
const sourceErr = ((_a2 = this.getSourceData().state.data) == null ? void 0 : _a2.errors) || [];
|
9759
|
+
const transformationError = runtime.toDataQueryError(err);
|
9760
|
+
transformationError.message = `Error transforming data: ${transformationError.message}`;
|
9761
|
+
const result = {
|
9762
|
+
...data$1,
|
9763
|
+
state: data.LoadingState.Error,
|
9764
|
+
// Combine transformation error with upstream errors
|
9765
|
+
errors: [...sourceErr, transformationError]
|
9766
|
+
};
|
9767
|
+
return rxjs.of(result);
|
9768
|
+
})
|
9769
|
+
).subscribe((transformedData) => {
|
9770
|
+
this.setState({ data: transformedData });
|
9771
|
+
this._results.next({ origin: this, data: transformedData });
|
9772
|
+
this._prevDataFromSource = data$1;
|
9773
|
+
});
|
9774
|
+
}
|
9775
|
+
_interpolateVariablesInTransformationConfigs(data) {
|
9776
|
+
var _a;
|
9777
|
+
const transformations = this.state.transformations;
|
9778
|
+
if (this._variableDependency.getNames().size === 0) {
|
9779
|
+
return transformations;
|
9780
|
+
}
|
9781
|
+
const onlyObjects = transformations.every((t) => typeof t === "object");
|
9782
|
+
if (onlyObjects) {
|
9783
|
+
return JSON.parse(sceneGraph.interpolate(this, JSON.stringify(transformations), (_a = data.request) == null ? void 0 : _a.scopedVars));
|
9784
|
+
}
|
9785
|
+
return transformations.map((t) => {
|
9786
|
+
var _a2;
|
9787
|
+
return typeof t === "object" ? JSON.parse(sceneGraph.interpolate(this, JSON.stringify(t), (_a2 = data.request) == null ? void 0 : _a2.scopedVars)) : t;
|
9788
|
+
});
|
9789
|
+
}
|
9790
|
+
}
|
9791
|
+
|
9786
9792
|
class VariableValueSelectors extends SceneObjectBase {
|
9787
9793
|
}
|
9788
9794
|
VariableValueSelectors.Component = VariableValueSelectorsRenderer;
|