@perses-dev/plugin-system 0.52.0-beta.3 → 0.52.0-beta.4

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 (62) hide show
  1. package/dist/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +1 -0
  2. package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +1 -0
  3. package/dist/cjs/components/PluginEditor/PluginEditor.js +27 -4
  4. package/dist/cjs/components/PluginSpecEditor/PluginSpecEditor.js +13 -9
  5. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +1 -0
  6. package/dist/cjs/model/log-queries.js +16 -0
  7. package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +10 -2
  8. package/dist/cjs/runtime/DataQueriesProvider/model.js +17 -4
  9. package/dist/cjs/runtime/RouterProvider.js +2 -1
  10. package/dist/cjs/runtime/log-queries.js +68 -0
  11. package/dist/cjs/runtime/variables.js +15 -0
  12. package/dist/cjs/test/mock-data.js +24 -0
  13. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
  14. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +1 -0
  15. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
  16. package/dist/components/MultiQueryEditor/QueryEditorContainer.js +1 -0
  17. package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
  18. package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
  19. package/dist/components/PluginEditor/PluginEditor.js +27 -4
  20. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  21. package/dist/components/PluginEditor/plugin-editor-api.d.ts +1 -0
  22. package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
  23. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  24. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
  25. package/dist/components/PluginSpecEditor/PluginSpecEditor.js +13 -9
  26. package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
  27. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  28. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +1 -0
  29. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  30. package/dist/model/log-queries.d.ts +24 -0
  31. package/dist/model/log-queries.d.ts.map +1 -0
  32. package/dist/model/log-queries.js +15 -0
  33. package/dist/model/log-queries.js.map +1 -0
  34. package/dist/model/plugin-base.d.ts +4 -0
  35. package/dist/model/plugin-base.d.ts.map +1 -1
  36. package/dist/model/plugin-base.js.map +1 -1
  37. package/dist/model/plugins.d.ts +2 -0
  38. package/dist/model/plugins.d.ts.map +1 -1
  39. package/dist/model/plugins.js.map +1 -1
  40. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -1
  41. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +10 -2
  42. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
  43. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
  44. package/dist/runtime/DataQueriesProvider/model.js +17 -4
  45. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  46. package/dist/runtime/RouterProvider.d.ts +2 -2
  47. package/dist/runtime/RouterProvider.d.ts.map +1 -1
  48. package/dist/runtime/RouterProvider.js +2 -1
  49. package/dist/runtime/RouterProvider.js.map +1 -1
  50. package/dist/runtime/log-queries.d.ts +7 -0
  51. package/dist/runtime/log-queries.d.ts.map +1 -0
  52. package/dist/runtime/log-queries.js +52 -0
  53. package/dist/runtime/log-queries.js.map +1 -0
  54. package/dist/runtime/variables.d.ts +1 -0
  55. package/dist/runtime/variables.d.ts.map +1 -1
  56. package/dist/runtime/variables.js +13 -0
  57. package/dist/runtime/variables.js.map +1 -1
  58. package/dist/test/mock-data.d.ts +2 -1
  59. package/dist/test/mock-data.d.ts.map +1 -1
  60. package/dist/test/mock-data.js +21 -0
  61. package/dist/test/mock-data.js.map +1 -1
  62. package/package.json +3 -3
@@ -238,6 +238,7 @@ function DatasourceEditorForm(props) {
238
238
  'Datasource'
239
239
  ],
240
240
  pluginKindLabel: "Source",
241
+ withRunQueryButton: false,
241
242
  value: {
242
243
  selection: {
243
244
  type: 'Datasource',
@@ -93,6 +93,7 @@ const QueryEditorContainer = ({ queryTypes, index, query, isCollapsed, onDelete,
93
93
  return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
94
94
  ...others,
95
95
  children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_PluginEditor.PluginEditor, {
96
+ withRunQueryButton: true,
96
97
  pluginTypes: queryTypes,
97
98
  pluginKindLabel: "Query Type",
98
99
  value: {
@@ -24,6 +24,7 @@ const _jsxruntime = require("react/jsx-runtime");
24
24
  const _material = require("@mui/material");
25
25
  const _Reload = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/Reload"));
26
26
  const _components = require("@perses-dev/components");
27
+ const _react = require("react");
27
28
  const _PluginKindSelect = require("../PluginKindSelect");
28
29
  const _PluginSpecEditor = require("../PluginSpecEditor");
29
30
  const _plugineditorapi = require("./plugin-editor-api");
@@ -34,8 +35,28 @@ function _interop_require_default(obj) {
34
35
  }
35
36
  function PluginEditor(props) {
36
37
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
37
- const { value, pluginTypes, pluginKindLabel, onChange: _, isReadonly, ...others } = props;
38
+ const { value, withRunQueryButton = true, pluginTypes, pluginKindLabel, onChange: _, isReadonly, ...others } = props;
38
39
  const { pendingSelection, isLoading, error, onSelectionChange, onSpecChange } = (0, _plugineditorapi.usePluginEditor)(props);
40
+ const [watchedQuery, setWatchQuery] = (0, _react.useState)(value.spec['query']);
41
+ const runQueryHandler = (0, _react.useCallback)(()=>{
42
+ onSpecChange({
43
+ ...value.spec,
44
+ query: watchedQuery
45
+ });
46
+ }, [
47
+ value.spec,
48
+ onSpecChange,
49
+ watchedQuery
50
+ ]);
51
+ let queryHandlerSettings = undefined;
52
+ if (withRunQueryButton) {
53
+ queryHandlerSettings = {
54
+ runWithOnBlur: false,
55
+ watchQueryChanges: (query)=>{
56
+ setWatchQuery(query);
57
+ }
58
+ };
59
+ }
39
60
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Box, {
40
61
  ...others,
41
62
  children: [
@@ -63,7 +84,8 @@ function PluginEditor(props) {
63
84
  helperText: error?.message,
64
85
  onChange: onSelectionChange
65
86
  }),
66
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
87
+ withRunQueryButton && !isLoading && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
88
+ "data-testid": "run_query_button",
67
89
  variant: "contained",
68
90
  sx: {
69
91
  marginTop: 1.5,
@@ -72,7 +94,7 @@ function PluginEditor(props) {
72
94
  marginLeft: 'auto'
73
95
  },
74
96
  startIcon: /*#__PURE__*/ (0, _jsxruntime.jsx)(_Reload.default, {}),
75
- onClick: ()=>onSpecChange(value.spec),
97
+ onClick: runQueryHandler,
76
98
  children: "Run Query"
77
99
  })
78
100
  ]
@@ -83,7 +105,8 @@ function PluginEditor(props) {
83
105
  pluginSelection: value.selection,
84
106
  value: value.spec,
85
107
  onChange: onSpecChange,
86
- isReadonly: isReadonly
108
+ isReadonly: isReadonly,
109
+ queryHandlerSettings: queryHandlerSettings
87
110
  })
88
111
  })
89
112
  ]
@@ -22,6 +22,7 @@ Object.defineProperty(exports, "PluginSpecEditor", {
22
22
  });
23
23
  const _jsxruntime = require("react/jsx-runtime");
24
24
  const _components = require("@perses-dev/components");
25
+ const _material = require("@mui/material");
25
26
  const _runtime = require("../../runtime");
26
27
  function PluginSpecEditor(props) {
27
28
  const { pluginSelection: { type: pluginType, kind: pluginKind }, ...others } = props;
@@ -31,21 +32,24 @@ function PluginSpecEditor(props) {
31
32
  error: error
32
33
  });
33
34
  }
34
- // TODO: Proper loading indicator
35
35
  if (isLoading) {
36
- return null;
36
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
37
+ width: "100%",
38
+ sx: {
39
+ alignItems: 'center',
40
+ justifyContent: 'center'
41
+ },
42
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.CircularProgress, {})
43
+ });
37
44
  }
38
- if (plugin === undefined) {
45
+ if (!plugin) {
39
46
  throw new Error(`Missing implementation for ${pluginType} plugin with kind '${pluginKind}'`);
40
47
  }
41
48
  if (pluginType === 'Panel') {
42
49
  throw new Error('This editor should not be used for panel type. Please use Panel Spec Editor instead.');
43
50
  }
44
51
  const { OptionsEditorComponent } = plugin;
45
- if (OptionsEditorComponent !== undefined) {
46
- return /*#__PURE__*/ (0, _jsxruntime.jsx)(OptionsEditorComponent, {
47
- ...others
48
- });
49
- }
50
- return null;
52
+ return OptionsEditorComponent ? /*#__PURE__*/ (0, _jsxruntime.jsx)(OptionsEditorComponent, {
53
+ ...others
54
+ }) : null;
51
55
  }
@@ -207,6 +207,7 @@ function ListVariableEditorForm({ action, control }) {
207
207
  name: "spec.plugin",
208
208
  render: ({ field })=>{
209
209
  return /*#__PURE__*/ (0, _jsxruntime.jsx)(_PluginEditor.PluginEditor, {
210
+ withRunQueryButton: true,
210
211
  width: "100%",
211
212
  pluginTypes: [
212
213
  'Variable'
@@ -0,0 +1,16 @@
1
+ // Copyright 2025 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
+ });
@@ -40,6 +40,7 @@ const _timeseriesqueries = require("../time-series-queries");
40
40
  const _tracequeries = require("../trace-queries");
41
41
  const _profilequeries = require("../profile-queries");
42
42
  const _UsageMetricsProvider = require("../UsageMetricsProvider");
43
+ const _logqueries = require("../log-queries");
43
44
  const _model = require("./model");
44
45
  const DataQueriesContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
45
46
  function useDataQueriesContext() {
@@ -86,20 +87,25 @@ function DataQueriesProvider(props) {
86
87
  const traceResults = (0, _tracequeries.useTraceQueries)(traceQueries);
87
88
  const profileQueries = queryDefinitions.filter((definition)=>definition.kind === 'ProfileQuery');
88
89
  const profileResults = (0, _profilequeries.useProfileQueries)(profileQueries);
90
+ const logQueries = queryDefinitions.filter((definition)=>definition.kind === 'LogQuery');
91
+ const logResults = (0, _logqueries.useLogQueries)(logQueries);
89
92
  const refetchAll = (0, _react.useCallback)(()=>{
90
93
  timeSeriesResults.forEach((result)=>result.refetch());
91
94
  traceResults.forEach((result)=>result.refetch());
92
95
  profileResults.forEach((result)=>result.refetch());
96
+ logResults.forEach((result)=>result.refetch());
93
97
  }, [
94
98
  timeSeriesResults,
95
99
  traceResults,
96
- profileResults
100
+ profileResults,
101
+ logResults
97
102
  ]);
98
103
  const ctx = (0, _react.useMemo)(()=>{
99
104
  const mergedQueryResults = [
100
105
  ...(0, _model.transformQueryResults)(timeSeriesResults, timeSeriesQueries),
101
106
  ...(0, _model.transformQueryResults)(traceResults, traceQueries),
102
- ...(0, _model.transformQueryResults)(profileResults, profileQueries)
107
+ ...(0, _model.transformQueryResults)(profileResults, profileQueries),
108
+ ...(0, _model.transformQueryResults)(logResults, logQueries)
103
109
  ];
104
110
  if (queryOptions?.enabled) {
105
111
  for (const result of mergedQueryResults){
@@ -126,6 +132,8 @@ function DataQueriesProvider(props) {
126
132
  traceResults,
127
133
  profileQueries,
128
134
  profileResults,
135
+ logQueries,
136
+ logResults,
129
137
  refetchAll,
130
138
  queryOptions?.enabled,
131
139
  usageMetrics
@@ -52,12 +52,16 @@ function useQueryType() {
52
52
  const { data: profileQueryPlugins, isLoading: isProfileQueryPluginLoading } = (0, _pluginregistry.useListPluginMetadata)([
53
53
  'ProfileQuery'
54
54
  ]);
55
+ const { data: logQueries, isLoading: isLogQueryPluginLoading } = (0, _pluginregistry.useListPluginMetadata)([
56
+ 'LogQuery'
57
+ ]);
55
58
  // For example, `map: {"TimeSeriesQuery":["PrometheusTimeSeriesQuery"],"TraceQuery":["TempoTraceQuery"]}`
56
59
  const queryTypeMap = (0, _react.useMemo)(()=>{
57
60
  const map = {
58
61
  TimeSeriesQuery: [],
59
62
  TraceQuery: [],
60
- ProfileQuery: []
63
+ ProfileQuery: [],
64
+ LogQuery: []
61
65
  };
62
66
  if (timeSeriesQueryPlugins) {
63
67
  timeSeriesQueryPlugins.forEach((plugin)=>{
@@ -74,11 +78,17 @@ function useQueryType() {
74
78
  map[plugin.kind]?.push(plugin.spec.name);
75
79
  });
76
80
  }
81
+ if (logQueries) {
82
+ logQueries.forEach((plugin)=>{
83
+ map[plugin.kind]?.push(plugin.spec.name);
84
+ });
85
+ }
77
86
  return map;
78
87
  }, [
79
88
  timeSeriesQueryPlugins,
80
89
  traceQueryPlugins,
81
- profileQueryPlugins
90
+ profileQueryPlugins,
91
+ logQueries
82
92
  ]);
83
93
  const getQueryType = (0, _react.useCallback)((pluginKind)=>{
84
94
  const isLoading = (pluginKind)=>{
@@ -89,8 +99,10 @@ function useQueryType() {
89
99
  return isTraceQueryPluginLoading;
90
100
  case 'PyroscopeProfileQuery':
91
101
  return isProfileQueryPluginLoading;
102
+ case 'LokiLogQuery':
103
+ return isLogQueryPluginLoading;
92
104
  }
93
- return isTraceQueryPluginLoading || isTimeSeriesQueryLoading || isProfileQueryPluginLoading;
105
+ return isTraceQueryPluginLoading || isTimeSeriesQueryLoading || isProfileQueryPluginLoading || isLogQueryPluginLoading;
94
106
  };
95
107
  if (isLoading(pluginKind)) {
96
108
  return undefined;
@@ -105,7 +117,8 @@ function useQueryType() {
105
117
  queryTypeMap,
106
118
  isTimeSeriesQueryLoading,
107
119
  isTraceQueryPluginLoading,
108
- isProfileQueryPluginLoading
120
+ isProfileQueryPluginLoading,
121
+ isLogQueryPluginLoading
109
122
  ]);
110
123
  return getQueryType;
111
124
  }
@@ -82,7 +82,8 @@ const RouterContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
82
82
  function useRouterContext() {
83
83
  const ctx = (0, _react.useContext)(RouterContext);
84
84
  if (ctx === undefined) {
85
- throw new Error('No RouterContext found. Did you forget a <RouterProvider>?');
85
+ console.warn('No RouterContext found. Did you forget a <RouterProvider>?');
86
+ return {};
86
87
  }
87
88
  return ctx;
88
89
  }
@@ -0,0 +1,68 @@
1
+ // Copyright 2025 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: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ LOG_QUERY_KEY: function() {
25
+ return LOG_QUERY_KEY;
26
+ },
27
+ useLogQueries: function() {
28
+ return useLogQueries;
29
+ }
30
+ });
31
+ const _reactquery = require("@tanstack/react-query");
32
+ const _datasources = require("./datasources");
33
+ const _pluginregistry = require("./plugin-registry");
34
+ const _TimeRangeProvider = require("./TimeRangeProvider");
35
+ const _variables = require("./variables");
36
+ const LOG_QUERY_KEY = 'LogQuery';
37
+ function useLogQueries(definitions) {
38
+ const { getPlugin } = (0, _pluginregistry.usePluginRegistry)();
39
+ const datasourceStore = (0, _datasources.useDatasourceStore)();
40
+ const { absoluteTimeRange } = (0, _TimeRangeProvider.useTimeRange)();
41
+ const variableValues = (0, _variables.useVariableValues)();
42
+ const context = {
43
+ timeRange: absoluteTimeRange,
44
+ variableState: variableValues,
45
+ datasourceStore,
46
+ refreshKey: ''
47
+ };
48
+ return (0, _reactquery.useQueries)({
49
+ queries: definitions.map((definition)=>{
50
+ const queryKey = [
51
+ definition,
52
+ datasourceStore,
53
+ absoluteTimeRange,
54
+ variableValues
55
+ ];
56
+ const logQueryKind = definition?.spec?.plugin?.kind;
57
+ return {
58
+ queryKey: queryKey,
59
+ queryFn: async ()=>{
60
+ const plugin = await getPlugin(LOG_QUERY_KEY, logQueryKind);
61
+ const data = await plugin.getLogData(definition.spec.plugin.spec, context);
62
+ return data;
63
+ },
64
+ structuralSharing: false
65
+ };
66
+ })
67
+ });
68
+ }
@@ -27,6 +27,9 @@ _export(exports, {
27
27
  VariableStoreStateMap: function() {
28
28
  return VariableStoreStateMap;
29
29
  },
30
+ replaceVariablesInString: function() {
31
+ return replaceVariablesInString;
32
+ },
30
33
  useAllVariableValues: function() {
31
34
  return useAllVariableValues;
32
35
  },
@@ -137,6 +140,18 @@ function useAllVariableValues(names) {
137
140
  builtinVariableValues
138
141
  ]);
139
142
  }
143
+ function replaceVariablesInString(text, variableValues, extraVariables) {
144
+ const vars = {
145
+ ...variableValues
146
+ }; // shallow clone to avoid modifying the original object
147
+ for (const [key, value] of Object.entries(extraVariables ?? {})){
148
+ vars[key] = {
149
+ value,
150
+ loading: false
151
+ };
152
+ }
153
+ return (0, _utils.replaceVariables)(text, vars);
154
+ }
140
155
  function useReplaceVariablesInString(str) {
141
156
  const variablesInString = str ? (0, _utils.parseVariables)(str) : [];
142
157
  const variableValues = useAllVariableValues(variablesInString);
@@ -21,6 +21,9 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
+ MOCK_LOG_DATA: function() {
25
+ return MOCK_LOG_DATA;
26
+ },
24
27
  MOCK_PROFILE_DATA: function() {
25
28
  return MOCK_PROFILE_DATA;
26
29
  },
@@ -102,6 +105,27 @@ const MOCK_TRACE_DATA = {
102
105
  executedQueryString: '{ duration > 1000ms }'
103
106
  }
104
107
  };
108
+ const MOCK_LOG_DATA = {
109
+ totalCount: 2,
110
+ entries: [
111
+ {
112
+ timestamp: 1666479357903,
113
+ line: 'Error: Something went wrong',
114
+ labels: {
115
+ level: 'error',
116
+ service: 'backend'
117
+ }
118
+ },
119
+ {
120
+ timestamp: 1666479382282,
121
+ line: 'Info: Request processed successfully',
122
+ labels: {
123
+ level: 'info',
124
+ service: 'frontend'
125
+ }
126
+ }
127
+ ]
128
+ };
105
129
  const MOCK_PROFILE_DATA = {
106
130
  profile: {
107
131
  stackTrace: {
@@ -1 +1 @@
1
- {"version":3,"file":"DatasourceEditorForm.d.ts","sourceRoot":"","sources":["../../../src/components/DatasourceEditorForm/DatasourceEditorForm.tsx"],"names":[],"mappings":"AAgBA,OAAO,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAY,MAAM,OAAO,CAAC;AAMtE,UAAU,yBAAyB;IACjC,2BAA2B,EAAE,oBAAoB,CAAC;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,MAAM,EAAE,CAAC,GAAG,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAC5C,OAAO,EAAE,qBAAqB,CAAC;IAC/B,QAAQ,CAAC,EAAE,qBAAqB,CAAC;CAClC;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,YAAY,CA6MnF"}
1
+ {"version":3,"file":"DatasourceEditorForm.d.ts","sourceRoot":"","sources":["../../../src/components/DatasourceEditorForm/DatasourceEditorForm.tsx"],"names":[],"mappings":"AAgBA,OAAO,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAY,MAAM,OAAO,CAAC;AAMtE,UAAU,yBAAyB;IACjC,2BAA2B,EAAE,oBAAoB,CAAC;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,MAAM,EAAE,CAAC,GAAG,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAC5C,OAAO,EAAE,qBAAqB,CAAC;IAC/B,QAAQ,CAAC,EAAE,qBAAqB,CAAC;CAClC;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,YAAY,CA8MnF"}
@@ -228,6 +228,7 @@ export function DatasourceEditorForm(props) {
228
228
  'Datasource'
229
229
  ],
230
230
  pluginKindLabel: "Source",
231
+ withRunQueryButton: false,
231
232
  value: {
232
233
  selection: {
233
234
  type: 'Datasource',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/DatasourceEditorForm/DatasourceEditorForm.tsx"],"sourcesContent":["// Copyright 2023 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 { zodResolver } from '@hookform/resolvers/zod';\nimport { Box, Divider, FormControlLabel, Grid, Stack, Switch, TextField, Typography } from '@mui/material';\nimport { DiscardChangesConfirmationDialog, FormActions } from '@perses-dev/components';\nimport { Action, DatasourceDefinition } from '@perses-dev/core';\nimport { DispatchWithoutAction, ReactElement, useState } from 'react';\nimport { Controller, FormProvider, SubmitHandler, useForm } from 'react-hook-form';\nimport { useValidationSchemas } from '../../context';\nimport { getSubmitText, getTitleAction } from '../../utils';\nimport { PluginEditor } from '../PluginEditor';\n\ninterface DatasourceEditorFormProps {\n initialDatasourceDefinition: DatasourceDefinition;\n action: Action;\n isDraft: boolean;\n isReadonly?: boolean;\n onActionChange?: (action: Action) => void;\n onSave: (def: DatasourceDefinition) => void;\n onClose: DispatchWithoutAction;\n onDelete?: DispatchWithoutAction;\n}\n\nexport function DatasourceEditorForm(props: DatasourceEditorFormProps): ReactElement {\n const { initialDatasourceDefinition, action, isDraft, isReadonly, onActionChange, onSave, onClose, onDelete } = props;\n\n const [isDiscardDialogOpened, setDiscardDialogOpened] = useState<boolean>(false);\n const titleAction = getTitleAction(action, isDraft);\n const submitText = getSubmitText(action, isDraft);\n\n const { datasourceEditorSchema } = useValidationSchemas();\n const form = useForm<DatasourceDefinition>({\n resolver: zodResolver(datasourceEditorSchema),\n mode: 'onBlur',\n defaultValues: initialDatasourceDefinition,\n });\n\n /*\n * Remove empty fields that are optional\n */\n function clearFormData(data: DatasourceDefinition): DatasourceDefinition {\n const result = { ...data };\n if (result.spec.display?.name === undefined && result.spec.display?.description === undefined) {\n delete result.spec.display;\n }\n return result;\n }\n\n const processForm: SubmitHandler<DatasourceDefinition> = (data: DatasourceDefinition) => {\n onSave(clearFormData(data));\n };\n\n // When user click on cancel, several possibilities:\n // - create action: ask for discard approval\n // - update action: ask for discard approval if changed\n // - read action: don´t ask for discard approval\n function handleCancel(): void {\n if (JSON.stringify(initialDatasourceDefinition) !== JSON.stringify(clearFormData(form.getValues()))) {\n setDiscardDialogOpened(true);\n } else {\n onClose();\n }\n }\n\n return (\n <FormProvider {...form}>\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n padding: (theme) => theme.spacing(1, 2),\n borderBottom: (theme) => `1px solid ${theme.palette.divider}`,\n }}\n >\n <Typography variant=\"h2\">{titleAction} Datasource</Typography>\n <FormActions\n action={action}\n submitText={submitText}\n isReadonly={isReadonly}\n isValid={form.formState.isValid}\n onActionChange={onActionChange}\n onSubmit={form.handleSubmit(processForm)}\n onDelete={onDelete}\n onCancel={handleCancel}\n />\n </Box>\n <Box padding={2} sx={{ overflowY: 'scroll' }}>\n <Grid container spacing={2} mb={2}>\n <Grid item xs={4}>\n <Controller\n control={form.control}\n name=\"name\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n required\n fullWidth\n name=\"name\"\n label=\"Name\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n disabled: action === 'update' && !isDraft,\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={8}>\n <Controller\n control={form.control}\n name=\"spec.display.name\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n name=\"title\"\n label=\"Display Label\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={12}>\n <Controller\n control={form.control}\n name=\"spec.display.description\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n name=\"description\"\n label=\"Description\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={6} sx={{ paddingTop: '5px !important' }}>\n <Stack>\n <Controller\n control={form.control}\n name=\"spec.default\"\n render={({ field }) => (\n <FormControlLabel\n label=\"Set as default\"\n control={\n <Switch\n {...field}\n checked={!!field.value}\n readOnly={action === 'read'}\n onChange={(event) => {\n if (action === 'read') return; // ReadOnly prop is not blocking user interaction...\n field.onChange(event);\n }}\n />\n }\n />\n )}\n />\n <Typography variant=\"caption\">\n Whether this datasource should be the default {form.getValues().spec.plugin.kind} to be used\n </Typography>\n </Stack>\n </Grid>\n </Grid>\n <Divider />\n <Typography py={1} variant=\"h3\">\n Plugin Options\n </Typography>\n <Controller\n control={form.control}\n name=\"spec.plugin\"\n render={({ field }) => (\n <PluginEditor\n width=\"100%\"\n pluginTypes={['Datasource']}\n pluginKindLabel=\"Source\"\n value={{\n selection: {\n type: 'Datasource',\n kind: field.value.kind,\n },\n spec: field.value.spec,\n }}\n isReadonly={action === 'read'}\n onChange={(v) => {\n field.onChange({ kind: v.selection.kind, spec: v.spec });\n }}\n />\n )}\n />\n </Box>\n <DiscardChangesConfirmationDialog\n description=\"Are you sure you want to discard your changes? Changes cannot be recovered.\"\n isOpen={isDiscardDialogOpened}\n onCancel={() => setDiscardDialogOpened(false)}\n onDiscardChanges={() => {\n setDiscardDialogOpened(false);\n onClose();\n }}\n />\n </FormProvider>\n );\n}\n"],"names":["zodResolver","Box","Divider","FormControlLabel","Grid","Stack","Switch","TextField","Typography","DiscardChangesConfirmationDialog","FormActions","useState","Controller","FormProvider","useForm","useValidationSchemas","getSubmitText","getTitleAction","PluginEditor","DatasourceEditorForm","props","initialDatasourceDefinition","action","isDraft","isReadonly","onActionChange","onSave","onClose","onDelete","isDiscardDialogOpened","setDiscardDialogOpened","titleAction","submitText","datasourceEditorSchema","form","resolver","mode","defaultValues","clearFormData","data","result","spec","display","name","undefined","description","processForm","handleCancel","JSON","stringify","getValues","sx","alignItems","padding","theme","spacing","borderBottom","palette","divider","variant","isValid","formState","onSubmit","handleSubmit","onCancel","overflowY","container","mb","item","xs","control","render","field","fieldState","required","fullWidth","label","InputLabelProps","shrink","InputProps","disabled","readOnly","error","helperText","message","value","onChange","event","paddingTop","checked","plugin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ACxD;;;;;0BAKR,KAAChC;gBACCoC,aAAY;gBACZsD,QAAQtE;gBACRmC,UAAU,IAAMlC,uBAAuB;gBACvCsE,kBAAkB;oBAChBtE,uBAAuB;oBACvBH;gBACF;;;;AAIR"}
1
+ {"version":3,"sources":["../../../src/components/DatasourceEditorForm/DatasourceEditorForm.tsx"],"sourcesContent":["// Copyright 2023 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 { zodResolver } from '@hookform/resolvers/zod';\nimport { Box, Divider, FormControlLabel, Grid, Stack, Switch, TextField, Typography } from '@mui/material';\nimport { DiscardChangesConfirmationDialog, FormActions } from '@perses-dev/components';\nimport { Action, DatasourceDefinition } from '@perses-dev/core';\nimport { DispatchWithoutAction, ReactElement, useState } from 'react';\nimport { Controller, FormProvider, SubmitHandler, useForm } from 'react-hook-form';\nimport { useValidationSchemas } from '../../context';\nimport { getSubmitText, getTitleAction } from '../../utils';\nimport { PluginEditor } from '../PluginEditor';\n\ninterface DatasourceEditorFormProps {\n initialDatasourceDefinition: DatasourceDefinition;\n action: Action;\n isDraft: boolean;\n isReadonly?: boolean;\n onActionChange?: (action: Action) => void;\n onSave: (def: DatasourceDefinition) => void;\n onClose: DispatchWithoutAction;\n onDelete?: DispatchWithoutAction;\n}\n\nexport function DatasourceEditorForm(props: DatasourceEditorFormProps): ReactElement {\n const { initialDatasourceDefinition, action, isDraft, isReadonly, onActionChange, onSave, onClose, onDelete } = props;\n\n const [isDiscardDialogOpened, setDiscardDialogOpened] = useState<boolean>(false);\n const titleAction = getTitleAction(action, isDraft);\n const submitText = getSubmitText(action, isDraft);\n\n const { datasourceEditorSchema } = useValidationSchemas();\n const form = useForm<DatasourceDefinition>({\n resolver: zodResolver(datasourceEditorSchema),\n mode: 'onBlur',\n defaultValues: initialDatasourceDefinition,\n });\n\n /*\n * Remove empty fields that are optional\n */\n function clearFormData(data: DatasourceDefinition): DatasourceDefinition {\n const result = { ...data };\n if (result.spec.display?.name === undefined && result.spec.display?.description === undefined) {\n delete result.spec.display;\n }\n return result;\n }\n\n const processForm: SubmitHandler<DatasourceDefinition> = (data: DatasourceDefinition) => {\n onSave(clearFormData(data));\n };\n\n // When user click on cancel, several possibilities:\n // - create action: ask for discard approval\n // - update action: ask for discard approval if changed\n // - read action: don´t ask for discard approval\n function handleCancel(): void {\n if (JSON.stringify(initialDatasourceDefinition) !== JSON.stringify(clearFormData(form.getValues()))) {\n setDiscardDialogOpened(true);\n } else {\n onClose();\n }\n }\n\n return (\n <FormProvider {...form}>\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n padding: (theme) => theme.spacing(1, 2),\n borderBottom: (theme) => `1px solid ${theme.palette.divider}`,\n }}\n >\n <Typography variant=\"h2\">{titleAction} Datasource</Typography>\n <FormActions\n action={action}\n submitText={submitText}\n isReadonly={isReadonly}\n isValid={form.formState.isValid}\n onActionChange={onActionChange}\n onSubmit={form.handleSubmit(processForm)}\n onDelete={onDelete}\n onCancel={handleCancel}\n />\n </Box>\n <Box padding={2} sx={{ overflowY: 'scroll' }}>\n <Grid container spacing={2} mb={2}>\n <Grid item xs={4}>\n <Controller\n control={form.control}\n name=\"name\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n required\n fullWidth\n name=\"name\"\n label=\"Name\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n disabled: action === 'update' && !isDraft,\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={8}>\n <Controller\n control={form.control}\n name=\"spec.display.name\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n name=\"title\"\n label=\"Display Label\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={12}>\n <Controller\n control={form.control}\n name=\"spec.display.description\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n name=\"description\"\n label=\"Description\"\n InputLabelProps={{ shrink: action === 'read' ? true : undefined }}\n InputProps={{\n readOnly: action === 'read',\n }}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={field.value ?? ''}\n onChange={(event) => {\n field.onChange(event);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={6} sx={{ paddingTop: '5px !important' }}>\n <Stack>\n <Controller\n control={form.control}\n name=\"spec.default\"\n render={({ field }) => (\n <FormControlLabel\n label=\"Set as default\"\n control={\n <Switch\n {...field}\n checked={!!field.value}\n readOnly={action === 'read'}\n onChange={(event) => {\n if (action === 'read') return; // ReadOnly prop is not blocking user interaction...\n field.onChange(event);\n }}\n />\n }\n />\n )}\n />\n <Typography variant=\"caption\">\n Whether this datasource should be the default {form.getValues().spec.plugin.kind} to be used\n </Typography>\n </Stack>\n </Grid>\n </Grid>\n <Divider />\n <Typography py={1} variant=\"h3\">\n Plugin Options\n </Typography>\n <Controller\n control={form.control}\n name=\"spec.plugin\"\n render={({ field }) => (\n <PluginEditor\n width=\"100%\"\n pluginTypes={['Datasource']}\n pluginKindLabel=\"Source\"\n withRunQueryButton={false}\n value={{\n selection: {\n type: 'Datasource',\n kind: field.value.kind,\n },\n spec: field.value.spec,\n }}\n isReadonly={action === 'read'}\n onChange={(v) => {\n field.onChange({ kind: v.selection.kind, spec: v.spec });\n }}\n />\n )}\n />\n </Box>\n <DiscardChangesConfirmationDialog\n description=\"Are you sure you want to discard your changes? Changes cannot be recovered.\"\n isOpen={isDiscardDialogOpened}\n onCancel={() => setDiscardDialogOpened(false)}\n onDiscardChanges={() => {\n setDiscardDialogOpened(false);\n onClose();\n }}\n />\n </FormProvider>\n );\n}\n"],"names":["zodResolver","Box","Divider","FormControlLabel","Grid","Stack","Switch","TextField","Typography","DiscardChangesConfirmationDialog","FormActions","useState","Controller","FormProvider","useForm","useValidationSchemas","getSubmitText","getTitleAction","PluginEditor","DatasourceEditorForm","props","initialDatasourceDefinition","action","isDraft","isReadonly","onActionChange","onSave","onClose","onDelete","isDiscardDialogOpened","setDiscardDialogOpened","titleAction","submitText","datasourceEditorSchema","form","resolver","mode","defaultValues","clearFormData","data","result","spec","display","name","undefined","description","processForm","handleCancel","JSON","stringify","getValues","sx","alignItems","padding","theme","spacing","borderBottom","palette","divider","variant","isValid","formState","onSubmit","handleSubmit","onCancel","overflowY","container","mb","item","xs","control","render","field","fieldState","required","fullWidth","label","InputLabelProps","shrink","InputProps","disabled","readOnly","error","helperText","message","value","onChange","event","paddingTop","checked","plugin","kind","py","width","pluginTypes","pluginKindLabel","withRunQueryButton","selection","type","v","isOpen","onDiscardChanges"],"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,SAASA,WAAW,QAAQ,0BAA0B;AACtD,SAASC,GAAG,EAAEC,OAAO,EAAEC,gBAAgB,EAAEC,IAAI,EAAEC,KAAK,EAAEC,MAAM,EAAEC,SAAS,EAAEC,UAAU,QAAQ,gBAAgB;AAC3G,SAASC,gCAAgC,EAAEC,WAAW,QAAQ,yBAAyB;AAEvF,SAA8CC,QAAQ,QAAQ,QAAQ;AACtE,SAASC,UAAU,EAAEC,YAAY,EAAiBC,OAAO,QAAQ,kBAAkB;AACnF,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,CAACC;wDACjB;;;;sDAMV,MAAC/E;4CAAWmD,SAAQ;;gDAAU;gDACmBzB,KAAKgB,SAAS,GAAGT,IAAI,CAACiD,MAAM,CAACC,IAAI;gDAAC;;;;;;;;kCAKzF,KAACzF;kCACD,KAACM;wBAAWoF,IAAI;wBAAGjC,SAAQ;kCAAK;;kCAGhC,KAAC/C;wBACC0D,SAASpC,KAAKoC,OAAO;wBACrB3B,MAAK;wBACL4B,QAAQ,CAAC,EAAEC,KAAK,EAAE,iBAChB,KAACtD;gCACC2E,OAAM;gCACNC,aAAa;oCAAC;iCAAa;gCAC3BC,iBAAgB;gCAChBC,oBAAoB;gCACpBX,OAAO;oCACLY,WAAW;wCACTC,MAAM;wCACNP,MAAMnB,MAAMa,KAAK,CAACM,IAAI;oCACxB;oCACAlD,MAAM+B,MAAMa,KAAK,CAAC5C,IAAI;gCACxB;gCACAjB,YAAYF,WAAW;gCACvBgE,UAAU,CAACa;oCACT3B,MAAMc,QAAQ,CAAC;wCAAEK,MAAMQ,EAAEF,SAAS,CAACN,IAAI;wCAAElD,MAAM0D,EAAE1D,IAAI;oCAAC;gCACxD;;;;;0BAKR,KAAChC;gBACCoC,aAAY;gBACZuD,QAAQvE;gBACRmC,UAAU,IAAMlC,uBAAuB;gBACvCuE,kBAAkB;oBAChBvE,uBAAuB;oBACvBH;gBACF;;;;AAIR"}
@@ -89,6 +89,7 @@ import { PluginEditor } from '../PluginEditor';
89
89
  return /*#__PURE__*/ _jsx(Box, {
90
90
  ...others,
91
91
  children: /*#__PURE__*/ _jsx(PluginEditor, {
92
+ withRunQueryButton: true,
92
93
  pluginTypes: queryTypes,
93
94
  pluginKindLabel: "Query Type",
94
95
  value: {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/MultiQueryEditor/QueryEditorContainer.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 { produce } from 'immer';\nimport { QueryDefinition, QueryPluginType } from '@perses-dev/core';\nimport { Stack, IconButton, Typography, BoxProps, Box } from '@mui/material';\nimport DeleteIcon from 'mdi-material-ui/DeleteOutline';\nimport ChevronDown from 'mdi-material-ui/ChevronDown';\nimport ChevronRight from 'mdi-material-ui/ChevronRight';\nimport { ReactElement } from 'react';\nimport { PluginEditor, PluginEditorProps } from '../PluginEditor';\n\n/**\n * Properties for {@link QueryEditorContainer}\n */\ninterface QueryEditorContainerProps {\n queryTypes: QueryPluginType[];\n index: number;\n query: QueryDefinition;\n onChange: (index: number, query: QueryDefinition) => void;\n onCollapseExpand: (index: number) => void;\n isCollapsed?: boolean;\n onDelete?: (index: number) => void;\n}\n\n/**\n * Container for a query editor. This component is responsible for rendering the query editor, and make it collapsible\n * to not take too much space.\n * @param queryTypes the supported query types\n * @param index the index of the query in the list\n * @param query the query definition\n * @param isCollapsed whether the query editor is collapsed or not\n * @param onDelete callback when the query is deleted\n * @param onChange callback when the query is changed\n * @param onCollapseExpand callback when the query is collapsed or expanded\n * @constructor\n */\nexport const QueryEditorContainer = ({\n queryTypes,\n index,\n query,\n isCollapsed,\n onDelete,\n onChange,\n onCollapseExpand,\n}: QueryEditorContainerProps): ReactElement => {\n return (\n <Stack key={index} spacing={1}>\n <Stack direction=\"row\" alignItems=\"center\" borderBottom={1} borderColor={(theme) => theme.palette.divider}>\n <IconButton size=\"small\" onClick={() => onCollapseExpand(index)}>\n {isCollapsed ? <ChevronRight /> : <ChevronDown />}\n </IconButton>\n <Typography variant=\"overline\" component=\"h4\">\n Query #{index + 1}\n </Typography>\n <IconButton\n size=\"small\"\n // Use `visibility` to ensure that the row has the same height when delete button is visible or not visible\n sx={{ marginLeft: 'auto', visibility: `${onDelete ? 'visible' : 'hidden'}` }}\n onClick={() => onDelete && onDelete(index)}\n >\n <DeleteIcon />\n </IconButton>\n </Stack>\n {!isCollapsed && <QueryEditor queryTypes={queryTypes} value={query} onChange={(next) => onChange(index, next)} />}\n </Stack>\n );\n};\n\n// Props on MUI Box that we don't want people to pass because we're either redefining them or providing them in\n// this component\ntype OmittedMuiProps = 'children' | 'value' | 'onChange';\ninterface QueryEditorProps extends Omit<BoxProps, OmittedMuiProps> {\n queryTypes: QueryPluginType[];\n value: QueryDefinition;\n onChange: (next: QueryDefinition) => void;\n}\n\n/**\n * Editor for a query definition. This component is responsible for rendering the plugin editor for the given query.\n * This will allow user to select a plugin extending from the given supported query types, and then edit the plugin\n * spec for this plugin.\n * @param props\n * @constructor\n */\nfunction QueryEditor(props: QueryEditorProps): ReactElement {\n const { value, onChange, queryTypes, ...others } = props;\n\n const handlePluginChange: PluginEditorProps['onChange'] = (next) => {\n onChange(\n produce(value, (draft) => {\n draft.kind = next.selection.type;\n draft.spec.plugin.kind = next.selection.kind;\n draft.spec.plugin.spec = next.spec;\n })\n );\n };\n\n return (\n <Box {...others}>\n <PluginEditor\n pluginTypes={queryTypes}\n pluginKindLabel=\"Query Type\"\n value={{\n selection: {\n kind: value.spec.plugin.kind,\n type: value.kind,\n },\n spec: value.spec.plugin.spec,\n }}\n onChange={handlePluginChange}\n />\n </Box>\n );\n}\n"],"names":["produce","Stack","IconButton","Typography","Box","DeleteIcon","ChevronDown","ChevronRight","PluginEditor","QueryEditorContainer","queryTypes","index","query","isCollapsed","onDelete","onChange","onCollapseExpand","spacing","direction","alignItems","borderBottom","borderColor","theme","palette","divider","size","onClick","variant","component","sx","marginLeft","visibility","QueryEditor","value","next","props","others","handlePluginChange","draft","kind","selection","type","spec","plugin","pluginTypes","pluginKindLabel"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CA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,GAAGD;IAEnD,MAAME,qBAAoD,CAACH;QACzDnB,SACEf,QAAQiC,OAAO,CAACK;YACdA,MAAMC,IAAI,GAAGL,KAAKM,SAAS,CAACC,IAAI;YAChCH,MAAMI,IAAI,CAACC,MAAM,CAACJ,IAAI,GAAGL,KAAKM,SAAS,CAACD,IAAI;YAC5CD,MAAMI,IAAI,CAACC,MAAM,CAACD,IAAI,GAAGR,KAAKQ,IAAI;QACpC;IAEJ;IAEA,qBACE,KAACtC;QAAK,GAAGgC,MAAM;kBACb,cAAA,KAAC5B;YACCoC,aAAalC;YACbmC,iBAAgB;YAChBZ,OAAO;gBACLO,WAAW;oBACTD,MAAMN,MAAMS,IAAI,CAACC,MAAM,CAACJ,IAAI;oBAC5BE,MAAMR,MAAMM,IAAI;gBAClB;gBACAG,MAAMT,MAAMS,IAAI,CAACC,MAAM,CAACD,IAAI;YAC9B;YACA3B,UAAUsB;;;AAIlB"}
1
+ {"version":3,"sources":["../../../src/components/MultiQueryEditor/QueryEditorContainer.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 { produce } from 'immer';\nimport { QueryDefinition, QueryPluginType } from '@perses-dev/core';\nimport { Stack, IconButton, Typography, BoxProps, Box } from '@mui/material';\nimport DeleteIcon from 'mdi-material-ui/DeleteOutline';\nimport ChevronDown from 'mdi-material-ui/ChevronDown';\nimport ChevronRight from 'mdi-material-ui/ChevronRight';\nimport { ReactElement } from 'react';\nimport { PluginEditor, PluginEditorProps } from '../PluginEditor';\n\n/**\n * Properties for {@link QueryEditorContainer}\n */\ninterface QueryEditorContainerProps {\n queryTypes: QueryPluginType[];\n index: number;\n query: QueryDefinition;\n onChange: (index: number, query: QueryDefinition) => void;\n onCollapseExpand: (index: number) => void;\n isCollapsed?: boolean;\n onDelete?: (index: number) => void;\n}\n\n/**\n * Container for a query editor. This component is responsible for rendering the query editor, and make it collapsible\n * to not take too much space.\n * @param queryTypes the supported query types\n * @param index the index of the query in the list\n * @param query the query definition\n * @param isCollapsed whether the query editor is collapsed or not\n * @param onDelete callback when the query is deleted\n * @param onChange callback when the query is changed\n * @param onCollapseExpand callback when the query is collapsed or expanded\n * @constructor\n */\nexport const QueryEditorContainer = ({\n queryTypes,\n index,\n query,\n isCollapsed,\n onDelete,\n onChange,\n onCollapseExpand,\n}: QueryEditorContainerProps): ReactElement => {\n return (\n <Stack key={index} spacing={1}>\n <Stack direction=\"row\" alignItems=\"center\" borderBottom={1} borderColor={(theme) => theme.palette.divider}>\n <IconButton size=\"small\" onClick={() => onCollapseExpand(index)}>\n {isCollapsed ? <ChevronRight /> : <ChevronDown />}\n </IconButton>\n <Typography variant=\"overline\" component=\"h4\">\n Query #{index + 1}\n </Typography>\n <IconButton\n size=\"small\"\n // Use `visibility` to ensure that the row has the same height when delete button is visible or not visible\n sx={{ marginLeft: 'auto', visibility: `${onDelete ? 'visible' : 'hidden'}` }}\n onClick={() => onDelete && onDelete(index)}\n >\n <DeleteIcon />\n </IconButton>\n </Stack>\n {!isCollapsed && <QueryEditor queryTypes={queryTypes} value={query} onChange={(next) => onChange(index, next)} />}\n </Stack>\n );\n};\n\n// Props on MUI Box that we don't want people to pass because we're either redefining them or providing them in\n// this component\ntype OmittedMuiProps = 'children' | 'value' | 'onChange';\ninterface QueryEditorProps extends Omit<BoxProps, OmittedMuiProps> {\n queryTypes: QueryPluginType[];\n value: QueryDefinition;\n onChange: (next: QueryDefinition) => void;\n}\n\n/**\n * Editor for a query definition. This component is responsible for rendering the plugin editor for the given query.\n * This will allow user to select a plugin extending from the given supported query types, and then edit the plugin\n * spec for this plugin.\n * @param props\n * @constructor\n */\nfunction QueryEditor(props: QueryEditorProps): ReactElement {\n const { value, onChange, queryTypes, ...others } = props;\n\n const handlePluginChange: PluginEditorProps['onChange'] = (next) => {\n onChange(\n produce(value, (draft) => {\n draft.kind = next.selection.type;\n draft.spec.plugin.kind = next.selection.kind;\n draft.spec.plugin.spec = next.spec;\n })\n );\n };\n\n return (\n <Box {...others}>\n <PluginEditor\n withRunQueryButton\n pluginTypes={queryTypes}\n pluginKindLabel=\"Query Type\"\n value={{\n selection: {\n kind: value.spec.plugin.kind,\n type: value.kind,\n },\n spec: value.spec.plugin.spec,\n }}\n onChange={handlePluginChange}\n />\n </Box>\n );\n}\n"],"names":["produce","Stack","IconButton","Typography","Box","DeleteIcon","ChevronDown","ChevronRight","PluginEditor","QueryEditorContainer","queryTypes","index","query","isCollapsed","onDelete","onChange","onCollapseExpand","spacing","direction","alignItems","borderBottom","borderColor","theme","palette","divider","size","onClick","variant","component","sx","marginLeft","visibility","QueryEditor","value","next","props","others","handlePluginChange","draft","kind","selection","type","spec","plugin","withRunQueryButton","pluginTypes","pluginKindLabel"],"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,SAASA,OAAO,QAAQ,QAAQ;AAEhC,SAASC,KAAK,EAAEC,UAAU,EAAEC,UAAU,EAAYC,GAAG,QAAQ,gBAAgB;AAC7E,OAAOC,gBAAgB,gCAAgC;AACvD,OAAOC,iBAAiB,8BAA8B;AACtD,OAAOC,kBAAkB,+BAA+B;AAExD,SAASC,YAAY,QAA2B,kBAAkB;AAelE;;;;;;;;;;;CAWC,GACD,OAAO,MAAMC,uBAAuB,CAAC,EACnCC,UAAU,EACVC,KAAK,EACLC,KAAK,EACLC,WAAW,EACXC,QAAQ,EACRC,QAAQ,EACRC,g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I;oBAC5BE,MAAMR,MAAMM,IAAI;gBAClB;gBACAG,MAAMT,MAAMS,IAAI,CAACC,MAAM,CAACD,IAAI;YAC9B;YACA3B,UAAUsB;;;AAIlB"}
@@ -1 +1 @@
1
- {"version":3,"file":"PluginEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"names":[],"mappings":"AAgBA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAGrC,OAAO,EAAE,iBAAiB,EAAmB,MAAM,qBAAqB,CAAC;AAEzE;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CAyCnE"}
1
+ {"version":3,"file":"PluginEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"names":[],"mappings":"AAgBA,OAAO,EAAE,YAAY,EAAyB,MAAM,OAAO,CAAC;AAG5D,OAAO,EAAE,iBAAiB,EAAmB,MAAM,qBAAqB,CAAC;AAEzE;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CA8DnE"}
@@ -14,6 +14,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { Box, Button } from '@mui/material';
15
15
  import Reload from 'mdi-material-ui/Reload';
16
16
  import { ErrorAlert, ErrorBoundary } from '@perses-dev/components';
17
+ import { useCallback, useState } from 'react';
17
18
  import { PluginKindSelect } from '../PluginKindSelect';
18
19
  import { PluginSpecEditor } from '../PluginSpecEditor';
19
20
  import { usePluginEditor } from './plugin-editor-api';
@@ -26,8 +27,28 @@ import { usePluginEditor } from './plugin-editor-api';
26
27
  * `usePluginEditor` hook that powers this component.
27
28
  */ export function PluginEditor(props) {
28
29
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
- const { value, pluginTypes, pluginKindLabel, onChange: _, isReadonly, ...others } = props;
30
+ const { value, withRunQueryButton = true, pluginTypes, pluginKindLabel, onChange: _, isReadonly, ...others } = props;
30
31
  const { pendingSelection, isLoading, error, onSelectionChange, onSpecChange } = usePluginEditor(props);
32
+ const [watchedQuery, setWatchQuery] = useState(value.spec['query']);
33
+ const runQueryHandler = useCallback(()=>{
34
+ onSpecChange({
35
+ ...value.spec,
36
+ query: watchedQuery
37
+ });
38
+ }, [
39
+ value.spec,
40
+ onSpecChange,
41
+ watchedQuery
42
+ ]);
43
+ let queryHandlerSettings = undefined;
44
+ if (withRunQueryButton) {
45
+ queryHandlerSettings = {
46
+ runWithOnBlur: false,
47
+ watchQueryChanges: (query)=>{
48
+ setWatchQuery(query);
49
+ }
50
+ };
51
+ }
31
52
  return /*#__PURE__*/ _jsxs(Box, {
32
53
  ...others,
33
54
  children: [
@@ -55,7 +76,8 @@ import { usePluginEditor } from './plugin-editor-api';
55
76
  helperText: error?.message,
56
77
  onChange: onSelectionChange
57
78
  }),
58
- /*#__PURE__*/ _jsx(Button, {
79
+ withRunQueryButton && !isLoading && /*#__PURE__*/ _jsx(Button, {
80
+ "data-testid": "run_query_button",
59
81
  variant: "contained",
60
82
  sx: {
61
83
  marginTop: 1.5,
@@ -64,7 +86,7 @@ import { usePluginEditor } from './plugin-editor-api';
64
86
  marginLeft: 'auto'
65
87
  },
66
88
  startIcon: /*#__PURE__*/ _jsx(Reload, {}),
67
- onClick: ()=>onSpecChange(value.spec),
89
+ onClick: runQueryHandler,
68
90
  children: "Run Query"
69
91
  })
70
92
  ]
@@ -75,7 +97,8 @@ import { usePluginEditor } from './plugin-editor-api';
75
97
  pluginSelection: value.selection,
76
98
  value: value.spec,
77
99
  onChange: onSpecChange,
78
- isReadonly: isReadonly
100
+ isReadonly: isReadonly,
101
+ queryHandlerSettings: queryHandlerSettings
79
102
  })
80
103
  })
81
104
  ]