@grafana/scenes 4.24.4--canary.716.9299472214.0 → 4.24.4--canary.734.9299631410.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -2046,7 +2046,11 @@ async function getDataSource(datasource, scopedVars) {
2046
2046
  }
2047
2047
 
2048
2048
  function writeSceneLog(logger, message, ...rest) {
2049
- if (window.grafanaSceneLogging) {
2049
+ let loggingEnabled = false;
2050
+ if (typeof window !== "undefined") {
2051
+ loggingEnabled = localStorage.getItem("grafana.debug.scenes") === "true";
2052
+ }
2053
+ if (loggingEnabled) {
2050
2054
  console.log(`${logger}: `, message, ...rest);
2051
2055
  }
2052
2056
  }
@@ -4601,12 +4605,6 @@ function VizPanelRenderer({ model }) {
4601
4605
  description
4602
4606
  } = model.useState();
4603
4607
  const [ref, { width, height }] = reactUse.useMeasure();
4604
- const appEvents = React.useMemo(() => runtime.getAppEvents(), []);
4605
- const setPanelAttention = React.useCallback(
4606
- () => appEvents.publish(new data.SetPanelAttentionEvent({ panelId: model.state.key })),
4607
- [model.state.key, appEvents]
4608
- );
4609
- const debouncedMouseMove = React.useMemo(() => lodash.debounce(setPanelAttention, 100), [setPanelAttention]);
4610
4608
  const plugin = model.getPlugin();
4611
4609
  const { dragClass, dragClassCancel } = getDragClasses(model);
4612
4610
  const dataObject = sceneGraph.getData(model);
@@ -4720,9 +4718,7 @@ function VizPanelRenderer({ model }) {
4720
4718
  dragClassCancel,
4721
4719
  padding: plugin.noPadding ? "none" : "md",
4722
4720
  menu: panelMenu,
4723
- onCancelQuery: model.onCancelQuery,
4724
- onFocus: () => setPanelAttention(),
4725
- onMouseMove: () => debouncedMouseMove()
4721
+ onCancelQuery: model.onCancelQuery
4726
4722
  }, (innerWidth, innerHeight) => /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, /* @__PURE__ */ React__default["default"].createElement(ui.ErrorBoundaryAlert, {
4727
4723
  dependencies: [plugin, data$1]
4728
4724
  }, /* @__PURE__ */ React__default["default"].createElement(data.PluginContextProvider, {
@@ -4745,7 +4741,7 @@ function VizPanelRenderer({ model }) {
4745
4741
  onOptionsChange: model.onOptionsChange,
4746
4742
  onFieldConfigChange: model.onFieldConfigChange,
4747
4743
  onChangeTimeRange: model.onTimeRangeChange,
4748
- eventBus: appEvents
4744
+ eventBus: runtime.getAppEvents()
4749
4745
  }))))))));
4750
4746
  }
4751
4747
  function getDragClasses(panel) {
@@ -5272,6 +5268,9 @@ class VizPanel extends SceneObjectBase {
5272
5268
  (_a = this._panelContext) != null ? _a : this._panelContext = this.buildPanelContext();
5273
5269
  return this._panelContext;
5274
5270
  }
5271
+ clearFieldConfigCache() {
5272
+ this._dataWithFieldConfig = void 0;
5273
+ }
5275
5274
  applyFieldConfig(rawData) {
5276
5275
  var _a, _b, _c, _d;
5277
5276
  const plugin = this._plugin;
@@ -7775,6 +7774,7 @@ class UrlSyncManager {
7775
7774
  this._locationSub = null;
7776
7775
  this._ignoreNextLocationUpdate = false;
7777
7776
  this._onLocationUpdate = (location) => {
7777
+ this._urlParams = new URLSearchParams(location.search);
7778
7778
  if (this._ignoreNextLocationUpdate) {
7779
7779
  this._ignoreNextLocationUpdate = false;
7780
7780
  return;
@@ -7782,9 +7782,8 @@ class UrlSyncManager {
7782
7782
  if (this._lastPath !== location.pathname) {
7783
7783
  return;
7784
7784
  }
7785
- const urlParams = new URLSearchParams(location.search);
7786
7785
  this._urlKeyMapper.rebuildIndex(this._sceneRoot);
7787
- syncStateFromUrl(this._sceneRoot, urlParams, this._urlKeyMapper);
7786
+ syncStateFromUrl(this._sceneRoot, this._urlParams, this._urlKeyMapper);
7788
7787
  this._lastPath = location.pathname;
7789
7788
  };
7790
7789
  this._onStateChanged = ({ payload }) => {
@@ -7817,8 +7816,10 @@ class UrlSyncManager {
7817
7816
  writeSceneLog("UrlSyncManager", "Unregister previous scene state subscription", this._sceneRoot.state.key);
7818
7817
  this._stateSub.unsubscribe();
7819
7818
  }
7819
+ const location = runtime.locationService.getLocation();
7820
7820
  this._sceneRoot = root;
7821
- this._lastPath = runtime.locationService.getLocation().pathname;
7821
+ this._lastPath = location.pathname;
7822
+ this._urlParams = new URLSearchParams(location.search);
7822
7823
  this._stateSub = root.subscribeToEvent(SceneObjectStateChangedEvent, this._onStateChanged);
7823
7824
  this.syncFrom(this._sceneRoot);
7824
7825
  }
@@ -7891,7 +7892,7 @@ EmbeddedScene.Component = EmbeddedSceneRenderer;
7891
7892
  function EmbeddedSceneRenderer({ model }) {
7892
7893
  const { body, controls } = model.useState();
7893
7894
  const styles = ui.useStyles2(getStyles$5);
7894
- return /* @__PURE__ */ React__default["default"].createElement("div", {
7895
+ const inner = /* @__PURE__ */ React__default["default"].createElement("div", {
7895
7896
  className: styles.container
7896
7897
  }, controls && /* @__PURE__ */ React__default["default"].createElement("div", {
7897
7898
  className: styles.controls
@@ -7903,6 +7904,7 @@ function EmbeddedSceneRenderer({ model }) {
7903
7904
  }, /* @__PURE__ */ React__default["default"].createElement(body.Component, {
7904
7905
  model: body
7905
7906
  })));
7907
+ return inner;
7906
7908
  }
7907
7909
  const getStyles$5 = (theme) => {
7908
7910
  return {
@@ -10961,6 +10963,174 @@ const PanelBuilders = {
10961
10963
  }
10962
10964
  };
10963
10965
 
10966
+ class VizConfigBuilder {
10967
+ constructor(pluginId, pluginVersion, defaultOptions, defaultFieldConfig) {
10968
+ this._pluginId = pluginId;
10969
+ this._pluginVersion = pluginVersion;
10970
+ this._fieldConfigBuilder = new FieldConfigBuilder(defaultFieldConfig);
10971
+ this._panelOptionsBuilder = new PanelOptionsBuilder(defaultOptions);
10972
+ }
10973
+ setColor(color) {
10974
+ this._fieldConfigBuilder.setColor(color);
10975
+ return this;
10976
+ }
10977
+ setDecimals(decimals) {
10978
+ this._fieldConfigBuilder.setDecimals(decimals);
10979
+ return this;
10980
+ }
10981
+ setDisplayName(displayName) {
10982
+ this._fieldConfigBuilder.setDisplayName(displayName);
10983
+ return this;
10984
+ }
10985
+ setFilterable(filterable) {
10986
+ this._fieldConfigBuilder.setFilterable(filterable);
10987
+ return this;
10988
+ }
10989
+ setLinks(links) {
10990
+ this._fieldConfigBuilder.setLinks(links);
10991
+ return this;
10992
+ }
10993
+ setMappings(mappings) {
10994
+ this._fieldConfigBuilder.setMappings(mappings);
10995
+ return this;
10996
+ }
10997
+ setMax(max) {
10998
+ this._fieldConfigBuilder.setMax(max);
10999
+ return this;
11000
+ }
11001
+ setMin(min) {
11002
+ this._fieldConfigBuilder.setMin(min);
11003
+ return this;
11004
+ }
11005
+ setNoValue(noValue) {
11006
+ this._fieldConfigBuilder.setNoValue(noValue);
11007
+ return this;
11008
+ }
11009
+ setThresholds(thresholds) {
11010
+ this._fieldConfigBuilder.setThresholds(thresholds);
11011
+ return this;
11012
+ }
11013
+ setUnit(unit) {
11014
+ this._fieldConfigBuilder.setUnit(unit);
11015
+ return this;
11016
+ }
11017
+ setCustomFieldConfig(id, value) {
11018
+ this._fieldConfigBuilder.setCustomFieldConfig(id, value);
11019
+ return this;
11020
+ }
11021
+ setOverrides(builder) {
11022
+ this._fieldConfigBuilder.setOverrides(builder);
11023
+ return this;
11024
+ }
11025
+ setOption(id, value) {
11026
+ this._panelOptionsBuilder.setOption(id, value);
11027
+ return this;
11028
+ }
11029
+ build() {
11030
+ return {
11031
+ pluginId: this._pluginId,
11032
+ pluginVersion: this._pluginVersion,
11033
+ options: this._panelOptionsBuilder.build(),
11034
+ fieldConfig: this._fieldConfigBuilder.build()
11035
+ };
11036
+ }
11037
+ }
11038
+
11039
+ const VizConfigBuilders = {
11040
+ barchart() {
11041
+ return new VizConfigBuilder(
11042
+ "barchart",
11043
+ "10.0.0",
11044
+ () => BarChartPanelCfg_types_gen.defaultOptions,
11045
+ () => BarChartPanelCfg_types_gen.defaultFieldConfig
11046
+ );
11047
+ },
11048
+ bargauge() {
11049
+ return new VizConfigBuilder("bargauge", "10.0.0", () => BarGaugePanelCfg_types_gen.defaultOptions);
11050
+ },
11051
+ datagrid() {
11052
+ return new VizConfigBuilder("datagrid", "10.0.0", () => DatagridPanelCfg_types_gen.defaultOptions);
11053
+ },
11054
+ flamegraph() {
11055
+ return new VizConfigBuilder("flamegraph", "10.0.0");
11056
+ },
11057
+ gauge() {
11058
+ return new VizConfigBuilder("gauge", "10.0.0", () => GaugePanelCfg_types_gen.defaultOptions);
11059
+ },
11060
+ geomap() {
11061
+ return new VizConfigBuilder("geomap", "10.0.0", () => GeomapPanelCfg_types_gen.defaultOptions);
11062
+ },
11063
+ heatmap() {
11064
+ return new VizConfigBuilder("heatmap", "10.0.0", () => HeatmapPanelCfg_types_gen.defaultOptions);
11065
+ },
11066
+ histogram() {
11067
+ return new VizConfigBuilder(
11068
+ "histogram",
11069
+ "10.0.0",
11070
+ () => HistogramPanelCfg_types_gen.defaultOptions,
11071
+ () => HistogramPanelCfg_types_gen.defaultFieldConfig
11072
+ );
11073
+ },
11074
+ logs() {
11075
+ return new VizConfigBuilder("logs", "10.0.0");
11076
+ },
11077
+ news() {
11078
+ return new VizConfigBuilder("news", "10.0.0", () => NewsPanelCfg_types_gen.defaultOptions);
11079
+ },
11080
+ nodegraph() {
11081
+ return new VizConfigBuilder("nodeGraph", "10.0.0");
11082
+ },
11083
+ piechart() {
11084
+ return new VizConfigBuilder(
11085
+ "piechart",
11086
+ "10.0.0",
11087
+ () => PieChartPanelCfg_types_gen.defaultOptions
11088
+ );
11089
+ },
11090
+ stat() {
11091
+ return new VizConfigBuilder("stat", "10.0.0", () => StatPanelCfg_types_gen.defaultOptions);
11092
+ },
11093
+ statetimeline() {
11094
+ return new VizConfigBuilder(
11095
+ "state-timeline",
11096
+ "10.0.0",
11097
+ () => StateTimelinePanelCfg_types_gen.defaultOptions,
11098
+ () => StateTimelinePanelCfg_types_gen.defaultFieldConfig
11099
+ );
11100
+ },
11101
+ statushistory() {
11102
+ return new VizConfigBuilder(
11103
+ "status-history",
11104
+ "10.0.0",
11105
+ () => StatusHistoryPanelCfg_types_gen.defaultOptions,
11106
+ () => StatusHistoryPanelCfg_types_gen.defaultFieldConfig
11107
+ );
11108
+ },
11109
+ table() {
11110
+ return new VizConfigBuilder("table", "10.0.0", () => TablePanelCfg_types_gen.defaultOptions);
11111
+ },
11112
+ text() {
11113
+ return new VizConfigBuilder("text", "10.0.0", () => TextPanelCfg_types_gen.defaultOptions);
11114
+ },
11115
+ timeseries() {
11116
+ return new VizConfigBuilder("timeseries", "10.0.0");
11117
+ },
11118
+ trend() {
11119
+ return new VizConfigBuilder("trend", "10.0.0");
11120
+ },
11121
+ traces() {
11122
+ return new VizConfigBuilder("traces", "10.0.0");
11123
+ },
11124
+ xychart() {
11125
+ return new VizConfigBuilder(
11126
+ "xychart",
11127
+ "10.0.0",
11128
+ () => XYChartPanelCfg_types_gen.defaultOptions,
11129
+ () => XYChartPanelCfg_types_gen.defaultFieldConfig
11130
+ );
11131
+ }
11132
+ };
11133
+
10964
11134
  const sceneUtils = {
10965
11135
  getUrlWithAppState,
10966
11136
  registerRuntimePanelPlugin,
@@ -10985,6 +11155,7 @@ exports.ConstantVariable = ConstantVariable;
10985
11155
  exports.CustomVariable = CustomVariable;
10986
11156
  exports.DataSourceVariable = DataSourceVariable;
10987
11157
  exports.EmbeddedScene = EmbeddedScene;
11158
+ exports.FieldConfigBuilder = FieldConfigBuilder;
10988
11159
  exports.FieldConfigBuilders = FieldConfigBuilders;
10989
11160
  exports.FieldConfigOverridesBuilder = FieldConfigOverridesBuilder;
10990
11161
  exports.GroupByVariable = GroupByVariable;
@@ -11039,7 +11210,10 @@ exports.UrlSyncManager = UrlSyncManager;
11039
11210
  exports.UserActionEvent = UserActionEvent;
11040
11211
  exports.VariableDependencyConfig = VariableDependencyConfig;
11041
11212
  exports.VariableValueControl = VariableValueControl;
11213
+ exports.VariableValueSelectWrapper = VariableValueSelectWrapper;
11042
11214
  exports.VariableValueSelectors = VariableValueSelectors;
11215
+ exports.VizConfigBuilder = VizConfigBuilder;
11216
+ exports.VizConfigBuilders = VizConfigBuilders;
11043
11217
  exports.VizPanel = VizPanel;
11044
11218
  exports.VizPanelBuilder = VizPanelBuilder;
11045
11219
  exports.VizPanelMenu = VizPanelMenu;