@grafana/scenes 6.35.0 → 6.35.1--canary.1148.17638385485.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/dist/index.js CHANGED
@@ -6491,6 +6491,8 @@ class SceneQueryRunner extends SceneObjectBase {
6491
6491
  this.setState({ data: dataWithLayersApplied, _hasFetchedData: hasFetchedData });
6492
6492
  this._results.next({ origin: this, data: dataWithLayersApplied });
6493
6493
  };
6494
+ this._isInView = true;
6495
+ this._queryNotExecutedWhenOutOfView = false;
6494
6496
  this.addActivationHandler(() => this._onActivate());
6495
6497
  }
6496
6498
  getResultsStream() {
@@ -6712,6 +6714,11 @@ class SceneQueryRunner extends SceneObjectBase {
6712
6714
  if (!this.state.maxDataPoints && this.state.maxDataPointsFromWidth && !this._containerWidth) {
6713
6715
  return;
6714
6716
  }
6717
+ if (this.isQueryModeAuto() && !this._isInView) {
6718
+ this._queryNotExecutedWhenOutOfView = true;
6719
+ return;
6720
+ }
6721
+ this._queryNotExecutedWhenOutOfView = false;
6715
6722
  if (!this._dataLayersSub) {
6716
6723
  this._handleDataLayers();
6717
6724
  }
@@ -6875,6 +6882,13 @@ class SceneQueryRunner extends SceneObjectBase {
6875
6882
  var _a;
6876
6883
  return ((_a = this.state.runQueriesMode) != null ? _a : "auto") === "auto";
6877
6884
  }
6885
+ isInViewChanged(isInView) {
6886
+ writeSceneLog("SceneQueryRunner", `isInViewChanged: ${isInView}`, this.state.key);
6887
+ this._isInView = isInView;
6888
+ if (isInView && this._queryNotExecutedWhenOutOfView) {
6889
+ this.runQueries();
6890
+ }
6891
+ }
6878
6892
  }
6879
6893
  function findFirstDatasource(targets) {
6880
6894
  var _a, _b;
@@ -8315,6 +8329,71 @@ const getStyles$8 = (theme) => ({
8315
8329
  })
8316
8330
  });
8317
8331
 
8332
+ function useUniqueId() {
8333
+ var _a;
8334
+ const idRefLazy = React.useRef(void 0);
8335
+ (_a = idRefLazy.current) != null ? _a : idRefLazy.current = lodash.uniqueId();
8336
+ return idRefLazy.current;
8337
+ }
8338
+ const LazyLoader = React__default.default.forwardRef(
8339
+ ({ children, onLoad, onChange, className, ...rest }, ref) => {
8340
+ const id = useUniqueId();
8341
+ const { hideEmpty } = ui.useStyles2(getStyles$7);
8342
+ const [loaded, setLoaded] = React.useState(false);
8343
+ const [isInView, setIsInView] = React.useState(false);
8344
+ const innerRef = React.useRef(null);
8345
+ React.useImperativeHandle(ref, () => innerRef.current);
8346
+ reactUse.useEffectOnce(() => {
8347
+ LazyLoader.addCallback(id, (entry) => {
8348
+ if (!loaded && entry.isIntersecting) {
8349
+ setLoaded(true);
8350
+ onLoad == null ? void 0 : onLoad();
8351
+ }
8352
+ setIsInView(entry.isIntersecting);
8353
+ onChange == null ? void 0 : onChange(entry.isIntersecting);
8354
+ });
8355
+ const wrapperEl = innerRef.current;
8356
+ if (wrapperEl) {
8357
+ LazyLoader.observer.observe(wrapperEl);
8358
+ }
8359
+ return () => {
8360
+ wrapperEl && LazyLoader.observer.unobserve(wrapperEl);
8361
+ delete LazyLoader.callbacks[id];
8362
+ if (Object.keys(LazyLoader.callbacks).length === 0) {
8363
+ LazyLoader.observer.disconnect();
8364
+ }
8365
+ };
8366
+ });
8367
+ return /* @__PURE__ */ React__default.default.createElement("div", { id, ref: innerRef, className: `${hideEmpty} ${className}`, ...rest }, !loaded || !isInView ? i18n.t("grafana-scenes.components.lazy-loader.placeholder", "\xA0") : /* @__PURE__ */ React__default.default.createElement(LazyLoaderInViewContext.Provider, { value: isInView }, children));
8368
+ }
8369
+ );
8370
+ function getStyles$7() {
8371
+ return {
8372
+ hideEmpty: css.css({
8373
+ "&:empty": {
8374
+ display: "none"
8375
+ }
8376
+ })
8377
+ };
8378
+ }
8379
+ LazyLoader.displayName = "LazyLoader";
8380
+ LazyLoader.callbacks = {};
8381
+ LazyLoader.addCallback = (id, c) => LazyLoader.callbacks[id] = c;
8382
+ LazyLoader.observer = new IntersectionObserver(
8383
+ (entries) => {
8384
+ for (const entry of entries) {
8385
+ if (typeof LazyLoader.callbacks[entry.target.id] === "function") {
8386
+ LazyLoader.callbacks[entry.target.id](entry);
8387
+ }
8388
+ }
8389
+ },
8390
+ { rootMargin: "100px" }
8391
+ );
8392
+ const LazyLoaderInViewContext = React__default.default.createContext(true);
8393
+ function useLazyLoaderIsInView() {
8394
+ return React__default.default.useContext(LazyLoaderInViewContext);
8395
+ }
8396
+
8318
8397
  function VizPanelRenderer({ model }) {
8319
8398
  var _a;
8320
8399
  const {
@@ -8357,6 +8436,12 @@ function VizPanelRenderer({ model }) {
8357
8436
  const sceneTimeRange = sceneGraph.getTimeRange(model);
8358
8437
  const timeZone = sceneTimeRange.getTimeZone();
8359
8438
  const timeRange = model.getTimeRange(dataWithFieldConfig);
8439
+ const isInView = useLazyLoaderIsInView();
8440
+ React.useEffect(() => {
8441
+ if (dataObject.isInViewChanged) {
8442
+ dataObject.isInViewChanged(isInView);
8443
+ }
8444
+ }, [isInView, dataObject]);
8360
8445
  const titleInterpolated = model.interpolate(title, void 0, "text");
8361
8446
  const alertStateStyles = ui.useStyles2(getAlertStateStyles);
8362
8447
  if (!plugin) {
@@ -11218,10 +11303,10 @@ class EmbeddedScene extends SceneObjectBase {
11218
11303
  EmbeddedScene.Component = EmbeddedSceneRenderer;
11219
11304
  function EmbeddedSceneRenderer({ model }) {
11220
11305
  const { body, controls } = model.useState();
11221
- const styles = ui.useStyles2(getStyles$7);
11306
+ const styles = ui.useStyles2(getStyles$6);
11222
11307
  return /* @__PURE__ */ React__default.default.createElement("div", { className: styles.container }, controls && /* @__PURE__ */ React__default.default.createElement("div", { className: styles.controls }, controls.map((control) => /* @__PURE__ */ React__default.default.createElement(control.Component, { key: control.state.key, model: control }))), /* @__PURE__ */ React__default.default.createElement("div", { className: styles.body }, /* @__PURE__ */ React__default.default.createElement(body.Component, { model: body })));
11223
11308
  }
11224
- const getStyles$7 = (theme) => {
11309
+ const getStyles$6 = (theme) => {
11225
11310
  return {
11226
11311
  container: css.css({
11227
11312
  flexGrow: 1,
@@ -11407,67 +11492,6 @@ function isSceneGridLayout(child) {
11407
11492
  return child instanceof SceneGridLayout;
11408
11493
  }
11409
11494
 
11410
- function useUniqueId() {
11411
- var _a;
11412
- const idRefLazy = React.useRef(void 0);
11413
- (_a = idRefLazy.current) != null ? _a : idRefLazy.current = lodash.uniqueId();
11414
- return idRefLazy.current;
11415
- }
11416
- const LazyLoader = React__default.default.forwardRef(
11417
- ({ children, onLoad, onChange, className, ...rest }, ref) => {
11418
- const id = useUniqueId();
11419
- const { hideEmpty } = ui.useStyles2(getStyles$6);
11420
- const [loaded, setLoaded] = React.useState(false);
11421
- const [isInView, setIsInView] = React.useState(false);
11422
- const innerRef = React.useRef(null);
11423
- React.useImperativeHandle(ref, () => innerRef.current);
11424
- reactUse.useEffectOnce(() => {
11425
- LazyLoader.addCallback(id, (entry) => {
11426
- if (!loaded && entry.isIntersecting) {
11427
- setLoaded(true);
11428
- onLoad == null ? void 0 : onLoad();
11429
- }
11430
- setIsInView(entry.isIntersecting);
11431
- onChange == null ? void 0 : onChange(entry.isIntersecting);
11432
- });
11433
- const wrapperEl = innerRef.current;
11434
- if (wrapperEl) {
11435
- LazyLoader.observer.observe(wrapperEl);
11436
- }
11437
- return () => {
11438
- wrapperEl && LazyLoader.observer.unobserve(wrapperEl);
11439
- delete LazyLoader.callbacks[id];
11440
- if (Object.keys(LazyLoader.callbacks).length === 0) {
11441
- LazyLoader.observer.disconnect();
11442
- }
11443
- };
11444
- });
11445
- return /* @__PURE__ */ React__default.default.createElement("div", { id, ref: innerRef, className: `${hideEmpty} ${className}`, ...rest }, !loaded || !isInView ? i18n.t("grafana-scenes.components.lazy-loader.placeholder", "\xA0") : children);
11446
- }
11447
- );
11448
- function getStyles$6() {
11449
- return {
11450
- hideEmpty: css.css({
11451
- "&:empty": {
11452
- display: "none"
11453
- }
11454
- })
11455
- };
11456
- }
11457
- LazyLoader.displayName = "LazyLoader";
11458
- LazyLoader.callbacks = {};
11459
- LazyLoader.addCallback = (id, c) => LazyLoader.callbacks[id] = c;
11460
- LazyLoader.observer = new IntersectionObserver(
11461
- (entries) => {
11462
- for (const entry of entries) {
11463
- if (typeof LazyLoader.callbacks[entry.target.id] === "function") {
11464
- LazyLoader.callbacks[entry.target.id](entry);
11465
- }
11466
- }
11467
- },
11468
- { rootMargin: "100px" }
11469
- );
11470
-
11471
11495
  function SceneGridLayoutRenderer({ model }) {
11472
11496
  const { children, isLazy, isDraggable, isResizable } = model.useState();
11473
11497
  const [outerDivRef, { width, height }] = reactUse.useMeasure();