@grafana/scenes 4.24.1 → 4.24.2--canary.755.9271425573.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -591,7 +591,7 @@ class UniqueUrlKeyMapper {
591
591
  getUniqueKey(key, obj) {
592
592
  const objectsWithKey = this.index.get(key);
593
593
  if (!objectsWithKey) {
594
- throw new Error("Cannot find any scene object that uses the key '" + key + "'");
594
+ return key;
595
595
  }
596
596
  const address = objectsWithKey.findIndex((o) => o.sceneObject === obj);
597
597
  if (address > 0) {
@@ -2042,7 +2042,11 @@ async function getDataSource(datasource, scopedVars) {
2042
2042
  }
2043
2043
 
2044
2044
  function writeSceneLog(logger, message, ...rest) {
2045
- if (window.grafanaSceneLogging) {
2045
+ let loggingEnabled = false;
2046
+ if (typeof window !== "undefined") {
2047
+ loggingEnabled = localStorage.getItem("grafana.debug.scenes") === "true";
2048
+ }
2049
+ if (loggingEnabled) {
2046
2050
  console.log(`${logger}: `, message, ...rest);
2047
2051
  }
2048
2052
  }
@@ -5229,6 +5233,9 @@ class VizPanel extends SceneObjectBase {
5229
5233
  (_a = this._panelContext) != null ? _a : this._panelContext = this.buildPanelContext();
5230
5234
  return this._panelContext;
5231
5235
  }
5236
+ clearFieldConfigCache() {
5237
+ this._dataWithFieldConfig = void 0;
5238
+ }
5232
5239
  applyFieldConfig(rawData) {
5233
5240
  var _a, _b, _c, _d;
5234
5241
  const plugin = this._plugin;
@@ -7732,6 +7739,7 @@ class UrlSyncManager {
7732
7739
  this._locationSub = null;
7733
7740
  this._ignoreNextLocationUpdate = false;
7734
7741
  this._onLocationUpdate = (location) => {
7742
+ this._urlParams = new URLSearchParams(location.search);
7735
7743
  if (this._ignoreNextLocationUpdate) {
7736
7744
  this._ignoreNextLocationUpdate = false;
7737
7745
  return;
@@ -7739,9 +7747,8 @@ class UrlSyncManager {
7739
7747
  if (this._lastPath !== location.pathname) {
7740
7748
  return;
7741
7749
  }
7742
- const urlParams = new URLSearchParams(location.search);
7743
7750
  this._urlKeyMapper.rebuildIndex(this._sceneRoot);
7744
- syncStateFromUrl(this._sceneRoot, urlParams, this._urlKeyMapper);
7751
+ syncStateFromUrl(this._sceneRoot, this._urlParams, this._urlKeyMapper);
7745
7752
  this._lastPath = location.pathname;
7746
7753
  };
7747
7754
  this._onStateChanged = ({ payload }) => {
@@ -7774,8 +7781,10 @@ class UrlSyncManager {
7774
7781
  writeSceneLog("UrlSyncManager", "Unregister previous scene state subscription", this._sceneRoot.state.key);
7775
7782
  this._stateSub.unsubscribe();
7776
7783
  }
7784
+ const location = runtime.locationService.getLocation();
7777
7785
  this._sceneRoot = root;
7778
- this._lastPath = runtime.locationService.getLocation().pathname;
7786
+ this._lastPath = location.pathname;
7787
+ this._urlParams = new URLSearchParams(location.search);
7779
7788
  this._stateSub = root.subscribeToEvent(SceneObjectStateChangedEvent, this._onStateChanged);
7780
7789
  this.syncFrom(this._sceneRoot);
7781
7790
  }
@@ -7805,6 +7814,12 @@ class UrlSyncManager {
7805
7814
  this._urlKeyMapper.rebuildIndex(this._sceneRoot);
7806
7815
  syncStateFromUrl(sceneObj, urlParams, this._urlKeyMapper);
7807
7816
  }
7817
+ syncNewObj(obj) {
7818
+ if (!this._urlParams) {
7819
+ throw new Error("UrlSyncManager not initialized");
7820
+ }
7821
+ syncStateFromUrl(obj, this._urlParams, this._urlKeyMapper);
7822
+ }
7808
7823
  getUrlState(root) {
7809
7824
  return getUrlState(root);
7810
7825
  }
@@ -7848,7 +7863,7 @@ EmbeddedScene.Component = EmbeddedSceneRenderer;
7848
7863
  function EmbeddedSceneRenderer({ model }) {
7849
7864
  const { body, controls } = model.useState();
7850
7865
  const styles = ui.useStyles2(getStyles$5);
7851
- return /* @__PURE__ */ React__default["default"].createElement("div", {
7866
+ const inner = /* @__PURE__ */ React__default["default"].createElement("div", {
7852
7867
  className: styles.container
7853
7868
  }, controls && /* @__PURE__ */ React__default["default"].createElement("div", {
7854
7869
  className: styles.controls
@@ -7860,6 +7875,7 @@ function EmbeddedSceneRenderer({ model }) {
7860
7875
  }, /* @__PURE__ */ React__default["default"].createElement(body.Component, {
7861
7876
  model: body
7862
7877
  })));
7878
+ return inner;
7863
7879
  }
7864
7880
  const getStyles$5 = (theme) => {
7865
7881
  return {
@@ -8318,9 +8334,7 @@ const _SceneGridLayout = class extends SceneObjectBase {
8318
8334
  let newParent = this.findGridItemSceneParent(gridLayout, indexOfUpdatedItem - 1);
8319
8335
  let newChildren = this.state.children;
8320
8336
  if (sceneChild instanceof SceneGridRow && newParent instanceof SceneGridRow) {
8321
- if (!this.isRowDropValid(gridLayout, updatedItem, indexOfUpdatedItem)) {
8322
- this._loadOldLayout = true;
8323
- }
8337
+ this._loadOldLayout = true;
8324
8338
  newParent = this;
8325
8339
  }
8326
8340
  if (newParent !== sceneChild.parent) {
@@ -8416,18 +8430,6 @@ const _SceneGridLayout = class extends SceneObjectBase {
8416
8430
  }
8417
8431
  return this;
8418
8432
  }
8419
- isRowDropValid(gridLayout, updatedItem, indexOfUpdatedItem) {
8420
- if (gridLayout[gridLayout.length - 1].i === updatedItem.i) {
8421
- return true;
8422
- }
8423
- const nextSceneChild = this.getSceneLayoutChild(gridLayout[indexOfUpdatedItem + 1].i);
8424
- if (nextSceneChild instanceof SceneGridRow) {
8425
- return true;
8426
- } else if (nextSceneChild.parent instanceof _SceneGridLayout) {
8427
- return true;
8428
- }
8429
- return false;
8430
- }
8431
8433
  moveChildTo(child, target) {
8432
8434
  const currentParent = child.parent;
8433
8435
  let rootChildren = this.state.children;
@@ -10918,6 +10920,174 @@ const PanelBuilders = {
10918
10920
  }
10919
10921
  };
10920
10922
 
10923
+ class VizConfigBuilder {
10924
+ constructor(pluginId, pluginVersion, defaultOptions, defaultFieldConfig) {
10925
+ this._pluginId = pluginId;
10926
+ this._pluginVersion = pluginVersion;
10927
+ this._fieldConfigBuilder = new FieldConfigBuilder(defaultFieldConfig);
10928
+ this._panelOptionsBuilder = new PanelOptionsBuilder(defaultOptions);
10929
+ }
10930
+ setColor(color) {
10931
+ this._fieldConfigBuilder.setColor(color);
10932
+ return this;
10933
+ }
10934
+ setDecimals(decimals) {
10935
+ this._fieldConfigBuilder.setDecimals(decimals);
10936
+ return this;
10937
+ }
10938
+ setDisplayName(displayName) {
10939
+ this._fieldConfigBuilder.setDisplayName(displayName);
10940
+ return this;
10941
+ }
10942
+ setFilterable(filterable) {
10943
+ this._fieldConfigBuilder.setFilterable(filterable);
10944
+ return this;
10945
+ }
10946
+ setLinks(links) {
10947
+ this._fieldConfigBuilder.setLinks(links);
10948
+ return this;
10949
+ }
10950
+ setMappings(mappings) {
10951
+ this._fieldConfigBuilder.setMappings(mappings);
10952
+ return this;
10953
+ }
10954
+ setMax(max) {
10955
+ this._fieldConfigBuilder.setMax(max);
10956
+ return this;
10957
+ }
10958
+ setMin(min) {
10959
+ this._fieldConfigBuilder.setMin(min);
10960
+ return this;
10961
+ }
10962
+ setNoValue(noValue) {
10963
+ this._fieldConfigBuilder.setNoValue(noValue);
10964
+ return this;
10965
+ }
10966
+ setThresholds(thresholds) {
10967
+ this._fieldConfigBuilder.setThresholds(thresholds);
10968
+ return this;
10969
+ }
10970
+ setUnit(unit) {
10971
+ this._fieldConfigBuilder.setUnit(unit);
10972
+ return this;
10973
+ }
10974
+ setCustomFieldConfig(id, value) {
10975
+ this._fieldConfigBuilder.setCustomFieldConfig(id, value);
10976
+ return this;
10977
+ }
10978
+ setOverrides(builder) {
10979
+ this._fieldConfigBuilder.setOverrides(builder);
10980
+ return this;
10981
+ }
10982
+ setOption(id, value) {
10983
+ this._panelOptionsBuilder.setOption(id, value);
10984
+ return this;
10985
+ }
10986
+ build() {
10987
+ return {
10988
+ pluginId: this._pluginId,
10989
+ pluginVersion: this._pluginVersion,
10990
+ options: this._panelOptionsBuilder.build(),
10991
+ fieldConfig: this._fieldConfigBuilder.build()
10992
+ };
10993
+ }
10994
+ }
10995
+
10996
+ const VizConfigBuilders = {
10997
+ barchart() {
10998
+ return new VizConfigBuilder(
10999
+ "barchart",
11000
+ "10.0.0",
11001
+ () => BarChartPanelCfg_types_gen.defaultOptions,
11002
+ () => BarChartPanelCfg_types_gen.defaultFieldConfig
11003
+ );
11004
+ },
11005
+ bargauge() {
11006
+ return new VizConfigBuilder("bargauge", "10.0.0", () => BarGaugePanelCfg_types_gen.defaultOptions);
11007
+ },
11008
+ datagrid() {
11009
+ return new VizConfigBuilder("datagrid", "10.0.0", () => DatagridPanelCfg_types_gen.defaultOptions);
11010
+ },
11011
+ flamegraph() {
11012
+ return new VizConfigBuilder("flamegraph", "10.0.0");
11013
+ },
11014
+ gauge() {
11015
+ return new VizConfigBuilder("gauge", "10.0.0", () => GaugePanelCfg_types_gen.defaultOptions);
11016
+ },
11017
+ geomap() {
11018
+ return new VizConfigBuilder("geomap", "10.0.0", () => GeomapPanelCfg_types_gen.defaultOptions);
11019
+ },
11020
+ heatmap() {
11021
+ return new VizConfigBuilder("heatmap", "10.0.0", () => HeatmapPanelCfg_types_gen.defaultOptions);
11022
+ },
11023
+ histogram() {
11024
+ return new VizConfigBuilder(
11025
+ "histogram",
11026
+ "10.0.0",
11027
+ () => HistogramPanelCfg_types_gen.defaultOptions,
11028
+ () => HistogramPanelCfg_types_gen.defaultFieldConfig
11029
+ );
11030
+ },
11031
+ logs() {
11032
+ return new VizConfigBuilder("logs", "10.0.0");
11033
+ },
11034
+ news() {
11035
+ return new VizConfigBuilder("news", "10.0.0", () => NewsPanelCfg_types_gen.defaultOptions);
11036
+ },
11037
+ nodegraph() {
11038
+ return new VizConfigBuilder("nodeGraph", "10.0.0");
11039
+ },
11040
+ piechart() {
11041
+ return new VizConfigBuilder(
11042
+ "piechart",
11043
+ "10.0.0",
11044
+ () => PieChartPanelCfg_types_gen.defaultOptions
11045
+ );
11046
+ },
11047
+ stat() {
11048
+ return new VizConfigBuilder("stat", "10.0.0", () => StatPanelCfg_types_gen.defaultOptions);
11049
+ },
11050
+ statetimeline() {
11051
+ return new VizConfigBuilder(
11052
+ "state-timeline",
11053
+ "10.0.0",
11054
+ () => StateTimelinePanelCfg_types_gen.defaultOptions,
11055
+ () => StateTimelinePanelCfg_types_gen.defaultFieldConfig
11056
+ );
11057
+ },
11058
+ statushistory() {
11059
+ return new VizConfigBuilder(
11060
+ "status-history",
11061
+ "10.0.0",
11062
+ () => StatusHistoryPanelCfg_types_gen.defaultOptions,
11063
+ () => StatusHistoryPanelCfg_types_gen.defaultFieldConfig
11064
+ );
11065
+ },
11066
+ table() {
11067
+ return new VizConfigBuilder("table", "10.0.0", () => TablePanelCfg_types_gen.defaultOptions);
11068
+ },
11069
+ text() {
11070
+ return new VizConfigBuilder("text", "10.0.0", () => TextPanelCfg_types_gen.defaultOptions);
11071
+ },
11072
+ timeseries() {
11073
+ return new VizConfigBuilder("timeseries", "10.0.0");
11074
+ },
11075
+ trend() {
11076
+ return new VizConfigBuilder("trend", "10.0.0");
11077
+ },
11078
+ traces() {
11079
+ return new VizConfigBuilder("traces", "10.0.0");
11080
+ },
11081
+ xychart() {
11082
+ return new VizConfigBuilder(
11083
+ "xychart",
11084
+ "10.0.0",
11085
+ () => XYChartPanelCfg_types_gen.defaultOptions,
11086
+ () => XYChartPanelCfg_types_gen.defaultFieldConfig
11087
+ );
11088
+ }
11089
+ };
11090
+
10921
11091
  const sceneUtils = {
10922
11092
  getUrlWithAppState,
10923
11093
  registerRuntimePanelPlugin,
@@ -10942,6 +11112,7 @@ exports.ConstantVariable = ConstantVariable;
10942
11112
  exports.CustomVariable = CustomVariable;
10943
11113
  exports.DataSourceVariable = DataSourceVariable;
10944
11114
  exports.EmbeddedScene = EmbeddedScene;
11115
+ exports.FieldConfigBuilder = FieldConfigBuilder;
10945
11116
  exports.FieldConfigBuilders = FieldConfigBuilders;
10946
11117
  exports.FieldConfigOverridesBuilder = FieldConfigOverridesBuilder;
10947
11118
  exports.GroupByVariable = GroupByVariable;
@@ -10996,7 +11167,10 @@ exports.UrlSyncManager = UrlSyncManager;
10996
11167
  exports.UserActionEvent = UserActionEvent;
10997
11168
  exports.VariableDependencyConfig = VariableDependencyConfig;
10998
11169
  exports.VariableValueControl = VariableValueControl;
11170
+ exports.VariableValueSelectWrapper = VariableValueSelectWrapper;
10999
11171
  exports.VariableValueSelectors = VariableValueSelectors;
11172
+ exports.VizConfigBuilder = VizConfigBuilder;
11173
+ exports.VizConfigBuilders = VizConfigBuilders;
11000
11174
  exports.VizPanel = VizPanel;
11001
11175
  exports.VizPanelBuilder = VizPanelBuilder;
11002
11176
  exports.VizPanelMenu = VizPanelMenu;