@grafana/scenes 5.14.7 → 5.15.0--canary.845.11012035874.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -8206,6 +8206,39 @@ class SceneTimeZoneOverride extends SceneTimeRangeTransformerBase {
8206
8206
  }
8207
8207
  }
8208
8208
 
8209
+ class DataProviderProxy extends SceneObjectBase {
8210
+ constructor(state) {
8211
+ super({
8212
+ source: state.source,
8213
+ data: state.source.resolve().state.data
8214
+ });
8215
+ this.addActivationHandler(() => {
8216
+ this._subs.add(
8217
+ this.state.source.resolve().subscribeToState((newState, oldState) => {
8218
+ if (newState.data !== oldState.data) {
8219
+ this.setState({ data: newState.data });
8220
+ }
8221
+ })
8222
+ );
8223
+ });
8224
+ }
8225
+ setContainerWidth(width) {
8226
+ var _a, _b;
8227
+ (_b = (_a = this.state.source.resolve()).setContainerWidth) == null ? void 0 : _b.call(_a, width);
8228
+ }
8229
+ isDataReadyToDisplay() {
8230
+ var _a, _b, _c;
8231
+ return (_c = (_b = (_a = this.state.source.resolve()).isDataReadyToDisplay) == null ? void 0 : _b.call(_a)) != null ? _c : true;
8232
+ }
8233
+ cancelQuery() {
8234
+ var _a, _b;
8235
+ (_b = (_a = this.state.source.resolve()).cancelQuery) == null ? void 0 : _b.call(_a);
8236
+ }
8237
+ getResultsStream() {
8238
+ return this.state.source.resolve().getResultsStream();
8239
+ }
8240
+ }
8241
+
8209
8242
  var __defProp$k = Object.defineProperty;
8210
8243
  var __defProps$b = Object.defineProperties;
8211
8244
  var __getOwnPropDescs$b = Object.getOwnPropertyDescriptors;
@@ -9797,7 +9830,7 @@ var __objRest = (source, exclude) => {
9797
9830
  return target;
9798
9831
  };
9799
9832
  function SceneGridLayoutRenderer({ model }) {
9800
- const { children, isLazy, isDraggable, isResizable } = model.useState();
9833
+ const { children, isLazy, isDraggable, isResizable, showPanelSearch } = model.useState();
9801
9834
  const [outerDivRef, { width, height }] = reactUse.useMeasure();
9802
9835
  const ref = React.useRef(null);
9803
9836
  React.useEffect(() => {
@@ -9843,7 +9876,67 @@ function SceneGridLayoutRenderer({ model }) {
9843
9876
  return /* @__PURE__ */ React__default["default"].createElement("div", {
9844
9877
  ref: outerDivRef,
9845
9878
  style: { flex: "1 1 auto", position: "relative", zIndex: 1, width: "100%" }
9846
- }, renderGrid(width, height));
9879
+ }, showPanelSearch && /* @__PURE__ */ React__default["default"].createElement(PanelSearchControls, {
9880
+ model
9881
+ }), renderGrid(width, height));
9882
+ }
9883
+ function PanelSearchControls({ model }) {
9884
+ const { searchString, panelsPerRow } = model.useState();
9885
+ const styles = ui.useStyles2(getPanelSearchStyles);
9886
+ const onSearchStringChange = React.useCallback(
9887
+ (e) => {
9888
+ model.setState({ searchString: e.currentTarget.value });
9889
+ },
9890
+ [model]
9891
+ );
9892
+ const onPanelsPerRowChange = React.useCallback(
9893
+ (e) => {
9894
+ model.setState({ panelsPerRow: Number.parseInt(e.currentTarget.value, 10) });
9895
+ },
9896
+ [model]
9897
+ );
9898
+ return /* @__PURE__ */ React__default["default"].createElement("div", {
9899
+ className: styles.wrapper
9900
+ }, /* @__PURE__ */ React__default["default"].createElement("div", {
9901
+ id: "panel-search",
9902
+ className: styles.input
9903
+ }, /* @__PURE__ */ React__default["default"].createElement(ControlsLabel, {
9904
+ isLoading: false,
9905
+ label: "Panel search",
9906
+ htmlFor: "panel-search-input"
9907
+ }), /* @__PURE__ */ React__default["default"].createElement(ui.Input, {
9908
+ id: "panel-search-input",
9909
+ label: "Search",
9910
+ placeholder: "Enter value",
9911
+ value: searchString,
9912
+ onChange: onSearchStringChange
9913
+ })), /* @__PURE__ */ React__default["default"].createElement("div", {
9914
+ id: "panels-per-row",
9915
+ className: styles.input
9916
+ }, /* @__PURE__ */ React__default["default"].createElement(ControlsLabel, {
9917
+ isLoading: false,
9918
+ label: "Panels per row",
9919
+ htmlFor: "panels-per-row-input"
9920
+ }), /* @__PURE__ */ React__default["default"].createElement(ui.Input, {
9921
+ id: "panels-per-row-input",
9922
+ type: "number",
9923
+ placeholder: "Enter value",
9924
+ label: "Panels per row",
9925
+ value: panelsPerRow,
9926
+ onChange: onPanelsPerRowChange
9927
+ })));
9928
+ }
9929
+ function getPanelSearchStyles(theme) {
9930
+ return {
9931
+ wrapper: css.css({
9932
+ display: "flex",
9933
+ gap: theme.spacing(1),
9934
+ marginBottom: theme.spacing(1)
9935
+ }),
9936
+ input: css.css({
9937
+ display: "flex"
9938
+ })
9939
+ };
9847
9940
  }
9848
9941
  const GridItemWrapper = React__default["default"].forwardRef((props, ref) => {
9849
9942
  var _b;
@@ -9992,6 +10085,7 @@ const _SceneGridLayout = class extends SceneObjectBase {
9992
10085
  this._skipOnLayoutChange = false;
9993
10086
  this._oldLayout = [];
9994
10087
  this._loadOldLayout = false;
10088
+ this.savedLayout = void 0;
9995
10089
  this.onLayoutChange = (layout) => {
9996
10090
  if (this._skipOnLayoutChange) {
9997
10091
  this._skipOnLayoutChange = false;
@@ -10200,7 +10294,38 @@ const _SceneGridLayout = class extends SceneObjectBase {
10200
10294
  }
10201
10295
  buildGridLayout(width, height) {
10202
10296
  let cells = [];
10203
- for (const child of this.state.children) {
10297
+ const searchString = this.state.searchString;
10298
+ const panelsPerRow = this.state.panelsPerRow;
10299
+ let children = this.state.children;
10300
+ if (searchString && searchString !== "" || panelsPerRow && Number.isInteger(panelsPerRow)) {
10301
+ if (this.savedLayout === void 0) {
10302
+ this.savedLayout = this.state.children.map((v) => v.clone());
10303
+ }
10304
+ const panelFilterInterpolated = interpolate(this, searchString).toLowerCase();
10305
+ const filteredChildren = this.state.children.filter((v) => {
10306
+ var _a, _b, _c, _d;
10307
+ const panelTitleInterpolated = interpolate(v, (_b = (_a = v.state.body) == null ? void 0 : _a.state) == null ? void 0 : _b.title).toLowerCase();
10308
+ return typeof ((_d = (_c = v.state.body) == null ? void 0 : _c.state) == null ? void 0 : _d.title) === "string" && panelTitleInterpolated.includes(panelFilterInterpolated);
10309
+ });
10310
+ this._skipOnLayoutChange = true;
10311
+ const rowSize = typeof panelsPerRow === "number" && Number.isInteger(panelsPerRow) && panelsPerRow > 0 ? panelsPerRow : 2;
10312
+ const panelWidth = GRID_COLUMN_COUNT / rowSize;
10313
+ const panelHeight = 5;
10314
+ return filteredChildren.map((child, i) => __spreadProps$5(__spreadValues$8({}, this.toGridCell(child)), {
10315
+ x: i % rowSize * panelWidth,
10316
+ y: Math.floor(i / rowSize) * panelHeight,
10317
+ w: panelWidth,
10318
+ h: panelHeight,
10319
+ isResizable: false,
10320
+ isDraggable: false
10321
+ }));
10322
+ } else if ((!searchString || searchString === "") && !panelsPerRow) {
10323
+ if (this.savedLayout) {
10324
+ children = this.savedLayout;
10325
+ this.savedLayout = void 0;
10326
+ }
10327
+ }
10328
+ for (const child of children) {
10204
10329
  cells.push(this.toGridCell(child));
10205
10330
  if (child instanceof SceneGridRow && !child.state.isCollapsed) {
10206
10331
  for (const rowChild of child.state.children) {
@@ -13105,6 +13230,7 @@ const sceneUtils = {
13105
13230
  exports.AdHocFiltersVariable = AdHocFiltersVariable;
13106
13231
  exports.ConstantVariable = ConstantVariable;
13107
13232
  exports.CustomVariable = CustomVariable;
13233
+ exports.DataProviderProxy = DataProviderProxy;
13108
13234
  exports.DataSourceVariable = DataSourceVariable;
13109
13235
  exports.EmbeddedScene = EmbeddedScene;
13110
13236
  exports.FieldConfigBuilder = FieldConfigBuilder;