@grafana/scenes 6.4.0--canary.1062.13769817941.0 → 6.4.0--canary.1062.13789113586.0
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 +15 -0
- package/dist/esm/components/SceneApp/SceneApp.js +9 -3
- package/dist/esm/components/SceneApp/SceneApp.js.map +1 -1
- package/dist/esm/components/SceneApp/SceneAppPage.js +16 -0
- package/dist/esm/components/SceneApp/SceneAppPage.js.map +1 -1
- package/dist/esm/core/SceneScopesBridge.js +108 -0
- package/dist/esm/core/SceneScopesBridge.js.map +1 -0
- package/dist/esm/core/sceneGraph/index.js +3 -2
- package/dist/esm/core/sceneGraph/index.js.map +1 -1
- package/dist/esm/core/sceneGraph/sceneGraph.js +6 -1
- package/dist/esm/core/sceneGraph/sceneGraph.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/querying/SceneQueryRunner.js +33 -8
- package/dist/esm/querying/SceneQueryRunner.js.map +1 -1
- package/dist/esm/variables/adhoc/AdHocFiltersVariable.js +32 -11
- package/dist/esm/variables/adhoc/AdHocFiltersVariable.js.map +1 -1
- package/dist/esm/variables/adhoc/getAdHocFiltersFromScopes.js +72 -0
- package/dist/esm/variables/adhoc/getAdHocFiltersFromScopes.js.map +1 -0
- package/dist/esm/variables/groupby/GroupByVariable.js +3 -2
- package/dist/esm/variables/groupby/GroupByVariable.js.map +1 -1
- package/dist/index.d.ts +71 -20
- package/dist/index.js +264 -25
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -3270,7 +3270,7 @@ class GroupByVariable extends MultiValueVariable {
|
|
|
3270
3270
|
this.isLazy = true;
|
|
3271
3271
|
this._urlSync = new GroupByVariableUrlSyncHandler(this);
|
|
3272
3272
|
this._getKeys = async (ds) => {
|
|
3273
|
-
var _a, _b, _c;
|
|
3273
|
+
var _a, _b, _c, _d;
|
|
3274
3274
|
const override = await ((_b = (_a = this.state).getTagKeysProvider) == null ? void 0 : _b.call(_a, this, null));
|
|
3275
3275
|
if (override && override.replace) {
|
|
3276
3276
|
return override.values;
|
|
@@ -3287,7 +3287,8 @@ class GroupByVariable extends MultiValueVariable {
|
|
|
3287
3287
|
const response = await ds.getTagKeys(__spreadValues$F({
|
|
3288
3288
|
filters: otherFilters,
|
|
3289
3289
|
queries,
|
|
3290
|
-
timeRange
|
|
3290
|
+
timeRange,
|
|
3291
|
+
scopes: (_d = this._scopesBridge) == null ? void 0 : _d.getValue()
|
|
3291
3292
|
}, getEnrichedFiltersRequest(this)));
|
|
3292
3293
|
if (responseHasError(response)) {
|
|
3293
3294
|
this.setState({ error: response.error.message });
|
|
@@ -5394,6 +5395,73 @@ const getStyles$a = (theme) => ({
|
|
|
5394
5395
|
})
|
|
5395
5396
|
});
|
|
5396
5397
|
|
|
5398
|
+
const reverseScopeFilterOperatorMap = Object.fromEntries(
|
|
5399
|
+
Object.entries(data.scopeFilterOperatorMap).map(([symbol, operator]) => [operator, symbol])
|
|
5400
|
+
);
|
|
5401
|
+
function isEqualityOrMultiOperator(value) {
|
|
5402
|
+
const operators = /* @__PURE__ */ new Set(["equals", "not-equals", "one-of", "not-one-of"]);
|
|
5403
|
+
return operators.has(value);
|
|
5404
|
+
}
|
|
5405
|
+
function getAdHocFiltersFromScopes(scopes) {
|
|
5406
|
+
const formattedFilters = /* @__PURE__ */ new Map();
|
|
5407
|
+
const duplicatedFilters = [];
|
|
5408
|
+
const allFilters = scopes.flatMap((scope) => scope.spec.filters);
|
|
5409
|
+
for (const filter of allFilters) {
|
|
5410
|
+
processFilter(formattedFilters, duplicatedFilters, filter);
|
|
5411
|
+
}
|
|
5412
|
+
return [...formattedFilters.values(), ...duplicatedFilters];
|
|
5413
|
+
}
|
|
5414
|
+
function processFilter(formattedFilters, duplicatedFilters, filter) {
|
|
5415
|
+
var _a, _b;
|
|
5416
|
+
const existingFilter = formattedFilters.get(filter.key);
|
|
5417
|
+
if (existingFilter && canValueBeMerged(existingFilter.operator, filter.operator)) {
|
|
5418
|
+
mergeFilterValues(existingFilter, filter);
|
|
5419
|
+
} else if (!existingFilter) {
|
|
5420
|
+
formattedFilters.set(filter.key, {
|
|
5421
|
+
key: filter.key,
|
|
5422
|
+
operator: reverseScopeFilterOperatorMap[filter.operator],
|
|
5423
|
+
value: filter.value,
|
|
5424
|
+
values: (_a = filter.values) != null ? _a : [filter.value],
|
|
5425
|
+
origin: FilterOrigin.Scopes
|
|
5426
|
+
});
|
|
5427
|
+
} else {
|
|
5428
|
+
duplicatedFilters.push({
|
|
5429
|
+
key: filter.key,
|
|
5430
|
+
operator: reverseScopeFilterOperatorMap[filter.operator],
|
|
5431
|
+
value: filter.value,
|
|
5432
|
+
values: (_b = filter.values) != null ? _b : [filter.value],
|
|
5433
|
+
origin: FilterOrigin.Scopes
|
|
5434
|
+
});
|
|
5435
|
+
}
|
|
5436
|
+
}
|
|
5437
|
+
function mergeFilterValues(adHocFilter, filter) {
|
|
5438
|
+
var _a, _b, _c, _d;
|
|
5439
|
+
const values = (_a = filter.values) != null ? _a : [filter.value];
|
|
5440
|
+
for (const value of values) {
|
|
5441
|
+
if (!((_b = adHocFilter.values) == null ? void 0 : _b.includes(value))) {
|
|
5442
|
+
(_c = adHocFilter.values) == null ? void 0 : _c.push(value);
|
|
5443
|
+
}
|
|
5444
|
+
}
|
|
5445
|
+
if (((_d = adHocFilter.values) == null ? void 0 : _d.length) === 1) {
|
|
5446
|
+
return;
|
|
5447
|
+
}
|
|
5448
|
+
if (filter.operator === "equals" && adHocFilter.operator === reverseScopeFilterOperatorMap["equals"]) {
|
|
5449
|
+
adHocFilter.operator = reverseScopeFilterOperatorMap["one-of"];
|
|
5450
|
+
} else if (filter.operator === "not-equals" && adHocFilter.operator === reverseScopeFilterOperatorMap["not-equals"]) {
|
|
5451
|
+
adHocFilter.operator = reverseScopeFilterOperatorMap["not-one-of"];
|
|
5452
|
+
}
|
|
5453
|
+
}
|
|
5454
|
+
function canValueBeMerged(adHocFilterOperator, filterOperator) {
|
|
5455
|
+
const scopeConvertedOperator = data.scopeFilterOperatorMap[adHocFilterOperator];
|
|
5456
|
+
if (!isEqualityOrMultiOperator(scopeConvertedOperator) || !isEqualityOrMultiOperator(filterOperator)) {
|
|
5457
|
+
return false;
|
|
5458
|
+
}
|
|
5459
|
+
if (scopeConvertedOperator.includes("not") && !filterOperator.includes("not") || !scopeConvertedOperator.includes("not") && filterOperator.includes("not")) {
|
|
5460
|
+
return false;
|
|
5461
|
+
}
|
|
5462
|
+
return true;
|
|
5463
|
+
}
|
|
5464
|
+
|
|
5397
5465
|
var __defProp$z = Object.defineProperty;
|
|
5398
5466
|
var __defProps$n = Object.defineProperties;
|
|
5399
5467
|
var __getOwnPropDescs$n = Object.getOwnPropertyDescriptors;
|
|
@@ -5473,9 +5541,32 @@ class AdHocFiltersVariable extends SceneObjectBase {
|
|
|
5473
5541
|
this._scopedVars = { __sceneObject: wrapInSafeSerializableSceneObject(this) };
|
|
5474
5542
|
this._dataSourceSrv = runtime.getDataSourceSrv();
|
|
5475
5543
|
this._urlSync = new AdHocFiltersVariableUrlSyncHandler(this);
|
|
5544
|
+
this._activationHandler = () => {
|
|
5545
|
+
var _a, _b;
|
|
5546
|
+
this._scopesBridge = sceneGraph.getScopesBridge(this);
|
|
5547
|
+
const scopes = (_a = this._scopesBridge) == null ? void 0 : _a.getValue();
|
|
5548
|
+
if (scopes) {
|
|
5549
|
+
this._updateScopesFilters(scopes);
|
|
5550
|
+
}
|
|
5551
|
+
const sub = (_b = this._scopesBridge) == null ? void 0 : _b.subscribeToValue((n, _) => {
|
|
5552
|
+
this._updateScopesFilters(n);
|
|
5553
|
+
});
|
|
5554
|
+
return () => {
|
|
5555
|
+
sub == null ? void 0 : sub.unsubscribe();
|
|
5556
|
+
};
|
|
5557
|
+
};
|
|
5558
|
+
this._updateScopesFilters = (scopes) => {
|
|
5559
|
+
var _a, _b;
|
|
5560
|
+
const newFilters = [
|
|
5561
|
+
...(_b = (_a = this.state.baseFilters) == null ? void 0 : _a.filter((f) => f.origin && f.origin !== "scopes" /* Scopes */)) != null ? _b : [],
|
|
5562
|
+
...getAdHocFiltersFromScopes(scopes)
|
|
5563
|
+
];
|
|
5564
|
+
this.setState({ baseFilters: newFilters });
|
|
5565
|
+
};
|
|
5476
5566
|
if (this.state.applyMode === "auto") {
|
|
5477
5567
|
patchGetAdhocFilters(this);
|
|
5478
5568
|
}
|
|
5569
|
+
this.addActivationHandler(this._activationHandler);
|
|
5479
5570
|
}
|
|
5480
5571
|
setState(update) {
|
|
5481
5572
|
var _a, _b, _c;
|
|
@@ -5598,7 +5689,7 @@ class AdHocFiltersVariable extends SceneObjectBase {
|
|
|
5598
5689
|
}
|
|
5599
5690
|
}
|
|
5600
5691
|
async _getKeys(currentKey) {
|
|
5601
|
-
var _a, _b, _c;
|
|
5692
|
+
var _a, _b, _c, _d;
|
|
5602
5693
|
const override = await ((_b = (_a = this.state).getTagKeysProvider) == null ? void 0 : _b.call(_a, this, currentKey));
|
|
5603
5694
|
if (override && override.replace) {
|
|
5604
5695
|
return dataFromResponse(override.values).map(toSelectableValue);
|
|
@@ -5616,7 +5707,8 @@ class AdHocFiltersVariable extends SceneObjectBase {
|
|
|
5616
5707
|
const response = await ds.getTagKeys(__spreadValues$z({
|
|
5617
5708
|
filters: otherFilters,
|
|
5618
5709
|
queries,
|
|
5619
|
-
timeRange
|
|
5710
|
+
timeRange,
|
|
5711
|
+
scopes: (_d = this._scopesBridge) == null ? void 0 : _d.getValue()
|
|
5620
5712
|
}, getEnrichedFiltersRequest(this)));
|
|
5621
5713
|
if (responseHasError(response)) {
|
|
5622
5714
|
this.setState({ error: response.error.message });
|
|
@@ -5632,7 +5724,7 @@ class AdHocFiltersVariable extends SceneObjectBase {
|
|
|
5632
5724
|
return keys.map(toSelectableValue);
|
|
5633
5725
|
}
|
|
5634
5726
|
async _getValuesFor(filter) {
|
|
5635
|
-
var _a, _b, _c, _d, _e
|
|
5727
|
+
var _a, _b, _c, _d, _e;
|
|
5636
5728
|
const override = await ((_b = (_a = this.state).getTagValuesProvider) == null ? void 0 : _b.call(_a, this, filter));
|
|
5637
5729
|
if (override && override.replace) {
|
|
5638
5730
|
return dataFromResponse(override.values).map(toSelectableValue);
|
|
@@ -5645,7 +5737,7 @@ class AdHocFiltersVariable extends SceneObjectBase {
|
|
|
5645
5737
|
const otherFilters = this.state.filters.filter((f) => f.key !== filter.key).concat(filteredBaseFilters);
|
|
5646
5738
|
const timeRange = sceneGraph.getTimeRange(this).state.value;
|
|
5647
5739
|
const queries = this.state.useQueriesAsFilterForOptions ? getQueriesForVariables(this) : void 0;
|
|
5648
|
-
const
|
|
5740
|
+
const scopes = (_e = this._scopesBridge) == null ? void 0 : _e.getValue().map((scope) => {
|
|
5649
5741
|
return __spreadProps$n(__spreadValues$z({}, scope), {
|
|
5650
5742
|
spec: __spreadProps$n(__spreadValues$z({}, scope.spec), {
|
|
5651
5743
|
filters: scope.spec.filters.filter(
|
|
@@ -5657,17 +5749,13 @@ class AdHocFiltersVariable extends SceneObjectBase {
|
|
|
5657
5749
|
})
|
|
5658
5750
|
});
|
|
5659
5751
|
});
|
|
5660
|
-
const scopeProps = {};
|
|
5661
|
-
if (injectedScopes) {
|
|
5662
|
-
scopeProps.scopes = injectedScopes;
|
|
5663
|
-
scopeProps.scopesInjected = true;
|
|
5664
|
-
}
|
|
5665
5752
|
const response = await ds.getTagValues(__spreadValues$z({
|
|
5666
5753
|
key: filter.key,
|
|
5667
5754
|
filters: otherFilters,
|
|
5668
5755
|
timeRange,
|
|
5669
|
-
queries
|
|
5670
|
-
|
|
5756
|
+
queries,
|
|
5757
|
+
scopes
|
|
5758
|
+
}, getEnrichedFiltersRequest(this)));
|
|
5671
5759
|
if (responseHasError(response)) {
|
|
5672
5760
|
this.setState({ error: response.error.message });
|
|
5673
5761
|
}
|
|
@@ -5854,6 +5942,7 @@ class SceneQueryRunner extends SceneObjectBase {
|
|
|
5854
5942
|
_onActivate() {
|
|
5855
5943
|
if (this.isQueryModeAuto()) {
|
|
5856
5944
|
const timeRange = sceneGraph.getTimeRange(this);
|
|
5945
|
+
const scopesBridge = sceneGraph.getScopesBridge(this);
|
|
5857
5946
|
const providers = this.getClosestExtraQueryProviders();
|
|
5858
5947
|
for (const provider of providers) {
|
|
5859
5948
|
this._subs.add(
|
|
@@ -5864,6 +5953,7 @@ class SceneQueryRunner extends SceneObjectBase {
|
|
|
5864
5953
|
})
|
|
5865
5954
|
);
|
|
5866
5955
|
}
|
|
5956
|
+
this.subscribeToScopesChanges(scopesBridge);
|
|
5867
5957
|
this.subscribeToTimeRangeChanges(timeRange);
|
|
5868
5958
|
if (this.shouldRunQueriesOnActivate()) {
|
|
5869
5959
|
this.runQueries();
|
|
@@ -6009,6 +6099,21 @@ class SceneQueryRunner extends SceneObjectBase {
|
|
|
6009
6099
|
isDataReadyToDisplay() {
|
|
6010
6100
|
return Boolean(this.state._hasFetchedData);
|
|
6011
6101
|
}
|
|
6102
|
+
subscribeToScopesChanges(scopesBridge) {
|
|
6103
|
+
if (!scopesBridge) {
|
|
6104
|
+
return;
|
|
6105
|
+
}
|
|
6106
|
+
if (this._scopesSubBridge === scopesBridge) {
|
|
6107
|
+
return;
|
|
6108
|
+
}
|
|
6109
|
+
if (this._scopesSub) {
|
|
6110
|
+
this._scopesSub.unsubscribe();
|
|
6111
|
+
}
|
|
6112
|
+
this._scopesSubBridge = scopesBridge;
|
|
6113
|
+
this._scopesSub = scopesBridge.subscribeToValue(() => {
|
|
6114
|
+
this.runWithTimeRangeAndScopes(sceneGraph.getTimeRange(this), scopesBridge);
|
|
6115
|
+
});
|
|
6116
|
+
}
|
|
6012
6117
|
subscribeToTimeRangeChanges(timeRange) {
|
|
6013
6118
|
if (this._timeSubRange === timeRange) {
|
|
6014
6119
|
return;
|
|
@@ -6018,15 +6123,17 @@ class SceneQueryRunner extends SceneObjectBase {
|
|
|
6018
6123
|
}
|
|
6019
6124
|
this._timeSubRange = timeRange;
|
|
6020
6125
|
this._timeSub = timeRange.subscribeToState(() => {
|
|
6021
|
-
this.
|
|
6126
|
+
this.runWithTimeRangeAndScopes(timeRange, sceneGraph.getScopesBridge(this));
|
|
6022
6127
|
});
|
|
6023
6128
|
}
|
|
6024
6129
|
runQueries() {
|
|
6025
6130
|
const timeRange = sceneGraph.getTimeRange(this);
|
|
6131
|
+
const scopesBridge = sceneGraph.getScopesBridge(this);
|
|
6026
6132
|
if (this.isQueryModeAuto()) {
|
|
6027
6133
|
this.subscribeToTimeRangeChanges(timeRange);
|
|
6134
|
+
this.subscribeToScopesChanges(scopesBridge);
|
|
6028
6135
|
}
|
|
6029
|
-
this.
|
|
6136
|
+
this.runWithTimeRangeAndScopes(timeRange, scopesBridge);
|
|
6030
6137
|
}
|
|
6031
6138
|
getMaxDataPoints() {
|
|
6032
6139
|
var _a;
|
|
@@ -6046,8 +6153,8 @@ class SceneQueryRunner extends SceneObjectBase {
|
|
|
6046
6153
|
data: __spreadProps$m(__spreadValues$y({}, this.state.data), { state: schema.LoadingState.Done })
|
|
6047
6154
|
});
|
|
6048
6155
|
}
|
|
6049
|
-
async
|
|
6050
|
-
var _a, _b, _c;
|
|
6156
|
+
async runWithTimeRangeAndScopes(timeRange, scopesBridge) {
|
|
6157
|
+
var _a, _b, _c, _d;
|
|
6051
6158
|
if (!this.state.maxDataPoints && this.state.maxDataPointsFromWidth && !this._containerWidth) {
|
|
6052
6159
|
return;
|
|
6053
6160
|
}
|
|
@@ -6060,17 +6167,22 @@ class SceneQueryRunner extends SceneObjectBase {
|
|
|
6060
6167
|
this.setState({ data: __spreadProps$m(__spreadValues$y({}, (_b = this.state.data) != null ? _b : emptyPanelData), { state: schema.LoadingState.Loading }) });
|
|
6061
6168
|
return;
|
|
6062
6169
|
}
|
|
6170
|
+
if (scopesBridge == null ? void 0 : scopesBridge.isLoading()) {
|
|
6171
|
+
writeSceneLog("SceneQueryRunner", "Scopes are in loading state, skipping query execution");
|
|
6172
|
+
this.setState({ data: __spreadProps$m(__spreadValues$y({}, (_c = this.state.data) != null ? _c : emptyPanelData), { state: schema.LoadingState.Loading }) });
|
|
6173
|
+
return;
|
|
6174
|
+
}
|
|
6063
6175
|
const { queries } = this.state;
|
|
6064
6176
|
if (!(queries == null ? void 0 : queries.length)) {
|
|
6065
6177
|
this._setNoDataState();
|
|
6066
6178
|
return;
|
|
6067
6179
|
}
|
|
6068
6180
|
try {
|
|
6069
|
-
const datasource = (
|
|
6181
|
+
const datasource = (_d = this.state.datasource) != null ? _d : findFirstDatasource(queries);
|
|
6070
6182
|
const ds = await getDataSource(datasource, this._scopedVars);
|
|
6071
6183
|
this.findAndSubscribeToAdHocFilters(ds.uid);
|
|
6072
6184
|
const runRequest = runtime.getRunRequest();
|
|
6073
|
-
const { primary, secondaries, processors } = this.prepareRequests(timeRange, ds);
|
|
6185
|
+
const { primary, secondaries, processors } = this.prepareRequests(timeRange, ds, scopesBridge);
|
|
6074
6186
|
writeSceneLog("SceneQueryRunner", "Starting runRequest", this.state.key);
|
|
6075
6187
|
let stream = runRequest(ds, primary);
|
|
6076
6188
|
if (secondaries.length > 0) {
|
|
@@ -6109,7 +6221,7 @@ class SceneQueryRunner extends SceneObjectBase {
|
|
|
6109
6221
|
clone["_results"].next({ origin: this, data: (_a = this.state.data) != null ? _a : emptyPanelData });
|
|
6110
6222
|
return clone;
|
|
6111
6223
|
}
|
|
6112
|
-
prepareRequests(timeRange, ds) {
|
|
6224
|
+
prepareRequests(timeRange, ds, scopesBridge) {
|
|
6113
6225
|
var _a, _b;
|
|
6114
6226
|
const { minInterval, queries } = this.state;
|
|
6115
6227
|
let request = __spreadValues$y({
|
|
@@ -6129,7 +6241,8 @@ class SceneQueryRunner extends SceneObjectBase {
|
|
|
6129
6241
|
to: timeRange.state.to
|
|
6130
6242
|
},
|
|
6131
6243
|
cacheTimeout: this.state.cacheTimeout,
|
|
6132
|
-
queryCachingTTL: this.state.queryCachingTTL
|
|
6244
|
+
queryCachingTTL: this.state.queryCachingTTL,
|
|
6245
|
+
scopes: scopesBridge == null ? void 0 : scopesBridge.getValue()
|
|
6133
6246
|
}, getEnrichedDataRequest(this));
|
|
6134
6247
|
if (this._adhocFiltersVar) {
|
|
6135
6248
|
request.filters = [];
|
|
@@ -7091,6 +7204,105 @@ function containsSearchFilter(query) {
|
|
|
7091
7204
|
return str.indexOf(SEARCH_FILTER_VARIABLE) > -1;
|
|
7092
7205
|
}
|
|
7093
7206
|
|
|
7207
|
+
class SceneScopesBridge extends SceneObjectBase {
|
|
7208
|
+
constructor() {
|
|
7209
|
+
super(...arguments);
|
|
7210
|
+
this._urlSync = new SceneObjectUrlSyncConfig(this, { keys: ["scopes"] });
|
|
7211
|
+
this._renderBeforeActivation = true;
|
|
7212
|
+
this._contextSubject = new rxjs.BehaviorSubject(void 0);
|
|
7213
|
+
this._pendingScopes = null;
|
|
7214
|
+
}
|
|
7215
|
+
getUrlState() {
|
|
7216
|
+
var _a, _b, _c;
|
|
7217
|
+
return {
|
|
7218
|
+
scopes: (_c = this._pendingScopes) != null ? _c : ((_b = (_a = this.context) == null ? void 0 : _a.state.value) != null ? _b : []).map((scope) => scope.metadata.name)
|
|
7219
|
+
};
|
|
7220
|
+
}
|
|
7221
|
+
updateFromUrl(values) {
|
|
7222
|
+
var _a, _b;
|
|
7223
|
+
let scopes = (_a = values["scopes"]) != null ? _a : [];
|
|
7224
|
+
scopes = (Array.isArray(scopes) ? scopes : [scopes]).map(String);
|
|
7225
|
+
if (!this.context) {
|
|
7226
|
+
this._pendingScopes = scopes;
|
|
7227
|
+
return;
|
|
7228
|
+
}
|
|
7229
|
+
(_b = this.context) == null ? void 0 : _b.changeScopes(scopes);
|
|
7230
|
+
}
|
|
7231
|
+
getValue() {
|
|
7232
|
+
var _a, _b;
|
|
7233
|
+
return (_b = (_a = this.context) == null ? void 0 : _a.state.value) != null ? _b : [];
|
|
7234
|
+
}
|
|
7235
|
+
subscribeToValue(cb) {
|
|
7236
|
+
return this.contextObservable.pipe(
|
|
7237
|
+
rxjs.map((context) => {
|
|
7238
|
+
var _a;
|
|
7239
|
+
return (_a = context == null ? void 0 : context.state.value) != null ? _a : [];
|
|
7240
|
+
}),
|
|
7241
|
+
rxjs.pairwise(),
|
|
7242
|
+
rxjs.filter(([prevScopes, newScopes]) => !lodash.isEqual(prevScopes, newScopes))
|
|
7243
|
+
).subscribe(([prevScopes, newScopes]) => {
|
|
7244
|
+
cb(newScopes, prevScopes);
|
|
7245
|
+
});
|
|
7246
|
+
}
|
|
7247
|
+
isLoading() {
|
|
7248
|
+
var _a, _b;
|
|
7249
|
+
return (_b = (_a = this.context) == null ? void 0 : _a.state.loading) != null ? _b : false;
|
|
7250
|
+
}
|
|
7251
|
+
subscribeToLoading(cb) {
|
|
7252
|
+
return this.contextObservable.pipe(
|
|
7253
|
+
rxjs.filter((context) => !!context),
|
|
7254
|
+
rxjs.pairwise(),
|
|
7255
|
+
rxjs.map(
|
|
7256
|
+
([prevContext, newContext]) => {
|
|
7257
|
+
var _a, _b;
|
|
7258
|
+
return [(_a = prevContext == null ? void 0 : prevContext.state.loading) != null ? _a : false, (_b = newContext == null ? void 0 : newContext.state.loading) != null ? _b : false];
|
|
7259
|
+
}
|
|
7260
|
+
),
|
|
7261
|
+
rxjs.filter(([prevLoading, newLoading]) => prevLoading !== newLoading)
|
|
7262
|
+
).subscribe(([_prevLoading, newLoading]) => {
|
|
7263
|
+
cb(newLoading);
|
|
7264
|
+
});
|
|
7265
|
+
}
|
|
7266
|
+
setEnabled(enabled) {
|
|
7267
|
+
var _a;
|
|
7268
|
+
(_a = this.context) == null ? void 0 : _a.setEnabled(enabled);
|
|
7269
|
+
}
|
|
7270
|
+
setReadOnly(readOnly) {
|
|
7271
|
+
var _a;
|
|
7272
|
+
(_a = this.context) == null ? void 0 : _a.setReadOnly(readOnly);
|
|
7273
|
+
}
|
|
7274
|
+
updateContext(newContext) {
|
|
7275
|
+
var _a, _b;
|
|
7276
|
+
if (this._pendingScopes && newContext) {
|
|
7277
|
+
setTimeout(() => {
|
|
7278
|
+
newContext == null ? void 0 : newContext.changeScopes(this._pendingScopes);
|
|
7279
|
+
this._pendingScopes = null;
|
|
7280
|
+
});
|
|
7281
|
+
}
|
|
7282
|
+
if (this.context !== newContext || ((_a = this.context) == null ? void 0 : _a.state) !== (newContext == null ? void 0 : newContext.state)) {
|
|
7283
|
+
const shouldUpdate = ((_b = this.context) == null ? void 0 : _b.state.value) !== (newContext == null ? void 0 : newContext.state.value);
|
|
7284
|
+
this._contextSubject.next(newContext);
|
|
7285
|
+
if (shouldUpdate) {
|
|
7286
|
+
this.forceRender();
|
|
7287
|
+
}
|
|
7288
|
+
}
|
|
7289
|
+
}
|
|
7290
|
+
get context() {
|
|
7291
|
+
return this._contextSubject.getValue();
|
|
7292
|
+
}
|
|
7293
|
+
get contextObservable() {
|
|
7294
|
+
return this._contextSubject.asObservable();
|
|
7295
|
+
}
|
|
7296
|
+
}
|
|
7297
|
+
SceneScopesBridge.Component = SceneScopesBridgeRenderer;
|
|
7298
|
+
function SceneScopesBridgeRenderer({ model }) {
|
|
7299
|
+
const context = runtime.useScopes();
|
|
7300
|
+
React.useEffect(() => {
|
|
7301
|
+
model.updateContext(context);
|
|
7302
|
+
}, [context, model]);
|
|
7303
|
+
return null;
|
|
7304
|
+
}
|
|
7305
|
+
|
|
7094
7306
|
function getVariables(sceneObject) {
|
|
7095
7307
|
var _a;
|
|
7096
7308
|
return (_a = getClosest(sceneObject, (s) => s.state.$variables)) != null ? _a : EmptyVariableSet;
|
|
@@ -7234,6 +7446,10 @@ function findDescendents(scene, descendentType) {
|
|
|
7234
7446
|
const targetScenes = findAllObjects(scene, isDescendentType);
|
|
7235
7447
|
return targetScenes.filter(isDescendentType);
|
|
7236
7448
|
}
|
|
7449
|
+
function getScopesBridge(sceneObject) {
|
|
7450
|
+
var _a;
|
|
7451
|
+
return (_a = findObject(sceneObject, (s) => s instanceof SceneScopesBridge)) != null ? _a : void 0;
|
|
7452
|
+
}
|
|
7237
7453
|
|
|
7238
7454
|
const sceneGraph = {
|
|
7239
7455
|
getVariables,
|
|
@@ -7250,7 +7466,8 @@ const sceneGraph = {
|
|
|
7250
7466
|
findAllObjects,
|
|
7251
7467
|
getAncestor,
|
|
7252
7468
|
getQueryController,
|
|
7253
|
-
findDescendents
|
|
7469
|
+
findDescendents,
|
|
7470
|
+
getScopesBridge
|
|
7254
7471
|
};
|
|
7255
7472
|
|
|
7256
7473
|
class UniqueUrlKeyMapper {
|
|
@@ -13004,6 +13221,10 @@ class SplitLayout extends SceneObjectBase {
|
|
|
13004
13221
|
SplitLayout.Component = SplitLayoutRenderer;
|
|
13005
13222
|
|
|
13006
13223
|
class SceneApp extends SceneObjectBase {
|
|
13224
|
+
constructor() {
|
|
13225
|
+
super(...arguments);
|
|
13226
|
+
this._renderBeforeActivation = true;
|
|
13227
|
+
}
|
|
13007
13228
|
enrichDataRequest() {
|
|
13008
13229
|
return {
|
|
13009
13230
|
app: this.state.name || "app"
|
|
@@ -13011,8 +13232,10 @@ class SceneApp extends SceneObjectBase {
|
|
|
13011
13232
|
}
|
|
13012
13233
|
}
|
|
13013
13234
|
SceneApp.Component = ({ model }) => {
|
|
13014
|
-
const { pages } = model.useState();
|
|
13015
|
-
return /* @__PURE__ */ React__default["default"].createElement(
|
|
13235
|
+
const { pages, scopesBridge } = model.useState();
|
|
13236
|
+
return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, scopesBridge && /* @__PURE__ */ React__default["default"].createElement(scopesBridge.Component, {
|
|
13237
|
+
model: scopesBridge
|
|
13238
|
+
}), /* @__PURE__ */ React__default["default"].createElement(SceneAppContext.Provider, {
|
|
13016
13239
|
value: model
|
|
13017
13240
|
}, /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Routes, null, pages.map((page) => /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Route, {
|
|
13018
13241
|
key: page.state.url,
|
|
@@ -13020,7 +13243,7 @@ SceneApp.Component = ({ model }) => {
|
|
|
13020
13243
|
element: /* @__PURE__ */ React__default["default"].createElement(page.Component, {
|
|
13021
13244
|
model: page
|
|
13022
13245
|
})
|
|
13023
|
-
}))));
|
|
13246
|
+
})))));
|
|
13024
13247
|
};
|
|
13025
13248
|
const SceneAppContext = React.createContext(null);
|
|
13026
13249
|
const sceneAppCache = /* @__PURE__ */ new Map();
|
|
@@ -13375,6 +13598,21 @@ class SceneAppPage extends SceneObjectBase {
|
|
|
13375
13598
|
super(state);
|
|
13376
13599
|
this._sceneCache = /* @__PURE__ */ new Map();
|
|
13377
13600
|
this._drilldownCache = /* @__PURE__ */ new Map();
|
|
13601
|
+
this._activationHandler = () => {
|
|
13602
|
+
if (!this.state.useScopes) {
|
|
13603
|
+
return;
|
|
13604
|
+
}
|
|
13605
|
+
this._scopesBridge = sceneGraph.getScopesBridge(this);
|
|
13606
|
+
if (!this._scopesBridge) {
|
|
13607
|
+
throw new Error("Use of scopes is enabled but no scopes bridge found");
|
|
13608
|
+
}
|
|
13609
|
+
this._scopesBridge.setEnabled(true);
|
|
13610
|
+
return () => {
|
|
13611
|
+
var _a;
|
|
13612
|
+
(_a = this._scopesBridge) == null ? void 0 : _a.setEnabled(false);
|
|
13613
|
+
};
|
|
13614
|
+
};
|
|
13615
|
+
this.addActivationHandler(this._activationHandler);
|
|
13378
13616
|
}
|
|
13379
13617
|
initializeScene(scene) {
|
|
13380
13618
|
this.setState({ initializedScene: scene });
|
|
@@ -14374,6 +14612,7 @@ exports.SceneObjectUrlSyncConfig = SceneObjectUrlSyncConfig;
|
|
|
14374
14612
|
exports.SceneQueryRunner = SceneQueryRunner;
|
|
14375
14613
|
exports.SceneReactObject = SceneReactObject;
|
|
14376
14614
|
exports.SceneRefreshPicker = SceneRefreshPicker;
|
|
14615
|
+
exports.SceneScopesBridge = SceneScopesBridge;
|
|
14377
14616
|
exports.SceneTimePicker = SceneTimePicker;
|
|
14378
14617
|
exports.SceneTimeRange = SceneTimeRange;
|
|
14379
14618
|
exports.SceneTimeRangeCompare = SceneTimeRangeCompare;
|