@grafana/scenes 5.15.0 → 5.15.1--canary.899.11016830015.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -61,8 +61,8 @@ function useAppQueryParams() {
61
61
  const location = reactRouterDom.useLocation();
62
62
  return runtime.locationSearchToObject(location.search || "");
63
63
  }
64
- function getUrlWithAppState(path, preserveParams) {
65
- const paramsCopy = __spreadValues$O({}, runtime.locationService.getSearchObject());
64
+ function getUrlWithAppState(path, searchObject, preserveParams) {
65
+ const paramsCopy = __spreadValues$O({}, searchObject);
66
66
  if (preserveParams) {
67
67
  for (const key of Object.keys(paramsCopy)) {
68
68
  if (!preserveParams.includes(key)) {
@@ -817,9 +817,17 @@ class SceneTimeRange extends SceneObjectBase {
817
817
  );
818
818
  }
819
819
  }
820
+ if (this.state.weekStart) {
821
+ data.setWeekStart(this.state.weekStart);
822
+ }
820
823
  if (data.rangeUtil.isRelativeTimeRange(this.state.value.raw)) {
821
824
  this.refreshIfStale();
822
825
  }
826
+ return () => {
827
+ if (this.state.weekStart) {
828
+ data.setWeekStart(runtime.config.bootData.user.weekStart);
829
+ }
830
+ };
823
831
  }
824
832
  refreshIfStale() {
825
833
  var _a, _b, _c, _d;
@@ -2188,6 +2196,9 @@ function findActiveGroupByVariablesByUid(dsUid) {
2188
2196
  function setBaseClassState(sceneObject, newState) {
2189
2197
  sceneObject.setState(newState);
2190
2198
  }
2199
+ function useLocationServiceSafe() {
2200
+ return runtime.useLocationService ? runtime.useLocationService() : runtime.locationService;
2201
+ }
2191
2202
 
2192
2203
  class MultiValueVariable extends SceneObjectBase {
2193
2204
  constructor() {
@@ -9391,10 +9402,11 @@ class NewSceneObjectAddedEvent extends data.BusEventWithPayload {
9391
9402
  }
9392
9403
  NewSceneObjectAddedEvent.type = "new-scene-object-added";
9393
9404
  class UrlSyncManager {
9394
- constructor(_options = {}) {
9405
+ constructor(_options = {}, locationService = runtime.locationService) {
9395
9406
  this._urlKeyMapper = new UniqueUrlKeyMapper();
9396
- this._paramsCache = new UrlParamsCache();
9397
9407
  this._options = _options;
9408
+ this._locationService = locationService;
9409
+ this._paramsCache = new UrlParamsCache(locationService);
9398
9410
  }
9399
9411
  initSync(root) {
9400
9412
  var _a;
@@ -9416,12 +9428,12 @@ class UrlSyncManager {
9416
9428
  })
9417
9429
  );
9418
9430
  this._urlKeyMapper.clear();
9419
- this._lastLocation = runtime.locationService.getLocation();
9431
+ this._lastLocation = this._locationService.getLocation();
9420
9432
  this.handleNewObject(this._sceneRoot);
9421
9433
  if (this._options.updateUrlOnInit) {
9422
9434
  const urlState = getUrlState(root);
9423
9435
  if (isUrlStateDifferent(urlState, this._paramsCache.getParams())) {
9424
- runtime.locationService.partial(urlState, true);
9436
+ this._locationService.partial(urlState, true);
9425
9437
  }
9426
9438
  }
9427
9439
  }
@@ -9463,7 +9475,7 @@ class UrlSyncManager {
9463
9475
  return;
9464
9476
  }
9465
9477
  const newUrlState = changedObject.urlSync.getUrlState();
9466
- const searchParams = runtime.locationService.getSearch();
9478
+ const searchParams = this._locationService.getSearch();
9467
9479
  const mappedUpdated = {};
9468
9480
  for (const [key, newUrlValue] of Object.entries(newUrlState)) {
9469
9481
  const uniqueKey = this._urlKeyMapper.getUniqueKey(key, changedObject);
@@ -9476,8 +9488,8 @@ class UrlSyncManager {
9476
9488
  const shouldCreateHistoryEntry = (_b = (_a = changedObject.urlSync).shouldCreateHistoryStep) == null ? void 0 : _b.call(_a, newUrlState);
9477
9489
  const shouldReplace = shouldCreateHistoryEntry !== true;
9478
9490
  writeSceneLog("UrlSyncManager", "onStateChange updating URL");
9479
- runtime.locationService.partial(mappedUpdated, shouldReplace);
9480
- this._lastLocation = runtime.locationService.getLocation();
9491
+ this._locationService.partial(mappedUpdated, shouldReplace);
9492
+ this._lastLocation = this._locationService.getLocation();
9481
9493
  }
9482
9494
  }
9483
9495
  getUrlState(root) {
@@ -9485,12 +9497,13 @@ class UrlSyncManager {
9485
9497
  }
9486
9498
  }
9487
9499
  class UrlParamsCache {
9488
- constructor() {
9500
+ constructor(locationService) {
9501
+ this.locationService = locationService;
9489
9502
  __privateAdd(this, _cache, void 0);
9490
9503
  __privateAdd(this, _location, void 0);
9491
9504
  }
9492
9505
  getParams() {
9493
- const location = runtime.locationService.getLocation();
9506
+ const location = this.locationService.getLocation();
9494
9507
  if (__privateGet(this, _location) === location) {
9495
9508
  return __privateGet(this, _cache);
9496
9509
  }
@@ -9509,33 +9522,37 @@ function isUrlStateDifferent(sceneUrlState, currentParams) {
9509
9522
  }
9510
9523
  return false;
9511
9524
  }
9512
- function useUrlSyncManager(options) {
9525
+ function useUrlSyncManager(options, locationService) {
9513
9526
  return React.useMemo(
9514
- () => new UrlSyncManager({
9515
- updateUrlOnInit: options.updateUrlOnInit,
9516
- createBrowserHistorySteps: options.createBrowserHistorySteps
9517
- }),
9518
- [options.updateUrlOnInit, options.createBrowserHistorySteps]
9527
+ () => new UrlSyncManager(
9528
+ {
9529
+ updateUrlOnInit: options.updateUrlOnInit,
9530
+ createBrowserHistorySteps: options.createBrowserHistorySteps
9531
+ },
9532
+ locationService
9533
+ ),
9534
+ [options.updateUrlOnInit, options.createBrowserHistorySteps, locationService]
9519
9535
  );
9520
9536
  }
9521
9537
 
9522
9538
  function useUrlSync(sceneRoot, options = {}) {
9523
9539
  const location = reactRouterDom.useLocation();
9540
+ const locationService = useLocationServiceSafe();
9524
9541
  const [isInitialized, setIsInitialized] = React.useState(false);
9525
- const urlSyncManager = useUrlSyncManager(options);
9542
+ const urlSyncManager = useUrlSyncManager(options, locationService);
9526
9543
  React.useEffect(() => {
9527
9544
  urlSyncManager.initSync(sceneRoot);
9528
9545
  setIsInitialized(true);
9529
9546
  return () => urlSyncManager.cleanUp(sceneRoot);
9530
9547
  }, [sceneRoot, urlSyncManager]);
9531
9548
  React.useEffect(() => {
9532
- const latestLocation = runtime.locationService.getLocation();
9549
+ const latestLocation = locationService.getLocation();
9533
9550
  const locationToHandle = latestLocation !== location ? latestLocation : location;
9534
9551
  if (latestLocation !== location) {
9535
9552
  writeSceneLog("useUrlSync", "latestLocation different from location");
9536
9553
  }
9537
9554
  urlSyncManager.handleNewLocation(locationToHandle);
9538
- }, [sceneRoot, urlSyncManager, location]);
9555
+ }, [sceneRoot, urlSyncManager, location, locationService]);
9539
9556
  return isInitialized;
9540
9557
  }
9541
9558
 
@@ -10620,8 +10637,7 @@ function SceneTimePickerRenderer({ model }) {
10620
10637
  onMoveForward: model.onMoveForward,
10621
10638
  onZoom: model.onZoom,
10622
10639
  onChangeTimeZone: timeRange.onTimeZoneChange,
10623
- onChangeFiscalYearStartMonth: model.onChangeFiscalYearStartMonth,
10624
- weekStart: timeRangeState.weekStart
10640
+ onChangeFiscalYearStartMonth: model.onChangeFiscalYearStartMonth
10625
10641
  });
10626
10642
  }
10627
10643
  function getZoomedTimeRange(timeRange, factor) {
@@ -12104,6 +12120,7 @@ function SceneAppPageView({ page, routeProps }) {
12104
12120
  const appContext = React.useContext(SceneAppContext);
12105
12121
  const isInitialized = containerState.initializedScene === scene;
12106
12122
  const { layout } = page.state;
12123
+ const locationService = useLocationServiceSafe();
12107
12124
  React.useLayoutEffect(() => {
12108
12125
  if (!isInitialized) {
12109
12126
  containerPage.initializeScene(scene);
@@ -12120,10 +12137,13 @@ function SceneAppPageView({ page, routeProps }) {
12120
12137
  text: containerState.title,
12121
12138
  img: containerState.titleImg,
12122
12139
  icon: containerState.titleIcon,
12123
- url: getUrlWithAppState(containerState.url, containerState.preserveUrlKeys),
12140
+ url: getUrlWithAppState(containerState.url, locationService.getSearchObject(), containerState.preserveUrlKeys),
12124
12141
  hideFromBreadcrumbs: containerState.hideFromBreadcrumbs,
12125
12142
  parentItem: getParentBreadcrumbs(
12126
- containerState.getParentPage ? containerState.getParentPage() : containerPage.parent)
12143
+ containerState.getParentPage ? containerState.getParentPage() : containerPage.parent,
12144
+ params,
12145
+ locationService.getSearchObject()
12146
+ )
12127
12147
  };
12128
12148
  if (containerState.tabs) {
12129
12149
  pageNav.children = containerState.tabs.map((tab) => {
@@ -12132,7 +12152,7 @@ function SceneAppPageView({ page, routeProps }) {
12132
12152
  icon: tab.state.titleIcon,
12133
12153
  tabSuffix: tab.state.tabSuffix,
12134
12154
  active: page === tab,
12135
- url: getUrlWithAppState(tab.state.url, tab.state.preserveUrlKeys),
12155
+ url: getUrlWithAppState(tab.state.url, locationService.getSearchObject(), tab.state.preserveUrlKeys),
12136
12156
  parentItem: pageNav
12137
12157
  };
12138
12158
  });
@@ -12166,14 +12186,17 @@ function getParentPageIfTab(page) {
12166
12186
  }
12167
12187
  return page;
12168
12188
  }
12169
- function getParentBreadcrumbs(parent, params) {
12189
+ function getParentBreadcrumbs(parent, params, searchObject) {
12170
12190
  if (parent instanceof SceneAppPage) {
12171
12191
  return {
12172
12192
  text: parent.state.title,
12173
- url: getUrlWithAppState(parent.state.url, parent.state.preserveUrlKeys),
12193
+ url: getUrlWithAppState(parent.state.url, searchObject, parent.state.preserveUrlKeys),
12174
12194
  hideFromBreadcrumbs: parent.state.hideFromBreadcrumbs,
12175
12195
  parentItem: getParentBreadcrumbs(
12176
- parent.state.getParentPage ? parent.state.getParentPage() : parent.parent)
12196
+ parent.state.getParentPage ? parent.state.getParentPage() : parent.parent,
12197
+ params,
12198
+ searchObject
12199
+ )
12177
12200
  };
12178
12201
  }
12179
12202
  return void 0;