@grafana/scenes 5.0.0 → 5.0.1--canary.793.9495469697.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/esm/querying/SceneQueryRunner.js +3 -3
- package/dist/esm/querying/SceneQueryRunner.js.map +1 -1
- package/dist/esm/services/UrlSyncManager.js +28 -33
- package/dist/esm/services/UrlSyncManager.js.map +1 -1
- package/dist/esm/services/utils.js +3 -3
- package/dist/esm/services/utils.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +34 -39
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
@@ -2027,14 +2027,14 @@ function syncStateFromSearchParams(root, urlParams) {
|
|
2027
2027
|
const urlKeyMapper = new UniqueUrlKeyMapper();
|
2028
2028
|
syncStateFromUrl(root, urlParams, urlKeyMapper);
|
2029
2029
|
}
|
2030
|
-
function syncStateFromUrl(root, urlParams, urlKeyMapper) {
|
2031
|
-
if (!
|
2030
|
+
function syncStateFromUrl(root, urlParams, urlKeyMapper, onlyChildren) {
|
2031
|
+
if (!onlyChildren) {
|
2032
2032
|
syncUrlStateToObject(root, urlParams, urlKeyMapper);
|
2033
2033
|
}
|
2034
2034
|
root.forEachChild((child) => {
|
2035
2035
|
syncUrlStateToObject(child, urlParams, urlKeyMapper);
|
2036
2036
|
});
|
2037
|
-
root.forEachChild((child) => syncStateFromUrl(child, urlParams, urlKeyMapper));
|
2037
|
+
root.forEachChild((child) => syncStateFromUrl(child, urlParams, urlKeyMapper, true));
|
2038
2038
|
}
|
2039
2039
|
function syncUrlStateToObject(sceneObject, urlParams, urlKeyMapper) {
|
2040
2040
|
if (sceneObject.urlSync) {
|
@@ -4184,7 +4184,7 @@ class SceneQueryRunner extends SceneObjectBase {
|
|
4184
4184
|
});
|
4185
4185
|
}
|
4186
4186
|
async runWithTimeRange(timeRange) {
|
4187
|
-
var _a, _b;
|
4187
|
+
var _a, _b, _c;
|
4188
4188
|
if (!this.state.maxDataPoints && this.state.maxDataPointsFromWidth && !this._containerWidth) {
|
4189
4189
|
return;
|
4190
4190
|
}
|
@@ -4194,7 +4194,7 @@ class SceneQueryRunner extends SceneObjectBase {
|
|
4194
4194
|
(_a = this._querySub) == null ? void 0 : _a.unsubscribe();
|
4195
4195
|
if (this._variableDependency.hasDependencyInLoadingState()) {
|
4196
4196
|
writeSceneLog("SceneQueryRunner", "Variable dependency is in loading state, skipping query execution");
|
4197
|
-
this.setState({ data: __spreadProps$l(__spreadValues$x({}, this.state.data), { state: schema.LoadingState.Loading }) });
|
4197
|
+
this.setState({ data: __spreadProps$l(__spreadValues$x({}, (_b = this.state.data) != null ? _b : emptyPanelData), { state: schema.LoadingState.Loading }) });
|
4198
4198
|
return;
|
4199
4199
|
}
|
4200
4200
|
const { queries } = this.state;
|
@@ -4203,7 +4203,7 @@ class SceneQueryRunner extends SceneObjectBase {
|
|
4203
4203
|
return;
|
4204
4204
|
}
|
4205
4205
|
try {
|
4206
|
-
const datasource = (
|
4206
|
+
const datasource = (_c = this.state.datasource) != null ? _c : findFirstDatasource(queries);
|
4207
4207
|
const ds = await getDataSource(datasource, this._scopedVars);
|
4208
4208
|
this.findAndSubscribeToAdHocFilters(datasource == null ? void 0 : datasource.uid);
|
4209
4209
|
const runRequest = runtime.getRunRequest();
|
@@ -7806,14 +7806,12 @@ var __privateSet = (obj, member, value, setter) => {
|
|
7806
7806
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
7807
7807
|
return value;
|
7808
7808
|
};
|
7809
|
-
var
|
7809
|
+
var _onStateChanged, _cache, _location;
|
7810
7810
|
class UrlSyncManager {
|
7811
7811
|
constructor() {
|
7812
|
-
|
7813
|
-
|
7814
|
-
|
7815
|
-
__privateAdd(this, _lastLocation, void 0);
|
7816
|
-
__privateAdd(this, _paramsCache, new UrlParamsCache());
|
7812
|
+
this._urlKeyMapper = new UniqueUrlKeyMapper();
|
7813
|
+
this._stateSub = null;
|
7814
|
+
this._paramsCache = new UrlParamsCache();
|
7817
7815
|
__privateAdd(this, _onStateChanged, ({ payload }) => {
|
7818
7816
|
const changedObject = payload.changedObject;
|
7819
7817
|
if (changedObject.urlSync) {
|
@@ -7821,7 +7819,7 @@ class UrlSyncManager {
|
|
7821
7819
|
const searchParams = runtime.locationService.getSearch();
|
7822
7820
|
const mappedUpdated = {};
|
7823
7821
|
for (const [key, newUrlValue] of Object.entries(newUrlState)) {
|
7824
|
-
const uniqueKey =
|
7822
|
+
const uniqueKey = this._urlKeyMapper.getUniqueKey(key, changedObject);
|
7825
7823
|
const currentUrlValue = searchParams.getAll(uniqueKey);
|
7826
7824
|
if (!isUrlValueEqual(currentUrlValue, newUrlValue)) {
|
7827
7825
|
mappedUpdated[uniqueKey] = newUrlValue;
|
@@ -7830,65 +7828,61 @@ class UrlSyncManager {
|
|
7830
7828
|
if (Object.keys(mappedUpdated).length > 0) {
|
7831
7829
|
writeSceneLog("UrlSyncManager", "onStateChange updating URL");
|
7832
7830
|
runtime.locationService.partial(mappedUpdated, true);
|
7833
|
-
|
7831
|
+
this._lastLocation = runtime.locationService.getLocation();
|
7834
7832
|
}
|
7835
7833
|
}
|
7836
7834
|
});
|
7837
7835
|
}
|
7838
7836
|
initSync(root) {
|
7839
7837
|
var _a;
|
7840
|
-
if (
|
7841
|
-
writeSceneLog("UrlSyncManager", "Unregister previous scene state subscription", (_a =
|
7842
|
-
|
7838
|
+
if (this._stateSub) {
|
7839
|
+
writeSceneLog("UrlSyncManager", "Unregister previous scene state subscription", (_a = this._sceneRoot) == null ? void 0 : _a.state.key);
|
7840
|
+
this._stateSub.unsubscribe();
|
7843
7841
|
}
|
7844
7842
|
writeSceneLog("UrlSyncManager", "init", root.state.key);
|
7845
|
-
|
7846
|
-
|
7847
|
-
|
7848
|
-
|
7849
|
-
|
7843
|
+
this._sceneRoot = root;
|
7844
|
+
this._stateSub = root.subscribeToEvent(SceneObjectStateChangedEvent, __privateGet(this, _onStateChanged));
|
7845
|
+
this._urlKeyMapper.clear();
|
7846
|
+
this._lastLocation = runtime.locationService.getLocation();
|
7847
|
+
console.log("initSync", this._lastLocation.search);
|
7848
|
+
this.handleNewObject(this._sceneRoot);
|
7850
7849
|
}
|
7851
7850
|
cleanUp(root) {
|
7852
|
-
if (
|
7851
|
+
if (this._sceneRoot !== root) {
|
7853
7852
|
return;
|
7854
7853
|
}
|
7855
7854
|
writeSceneLog("UrlSyncManager", "Clean up");
|
7856
|
-
if (
|
7857
|
-
|
7858
|
-
|
7855
|
+
if (this._stateSub) {
|
7856
|
+
this._stateSub.unsubscribe();
|
7857
|
+
this._stateSub = null;
|
7859
7858
|
writeSceneLog(
|
7860
7859
|
"UrlSyncManager",
|
7861
7860
|
"Root deactived, unsub to state",
|
7862
7861
|
"same key",
|
7863
|
-
|
7862
|
+
this._sceneRoot.state.key === root.state.key
|
7864
7863
|
);
|
7865
7864
|
}
|
7866
|
-
|
7867
|
-
|
7865
|
+
this._sceneRoot = void 0;
|
7866
|
+
this._lastLocation = void 0;
|
7868
7867
|
}
|
7869
7868
|
handleNewLocation(location) {
|
7870
|
-
if (!
|
7869
|
+
if (!this._sceneRoot || this._lastLocation === location) {
|
7871
7870
|
return;
|
7872
7871
|
}
|
7873
7872
|
writeSceneLog("UrlSyncManager", "handleNewLocation");
|
7874
|
-
|
7875
|
-
syncStateFromUrl(
|
7873
|
+
this._lastLocation = location;
|
7874
|
+
syncStateFromUrl(this._sceneRoot, this._paramsCache.getParams(), this._urlKeyMapper);
|
7876
7875
|
}
|
7877
7876
|
handleNewObject(sceneObj) {
|
7878
|
-
if (!
|
7877
|
+
if (!this._sceneRoot) {
|
7879
7878
|
return;
|
7880
7879
|
}
|
7881
|
-
syncStateFromUrl(sceneObj,
|
7880
|
+
syncStateFromUrl(sceneObj, this._paramsCache.getParams(), this._urlKeyMapper);
|
7882
7881
|
}
|
7883
7882
|
getUrlState(root) {
|
7884
7883
|
return getUrlState(root);
|
7885
7884
|
}
|
7886
7885
|
}
|
7887
|
-
_urlKeyMapper = new WeakMap();
|
7888
|
-
_sceneRoot = new WeakMap();
|
7889
|
-
_stateSub = new WeakMap();
|
7890
|
-
_lastLocation = new WeakMap();
|
7891
|
-
_paramsCache = new WeakMap();
|
7892
7886
|
_onStateChanged = new WeakMap();
|
7893
7887
|
class UrlParamsCache {
|
7894
7888
|
constructor() {
|
@@ -7902,6 +7896,7 @@ class UrlParamsCache {
|
|
7902
7896
|
}
|
7903
7897
|
__privateSet(this, _location, location);
|
7904
7898
|
__privateSet(this, _cache, new URLSearchParams(location.search));
|
7899
|
+
console.log("UrlParamsCache.getParams", __privateGet(this, _cache).toString());
|
7905
7900
|
return __privateGet(this, _cache);
|
7906
7901
|
}
|
7907
7902
|
}
|