@perses-dev/plugin-system 0.54.0-beta.8 → 0.54.0-beta.9

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 (40) hide show
  1. package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +97 -12
  2. package/dist/cjs/components/MultiQueryEditor/index.js +1 -0
  3. package/dist/cjs/components/MultiQueryEditor/utils.js +36 -0
  4. package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +3 -6
  5. package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +21 -28
  6. package/dist/cjs/runtime/DataQueriesProvider/model.js +3 -119
  7. package/dist/cjs/runtime/index.js +0 -1
  8. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts.map +1 -1
  9. package/dist/components/MultiQueryEditor/QueryEditorContainer.js +99 -14
  10. package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
  11. package/dist/components/MultiQueryEditor/index.d.ts +1 -0
  12. package/dist/components/MultiQueryEditor/index.d.ts.map +1 -1
  13. package/dist/components/MultiQueryEditor/index.js +1 -0
  14. package/dist/components/MultiQueryEditor/index.js.map +1 -1
  15. package/dist/components/MultiQueryEditor/utils.d.ts +8 -0
  16. package/dist/components/MultiQueryEditor/utils.d.ts.map +1 -0
  17. package/dist/{runtime/QueryCountProvider.js → components/MultiQueryEditor/utils.js} +10 -13
  18. package/dist/components/MultiQueryEditor/utils.js.map +1 -0
  19. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
  20. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +4 -7
  21. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  22. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -1
  23. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +22 -29
  24. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
  25. package/dist/runtime/DataQueriesProvider/model.d.ts +4 -4
  26. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
  27. package/dist/runtime/DataQueriesProvider/model.js +0 -108
  28. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  29. package/dist/runtime/index.d.ts +0 -1
  30. package/dist/runtime/index.d.ts.map +1 -1
  31. package/dist/runtime/index.js +0 -1
  32. package/dist/runtime/index.js.map +1 -1
  33. package/dist/runtime/plugin-registry.d.ts +1 -2
  34. package/dist/runtime/plugin-registry.d.ts.map +1 -1
  35. package/dist/runtime/plugin-registry.js.map +1 -1
  36. package/package.json +4 -4
  37. package/dist/cjs/runtime/QueryCountProvider.js +0 -83
  38. package/dist/runtime/QueryCountProvider.d.ts +0 -9
  39. package/dist/runtime/QueryCountProvider.d.ts.map +0 -1
  40. package/dist/runtime/QueryCountProvider.js.map +0 -1
@@ -29,7 +29,11 @@ const _ChevronRight = /*#__PURE__*/ _interop_require_default(require("mdi-materi
29
29
  const _react = require("react");
30
30
  const _Alert = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/Alert"));
31
31
  const _components = require("@perses-dev/components");
32
+ const _Pencil = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/Pencil"));
33
+ const _Check = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/Check"));
34
+ const _Close = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/Close"));
32
35
  const _PluginEditor = require("../PluginEditor");
36
+ const _utils = require("./utils");
33
37
  function _interop_require_default(obj) {
34
38
  return obj && obj.__esModule ? obj : {
35
39
  default: obj
@@ -37,6 +41,16 @@ function _interop_require_default(obj) {
37
41
  }
38
42
  const QueryEditorContainer = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
39
43
  const { queryTypes, index, query, queryResult, filteredQueryPlugins, isCollapsed, onDelete, onChange, onQueryRun, onCollapseExpand } = props;
44
+ // The displayed name is always derived from props so it stays in sync with the
45
+ // current query/index, even when queries are added, removed or reordered.
46
+ const displayedName = query.spec.name ?? (0, _utils.defaultQueryName)(index);
47
+ const [isEditingName, setIsEditingName] = (0, _react.useState)(false);
48
+ function handleNameSave(name) {
49
+ setIsEditingName(false);
50
+ onChange(index, (0, _immer.produce)(query, (draft)=>{
51
+ draft.spec.name = name;
52
+ }));
53
+ }
40
54
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
41
55
  spacing: 1,
42
56
  children: [
@@ -49,19 +63,40 @@ const QueryEditorContainer = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>
49
63
  children: [
50
64
  /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
51
65
  direction: "row",
66
+ gap: 1,
67
+ sx: {
68
+ width: '100%'
69
+ },
52
70
  children: [
53
71
  /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.IconButton, {
54
72
  size: "small",
73
+ sx: {
74
+ width: 'fit-content',
75
+ height: 'fit-content'
76
+ },
55
77
  onClick: ()=>onCollapseExpand(index),
56
78
  children: isCollapsed ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_ChevronRight.default, {}) : /*#__PURE__*/ (0, _jsxruntime.jsx)(_ChevronDown.default, {})
57
79
  }),
58
- /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Typography, {
59
- variant: "overline",
60
- component: "h4",
61
- children: [
62
- "Query #",
63
- index + 1
64
- ]
80
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
81
+ direction: "row",
82
+ gap: 1,
83
+ alignItems: "center",
84
+ alignContent: "center",
85
+ sx: {
86
+ width: '100%',
87
+ '&:hover button': {
88
+ visibility: 'visible'
89
+ }
90
+ },
91
+ children: isEditingName ? /*#__PURE__*/ (0, _jsxruntime.jsx)(QueryNameInput, {
92
+ initialName: displayedName,
93
+ onSave: handleNameSave,
94
+ onCancel: ()=>setIsEditingName(false)
95
+ }, displayedName) : /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Typography, {
96
+ variant: "overline",
97
+ component: "h4",
98
+ children: displayedName
99
+ })
65
100
  })
66
101
  ]
67
102
  }),
@@ -105,11 +140,24 @@ const QueryEditorContainer = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>
105
140
  ]
106
141
  })
107
142
  }),
108
- onDelete && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.IconButton, {
109
- "aria-label": "delete query",
110
- size: "small",
111
- onClick: ()=>onDelete && onDelete(index),
112
- children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_DeleteOutline.default, {})
143
+ /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
144
+ direction: "row",
145
+ children: [
146
+ !isEditingName && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.IconButton, {
147
+ "aria-label": "edit query name",
148
+ size: "small",
149
+ onClick: ()=>setIsEditingName(true),
150
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_Pencil.default, {
151
+ fontSize: "small"
152
+ })
153
+ }),
154
+ onDelete && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.IconButton, {
155
+ "aria-label": "delete query",
156
+ size: "small",
157
+ onClick: ()=>onDelete && onDelete(index),
158
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_DeleteOutline.default, {})
159
+ })
160
+ ]
113
161
  })
114
162
  ]
115
163
  })
@@ -127,6 +175,43 @@ const QueryEditorContainer = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>
127
175
  }, index);
128
176
  });
129
177
  QueryEditorContainer.displayName = 'QueryEditorContainer';
178
+ /**
179
+ * Self-contained input to edit a query name. The draft value is local state seeded from
180
+ * `initialName`; callers reset it by changing the `key` (remounting) rather than syncing
181
+ * with an useEffect.
182
+ */ function QueryNameInput({ initialName, onSave, onCancel }) {
183
+ const [draftName, setDraftName] = (0, _react.useState)(initialName);
184
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
185
+ size: "small",
186
+ variant: "outlined",
187
+ label: "Query name",
188
+ "aria-label": "query name",
189
+ value: draftName,
190
+ onChange: (e)=>setDraftName(e.target.value),
191
+ fullWidth: true,
192
+ InputProps: {
193
+ endAdornment: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.InputAdornment, {
194
+ position: "end",
195
+ children: [
196
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.IconButton, {
197
+ size: "small",
198
+ "aria-label": "cancel edit",
199
+ onClick: onCancel,
200
+ edge: "end",
201
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_Close.default, {})
202
+ }),
203
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.IconButton, {
204
+ size: "small",
205
+ "aria-label": "save query name",
206
+ onClick: ()=>onSave(draftName),
207
+ edge: "end",
208
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_Check.default, {})
209
+ })
210
+ ]
211
+ })
212
+ }
213
+ });
214
+ }
130
215
  /**
131
216
  * Editor for a query definition. This component is responsible for rendering the plugin editor for the given query.
132
217
  * This will allow user to select a plugin extending from the given supported query types, and then edit the plugin
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
17
  _export_star(require("./MultiQueryEditor"), exports);
18
+ _export_star(require("./utils"), exports);
18
19
  function _export_star(from, to) {
19
20
  Object.keys(from).forEach(function(k) {
20
21
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -0,0 +1,36 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: Object.getOwnPropertyDescriptor(all, name).get
21
+ });
22
+ }
23
+ _export(exports, {
24
+ get defaultQueryName () {
25
+ return defaultQueryName;
26
+ },
27
+ get generateQueryNames () {
28
+ return generateQueryNames;
29
+ }
30
+ });
31
+ function defaultQueryName(index) {
32
+ return `Query #${index + 1}`;
33
+ }
34
+ function generateQueryNames(definitions) {
35
+ return definitions.map((queryDef, index)=>queryDef.spec.name ?? defaultQueryName(index));
36
+ }
@@ -109,11 +109,8 @@ const PanelSpecEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
109
109
  })
110
110
  })
111
111
  });
112
- return /*#__PURE__*/ (0, _jsxruntime.jsx)(_runtime.QueryCountProvider, {
113
- queryCount: (panelDefinition.spec.queries ?? []).length,
114
- children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_OptionsEditorTabs.OptionsEditorTabs, {
115
- tabs: tabs
116
- }, tabs.length)
117
- });
112
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_OptionsEditorTabs.OptionsEditorTabs, {
113
+ tabs: tabs
114
+ }, tabs.length);
118
115
  });
119
116
  PanelSpecEditor.displayName = 'PanelSpecEditor';
@@ -54,46 +54,37 @@ function useDataQueriesContext() {
54
54
  }
55
55
  function useDataQueries(queryType) {
56
56
  const ctx = useDataQueriesContext();
57
+ // Filter query definitions based on the specified query type
58
+ const filteredQueryDefinitions = ctx.queryDefinitions.filter((definition)=>definition.kind === queryType);
57
59
  // Filter the query results based on the specified query type
58
60
  const filteredQueryResults = ctx.queryResults.filter((queryResult)=>queryResult?.definition?.kind === queryType);
59
61
  // Filter the errors based on the specified query type
60
62
  const filteredErrors = ctx.errors.filter((errors, index)=>ctx.queryResults[index]?.definition?.kind === queryType);
61
63
  // Create a new context object with the filtered results and errors
62
- const filteredCtx = {
64
+ return {
65
+ queryDefinitions: filteredQueryDefinitions,
63
66
  queryResults: filteredQueryResults,
64
67
  isFetching: filteredQueryResults.some((result)=>result.isFetching),
65
68
  isLoading: filteredQueryResults.some((result)=>result.isLoading),
66
69
  refetchAll: ctx.refetchAll,
67
70
  errors: filteredErrors
68
71
  };
69
- return filteredCtx;
70
72
  }
71
73
  function DataQueriesProvider(props) {
72
74
  const { definitions, options, children, queryOptions } = props;
73
- // Returns a query kind, for example "TimeSeriesQuery" = getQueryType("PrometheusTimeSeriesQuery")
74
- const getQueryType = (0, _model.useQueryType)();
75
- const queryDefinitions = definitions.map((definition)=>{
76
- const type = getQueryType(definition.kind);
77
- return {
78
- kind: type,
79
- spec: {
80
- plugin: definition
81
- }
82
- };
83
- });
84
75
  const usageMetrics = (0, _UsageMetricsProvider.useUsageMetrics)();
85
76
  // Filter definitions for time series query and other future query plugins
86
- const timeSeriesQueries = queryDefinitions.filter((definition)=>definition.kind === 'TimeSeriesQuery');
77
+ const timeSeriesQueries = definitions.filter((definition)=>definition.kind === 'TimeSeriesQuery');
87
78
  const timeSeriesResults = (0, _timeseriesqueries.useTimeSeriesQueries)(timeSeriesQueries, options, queryOptions);
88
- const traceQueries = queryDefinitions.filter((definition)=>definition.kind === 'TraceQuery');
79
+ const traceQueries = definitions.filter((definition)=>definition.kind === 'TraceQuery');
89
80
  const traceResults = (0, _tracequeries.useTraceQueries)(traceQueries);
90
- const profileQueries = queryDefinitions.filter((definition)=>definition.kind === 'ProfileQuery');
81
+ const profileQueries = definitions.filter((definition)=>definition.kind === 'ProfileQuery');
91
82
  const profileResults = (0, _profilequeries.useProfileQueries)(profileQueries);
92
- const logQueries = queryDefinitions.filter((definition)=>definition.kind === 'LogQuery');
83
+ const logQueries = definitions.filter((definition)=>definition.kind === 'LogQuery');
93
84
  const logResults = (0, _logqueries.useLogQueries)(logQueries);
94
- const alertsQueries = queryDefinitions.filter((definition)=>definition.kind === 'AlertsQuery');
85
+ const alertsQueries = definitions.filter((definition)=>definition.kind === 'AlertsQuery');
95
86
  const alertsResults = (0, _alertsqueries.useAlertsQueries)(alertsQueries);
96
- const silencesQueries = queryDefinitions.filter((definition)=>definition.kind === 'SilencesQuery');
87
+ const silencesQueries = definitions.filter((definition)=>definition.kind === 'SilencesQuery');
97
88
  const silencesResults = (0, _silencesqueries.useSilencesQueries)(silencesQueries);
98
89
  const refetchAll = (0, _react.useCallback)(()=>{
99
90
  timeSeriesResults.forEach((result)=>result.refetch());
@@ -131,6 +122,7 @@ function DataQueriesProvider(props) {
131
122
  }
132
123
  }
133
124
  return {
125
+ queryDefinitions: definitions,
134
126
  queryResults: mergedQueryResults,
135
127
  isFetching: mergedQueryResults.some((result)=>result.isFetching),
136
128
  isLoading: mergedQueryResults.some((result)=>result.isLoading),
@@ -138,20 +130,21 @@ function DataQueriesProvider(props) {
138
130
  errors: mergedQueryResults.map((result)=>result.error)
139
131
  };
140
132
  }, [
141
- timeSeriesQueries,
142
- timeSeriesResults,
143
- traceQueries,
144
- traceResults,
145
- profileQueries,
146
- profileResults,
147
- logQueries,
148
- logResults,
149
133
  alertsQueries,
150
134
  alertsResults,
135
+ logQueries,
136
+ logResults,
137
+ profileQueries,
138
+ profileResults,
151
139
  silencesQueries,
152
140
  silencesResults,
153
- refetchAll,
141
+ timeSeriesQueries,
142
+ timeSeriesResults,
143
+ traceQueries,
144
+ traceResults,
145
+ definitions,
154
146
  queryOptions?.enabled,
147
+ refetchAll,
155
148
  usageMetrics
156
149
  ]);
157
150
  return /*#__PURE__*/ (0, _jsxruntime.jsx)(DataQueriesContext.Provider, {
@@ -14,22 +14,12 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- function _export(target, all) {
18
- for(var name in all)Object.defineProperty(target, name, {
19
- enumerable: true,
20
- get: Object.getOwnPropertyDescriptor(all, name).get
21
- });
22
- }
23
- _export(exports, {
24
- get transformQueryResults () {
17
+ Object.defineProperty(exports, "transformQueryResults", {
18
+ enumerable: true,
19
+ get: function() {
25
20
  return transformQueryResults;
26
- },
27
- get useQueryType () {
28
- return useQueryType;
29
21
  }
30
22
  });
31
- const _react = require("react");
32
- const _pluginregistry = require("../plugin-registry");
33
23
  function transformQueryResults(results, definitions) {
34
24
  return results.map(({ data, isFetching, isLoading, refetch, error }, i)=>{
35
25
  return {
@@ -42,109 +32,3 @@ function transformQueryResults(results, definitions) {
42
32
  };
43
33
  });
44
34
  }
45
- function useQueryType() {
46
- const { data: timeSeriesQueryPlugins, isLoading: isTimeSeriesQueryLoading } = (0, _pluginregistry.useListPluginMetadata)([
47
- 'TimeSeriesQuery'
48
- ]);
49
- const { data: traceQueryPlugins, isLoading: isTraceQueryPluginLoading } = (0, _pluginregistry.useListPluginMetadata)([
50
- 'TraceQuery'
51
- ]);
52
- const { data: profileQueryPlugins, isLoading: isProfileQueryPluginLoading } = (0, _pluginregistry.useListPluginMetadata)([
53
- 'ProfileQuery'
54
- ]);
55
- const { data: logQueries, isLoading: isLogQueryPluginLoading } = (0, _pluginregistry.useListPluginMetadata)([
56
- 'LogQuery'
57
- ]);
58
- const { data: alertsQueryPlugins, isLoading: isAlertsQueryPluginLoading } = (0, _pluginregistry.useListPluginMetadata)([
59
- 'AlertsQuery'
60
- ]);
61
- const { data: silencesQueryPlugins, isLoading: isSilencesQueryPluginLoading } = (0, _pluginregistry.useListPluginMetadata)([
62
- 'SilencesQuery'
63
- ]);
64
- // For example, `map: {"TimeSeriesQuery":["PrometheusTimeSeriesQuery"],"TraceQuery":["TempoTraceQuery"]}`
65
- const queryTypeMap = (0, _react.useMemo)(()=>{
66
- const map = {
67
- TimeSeriesQuery: [],
68
- TraceQuery: [],
69
- ProfileQuery: [],
70
- LogQuery: [],
71
- AlertsQuery: [],
72
- SilencesQuery: []
73
- };
74
- if (timeSeriesQueryPlugins) {
75
- timeSeriesQueryPlugins.forEach((plugin)=>{
76
- map[plugin.kind]?.push(plugin.spec.name);
77
- });
78
- }
79
- if (traceQueryPlugins) {
80
- traceQueryPlugins.forEach((plugin)=>{
81
- map[plugin.kind]?.push(plugin.spec.name);
82
- });
83
- }
84
- if (profileQueryPlugins) {
85
- profileQueryPlugins.forEach((plugin)=>{
86
- map[plugin.kind]?.push(plugin.spec.name);
87
- });
88
- }
89
- if (logQueries) {
90
- logQueries.forEach((plugin)=>{
91
- map[plugin.kind]?.push(plugin.spec.name);
92
- });
93
- }
94
- if (alertsQueryPlugins) {
95
- alertsQueryPlugins.forEach((plugin)=>{
96
- map[plugin.kind]?.push(plugin.spec.name);
97
- });
98
- }
99
- if (silencesQueryPlugins) {
100
- silencesQueryPlugins.forEach((plugin)=>{
101
- map[plugin.kind]?.push(plugin.spec.name);
102
- });
103
- }
104
- return map;
105
- }, [
106
- timeSeriesQueryPlugins,
107
- traceQueryPlugins,
108
- profileQueryPlugins,
109
- logQueries,
110
- alertsQueryPlugins,
111
- silencesQueryPlugins
112
- ]);
113
- const getQueryType = (0, _react.useCallback)((pluginKind)=>{
114
- const isLoading = (pluginKind)=>{
115
- switch(pluginKind){
116
- case 'PrometheusTimeSeriesQuery':
117
- return isTimeSeriesQueryLoading;
118
- case 'TempoTraceQuery':
119
- return isTraceQueryPluginLoading;
120
- case 'PyroscopeProfileQuery':
121
- return isProfileQueryPluginLoading;
122
- case 'LokiLogQuery':
123
- return isLogQueryPluginLoading;
124
- case 'AlertmanagerAlertsQuery':
125
- return isAlertsQueryPluginLoading;
126
- case 'AlertmanagerSilencesQuery':
127
- return isSilencesQueryPluginLoading;
128
- }
129
- return isTraceQueryPluginLoading || isTimeSeriesQueryLoading || isProfileQueryPluginLoading || isLogQueryPluginLoading || isAlertsQueryPluginLoading || isSilencesQueryPluginLoading;
130
- };
131
- if (isLoading(pluginKind)) {
132
- return undefined;
133
- }
134
- for(const queryType in queryTypeMap){
135
- if (queryTypeMap[queryType]?.includes(pluginKind)) {
136
- return queryType;
137
- }
138
- }
139
- throw new Error(`Unable to determine the query type: ${pluginKind}`);
140
- }, [
141
- queryTypeMap,
142
- isTimeSeriesQueryLoading,
143
- isTraceQueryPluginLoading,
144
- isProfileQueryPluginLoading,
145
- isLogQueryPluginLoading,
146
- isAlertsQueryPluginLoading,
147
- isSilencesQueryPluginLoading
148
- ]);
149
- return getQueryType;
150
- }
@@ -27,7 +27,6 @@ _export_star(require("./alerts-queries"), exports);
27
27
  _export_star(require("./silences-queries"), exports);
28
28
  _export_star(require("./item-actions"), exports);
29
29
  _export_star(require("./DataQueriesProvider"), exports);
30
- _export_star(require("./QueryCountProvider"), exports);
31
30
  _export_star(require("./RouterProvider"), exports);
32
31
  _export_star(require("./UsageMetricsProvider"), exports);
33
32
  function _export_star(from, to) {
@@ -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;AAQpE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAmC,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEnF;;GAEG;AACH,UAAU,yBAAyB;IACjC,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,eAAe,CAAC;IACvB,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAC1D,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAC5D,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,oBAAoB,uHAqFhC,CAAC"}
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;AAoBpE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAmC,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGnF;;GAEG;AACH,UAAU,yBAAyB;IACjC,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,eAAe,CAAC;IACvB,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAC1D,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAC5D,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,oBAAoB,uHAyIhC,CAAC"}
@@ -12,14 +12,18 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
  import { produce } from 'immer';
15
- import { Stack, IconButton, Typography, Box, CircularProgress } from '@mui/material';
15
+ import { Stack, IconButton, Typography, Box, CircularProgress, TextField, InputAdornment } from '@mui/material';
16
16
  import DeleteIcon from 'mdi-material-ui/DeleteOutline';
17
17
  import ChevronDown from 'mdi-material-ui/ChevronDown';
18
18
  import ChevronRight from 'mdi-material-ui/ChevronRight';
19
- import { forwardRef } from 'react';
19
+ import { forwardRef, useState } from 'react';
20
20
  import AlertIcon from 'mdi-material-ui/Alert';
21
21
  import { InfoTooltip } from '@perses-dev/components';
22
+ import PencilIcon from 'mdi-material-ui/Pencil';
23
+ import CheckIcon from 'mdi-material-ui/Check';
24
+ import CloseIcon from 'mdi-material-ui/Close';
22
25
  import { PluginEditor } from '../PluginEditor';
26
+ import { defaultQueryName } from './utils';
23
27
  /**
24
28
  * Container for a query editor. This component is responsible for rendering the query editor, and make it collapsible
25
29
  * to not take too much space.
@@ -33,6 +37,16 @@ import { PluginEditor } from '../PluginEditor';
33
37
  * @constructor
34
38
  */ export const QueryEditorContainer = /*#__PURE__*/ forwardRef((props, ref)=>{
35
39
  const { queryTypes, index, query, queryResult, filteredQueryPlugins, isCollapsed, onDelete, onChange, onQueryRun, onCollapseExpand } = props;
40
+ // The displayed name is always derived from props so it stays in sync with the
41
+ // current query/index, even when queries are added, removed or reordered.
42
+ const displayedName = query.spec.name ?? defaultQueryName(index);
43
+ const [isEditingName, setIsEditingName] = useState(false);
44
+ function handleNameSave(name) {
45
+ setIsEditingName(false);
46
+ onChange(index, produce(query, (draft)=>{
47
+ draft.spec.name = name;
48
+ }));
49
+ }
36
50
  return /*#__PURE__*/ _jsxs(Stack, {
37
51
  spacing: 1,
38
52
  children: [
@@ -45,19 +59,40 @@ import { PluginEditor } from '../PluginEditor';
45
59
  children: [
46
60
  /*#__PURE__*/ _jsxs(Stack, {
47
61
  direction: "row",
62
+ gap: 1,
63
+ sx: {
64
+ width: '100%'
65
+ },
48
66
  children: [
49
67
  /*#__PURE__*/ _jsx(IconButton, {
50
68
  size: "small",
69
+ sx: {
70
+ width: 'fit-content',
71
+ height: 'fit-content'
72
+ },
51
73
  onClick: ()=>onCollapseExpand(index),
52
74
  children: isCollapsed ? /*#__PURE__*/ _jsx(ChevronRight, {}) : /*#__PURE__*/ _jsx(ChevronDown, {})
53
75
  }),
54
- /*#__PURE__*/ _jsxs(Typography, {
55
- variant: "overline",
56
- component: "h4",
57
- children: [
58
- "Query #",
59
- index + 1
60
- ]
76
+ /*#__PURE__*/ _jsx(Stack, {
77
+ direction: "row",
78
+ gap: 1,
79
+ alignItems: "center",
80
+ alignContent: "center",
81
+ sx: {
82
+ width: '100%',
83
+ '&:hover button': {
84
+ visibility: 'visible'
85
+ }
86
+ },
87
+ children: isEditingName ? /*#__PURE__*/ _jsx(QueryNameInput, {
88
+ initialName: displayedName,
89
+ onSave: handleNameSave,
90
+ onCancel: ()=>setIsEditingName(false)
91
+ }, displayedName) : /*#__PURE__*/ _jsx(Typography, {
92
+ variant: "overline",
93
+ component: "h4",
94
+ children: displayedName
95
+ })
61
96
  })
62
97
  ]
63
98
  }),
@@ -101,11 +136,24 @@ import { PluginEditor } from '../PluginEditor';
101
136
  ]
102
137
  })
103
138
  }),
104
- onDelete && /*#__PURE__*/ _jsx(IconButton, {
105
- "aria-label": "delete query",
106
- size: "small",
107
- onClick: ()=>onDelete && onDelete(index),
108
- children: /*#__PURE__*/ _jsx(DeleteIcon, {})
139
+ /*#__PURE__*/ _jsxs(Stack, {
140
+ direction: "row",
141
+ children: [
142
+ !isEditingName && /*#__PURE__*/ _jsx(IconButton, {
143
+ "aria-label": "edit query name",
144
+ size: "small",
145
+ onClick: ()=>setIsEditingName(true),
146
+ children: /*#__PURE__*/ _jsx(PencilIcon, {
147
+ fontSize: "small"
148
+ })
149
+ }),
150
+ onDelete && /*#__PURE__*/ _jsx(IconButton, {
151
+ "aria-label": "delete query",
152
+ size: "small",
153
+ onClick: ()=>onDelete && onDelete(index),
154
+ children: /*#__PURE__*/ _jsx(DeleteIcon, {})
155
+ })
156
+ ]
109
157
  })
110
158
  ]
111
159
  })
@@ -123,6 +171,43 @@ import { PluginEditor } from '../PluginEditor';
123
171
  }, index);
124
172
  });
125
173
  QueryEditorContainer.displayName = 'QueryEditorContainer';
174
+ /**
175
+ * Self-contained input to edit a query name. The draft value is local state seeded from
176
+ * `initialName`; callers reset it by changing the `key` (remounting) rather than syncing
177
+ * with an useEffect.
178
+ */ function QueryNameInput({ initialName, onSave, onCancel }) {
179
+ const [draftName, setDraftName] = useState(initialName);
180
+ return /*#__PURE__*/ _jsx(TextField, {
181
+ size: "small",
182
+ variant: "outlined",
183
+ label: "Query name",
184
+ "aria-label": "query name",
185
+ value: draftName,
186
+ onChange: (e)=>setDraftName(e.target.value),
187
+ fullWidth: true,
188
+ InputProps: {
189
+ endAdornment: /*#__PURE__*/ _jsxs(InputAdornment, {
190
+ position: "end",
191
+ children: [
192
+ /*#__PURE__*/ _jsx(IconButton, {
193
+ size: "small",
194
+ "aria-label": "cancel edit",
195
+ onClick: onCancel,
196
+ edge: "end",
197
+ children: /*#__PURE__*/ _jsx(CloseIcon, {})
198
+ }),
199
+ /*#__PURE__*/ _jsx(IconButton, {
200
+ size: "small",
201
+ "aria-label": "save query name",
202
+ onClick: ()=>onSave(draftName),
203
+ edge: "end",
204
+ children: /*#__PURE__*/ _jsx(CheckIcon, {})
205
+ })
206
+ ]
207
+ })
208
+ }
209
+ });
210
+ }
126
211
  /**
127
212
  * Editor for a query definition. This component is responsible for rendering the plugin editor for the given query.
128
213
  * This will allow user to select a plugin extending from the given supported query types, and then edit the plugin