@grafana/scenes 5.33.1--canary.996.12371059735.0 → 5.34.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -2481,7 +2481,7 @@ function patchGetAdhocFilters(filterVar) {
2481
2481
  function findActiveAdHocFilterVariableByUid(dsUid) {
2482
2482
  var _a;
2483
2483
  for (const filter of allActiveFilterSets.values()) {
2484
- if (interpolate(filter, (_a = filter.state.datasource) == null ? void 0 : _a.uid) === dsUid) {
2484
+ if (((_a = filter.state.datasource) == null ? void 0 : _a.uid) === dsUid) {
2485
2485
  return filter;
2486
2486
  }
2487
2487
  }
@@ -2527,7 +2527,7 @@ const allActiveGroupByVariables = /* @__PURE__ */ new Set();
2527
2527
  function findActiveGroupByVariablesByUid(dsUid) {
2528
2528
  var _a;
2529
2529
  for (const groupByVariable of allActiveGroupByVariables.values()) {
2530
- if (interpolate(groupByVariable, (_a = groupByVariable.state.datasource) == null ? void 0 : _a.uid) === dsUid) {
2530
+ if (((_a = groupByVariable.state.datasource) == null ? void 0 : _a.uid) === dsUid) {
2531
2531
  return groupByVariable;
2532
2532
  }
2533
2533
  }
@@ -5570,7 +5570,7 @@ class SceneQueryRunner extends SceneObjectBase {
5570
5570
  try {
5571
5571
  const datasource = (_c = this.state.datasource) != null ? _c : findFirstDatasource(queries);
5572
5572
  const ds = await getDataSource(datasource, this._scopedVars);
5573
- this.findAndSubscribeToAdHocFilters(ds.uid);
5573
+ this.findAndSubscribeToAdHocFilters(datasource == null ? void 0 : datasource.uid);
5574
5574
  const runRequest = runtime.getRunRequest();
5575
5575
  const { primary, secondaries, processors } = this.prepareRequests(timeRange, ds);
5576
5576
  writeSceneLog("SceneQueryRunner", "Starting runRequest", this.state.key);
@@ -5699,13 +5699,13 @@ class SceneQueryRunner extends SceneObjectBase {
5699
5699
  });
5700
5700
  return Array.from(found.values());
5701
5701
  }
5702
- findAndSubscribeToAdHocFilters(interpolatedUid) {
5703
- const filtersVar = findActiveAdHocFilterVariableByUid(interpolatedUid);
5702
+ findAndSubscribeToAdHocFilters(uid) {
5703
+ const filtersVar = findActiveAdHocFilterVariableByUid(uid);
5704
5704
  if (this._adhocFiltersVar !== filtersVar) {
5705
5705
  this._adhocFiltersVar = filtersVar;
5706
5706
  this._updateExplicitVariableDependencies();
5707
5707
  }
5708
- const groupByVar = findActiveGroupByVariablesByUid(interpolatedUid);
5708
+ const groupByVar = findActiveGroupByVariablesByUid(uid);
5709
5709
  if (this._groupByVar !== groupByVar) {
5710
5710
  this._groupByVar = groupByVar;
5711
5711
  this._updateExplicitVariableDependencies();
@@ -5799,16 +5799,13 @@ function escapeLokiRegexp(value) {
5799
5799
  return value.replace(RE2_METACHARACTERS, "\\$&");
5800
5800
  }
5801
5801
  function getQueriesForVariables(sourceObject) {
5802
- var _a;
5803
5802
  const runners = sceneGraph.findAllObjects(
5804
5803
  sourceObject.getRoot(),
5805
5804
  (o) => o instanceof SceneQueryRunner
5806
5805
  );
5807
- const interpolatedDsUuid = sceneGraph.interpolate(sourceObject, (_a = sourceObject.state.datasource) == null ? void 0 : _a.uid);
5808
5806
  const applicableRunners = filterOutInactiveRunnerDuplicates(runners).filter((r) => {
5809
- var _a2;
5810
- const interpolatedQueryDsUuid = sceneGraph.interpolate(sourceObject, (_a2 = r.state.datasource) == null ? void 0 : _a2.uid);
5811
- return interpolatedQueryDsUuid === interpolatedDsUuid;
5807
+ var _a, _b;
5808
+ return ((_a = r.state.datasource) == null ? void 0 : _a.uid) === ((_b = sourceObject.state.datasource) == null ? void 0 : _b.uid);
5812
5809
  });
5813
5810
  if (applicableRunners.length === 0) {
5814
5811
  return [];
@@ -6108,6 +6105,12 @@ const hasCustomVariableSupport = (datasource) => {
6108
6105
  const variableSupport = datasource.variables;
6109
6106
  return "query" in variableSupport && "editor" in variableSupport && Boolean(variableSupport.query) && Boolean(variableSupport.editor);
6110
6107
  };
6108
+ const hasDataSourceVariableSupport = (datasource) => {
6109
+ if (!datasource.variables) {
6110
+ return false;
6111
+ }
6112
+ return datasource.variables.getType() === data.VariableSupportType.Datasource;
6113
+ };
6111
6114
 
6112
6115
  var __defProp$w = Object.defineProperty;
6113
6116
  var __defProps$k = Object.defineProperties;
@@ -6203,6 +6206,29 @@ class CustomQueryRunner {
6203
6206
  return this._runRequest(this.datasource, request, this.datasource.variables.query.bind(this.datasource.variables));
6204
6207
  }
6205
6208
  }
6209
+ const variableDummyRefId = "variable-query";
6210
+ class DatasourceQueryRunner {
6211
+ constructor(datasource, _runRequest = runtime.getRunRequest()) {
6212
+ this.datasource = datasource;
6213
+ this._runRequest = _runRequest;
6214
+ }
6215
+ getTarget(variable) {
6216
+ var _a;
6217
+ if (hasDataSourceVariableSupport(this.datasource)) {
6218
+ if (typeof variable.state.query === "string") {
6219
+ return variable.state.query;
6220
+ }
6221
+ return __spreadProps$k(__spreadValues$w({}, variable.state.query), { refId: (_a = variable.state.query.refId) != null ? _a : variableDummyRefId });
6222
+ }
6223
+ throw new Error("Couldn't create a target with supplied arguments.");
6224
+ }
6225
+ runRequest(_, request) {
6226
+ if (!hasDataSourceVariableSupport(this.datasource)) {
6227
+ return getEmptyMetricFindValueObservable();
6228
+ }
6229
+ return this._runRequest(this.datasource, request, this.datasource.query);
6230
+ }
6231
+ }
6206
6232
  function getEmptyMetricFindValueObservable() {
6207
6233
  return rxjs.of({ state: data.LoadingState.Done, series: [], timeRange: data.getDefaultTimeRange() });
6208
6234
  }
@@ -6216,6 +6242,9 @@ function createQueryVariableRunnerFactory(datasource) {
6216
6242
  if (hasCustomVariableSupport(datasource)) {
6217
6243
  return new CustomQueryRunner(datasource);
6218
6244
  }
6245
+ if (hasDataSourceVariableSupport(datasource)) {
6246
+ return new DatasourceQueryRunner(datasource);
6247
+ }
6219
6248
  throw new Error(`Couldn't create a query runner for datasource ${datasource.type}`);
6220
6249
  }
6221
6250
  let createQueryVariableRunner = createQueryVariableRunnerFactory;