@perses-dev/plugin-system 0.52.0-rc.0 → 0.52.0-rc.1

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.
Files changed (45) hide show
  1. package/dist/cjs/components/MultiQueryEditor/MultiQueryEditor.js +5 -2
  2. package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +13 -4
  3. package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +7 -5
  4. package/dist/cjs/components/PluginEditor/PluginEditor.js +16 -11
  5. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +5 -11
  6. package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +2 -13
  7. package/dist/cjs/context/query-params.js +4 -4
  8. package/dist/cjs/runtime/TimeRangeProvider/query-params.js +27 -27
  9. package/dist/cjs/test/utils.js +17 -8
  10. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts +3 -2
  11. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -1
  12. package/dist/components/MultiQueryEditor/MultiQueryEditor.js +6 -3
  13. package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
  14. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts +3 -2
  15. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts.map +1 -1
  16. package/dist/components/MultiQueryEditor/QueryEditorContainer.js +13 -4
  17. package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
  18. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts +3 -2
  19. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
  20. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +7 -5
  21. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  22. package/dist/components/PluginEditor/PluginEditor.d.ts +3 -3
  23. package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
  24. package/dist/components/PluginEditor/PluginEditor.js +17 -12
  25. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  26. package/dist/components/PluginEditor/plugin-editor-api.d.ts +4 -0
  27. package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
  28. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  29. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  30. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +5 -11
  31. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  32. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +0 -2
  33. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -1
  34. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +2 -13
  35. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
  36. package/dist/context/query-params.js +4 -4
  37. package/dist/context/query-params.js.map +1 -1
  38. package/dist/runtime/TimeRangeProvider/query-params.d.ts +7 -12
  39. package/dist/runtime/TimeRangeProvider/query-params.d.ts.map +1 -1
  40. package/dist/runtime/TimeRangeProvider/query-params.js +20 -23
  41. package/dist/runtime/TimeRangeProvider/query-params.js.map +1 -1
  42. package/dist/test/utils.d.ts.map +1 -1
  43. package/dist/test/utils.js +17 -8
  44. package/dist/test/utils.js.map +1 -1
  45. package/package.json +4 -4
@@ -60,7 +60,8 @@ function useDefaultQueryDefinition(queryTypes) {
60
60
  isLoading
61
61
  };
62
62
  }
63
- function MultiQueryEditor({ queryTypes, queries = [], onChange }) {
63
+ const MultiQueryEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
64
+ const { queryTypes, queries = [], onChange } = props;
64
65
  const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes);
65
66
  // State for which queries are collapsed
66
67
  const [queriesCollapsed, setQueriesCollapsed] = (0, _react.useState)(queries.map(()=>false));
@@ -122,6 +123,7 @@ function MultiQueryEditor({ queryTypes, queries = [], onChange }) {
122
123
  /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
123
124
  spacing: 1,
124
125
  children: queryDefinitions.map((query, i)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_QueryEditorContainer.QueryEditorContainer, {
126
+ ref: ref,
125
127
  queryTypes: queryTypes,
126
128
  index: i,
127
129
  query: query,
@@ -142,4 +144,5 @@ function MultiQueryEditor({ queryTypes, queries = [], onChange }) {
142
144
  })
143
145
  ]
144
146
  });
145
- }
147
+ });
148
+ MultiQueryEditor.displayName = 'MultiQueryEditor';
@@ -26,13 +26,16 @@ const _material = require("@mui/material");
26
26
  const _DeleteOutline = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/DeleteOutline"));
27
27
  const _ChevronDown = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/ChevronDown"));
28
28
  const _ChevronRight = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/ChevronRight"));
29
+ const _react = require("react");
29
30
  const _PluginEditor = require("../PluginEditor");
31
+ const _runtime = require("../../runtime");
30
32
  function _interop_require_default(obj) {
31
33
  return obj && obj.__esModule ? obj : {
32
34
  default: obj
33
35
  };
34
36
  }
35
- const QueryEditorContainer = ({ queryTypes, index, query, isCollapsed, onDelete, onChange, onCollapseExpand })=>{
37
+ const QueryEditorContainer = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
38
+ const { queryTypes, index, query, isCollapsed, onDelete, onChange, onCollapseExpand } = props;
36
39
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
37
40
  spacing: 1,
38
41
  children: [
@@ -68,21 +71,24 @@ const QueryEditorContainer = ({ queryTypes, index, query, isCollapsed, onDelete,
68
71
  ]
69
72
  }),
70
73
  !isCollapsed && /*#__PURE__*/ (0, _jsxruntime.jsx)(QueryEditor, {
74
+ ref: ref,
71
75
  queryTypes: queryTypes,
72
76
  value: query,
73
77
  onChange: (next)=>onChange(index, next)
74
78
  })
75
79
  ]
76
80
  }, index);
77
- };
81
+ });
82
+ QueryEditorContainer.displayName = 'QueryEditorContainer';
78
83
  /**
79
84
  * Editor for a query definition. This component is responsible for rendering the plugin editor for the given query.
80
85
  * This will allow user to select a plugin extending from the given supported query types, and then edit the plugin
81
86
  * spec for this plugin.
82
87
  * @param props
83
88
  * @constructor
84
- */ function QueryEditor(props) {
89
+ */ const QueryEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
85
90
  const { value, onChange, queryTypes, ...others } = props;
91
+ const { refresh } = (0, _runtime.useTimeRange)();
86
92
  const handlePluginChange = (next)=>{
87
93
  onChange((0, _immer.produce)(value, (draft)=>{
88
94
  draft.kind = next.selection.type;
@@ -93,6 +99,8 @@ const QueryEditorContainer = ({ queryTypes, index, query, isCollapsed, onDelete,
93
99
  return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
94
100
  ...others,
95
101
  children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_PluginEditor.PluginEditor, {
102
+ postExecuteRunQuery: refresh,
103
+ ref: ref,
96
104
  withRunQueryButton: true,
97
105
  pluginTypes: queryTypes,
98
106
  pluginKindLabel: "Query Type",
@@ -106,4 +114,5 @@ const QueryEditorContainer = ({ queryTypes, index, query, isCollapsed, onDelete,
106
114
  onChange: handlePluginChange
107
115
  })
108
116
  });
109
- }
117
+ });
118
+ QueryEditor.displayName = 'QueryEditor';
@@ -23,10 +23,11 @@ Object.defineProperty(exports, "PanelSpecEditor", {
23
23
  const _jsxruntime = require("react/jsx-runtime");
24
24
  const _components = require("@perses-dev/components");
25
25
  const _reacthookform = require("react-hook-form");
26
+ const _react = require("react");
26
27
  const _runtime = require("../../runtime");
27
28
  const _OptionsEditorTabs = require("../OptionsEditorTabs");
28
29
  const _MultiQueryEditor = require("../MultiQueryEditor");
29
- function PanelSpecEditor(props) {
30
+ const PanelSpecEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
30
31
  const { control, panelDefinition, onJSONChange, onQueriesChange, onPluginSpecChange } = props;
31
32
  const { kind } = panelDefinition.spec.plugin;
32
33
  const { data: plugin, isLoading, error } = (0, _runtime.usePlugin)('Panel', kind);
@@ -35,11 +36,10 @@ function PanelSpecEditor(props) {
35
36
  error: error
36
37
  });
37
38
  }
38
- // TODO: Proper loading indicator
39
39
  if (isLoading) {
40
40
  return null;
41
41
  }
42
- if (plugin === undefined) {
42
+ if (!plugin) {
43
43
  throw new Error(`Missing implementation for panel plugin with kind '${kind}'`);
44
44
  }
45
45
  const { panelOptionsEditorComponents, hideQueryEditor } = plugin;
@@ -51,6 +51,7 @@ function PanelSpecEditor(props) {
51
51
  control: control,
52
52
  name: "panelDefinition.spec.queries",
53
53
  render: ({ field })=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_MultiQueryEditor.MultiQueryEditor, {
54
+ ref: ref,
54
55
  queryTypes: plugin.supportedQueryTypes ?? [],
55
56
  queries: panelDefinition.spec.queries ?? [],
56
57
  onChange: (queries)=>{
@@ -61,7 +62,7 @@ function PanelSpecEditor(props) {
61
62
  })
62
63
  });
63
64
  }
64
- if (panelOptionsEditorComponents !== undefined) {
65
+ if (panelOptionsEditorComponents) {
65
66
  tabs = tabs.concat(panelOptionsEditorComponents.map(({ label, content: OptionsEditorComponent })=>({
66
67
  label,
67
68
  content: /*#__PURE__*/ (0, _jsxruntime.jsx)(_reacthookform.Controller, {
@@ -105,4 +106,5 @@ function PanelSpecEditor(props) {
105
106
  tabs: tabs
106
107
  }, tabs.length)
107
108
  });
108
- }
109
+ });
110
+ PanelSpecEditor.displayName = 'PanelSpecEditor';
@@ -33,17 +33,16 @@ function _interop_require_default(obj) {
33
33
  default: obj
34
34
  };
35
35
  }
36
- function PluginEditor(props) {
37
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
38
- const { value, withRunQueryButton = true, pluginTypes, pluginKindLabel, onChange: _, isReadonly, ...others } = props;
36
+ const PluginEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
37
+ const { value, withRunQueryButton = true, pluginTypes, pluginKindLabel, onChange: _, isReadonly, postExecuteRunQuery: refresh, ...others } = props;
39
38
  const { pendingSelection, isLoading, error, onSelectionChange, onSpecChange } = (0, _plugineditorapi.usePluginEditor)(props);
40
39
  /*
41
- We could technically merge the watchedQuery, watchedOtherSpecs into a single watched-object,
42
- because at the end of the day, they are all specs.
43
- However, let's have them separated to keep the code simple and readable.
44
- Reason: Only Query string field is common between all of them. Other specs may be different
45
- Example: Legend, and MinSteps
46
- */ const [watchedQuery, setWatchQuery] = (0, _react.useState)(value.spec['query']);
40
+ We could technically merge the watchedQuery, watchedOtherSpecs into a single watched-object,
41
+ because at the end of the day, they are all specs.
42
+ However, let's have them separated to keep the code simple and readable.
43
+ Reason: Only Query string field is common between all of them. Other specs may be different
44
+ Example: Legend, and MinSteps
45
+ */ const [watchedQuery, setWatchQuery] = (0, _react.useState)(value.spec['query']);
47
46
  const [watchedOtherSpecs, setWatchOtherSpecs] = (0, _react.useState)(value.spec);
48
47
  const runQueryHandler = (0, _react.useCallback)(()=>{
49
48
  onSpecChange({
@@ -51,11 +50,13 @@ function PluginEditor(props) {
51
50
  ...watchedOtherSpecs,
52
51
  query: watchedQuery
53
52
  });
53
+ refresh?.();
54
54
  }, [
55
55
  value.spec,
56
56
  onSpecChange,
57
57
  watchedQuery,
58
- watchedOtherSpecs
58
+ watchedOtherSpecs,
59
+ refresh
59
60
  ]);
60
61
  const queryHandlerSettings = (0, _react.useMemo)(()=>{
61
62
  return withRunQueryButton ? {
@@ -70,6 +71,9 @@ function PluginEditor(props) {
70
71
  }, [
71
72
  withRunQueryButton
72
73
  ]);
74
+ (0, _react.useImperativeHandle)(ref, ()=>({
75
+ flushChanges: runQueryHandler
76
+ }));
73
77
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Box, {
74
78
  ...others,
75
79
  children: [
@@ -124,4 +128,5 @@ function PluginEditor(props) {
124
128
  })
125
129
  ]
126
130
  });
127
- }
131
+ });
132
+ PluginEditor.displayName = 'PluginEditor';
@@ -106,12 +106,7 @@ function ListVariableEditorForm({ action, control }) {
106
106
  /** We use `previewSpec` to know when to explicitly update the
107
107
  * spec that will be used for preview. The reason why we do this is to avoid
108
108
  * having to re-fetch the values when the user is still editing the spec.
109
- */ const [previewSpec, setPreviewSpec] = (0, _react.useState)(form.getValues());
110
- const { refresh } = (0, _runtime.useTimeRange)();
111
- const refreshPreview = ()=>{
112
- refresh();
113
- setPreviewSpec(form.getValues());
114
- };
109
+ */ const previewSpec = form.getValues();
115
110
  const plugin = (0, _reacthookform.useWatch)({
116
111
  control,
117
112
  name: 'spec.plugin'
@@ -131,6 +126,7 @@ function ListVariableEditorForm({ action, control }) {
131
126
  if (values.spec.allowMultiple === undefined) {
132
127
  form.setValue('spec.allowMultiple', false);
133
128
  }
129
+ const { refresh } = (0, _runtime.useTimeRange)();
134
130
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
135
131
  children: [
136
132
  /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Typography, {
@@ -149,8 +145,7 @@ function ListVariableEditorForm({ action, control }) {
149
145
  previewSpec
150
146
  ],
151
147
  children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_VariablePreview.VariableListPreview, {
152
- definition: previewSpec,
153
- onRefresh: refreshPreview
148
+ definition: previewSpec
154
149
  })
155
150
  })
156
151
  }) : /*#__PURE__*/ (0, _jsxruntime.jsx)(_VariablePreview.VariablePreview, {
@@ -164,6 +159,7 @@ function ListVariableEditorForm({ action, control }) {
164
159
  name: "spec.plugin",
165
160
  render: ({ field })=>{
166
161
  return /*#__PURE__*/ (0, _jsxruntime.jsx)(_PluginEditor.PluginEditor, {
162
+ postExecuteRunQuery: refresh,
167
163
  withRunQueryButton: true,
168
164
  width: "100%",
169
165
  pluginTypes: [
@@ -175,9 +171,7 @@ function ListVariableEditorForm({ action, control }) {
175
171
  type: 'Variable',
176
172
  kind: kind ?? 'StaticListVariable'
177
173
  },
178
- spec: pluginSpec ?? {
179
- values: []
180
- }
174
+ spec: pluginSpec ?? {}
181
175
  },
182
176
  isReadonly: action === 'read',
183
177
  onChange: (v)=>{
@@ -32,7 +32,6 @@ const _jsxruntime = require("react/jsx-runtime");
32
32
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
33
33
  const _material = require("@mui/material");
34
34
  const _components = require("@perses-dev/components");
35
- const _Refresh = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/Refresh"));
36
35
  const _ClipboardOutline = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/ClipboardOutline"));
37
36
  const _constants = require("../../../constants");
38
37
  const _variablemodel = require("../variable-model");
@@ -84,7 +83,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
84
83
  }
85
84
  const DEFAULT_MAX_PREVIEW_VALUES = 50;
86
85
  function VariablePreview(props) {
87
- const { values, onRefresh, isLoading, error } = props;
86
+ const { values, isLoading, error } = props;
88
87
  const [maxValues, setMaxValues] = (0, _react.useState)(DEFAULT_MAX_PREVIEW_VALUES);
89
88
  const { infoSnackbar } = (0, _components.useSnackbar)();
90
89
  const showAll = ()=>{
@@ -106,14 +105,6 @@ function VariablePreview(props) {
106
105
  variant: "h4",
107
106
  children: "Preview Values"
108
107
  }),
109
- onRefresh && /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.InfoTooltip, {
110
- description: _constants.TOOLTIP_TEXT.refreshVariableValues,
111
- children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.IconButton, {
112
- onClick: onRefresh,
113
- size: "small",
114
- children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_Refresh.default, {})
115
- })
116
- }),
117
108
  /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.InfoTooltip, {
118
109
  description: _constants.TOOLTIP_TEXT.copyVariableValues,
119
110
  children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.IconButton, {
@@ -172,18 +163,16 @@ function VariablePreview(props) {
172
163
  });
173
164
  }
174
165
  function VariableListPreview(props) {
175
- const { onRefresh, definition } = props;
166
+ const { definition } = props;
176
167
  const { data, isFetching, error } = (0, _variablemodel.useListVariablePluginValues)(definition);
177
168
  const errorMessage = error?.message;
178
169
  const variablePreview = (0, _react.useMemo)(()=>/*#__PURE__*/ (0, _jsxruntime.jsx)(VariablePreview, {
179
170
  values: data?.map((val)=>val.value) || [],
180
- onRefresh: onRefresh,
181
171
  isLoading: isFetching,
182
172
  error: errorMessage
183
173
  }), [
184
174
  errorMessage,
185
175
  isFetching,
186
- onRefresh,
187
176
  data
188
177
  ]);
189
178
  return variablePreview;
@@ -21,12 +21,12 @@ Object.defineProperty(exports, "useSetProjectParams", {
21
21
  }
22
22
  });
23
23
  const _react = require("react");
24
- const _usequeryparams = require("use-query-params");
24
+ const _nuqs = require("nuqs");
25
25
  function useSetProjectParams(enabledURLParams = true) {
26
- const [query, setQuery] = (0, _usequeryparams.useQueryParams)({
27
- project: ''
26
+ const [query, setQuery] = (0, _nuqs.useQueryStates)({
27
+ project: _nuqs.parseAsString
28
28
  }, {
29
- updateType: 'replaceIn'
29
+ history: 'replace'
30
30
  });
31
31
  const [projectState, setProjectState] = (0, _react.useState)('none');
32
32
  const setProject = (0, _react.useCallback)((project)=>{
@@ -21,20 +21,20 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- TimeRangeParam: function() {
25
- return TimeRangeParam;
26
- },
27
24
  decodeTimeRangeValue: function() {
28
25
  return decodeTimeRangeValue;
29
26
  },
30
27
  encodeTimeRangeValue: function() {
31
28
  return encodeTimeRangeValue;
32
29
  },
33
- refreshIntervalQueryConfig: function() {
34
- return refreshIntervalQueryConfig;
30
+ parseAsRefreshInterval: function() {
31
+ return parseAsRefreshInterval;
32
+ },
33
+ parseAsTimeRange: function() {
34
+ return parseAsTimeRange;
35
35
  },
36
- timeRangeQueryConfig: function() {
37
- return timeRangeQueryConfig;
36
+ parseAsTimeRangeValue: function() {
37
+ return parseAsTimeRangeValue;
38
38
  },
39
39
  useInitialRefreshInterval: function() {
40
40
  return useInitialRefreshInterval;
@@ -50,9 +50,9 @@ _export(exports, {
50
50
  }
51
51
  });
52
52
  const _react = require("react");
53
- const _usequeryparams = require("use-query-params");
54
53
  const _datefns = require("date-fns");
55
54
  const _core = require("@perses-dev/core");
55
+ const _nuqs = require("nuqs");
56
56
  /* Interprets an encoded string and returns either the string or null/undefined if not available */ function getEncodedValue(input, allowEmptyString) {
57
57
  // '' or []
58
58
  if (!input || input.length === 0 && (!allowEmptyString || allowEmptyString && input !== '')) {
@@ -69,7 +69,7 @@ const _core = require("@perses-dev/core");
69
69
  }
70
70
  function encodeTimeRangeValue(timeOptionValue) {
71
71
  if (!timeOptionValue) {
72
- return timeOptionValue;
72
+ return '';
73
73
  }
74
74
  if (typeof timeOptionValue === 'string') {
75
75
  if ((0, _core.isDurationString)(timeOptionValue)) {
@@ -83,25 +83,25 @@ function decodeTimeRangeValue(input) {
83
83
  if (!paramString) return null;
84
84
  return (0, _core.isDurationString)(paramString) ? paramString : new Date(Number(paramString));
85
85
  }
86
- const TimeRangeParam = {
87
- encode: encodeTimeRangeValue,
88
- decode: decodeTimeRangeValue,
89
- equals: (valueA, valueB)=>{
86
+ const parseAsTimeRangeValue = (0, _nuqs.createParser)({
87
+ parse: decodeTimeRangeValue,
88
+ serialize: encodeTimeRangeValue,
89
+ eq: (valueA, valueB)=>{
90
90
  if (valueA === valueB) return true;
91
91
  if (!valueA || !valueB) return valueA === valueB;
92
92
  return valueA.valueOf() === valueB.valueOf();
93
93
  }
94
+ });
95
+ const parseAsTimeRange = {
96
+ start: parseAsTimeRangeValue,
97
+ end: parseAsTimeRangeValue
94
98
  };
95
- const timeRangeQueryConfig = {
96
- start: TimeRangeParam,
97
- end: TimeRangeParam
98
- };
99
- const refreshIntervalQueryConfig = {
100
- refresh: TimeRangeParam
99
+ const parseAsRefreshInterval = {
100
+ refresh: parseAsTimeRangeValue
101
101
  };
102
102
  function useInitialTimeRange(dashboardDuration) {
103
- const [query] = (0, _usequeryparams.useQueryParams)(timeRangeQueryConfig, {
104
- updateType: 'replaceIn'
103
+ const [query] = (0, _nuqs.useQueryStates)(parseAsTimeRange, {
104
+ history: 'replace'
105
105
  });
106
106
  const { start, end } = query;
107
107
  return (0, _react.useMemo)(()=>{
@@ -130,8 +130,8 @@ function useInitialTimeRange(dashboardDuration) {
130
130
  ]);
131
131
  }
132
132
  function useTimeRangeParams(initialTimeRange) {
133
- const [query, setQuery] = (0, _usequeryparams.useQueryParams)(timeRangeQueryConfig, {
134
- updateType: 'replaceIn'
133
+ const [query, setQuery] = (0, _nuqs.useQueryStates)(parseAsTimeRange, {
134
+ history: 'replace'
135
135
  });
136
136
  // determine whether initial param had previously been populated to fix back btn
137
137
  const [paramsLoaded, setParamsLoaded] = (0, _react.useState)(false);
@@ -171,8 +171,8 @@ function useTimeRangeParams(initialTimeRange) {
171
171
  };
172
172
  }
173
173
  function useInitialRefreshInterval(dashboardDuration) {
174
- const [query] = (0, _usequeryparams.useQueryParams)(refreshIntervalQueryConfig, {
175
- updateType: 'replaceIn'
174
+ const [query] = (0, _nuqs.useQueryStates)(parseAsRefreshInterval, {
175
+ history: 'replace'
176
176
  });
177
177
  const { refresh } = query;
178
178
  return (0, _react.useMemo)(()=>{
@@ -191,8 +191,8 @@ function useInitialRefreshInterval(dashboardDuration) {
191
191
  ]);
192
192
  }
193
193
  function useSetRefreshIntervalParams(initialRefreshInterval) {
194
- const [query, setQuery] = (0, _usequeryparams.useQueryParams)(refreshIntervalQueryConfig, {
195
- updateType: 'replaceIn'
194
+ const [query, setQuery] = (0, _nuqs.useQueryStates)(parseAsRefreshInterval, {
195
+ history: 'replace'
196
196
  });
197
197
  // determine whether initial param had previously been populated to fix back btn
198
198
  const [paramsLoaded, setParamsLoaded] = (0, _react.useState)(false);
@@ -22,7 +22,9 @@ Object.defineProperty(exports, "getTestContextWrapper", {
22
22
  });
23
23
  const _jsxruntime = require("react/jsx-runtime");
24
24
  const _reactquery = require("@tanstack/react-query");
25
+ const _core = require("@perses-dev/core");
25
26
  const _components = require("../components");
27
+ const _runtime = require("../runtime");
26
28
  const _testplugins = require("./test-plugins");
27
29
  function getTestContextWrapper(contextOptions) {
28
30
  // Create a new QueryClient for each test to avoid caching issues
@@ -34,15 +36,22 @@ function getTestContextWrapper(contextOptions) {
34
36
  }
35
37
  }
36
38
  });
39
+ const timeRange = {
40
+ start: new Date(Date.now() - Number(_core.DEFAULT_DASHBOARD_DURATION)),
41
+ end: new Date()
42
+ };
37
43
  return function Wrapper({ children }) {
38
- return /*#__PURE__*/ (0, _jsxruntime.jsx)(_reactquery.QueryClientProvider, {
39
- client: queryClient,
40
- children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.PluginRegistry, {
41
- pluginLoader: _testplugins.testPluginLoader,
42
- defaultPluginKinds: contextOptions?.defaultPluginKinds ?? {
43
- TimeSeriesQuery: 'PrometheusTimeSeriesQuery'
44
- },
45
- children: children
44
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_runtime.TimeRangeProvider, {
45
+ timeRange: timeRange,
46
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_reactquery.QueryClientProvider, {
47
+ client: queryClient,
48
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.PluginRegistry, {
49
+ pluginLoader: _testplugins.testPluginLoader,
50
+ defaultPluginKinds: contextOptions?.defaultPluginKinds ?? {
51
+ TimeSeriesQuery: 'PrometheusTimeSeriesQuery'
52
+ },
53
+ children: children
54
+ })
46
55
  })
47
56
  });
48
57
  };
@@ -1,5 +1,6 @@
1
- import { ReactElement } from 'react';
1
+ /// <reference types="react" />
2
2
  import { QueryDefinition, QueryPluginType } from '@perses-dev/core';
3
+ import { PluginEditorRef } from '../PluginEditor';
3
4
  export interface MultiQueryEditorProps {
4
5
  queryTypes: QueryPluginType[];
5
6
  queries?: QueryDefinition[];
@@ -13,5 +14,5 @@ export interface MultiQueryEditorProps {
13
14
  * @param onChange The callback to call when the queries are modified
14
15
  * @constructor
15
16
  */
16
- export declare function MultiQueryEditor({ queryTypes, queries, onChange }: MultiQueryEditorProps): ReactElement;
17
+ export declare const MultiQueryEditor: import("react").ForwardRefExoticComponent<MultiQueryEditorProps & import("react").RefAttributes<PluginEditorRef>>;
17
18
  //# sourceMappingURL=MultiQueryEditor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MultiQueryEditor.d.ts","sourceRoot":"","sources":["../../../src/components/MultiQueryEditor/MultiQueryEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAY,MAAM,OAAO,CAAC;AAI/C,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAIpE,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,OAAO,CAAC,EAAE,eAAe,EAAE,CAAC;IAC5B,QAAQ,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,IAAI,CAAC;CAChD;AAmCD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,UAAU,EAAE,OAAY,EAAE,QAAQ,EAAE,EAAE,qBAAqB,GAAG,YAAY,CAkF5G"}
1
+ {"version":3,"file":"MultiQueryEditor.d.ts","sourceRoot":"","sources":["../../../src/components/MultiQueryEditor/MultiQueryEditor.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,OAAO,CAAC,EAAE,eAAe,EAAE,CAAC;IAC5B,QAAQ,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,IAAI,CAAC;CAChD;AAmCD;;;;;;;GAOG;AAEH,eAAO,MAAM,gBAAgB,mHAmF3B,CAAC"}
@@ -11,7 +11,7 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
- import { useState } from 'react';
14
+ import { forwardRef, useState } from 'react';
15
15
  import { produce } from 'immer';
16
16
  import { Button, Stack } from '@mui/material';
17
17
  import AddIcon from 'mdi-material-ui/Plus';
@@ -52,7 +52,8 @@ function useDefaultQueryDefinition(queryTypes) {
52
52
  * @param queries The list of query definitions to render
53
53
  * @param onChange The callback to call when the queries are modified
54
54
  * @constructor
55
- */ export function MultiQueryEditor({ queryTypes, queries = [], onChange }) {
55
+ */ export const MultiQueryEditor = /*#__PURE__*/ forwardRef((props, ref)=>{
56
+ const { queryTypes, queries = [], onChange } = props;
56
57
  const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes);
57
58
  // State for which queries are collapsed
58
59
  const [queriesCollapsed, setQueriesCollapsed] = useState(queries.map(()=>false));
@@ -114,6 +115,7 @@ function useDefaultQueryDefinition(queryTypes) {
114
115
  /*#__PURE__*/ _jsx(Stack, {
115
116
  spacing: 1,
116
117
  children: queryDefinitions.map((query, i)=>/*#__PURE__*/ _jsx(QueryEditorContainer, {
118
+ ref: ref,
117
119
  queryTypes: queryTypes,
118
120
  index: i,
119
121
  query: query,
@@ -134,6 +136,7 @@ function useDefaultQueryDefinition(queryTypes) {
134
136
  })
135
137
  ]
136
138
  });
137
- }
139
+ });
140
+ MultiQueryEditor.displayName = 'MultiQueryEditor';
138
141
 
139
142
  //# sourceMappingURL=MultiQueryEditor.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/MultiQueryEditor/MultiQueryEditor.tsx"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ReactElement, useState } from 'react';\nimport { produce } from 'immer';\nimport { Button, Stack } from '@mui/material';\nimport AddIcon from 'mdi-material-ui/Plus';\nimport { QueryDefinition, QueryPluginType } from '@perses-dev/core';\nimport { useListPluginMetadata, usePlugin, usePluginRegistry } from '../../runtime';\nimport { QueryEditorContainer } from './QueryEditorContainer';\n\nexport interface MultiQueryEditorProps {\n queryTypes: QueryPluginType[];\n queries?: QueryDefinition[];\n onChange: (queries: QueryDefinition[]) => void;\n}\n\nfunction useDefaultQueryDefinition(queryTypes: QueryPluginType[]): {\n defaultInitialQueryDefinition: QueryDefinition;\n isLoading: boolean;\n} {\n // Build the default query plugin\n // This will be used only if the queries are empty, to open a starting query\n\n // Firs the default query type\n const defaultQueryType = queryTypes[0]!;\n\n // Then the default plugin kind\n // Use as default the plugin kind explicitly set as default or the first in the list\n const { data: queryPlugins, isLoading } = useListPluginMetadata(queryTypes);\n const { defaultPluginKinds } = usePluginRegistry();\n const defaultQueryKind = defaultPluginKinds?.[defaultQueryType] ?? queryPlugins?.[0]?.spec.name ?? '';\n\n const { data: defaultQueryPlugin } = usePlugin(defaultQueryType, defaultQueryKind, {\n useErrorBoundary: true,\n enabled: true,\n });\n\n // This default query definition is used if no query is provided initially or when we add a new query\n return {\n defaultInitialQueryDefinition: {\n kind: defaultQueryType,\n spec: {\n plugin: { kind: defaultQueryKind, spec: defaultQueryPlugin?.createInitialOptions() || {} },\n },\n },\n isLoading,\n };\n}\n\n/**\n * A component render a list of {@link QueryEditorContainer} for the given query definitions.\n * It allows adding, removing and editing queries.\n * @param queryTypes The list of query types that the underlying editor will propose\n * @param queries The list of query definitions to render\n * @param onChange The callback to call when the queries are modified\n * @constructor\n */\nexport function MultiQueryEditor({ queryTypes, queries = [], onChange }: MultiQueryEditorProps): ReactElement {\n const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes);\n\n // State for which queries are collapsed\n const [queriesCollapsed, setQueriesCollapsed] = useState(queries.map(() => false));\n\n // Query handlers\n const handleQueryChange = (index: number, queryDef: QueryDefinition): void => {\n onChange(\n produce(queries, (draft) => {\n if (draft) {\n draft[index] = queryDef;\n } else {\n draft = [queryDef];\n }\n })\n );\n };\n\n const handleQueryAdd = (): void => {\n onChange(\n produce(queries, (draft) => {\n if (draft) {\n draft.push(defaultInitialQueryDefinition);\n } else {\n draft = [...queries, defaultInitialQueryDefinition];\n }\n })\n );\n setQueriesCollapsed((queriesCollapsed) => {\n queriesCollapsed.push(false);\n return [...queriesCollapsed];\n });\n };\n\n const handleQueryDelete = (index: number): void => {\n onChange(\n produce(queries, (draft) => {\n draft.splice(index, 1);\n })\n );\n setQueriesCollapsed((queriesCollapsed) => {\n queriesCollapsed.splice(index, 1);\n return [...queriesCollapsed];\n });\n };\n\n const handleQueryCollapseExpand = (index: number): void => {\n setQueriesCollapsed((queriesCollapsed) => {\n queriesCollapsed[index] = !queriesCollapsed[index];\n return [...queriesCollapsed];\n });\n };\n\n // show one query input if queries is empty\n const queryDefinitions: QueryDefinition[] = queries.length\n ? queries\n : !isLoading\n ? [defaultInitialQueryDefinition]\n : [];\n\n return (\n <>\n <Stack spacing={1}>\n {queryDefinitions.map((query: QueryDefinition, i: number) => (\n <QueryEditorContainer\n queryTypes={queryTypes}\n key={i}\n index={i}\n query={query}\n isCollapsed={!!queriesCollapsed[i]}\n onChange={handleQueryChange}\n onDelete={queries.length > 1 ? handleQueryDelete : undefined}\n onCollapseExpand={handleQueryCollapseExpand}\n />\n ))}\n </Stack>\n <Button variant=\"contained\" startIcon={<AddIcon />} sx={{ marginTop: 1 }} onClick={handleQueryAdd}>\n Add Query\n </Button>\n </>\n );\n}\n"],"names":["useState","produce","Button","Stack","AddIcon","useListPluginMetadata","usePlugin","usePluginRegistry","QueryEditorContainer","useDefaultQueryDefinition","queryTypes","defaultQueryType","data","queryPlugins","isLoading","defaultPluginKinds","defaultQueryKind","spec","name","defaultQueryPlugin","useErrorBoundary","enabled","defaultInitialQueryDefinition","kind","plugin","createInitialOptions","MultiQueryEditor","queries","onChange","queriesCollapsed","setQueriesCollapsed","map","handleQueryChange","index","queryDef","draft","handleQueryAdd","push","handleQueryDelete","splice","handleQueryCollapseExpand","queryDefinitions","length","spacing","query","i","isCollapsed","onDelete","undefined","onCollapseExpand","variant","startIcon","sx","marginTop","onClick"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAAuBA,QAAQ,QAAQ,QAAQ;AAC/C,SAASC,OAAO,QAAQ,QAAQ;AAChC,SAASC,MAAM,EAAEC,KAAK,QAAQ,gBAAgB;AAC9C,OAAOC,aAAa,uBAAuB;AAE3C,SAASC,qBAAqB,EAAEC,SAAS,EAAEC,iBAAiB,QAAQ,gBAAgB;AACpF,SAASC,oBAAoB,QAAQ,yBAAyB;AAQ9D,SAASC,0BAA0BC,UAA6B;IAI9D,iCAAiC;IACjC,4EAA4E;IAE5E,8BAA8B;IAC9B,MAAMC,mBAAmBD,UAAU,CAAC,EAAE;IAEtC,+BAA+B;IAC/B,oFAAoF;IACpF,MAAM,EAAEE,MAAMC,YAAY,EAAEC,SAAS,EAAE,GAAGT,sBAAsBK;IAChE,MAAM,EAAEK,kBAAkB,EAAE,GAAGR;IAC/B,MAAMS,mBAAmBD,oBAAoB,CAACJ,iBAAiB,IAAIE,cAAc,CAAC,EAAE,EAAEI,KAAKC,QAAQ;IAEnG,MAAM,EAAEN,MAAMO,kBAAkB,EAAE,GAAGb,UAAUK,kBAAkBK,kBAAkB;QACjFI,kBAAkB;QAClBC,SAAS;IACX;IAEA,qGAAqG;IACrG,OAAO;QACLC,+BAA+B;YAC7BC,MAAMZ;YACNM,MAAM;gBACJO,QAAQ;oBAAED,MA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8B,GAC/B,EAAE;IAER,qBACE;;0BACE,KAACnB;gBAAMwC,SAAS;0BACbF,iBAAiBV,GAAG,CAAC,CAACa,OAAwBC,kBAC7C,KAACrC;wBACCE,YAAYA;wBAEZuB,OAAOY;wBACPD,OAAOA;wBACPE,aAAa,CAAC,CAACjB,gBAAgB,CAACgB,EAAE;wBAClCjB,UAAUI;wBACVe,UAAUpB,QAAQe,MAAM,GAAG,IAAIJ,oBAAoBU;wBACnDC,kBAAkBT;uBANbK;;0BAUX,KAAC3C;gBAAOgD,SAAQ;gBAAYC,yBAAW,KAAC/C;gBAAYgD,IAAI;oBAAEC,WAAW;gBAAE;gBAAGC,SAASlB;0BAAgB;;;;AAKzG"}
1
+ {"version":3,"sources":["../../../src/components/MultiQueryEditor/MultiQueryEditor.tsx"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { forwardRef, ReactElement, useState } from 'react';\nimport { produce } from 'immer';\nimport { Button, Stack } from '@mui/material';\nimport AddIcon from 'mdi-material-ui/Plus';\nimport { QueryDefinition, QueryPluginType } from '@perses-dev/core';\nimport { useListPluginMetadata, usePlugin, usePluginRegistry } from '../../runtime';\nimport { PluginEditorRef } from '../PluginEditor';\nimport { QueryEditorContainer } from './QueryEditorContainer';\n\nexport interface MultiQueryEditorProps {\n queryTypes: QueryPluginType[];\n queries?: QueryDefinition[];\n onChange: (queries: QueryDefinition[]) => void;\n}\n\nfunction useDefaultQueryDefinition(queryTypes: QueryPluginType[]): {\n defaultInitialQueryDefinition: QueryDefinition;\n isLoading: boolean;\n} {\n // Build the default query plugin\n // This will be used only if the queries are empty, to open a starting query\n\n // Firs the default query type\n const defaultQueryType = queryTypes[0]!;\n\n // Then the default plugin kind\n // Use as default the plugin kind explicitly set as default or the first in the list\n const { data: queryPlugins, isLoading } = useListPluginMetadata(queryTypes);\n const { defaultPluginKinds } = usePluginRegistry();\n const defaultQueryKind = defaultPluginKinds?.[defaultQueryType] ?? queryPlugins?.[0]?.spec.name ?? '';\n\n const { data: defaultQueryPlugin } = usePlugin(defaultQueryType, defaultQueryKind, {\n useErrorBoundary: true,\n enabled: true,\n });\n\n // This default query definition is used if no query is provided initially or when we add a new query\n return {\n defaultInitialQueryDefinition: {\n kind: defaultQueryType,\n spec: {\n plugin: { kind: defaultQueryKind, spec: defaultQueryPlugin?.createInitialOptions() || {} },\n },\n },\n isLoading,\n };\n}\n\n/**\n * A component render a list of {@link QueryEditorContainer} for the given query definitions.\n * It allows adding, removing and editing queries.\n * @param queryTypes The list of query types that the underlying editor will propose\n * @param queries The list of query definitions to render\n * @param onChange The callback to call when the queries are modified\n * @constructor\n */\n\nexport const MultiQueryEditor = forwardRef<PluginEditorRef, MultiQueryEditorProps>((props, ref): ReactElement => {\n const { queryTypes, queries = [], onChange } = props;\n const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes);\n // State for which queries are collapsed\n const [queriesCollapsed, setQueriesCollapsed] = useState(queries.map(() => false));\n\n // Query handlers\n const handleQueryChange = (index: number, queryDef: QueryDefinition): void => {\n onChange(\n produce(queries, (draft) => {\n if (draft) {\n draft[index] = queryDef;\n } else {\n draft = [queryDef];\n }\n })\n );\n };\n\n const handleQueryAdd = (): void => {\n onChange(\n produce(queries, (draft) => {\n if (draft) {\n draft.push(defaultInitialQueryDefinition);\n } else {\n draft = [...queries, defaultInitialQueryDefinition];\n }\n })\n );\n setQueriesCollapsed((queriesCollapsed) => {\n queriesCollapsed.push(false);\n return [...queriesCollapsed];\n });\n };\n\n const handleQueryDelete = (index: number): void => {\n onChange(\n produce(queries, (draft) => {\n draft.splice(index, 1);\n })\n );\n setQueriesCollapsed((queriesCollapsed) => {\n queriesCollapsed.splice(index, 1);\n return [...queriesCollapsed];\n });\n };\n\n const handleQueryCollapseExpand = (index: number): void => {\n setQueriesCollapsed((queriesCollapsed) => {\n queriesCollapsed[index] = !queriesCollapsed[index];\n return [...queriesCollapsed];\n });\n };\n\n // show one query input if queries is empty\n const queryDefinitions: QueryDefinition[] = queries.length\n ? queries\n : !isLoading\n ? [defaultInitialQueryDefinition]\n : [];\n\n return (\n <>\n <Stack spacing={1}>\n {queryDefinitions.map((query: QueryDefinition, i: number) => (\n <QueryEditorContainer\n ref={ref}\n queryTypes={queryTypes}\n key={i}\n index={i}\n query={query}\n isCollapsed={!!queriesCollapsed[i]}\n onChange={handleQueryChange}\n onDelete={queries.length > 1 ? handleQueryDelete : undefined}\n onCollapseExpand={handleQueryCollapseExpand}\n />\n ))}\n </Stack>\n <Button variant=\"contained\" startIcon={<AddIcon />} sx={{ marginTop: 1 }} onClick={handleQueryAdd}>\n Add Query\n </Button>\n </>\n );\n});\n\nMultiQueryEditor.displayName = 'MultiQueryEditor';\n"],"names":["forwardRef","useState","produce","Button","Stack","AddIcon","useListPluginMetadata","usePlugin","usePluginRegistry","QueryEditorContainer","useDefaultQueryDefinition","queryTypes","defaultQueryType","data","queryPlugins","isLoading","defaultPluginKinds","defaultQueryKind","spec","name","defaultQueryPlugin","useErrorBoundary","enabled","defaultInitialQueryDefinition","kind","plugin","createInitialOptions","MultiQueryEditor","props","ref","queries","onChange","queriesCollapsed","setQueriesCollapsed","map","handleQueryChange","index","queryDef","draft","handleQueryAdd","push","handleQueryDelete","splice","handleQueryCollapseExpand","queryDefinitions","length","spacing","query","i","isCollapsed","onDelete","undefined","onCollapseExpand","variant","startIcon","sx","marginTop","onClick","displayName"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,o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BANbK;;0BAUX,KAAC7C;gBAAOkD,SAAQ;gBAAYC,yBAAW,KAACjD;gBAAYkD,IAAI;oBAAEC,WAAW;gBAAE;gBAAGC,SAASlB;0BAAgB;;;;AAKzG,GAAG;AAEHZ,iBAAiB+B,WAAW,GAAG"}
@@ -1,5 +1,6 @@
1
+ /// <reference types="react" />
1
2
  import { QueryDefinition, QueryPluginType } from '@perses-dev/core';
2
- import { ReactElement } from 'react';
3
+ import { PluginEditorRef } from '../PluginEditor';
3
4
  /**
4
5
  * Properties for {@link QueryEditorContainer}
5
6
  */
@@ -24,6 +25,6 @@ interface QueryEditorContainerProps {
24
25
  * @param onCollapseExpand callback when the query is collapsed or expanded
25
26
  * @constructor
26
27
  */
27
- export declare const QueryEditorContainer: ({ queryTypes, index, query, isCollapsed, onDelete, onChange, onCollapseExpand, }: QueryEditorContainerProps) => ReactElement;
28
+ export declare const QueryEditorContainer: import("react").ForwardRefExoticComponent<QueryEditorContainerProps & import("react").RefAttributes<PluginEditorRef>>;
28
29
  export {};
29
30
  //# sourceMappingURL=QueryEditorContainer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"QueryEditorContainer.d.ts","sourceRoot":"","sources":["../../../src/components/MultiQueryEditor/QueryEditorContainer.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAKpE,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAGrC;;GAEG;AACH,UAAU,yBAAyB;IACjC,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAC1D,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ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