@perses-dev/plugin-system 0.53.0-beta.0 → 0.53.0-beta.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.
- package/dist/cjs/components/MultiQueryEditor/MultiQueryEditor.js +11 -5
- package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +5 -3
- package/dist/cjs/components/PluginEditor/PluginEditor.js +3 -2
- package/dist/cjs/components/PluginEditor/plugin-editor-api.js +4 -4
- package/dist/cjs/components/PluginKindSelect/PluginKindSelect.js +9 -3
- package/dist/cjs/components/PluginRegistry/PluginRegistry.js +2 -2
- package/dist/cjs/components/PluginRegistry/plugin-indexes.js +2 -2
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +5 -1
- package/dist/cjs/runtime/trace-queries.js +0 -11
- package/dist/cjs/utils/event.js +30 -0
- package/dist/cjs/utils/index.js +1 -0
- package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts +1 -0
- package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js +11 -5
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts +1 -0
- package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts.map +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.js +5 -3
- package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.js +3 -2
- package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts +1 -0
- package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.js +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.d.ts +1 -0
- package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.js +9 -3
- package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.js +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.js +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js +5 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
- package/dist/runtime/profile-queries.d.ts.map +1 -1
- package/dist/runtime/profile-queries.js.map +1 -1
- package/dist/runtime/trace-queries.d.ts +1 -5
- package/dist/runtime/trace-queries.d.ts.map +1 -1
- package/dist/runtime/trace-queries.js +0 -8
- package/dist/runtime/trace-queries.js.map +1 -1
- package/dist/utils/event.d.ts +8 -0
- package/dist/utils/event.d.ts.map +1 -0
- package/dist/utils/event.js +27 -0
- package/dist/utils/event.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -32,7 +32,7 @@ function _interop_require_default(obj) {
|
|
|
32
32
|
default: obj
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
function useDefaultQueryDefinition(queryTypes) {
|
|
35
|
+
function useDefaultQueryDefinition(queryTypes, filteredQueryPlugins) {
|
|
36
36
|
// Build the default query plugin
|
|
37
37
|
// This will be used only if the queries are empty, to open a starting query
|
|
38
38
|
// Firs the default query type
|
|
@@ -41,7 +41,12 @@ function useDefaultQueryDefinition(queryTypes) {
|
|
|
41
41
|
// Use as default the plugin kind explicitly set as default or the first in the list
|
|
42
42
|
const { data: queryPlugins, isLoading } = (0, _runtime.useListPluginMetadata)(queryTypes);
|
|
43
43
|
const { defaultPluginKinds } = (0, _runtime.usePluginRegistry)();
|
|
44
|
-
|
|
44
|
+
let defaultQueryKind = '';
|
|
45
|
+
if (filteredQueryPlugins?.length) {
|
|
46
|
+
defaultQueryKind = queryPlugins?.find((i)=>filteredQueryPlugins.includes(i.spec.name)).spec.name ?? '';
|
|
47
|
+
} else {
|
|
48
|
+
defaultQueryKind = defaultPluginKinds?.[defaultQueryType] ?? queryPlugins?.[0]?.spec.name ?? '';
|
|
49
|
+
}
|
|
45
50
|
const { data: defaultQueryPlugin } = (0, _runtime.usePlugin)(defaultQueryType, defaultQueryKind, {
|
|
46
51
|
useErrorBoundary: true,
|
|
47
52
|
enabled: true
|
|
@@ -61,8 +66,8 @@ function useDefaultQueryDefinition(queryTypes) {
|
|
|
61
66
|
};
|
|
62
67
|
}
|
|
63
68
|
const MultiQueryEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
64
|
-
const { queryTypes, queries = [], onChange } = props;
|
|
65
|
-
const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes);
|
|
69
|
+
const { queryTypes, queries = [], filteredQueryPlugins, onChange } = props;
|
|
70
|
+
const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes, filteredQueryPlugins);
|
|
66
71
|
// State for which queries are collapsed
|
|
67
72
|
const [queriesCollapsed, setQueriesCollapsed] = (0, _react.useState)(queries.map(()=>false));
|
|
68
73
|
// Query handlers
|
|
@@ -130,7 +135,8 @@ const MultiQueryEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
130
135
|
isCollapsed: !!queriesCollapsed[i],
|
|
131
136
|
onChange: handleQueryChange,
|
|
132
137
|
onDelete: queries.length > 1 ? handleQueryDelete : undefined,
|
|
133
|
-
onCollapseExpand: handleQueryCollapseExpand
|
|
138
|
+
onCollapseExpand: handleQueryCollapseExpand,
|
|
139
|
+
filteredQueryPlugins: filteredQueryPlugins
|
|
134
140
|
}, i))
|
|
135
141
|
}),
|
|
136
142
|
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
|
|
@@ -35,7 +35,7 @@ function _interop_require_default(obj) {
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
const QueryEditorContainer = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
38
|
-
const { queryTypes, index, query, isCollapsed, onDelete, onChange, onCollapseExpand } = props;
|
|
38
|
+
const { queryTypes, filteredQueryPlugins, index, query, isCollapsed, onDelete, onChange, onCollapseExpand } = props;
|
|
39
39
|
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
|
|
40
40
|
spacing: 1,
|
|
41
41
|
children: [
|
|
@@ -71,6 +71,7 @@ const QueryEditorContainer = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>
|
|
|
71
71
|
]
|
|
72
72
|
}),
|
|
73
73
|
!isCollapsed && /*#__PURE__*/ (0, _jsxruntime.jsx)(QueryEditor, {
|
|
74
|
+
filteredQueryPlugins: filteredQueryPlugins,
|
|
74
75
|
ref: ref,
|
|
75
76
|
queryTypes: queryTypes,
|
|
76
77
|
value: query,
|
|
@@ -87,7 +88,7 @@ QueryEditorContainer.displayName = 'QueryEditorContainer';
|
|
|
87
88
|
* @param props
|
|
88
89
|
* @constructor
|
|
89
90
|
*/ const QueryEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
90
|
-
const { value, onChange, queryTypes, ...others } = props;
|
|
91
|
+
const { value, onChange, queryTypes, filteredQueryPlugins, ...others } = props;
|
|
91
92
|
const { refresh } = (0, _runtime.useTimeRange)();
|
|
92
93
|
const handlePluginChange = (next)=>{
|
|
93
94
|
onChange((0, _immer.produce)(value, (draft)=>{
|
|
@@ -111,7 +112,8 @@ QueryEditorContainer.displayName = 'QueryEditorContainer';
|
|
|
111
112
|
},
|
|
112
113
|
spec: value.spec.plugin.spec
|
|
113
114
|
},
|
|
114
|
-
onChange: handlePluginChange
|
|
115
|
+
onChange: handlePluginChange,
|
|
116
|
+
filteredQueryPlugins: filteredQueryPlugins
|
|
115
117
|
})
|
|
116
118
|
});
|
|
117
119
|
});
|
|
@@ -34,7 +34,7 @@ function _interop_require_default(obj) {
|
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
const PluginEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
37
|
-
const { value, withRunQueryButton = true, pluginTypes, pluginKindLabel, onChange: _, isReadonly, postExecuteRunQuery: refresh, ...others } = props;
|
|
37
|
+
const { value, withRunQueryButton = true, pluginTypes, pluginKindLabel, onChange: _, isReadonly, postExecuteRunQuery: refresh, filteredQueryPlugins, ...others } = props;
|
|
38
38
|
const { pendingSelection, isLoading, error, onSelectionChange, onSpecChange } = (0, _plugineditorapi.usePluginEditor)(props);
|
|
39
39
|
/*
|
|
40
40
|
We could technically merge the watchedQuery, watchedOtherSpecs into a single watched-object,
|
|
@@ -104,7 +104,8 @@ const PluginEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
|
104
104
|
},
|
|
105
105
|
error: !!error,
|
|
106
106
|
helperText: error?.message,
|
|
107
|
-
onChange: onSelectionChange
|
|
107
|
+
onChange: onSelectionChange,
|
|
108
|
+
filteredQueryPlugins: filteredQueryPlugins
|
|
108
109
|
}),
|
|
109
110
|
withRunQueryButton && !isLoading && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
|
|
110
111
|
"data-testid": "run_query_button",
|
|
@@ -20,23 +20,23 @@ Object.defineProperty(exports, "usePluginEditor", {
|
|
|
20
20
|
return usePluginEditor;
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
|
-
const _core = require("@perses-dev/core");
|
|
24
23
|
const _react = require("react");
|
|
25
24
|
const _immer = require("immer");
|
|
26
25
|
const _runtime = require("../../runtime");
|
|
26
|
+
const _utils = require("../../utils");
|
|
27
27
|
function usePluginEditor(props) {
|
|
28
28
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
29
29
|
const { pluginTypes, value, onHideQueryEditorChange = ()=>{} } = props; // setting onHideQueryEditorChange to empty function here because useEvent requires a function
|
|
30
30
|
// Keep a stable reference, so we don't run the effect below when we don't need to
|
|
31
|
-
const onChange = (0,
|
|
32
|
-
const onHideQuery = (0,
|
|
31
|
+
const onChange = (0, _utils.useEvent)(props.onChange);
|
|
32
|
+
const onHideQuery = (0, _utils.useEvent)(onHideQueryEditorChange);
|
|
33
33
|
// The previous spec state for PluginType and kind and a helper function for remembering current values
|
|
34
34
|
const prevSpecState = (0, _react.useRef)({
|
|
35
35
|
[value.selection.type]: {
|
|
36
36
|
[value.selection.kind]: value.spec
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
|
-
const rememberCurrentSpecState = (0,
|
|
39
|
+
const rememberCurrentSpecState = (0, _utils.useEvent)(()=>{
|
|
40
40
|
let byPluginType = prevSpecState.current[value.selection.type];
|
|
41
41
|
if (byPluginType === undefined) {
|
|
42
42
|
byPluginType = {};
|
|
@@ -25,10 +25,16 @@ const _material = require("@mui/material");
|
|
|
25
25
|
const _react = require("react");
|
|
26
26
|
const _runtime = require("../../runtime");
|
|
27
27
|
const PluginKindSelect = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
|
|
28
|
-
const { pluginTypes, value: propValue, onChange, ...others } = props;
|
|
28
|
+
const { pluginTypes, value: propValue, onChange, filteredQueryPlugins, ...others } = props;
|
|
29
29
|
const { data, isLoading } = (0, _runtime.useListPluginMetadata)(pluginTypes);
|
|
30
|
-
const sortedData = (0, _react.useMemo)(()=>
|
|
31
|
-
|
|
30
|
+
const sortedData = (0, _react.useMemo)(()=>{
|
|
31
|
+
if (filteredQueryPlugins?.length) {
|
|
32
|
+
return data?.filter((i)=>filteredQueryPlugins.includes(i.spec.name))?.sort((a, b)=>a.spec.display.name.localeCompare(b.spec.display.name));
|
|
33
|
+
}
|
|
34
|
+
return data?.sort((a, b)=>a.spec.display.name.localeCompare(b.spec.display.name));
|
|
35
|
+
}, [
|
|
36
|
+
data,
|
|
37
|
+
filteredQueryPlugins
|
|
32
38
|
]);
|
|
33
39
|
// Pass an empty value while options are still loading so MUI doesn't complain about us using an "out of range" value
|
|
34
40
|
const value = !propValue || isLoading ? '' : selectionToOptionValue(propValue);
|
|
@@ -21,9 +21,9 @@ Object.defineProperty(exports, "PluginRegistry", {
|
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
const _jsxruntime = require("react/jsx-runtime");
|
|
24
|
-
const _core = require("@perses-dev/core");
|
|
25
24
|
const _react = require("react");
|
|
26
25
|
const _runtime = require("../../runtime");
|
|
26
|
+
const _utils = require("../../utils");
|
|
27
27
|
const _pluginindexes = require("./plugin-indexes");
|
|
28
28
|
function PluginRegistry(props) {
|
|
29
29
|
const { pluginLoader: { getInstalledPlugins, importPluginModule }, children, defaultPluginKinds } = props;
|
|
@@ -32,7 +32,7 @@ function PluginRegistry(props) {
|
|
|
32
32
|
const importCache = (0, _react.useRef)(new Map());
|
|
33
33
|
// Do useEvent here since this accesses the importPluginModule prop and we want a stable reference to it for the
|
|
34
34
|
// callback below
|
|
35
|
-
const loadPluginModule = (0,
|
|
35
|
+
const loadPluginModule = (0, _utils.useEvent)((resource)=>{
|
|
36
36
|
let request = importCache.current.get(resource);
|
|
37
37
|
if (request === undefined) {
|
|
38
38
|
request = importPluginModule(resource);
|
|
@@ -28,12 +28,12 @@ _export(exports, {
|
|
|
28
28
|
return usePluginIndexes;
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
|
-
const _core = require("@perses-dev/core");
|
|
32
31
|
const _react = require("react");
|
|
32
|
+
const _utils = require("../../utils");
|
|
33
33
|
function usePluginIndexes(getInstalledPlugins) {
|
|
34
34
|
// Creates indexes from the installed plugins data (does useEvent because this accesses the getInstalledPlugins prop
|
|
35
35
|
// and we want a stable reference for the callback below)
|
|
36
|
-
const createPluginIndexes = (0,
|
|
36
|
+
const createPluginIndexes = (0, _utils.useEvent)(async ()=>{
|
|
37
37
|
const installedPlugins = await getInstalledPlugins();
|
|
38
38
|
// Create the two indexes from the installed plugins
|
|
39
39
|
const pluginResourcesByNameAndKind = new Map();
|
|
@@ -211,7 +211,11 @@ function TimeRangeControls({ heightPx, showTimeRangeSelector = true, showRefresh
|
|
|
211
211
|
description: _constants.TOOLTIP_TEXT.refreshInterval,
|
|
212
212
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.RefreshIntervalPicker, {
|
|
213
213
|
timeOptions: DEFAULT_REFRESH_INTERVAL_OPTIONS,
|
|
214
|
-
value:
|
|
214
|
+
value: /* TODO: There is a bug here which should be fixed in a proper way. (This is only a quick remedy)
|
|
215
|
+
display: 1m has the pastDuration of 60s. Initially (if the persisted value is 1m) when the page is loaded, instead of 60s, 1m is passed down.
|
|
216
|
+
This only happens for 1m, because for other items the display and the pastDuration are the same. Example 30s-30s
|
|
217
|
+
HERE The value MUST always be pastDuration, otherwise the component would not work as expected.
|
|
218
|
+
*/ DEFAULT_REFRESH_INTERVAL_OPTIONS.some((i)=>i.value.pastDuration === refreshInterval) ? refreshInterval : DEFAULT_REFRESH_INTERVAL_OPTIONS.find((i)=>i.display === refreshInterval)?.value.pastDuration,
|
|
215
219
|
onChange: handleRefreshIntervalChange,
|
|
216
220
|
height: height
|
|
217
221
|
})
|
|
@@ -24,14 +24,10 @@ _export(exports, {
|
|
|
24
24
|
TRACE_QUERY_KEY: function() {
|
|
25
25
|
return TRACE_QUERY_KEY;
|
|
26
26
|
},
|
|
27
|
-
getUnixTimeRange: function() {
|
|
28
|
-
return getUnixTimeRange;
|
|
29
|
-
},
|
|
30
27
|
useTraceQueries: function() {
|
|
31
28
|
return useTraceQueries;
|
|
32
29
|
}
|
|
33
30
|
});
|
|
34
|
-
const _datefns = require("date-fns");
|
|
35
31
|
const _reactquery = require("@tanstack/react-query");
|
|
36
32
|
const _datasources = require("./datasources");
|
|
37
33
|
const _pluginregistry = require("./plugin-registry");
|
|
@@ -39,13 +35,6 @@ const _TimeRangeProvider = require("./TimeRangeProvider");
|
|
|
39
35
|
const _variables = require("./variables");
|
|
40
36
|
const _utils = require("./utils");
|
|
41
37
|
const TRACE_QUERY_KEY = 'TraceQuery';
|
|
42
|
-
function getUnixTimeRange(timeRange) {
|
|
43
|
-
const { start, end } = timeRange;
|
|
44
|
-
return {
|
|
45
|
-
start: Math.ceil((0, _datefns.getUnixTime)(start)),
|
|
46
|
-
end: Math.ceil((0, _datefns.getUnixTime)(end))
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
38
|
function useTraceQueries(definitions) {
|
|
50
39
|
const { getPlugin } = (0, _pluginregistry.usePluginRegistry)();
|
|
51
40
|
const context = useTraceQueryContext();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright 2023 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
|
+
Object.defineProperty(exports, "useEvent", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return useEvent;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const _react = require("react");
|
|
24
|
+
function useEvent(handler) {
|
|
25
|
+
const handlerRef = (0, _react.useRef)(handler);
|
|
26
|
+
(0, _react.useLayoutEffect)(()=>{
|
|
27
|
+
handlerRef.current = handler;
|
|
28
|
+
});
|
|
29
|
+
return (0, _react.useCallback)((...args)=>handlerRef.current(...args), []);
|
|
30
|
+
}
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
17
|
_export_star(require("./action"), exports);
|
|
18
|
+
_export_star(require("./event"), exports);
|
|
18
19
|
_export_star(require("./variables"), exports);
|
|
19
20
|
function _export_star(from, to) {
|
|
20
21
|
Object.keys(from).forEach(function(k) {
|
|
@@ -3,6 +3,7 @@ import { QueryDefinition, QueryPluginType } from '@perses-dev/core';
|
|
|
3
3
|
import { PluginEditorRef } from '../PluginEditor';
|
|
4
4
|
export interface MultiQueryEditorProps {
|
|
5
5
|
queryTypes: QueryPluginType[];
|
|
6
|
+
filteredQueryPlugins?: string[];
|
|
6
7
|
queries?: QueryDefinition[];
|
|
7
8
|
onChange: (queries: QueryDefinition[]) => void;
|
|
8
9
|
}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,OAAO,CAAC,EAAE,eAAe,EAAE,CAAC;IAC5B,QAAQ,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,IAAI,CAAC;CAChD;AA4CD;;;;;;;GAOG;AAEH,eAAO,MAAM,gBAAgB,mHAoF3B,CAAC"}
|
|
@@ -17,7 +17,7 @@ import { Button, Stack } from '@mui/material';
|
|
|
17
17
|
import AddIcon from 'mdi-material-ui/Plus';
|
|
18
18
|
import { useListPluginMetadata, usePlugin, usePluginRegistry } from '../../runtime';
|
|
19
19
|
import { QueryEditorContainer } from './QueryEditorContainer';
|
|
20
|
-
function useDefaultQueryDefinition(queryTypes) {
|
|
20
|
+
function useDefaultQueryDefinition(queryTypes, filteredQueryPlugins) {
|
|
21
21
|
// Build the default query plugin
|
|
22
22
|
// This will be used only if the queries are empty, to open a starting query
|
|
23
23
|
// Firs the default query type
|
|
@@ -26,7 +26,12 @@ function useDefaultQueryDefinition(queryTypes) {
|
|
|
26
26
|
// Use as default the plugin kind explicitly set as default or the first in the list
|
|
27
27
|
const { data: queryPlugins, isLoading } = useListPluginMetadata(queryTypes);
|
|
28
28
|
const { defaultPluginKinds } = usePluginRegistry();
|
|
29
|
-
|
|
29
|
+
let defaultQueryKind = '';
|
|
30
|
+
if (filteredQueryPlugins?.length) {
|
|
31
|
+
defaultQueryKind = queryPlugins?.find((i)=>filteredQueryPlugins.includes(i.spec.name)).spec.name ?? '';
|
|
32
|
+
} else {
|
|
33
|
+
defaultQueryKind = defaultPluginKinds?.[defaultQueryType] ?? queryPlugins?.[0]?.spec.name ?? '';
|
|
34
|
+
}
|
|
30
35
|
const { data: defaultQueryPlugin } = usePlugin(defaultQueryType, defaultQueryKind, {
|
|
31
36
|
useErrorBoundary: true,
|
|
32
37
|
enabled: true
|
|
@@ -53,8 +58,8 @@ function useDefaultQueryDefinition(queryTypes) {
|
|
|
53
58
|
* @param onChange The callback to call when the queries are modified
|
|
54
59
|
* @constructor
|
|
55
60
|
*/ export const MultiQueryEditor = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
56
|
-
const { queryTypes, queries = [], onChange } = props;
|
|
57
|
-
const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes);
|
|
61
|
+
const { queryTypes, queries = [], filteredQueryPlugins, onChange } = props;
|
|
62
|
+
const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes, filteredQueryPlugins);
|
|
58
63
|
// State for which queries are collapsed
|
|
59
64
|
const [queriesCollapsed, setQueriesCollapsed] = useState(queries.map(()=>false));
|
|
60
65
|
// Query handlers
|
|
@@ -122,7 +127,8 @@ function useDefaultQueryDefinition(queryTypes) {
|
|
|
122
127
|
isCollapsed: !!queriesCollapsed[i],
|
|
123
128
|
onChange: handleQueryChange,
|
|
124
129
|
onDelete: queries.length > 1 ? handleQueryDelete : undefined,
|
|
125
|
-
onCollapseExpand: handleQueryCollapseExpand
|
|
130
|
+
onCollapseExpand: handleQueryCollapseExpand,
|
|
131
|
+
filteredQueryPlugins: filteredQueryPlugins
|
|
126
132
|
}, i))
|
|
127
133
|
}),
|
|
128
134
|
/*#__PURE__*/ _jsx(Button, {
|
|
@@ -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 { 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
|
|
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 filteredQueryPlugins?: string[];\n queries?: QueryDefinition[];\n onChange: (queries: QueryDefinition[]) => void;\n}\n\nfunction useDefaultQueryDefinition(\n queryTypes: QueryPluginType[],\n filteredQueryPlugins?: string[]\n): {\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 // 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\n let defaultQueryKind: string = '';\n\n if (filteredQueryPlugins?.length) {\n defaultQueryKind = queryPlugins?.find((i) => filteredQueryPlugins.includes(i.spec.name))!.spec.name ?? '';\n } else {\n defaultQueryKind = defaultPluginKinds?.[defaultQueryType] ?? queryPlugins?.[0]?.spec.name ?? '';\n }\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 = [], filteredQueryPlugins, onChange } = props;\n const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes, filteredQueryPlugins);\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 filteredQueryPlugins={filteredQueryPlugins}\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","filteredQueryPlugins","defaultQueryType","data","queryPlugins","isLoading","defaultPluginKinds","defaultQueryKind","length","find","i","includes","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","spacing","query","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,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,UAAU,EAAgBC,QAAQ,QAAQ,QAAQ;AAC3D,SAASC,OAAO,QAAQ,QAAQ;AAChC,SAASC,MAAM,EAAEC,KAAK,QAAQ,gBAAgB;AAC9C,OAAOC,aAAa,uBAAuB;AAE3C,SAASC,qBAAqB,EAAEC,SAAS,EAAEC,iBAAiB,QAAQ,gBAAgB;AAEpF,SAASC,oBAAoB,QAAQ,yBAAyB;AAS9D,SAASC,0BACPC,UAA6B,EAC7BC,oBAA+B;IAK/B,iCAAiC;IACjC,4EAA4E;IAE5E,8BAA8B;IAC9B,MAAMC,mBAAmBF,UAAU,CAAC,EAAE;IACtC,+BAA+B;IAC/B,oFAAoF;IACpF,MAAM,EAAEG,MAAMC,YAAY,EAAEC,SAAS,EAAE,GAAGV,sBAAsBK;IAChE,MAAM,EAAEM,kBAAkB,EAAE,GAAGT;IAE/B,IAAIU,mBAA2B;IAE/B,IAAIN,sBAAsBO,QAAQ;QAChCD,mBAAmBH,cAAcK,KAAK,CAACC,IAAMT,qBAAqBU,QAAQ,CAACD,EAAEE,IAAI,CAACC,IAAI,GAAID,KAAKC,QAAQ;IACzG,OAAO;QACLN,mBAAmBD,oBAAoB,CAACJ,iBAAiB,IAAIE,cAAc,CAAC,E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BU,MAAM,CAACN,OAAO;YAC/B,OAAO;mBAAIJ;aAAiB;QAC9B;IACF;IAEA,MAAMW,4BAA4B,CAACP;QACjCH,oBAAoB,CAACD;YACnBA,gBAAgB,CAACI,MAAM,GAAG,CAACJ,gBAAgB,CAACI,MAAM;YAClD,OAAO;mBAAIJ;aAAiB;QAC9B;IACF;IAEA,2CAA2C;IAC3C,MAAMY,mBAAsCd,QAAQhB,MAAM,GACtDgB,UACA,CAACnB,YACC;QAACY;KAA8B,GAC/B,EAAE;IAER,qBACE;;0BACE,KAACxB;gBAAM8C,SAAS;0BACbD,iBAAiBV,GAAG,CAAC,CAACY,OAAwB9B,kBAC7C,KAACZ;wBACCyB,KAAKA;wBACLvB,YAAYA;wBAEZ8B,OAAOpB;wBACP8B,OAAOA;wBACPC,aAAa,CAAC,CAACf,gBAAgB,CAAChB,EAAE;wBAClCe,UAAUI;wBACVa,UAAUlB,QAAQhB,MAAM,GAAG,IAAI2B,oBAAoBQ;wBACnDC,kBAAkBP;wBAClBpC,sBAAsBA;uBAPjBS;;0BAWX,KAAClB;gBAAOqD,SAAQ;gBAAYC,yBAAW,KAACpD;gBAAYqD,IAAI;oBAAEC,WAAW;gBAAE;gBAAGC,SAAShB;0BAAgB;;;;AAKzG,GAAG;AAEHZ,iBAAiB6B,WAAW,GAAG"}
|
|
@@ -8,6 +8,7 @@ interface QueryEditorContainerProps {
|
|
|
8
8
|
queryTypes: QueryPluginType[];
|
|
9
9
|
index: number;
|
|
10
10
|
query: QueryDefinition;
|
|
11
|
+
filteredQueryPlugins?: string[];
|
|
11
12
|
onChange: (index: number, query: QueryDefinition) => void;
|
|
12
13
|
onCollapseExpand: (index: number) => void;
|
|
13
14
|
isCollapsed?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryEditorContainer.d.ts","sourceRoot":"","sources":["../../../src/components/MultiQueryEditor/QueryEditorContainer.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,eAAe,EAAE,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B,uHAiChC,CAAC"}
|
|
@@ -31,7 +31,7 @@ import { useTimeRange } from '../../runtime';
|
|
|
31
31
|
* @param onCollapseExpand callback when the query is collapsed or expanded
|
|
32
32
|
* @constructor
|
|
33
33
|
*/ export const QueryEditorContainer = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
34
|
-
const { queryTypes, index, query, isCollapsed, onDelete, onChange, onCollapseExpand } = props;
|
|
34
|
+
const { queryTypes, filteredQueryPlugins, index, query, isCollapsed, onDelete, onChange, onCollapseExpand } = props;
|
|
35
35
|
return /*#__PURE__*/ _jsxs(Stack, {
|
|
36
36
|
spacing: 1,
|
|
37
37
|
children: [
|
|
@@ -67,6 +67,7 @@ import { useTimeRange } from '../../runtime';
|
|
|
67
67
|
]
|
|
68
68
|
}),
|
|
69
69
|
!isCollapsed && /*#__PURE__*/ _jsx(QueryEditor, {
|
|
70
|
+
filteredQueryPlugins: filteredQueryPlugins,
|
|
70
71
|
ref: ref,
|
|
71
72
|
queryTypes: queryTypes,
|
|
72
73
|
value: query,
|
|
@@ -83,7 +84,7 @@ QueryEditorContainer.displayName = 'QueryEditorContainer';
|
|
|
83
84
|
* @param props
|
|
84
85
|
* @constructor
|
|
85
86
|
*/ const QueryEditor = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
86
|
-
const { value, onChange, queryTypes, ...others } = props;
|
|
87
|
+
const { value, onChange, queryTypes, filteredQueryPlugins, ...others } = props;
|
|
87
88
|
const { refresh } = useTimeRange();
|
|
88
89
|
const handlePluginChange = (next)=>{
|
|
89
90
|
onChange(produce(value, (draft)=>{
|
|
@@ -107,7 +108,8 @@ QueryEditorContainer.displayName = 'QueryEditorContainer';
|
|
|
107
108
|
},
|
|
108
109
|
spec: value.spec.plugin.spec
|
|
109
110
|
},
|
|
110
|
-
onChange: handlePluginChange
|
|
111
|
+
onChange: handlePluginChange,
|
|
112
|
+
filteredQueryPlugins: filteredQueryPlugins
|
|
111
113
|
})
|
|
112
114
|
});
|
|
113
115
|
});
|
|
@@ -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 { forwardRef, ReactElement } from 'react';\nimport { PluginEditor, PluginEditorProps, PluginEditorRef } from '../PluginEditor';\nimport { useTimeRange } from '../../runtime';\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 */\n\nexport const QueryEditorContainer = forwardRef<PluginEditorRef, QueryEditorContainerProps>(\n (props, ref): ReactElement => {\n const { queryTypes, index, query, isCollapsed, onDelete, onChange, onCollapseExpand } = props;\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 && (\n <QueryEditor
|
|
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 { forwardRef, ReactElement } from 'react';\nimport { PluginEditor, PluginEditorProps, PluginEditorRef } from '../PluginEditor';\nimport { useTimeRange } from '../../runtime';\n\n/**\n * Properties for {@link QueryEditorContainer}\n */\ninterface QueryEditorContainerProps {\n queryTypes: QueryPluginType[];\n index: number;\n query: QueryDefinition;\n filteredQueryPlugins?: string[];\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 */\n\nexport const QueryEditorContainer = forwardRef<PluginEditorRef, QueryEditorContainerProps>(\n (props, ref): ReactElement => {\n const { queryTypes, filteredQueryPlugins, index, query, isCollapsed, onDelete, onChange, onCollapseExpand } = props;\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 && (\n <QueryEditor\n filteredQueryPlugins={filteredQueryPlugins}\n ref={ref}\n queryTypes={queryTypes}\n value={query}\n onChange={(next) => onChange(index, next)}\n />\n )}\n </Stack>\n );\n }\n);\n\nQueryEditorContainer.displayName = 'QueryEditorContainer';\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 filteredQueryPlugins?: string[];\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 */\n\nconst QueryEditor = forwardRef<PluginEditorRef, QueryEditorProps>((props, ref): ReactElement => {\n const { value, onChange, queryTypes, filteredQueryPlugins, ...others } = props;\n const { refresh } = useTimeRange();\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 postExecuteRunQuery={refresh}\n ref={ref}\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 filteredQueryPlugins={filteredQueryPlugins}\n />\n </Box>\n );\n});\n\nQueryEditor.displayName = 'QueryEditor';\n"],"names":["produce","Stack","IconButton","Typography","Box","DeleteIcon","ChevronDown","ChevronRight","forwardRef","PluginEditor","useTimeRange","QueryEditorContainer","props","ref","queryTypes","filteredQueryPlugins","index","query","isCollapsed","onDelete","onChange","onCollapseExpand","spacing","direction","alignItems","borderBottom","borderColor","theme","palette","divider","size","onClick","variant","component","sx","marginLeft","visibility","QueryEditor","value","next","displayName","others","refresh","handlePluginChange","draft","kind","selection","type","spec","plugin","postExecuteRunQuery","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;AAC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AM,EAAE8B,OAAO,EAAE,GAAGhC;IACpB,MAAMiC,qBAAoD,CAACJ;QACzDnB,SACEpB,QAAQsC,OAAO,CAACM;YACdA,MAAMC,IAAI,GAAGN,KAAKO,SAAS,CAACC,IAAI;YAChCH,MAAMI,IAAI,CAACC,MAAM,CAACJ,IAAI,GAAGN,KAAKO,SAAS,CAACD,IAAI;YAC5CD,MAAMI,IAAI,CAACC,MAAM,CAACD,IAAI,GAAGT,KAAKS,IAAI;QACpC;IAEJ;IAEA,qBACE,KAAC5C;QAAK,GAAGqC,MAAM;kBACb,cAAA,KAAChC;YACCyC,qBAAqBR;YACrB7B,KAAKA;YACLsC,kBAAkB;YAClBC,aAAatC;YACbuC,iBAAgB;YAChBf,OAAO;gBACLQ,WAAW;oBACTD,MAAMP,MAAMU,IAAI,CAACC,MAAM,CAACJ,IAAI;oBAC5BE,MAAMT,MAAMO,IAAI;gBAClB;gBACAG,MAAMV,MAAMU,IAAI,CAACC,MAAM,CAACD,IAAI;YAC9B;YACA5B,UAAUuB;YACV5B,sBAAsBA;;;AAI9B;AAEAsB,YAAYG,WAAW,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"names":[],"mappings":";AAoBA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAmB,MAAM,qBAAqB,CAAC;AAE1F;;;;;;;GAOG;AAEH,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"PluginEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"names":[],"mappings":";AAoBA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAmB,MAAM,qBAAqB,CAAC;AAE1F;;;;;;;GAOG;AAEH,eAAO,MAAM,YAAY,4HA0FvB,CAAC"}
|
|
@@ -26,7 +26,7 @@ import { usePluginEditor } from './plugin-editor-api';
|
|
|
26
26
|
* previous plugin's spec state. If you just want this behavior, but in a different UI layout from this, try the
|
|
27
27
|
* `usePluginEditor` hook that powers this component.
|
|
28
28
|
*/ export const PluginEditor = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
29
|
-
const { value, withRunQueryButton = true, pluginTypes, pluginKindLabel, onChange: _, isReadonly, postExecuteRunQuery: refresh, ...others } = props;
|
|
29
|
+
const { value, withRunQueryButton = true, pluginTypes, pluginKindLabel, onChange: _, isReadonly, postExecuteRunQuery: refresh, filteredQueryPlugins, ...others } = props;
|
|
30
30
|
const { pendingSelection, isLoading, error, onSelectionChange, onSpecChange } = usePluginEditor(props);
|
|
31
31
|
/*
|
|
32
32
|
We could technically merge the watchedQuery, watchedOtherSpecs into a single watched-object,
|
|
@@ -96,7 +96,8 @@ import { usePluginEditor } from './plugin-editor-api';
|
|
|
96
96
|
},
|
|
97
97
|
error: !!error,
|
|
98
98
|
helperText: error?.message,
|
|
99
|
-
onChange: onSelectionChange
|
|
99
|
+
onChange: onSelectionChange,
|
|
100
|
+
filteredQueryPlugins: filteredQueryPlugins
|
|
100
101
|
}),
|
|
101
102
|
withRunQueryButton && !isLoading && /*#__PURE__*/ _jsx(Button, {
|
|
102
103
|
"data-testid": "run_query_button",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/PluginEditor/PluginEditor.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 { Box, Button } from '@mui/material';\nimport Reload from 'mdi-material-ui/Reload';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { forwardRef, ReactElement, useCallback, useImperativeHandle, useMemo, useState } from 'react';\nimport { UnknownSpec } from '@perses-dev/core';\nimport { PluginKindSelect } from '../PluginKindSelect';\nimport { PluginSpecEditor } from '../PluginSpecEditor';\nimport { PluginEditorProps, PluginEditorRef, usePluginEditor } from './plugin-editor-api';\n\n/**\n * A combination `PluginKindSelect` and `PluginSpecEditor` component. This is meant for editing the `plugin` property\n * that's common in our JSON specs where a user selects a plugin `kind` and then edits the `spec` via that plugin's\n * editor component. It takes care of transitioning from one plugin kind to another \"all at once\" so that when the\n * plugin's kind changes, the spec is also changed at the same time so those options editor components don't see a\n * previous plugin's spec state. If you just want this behavior, but in a different UI layout from this, try the\n * `usePluginEditor` hook that powers this component.\n */\n\nexport const PluginEditor = forwardRef<PluginEditorRef, PluginEditorProps>((props, ref): ReactElement => {\n const {\n value,\n withRunQueryButton = true,\n pluginTypes,\n pluginKindLabel,\n onChange: _,\n isReadonly,\n postExecuteRunQuery: refresh,\n ...others\n } = props;\n const { pendingSelection, isLoading, error, onSelectionChange, onSpecChange } = usePluginEditor(props);\n\n /* \n We could technically merge the watchedQuery, watchedOtherSpecs into a single watched-object,\n because at the end of the day, they are all specs.\n However, let's have them separated to keep the code simple and readable.\n Reason: Only Query string field is common between all of them. Other specs may be different\n Example: Legend, and MinSteps\n */\n const [watchedQuery, setWatchQuery] = useState<string>(value.spec['query'] as string);\n const [watchedOtherSpecs, setWatchOtherSpecs] = useState<UnknownSpec>(value.spec);\n\n const runQueryHandler = useCallback((): void => {\n onSpecChange({ ...value.spec, ...watchedOtherSpecs, query: watchedQuery });\n refresh?.();\n }, [value.spec, onSpecChange, watchedQuery, watchedOtherSpecs, refresh]);\n\n const queryHandlerSettings = useMemo(() => {\n return withRunQueryButton\n ? {\n runWithOnBlur: false,\n watchQueryChanges: (query: string): void => {\n setWatchQuery(query);\n },\n setWatchOtherSpecs: (otherSpecs: UnknownSpec): void => {\n setWatchOtherSpecs(otherSpecs);\n },\n }\n : undefined;\n }, [withRunQueryButton]);\n\n useImperativeHandle(ref, () => ({ flushChanges: runQueryHandler }));\n\n return (\n <Box {...others}>\n <Box\n sx={{\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: 1,\n mb: 1,\n }}\n >\n <PluginKindSelect\n fullWidth={false}\n sx={{ minWidth: 120 }}\n margin=\"dense\"\n label={pluginKindLabel}\n pluginTypes={pluginTypes}\n disabled={isLoading}\n value={pendingSelection ? pendingSelection : value.selection}\n slotProps={{ input: { readOnly: isReadonly } }}\n error={!!error}\n helperText={error?.message}\n onChange={onSelectionChange}\n />\n\n {withRunQueryButton && !isLoading && (\n <Button data-testid=\"run_query_button\" variant=\"contained\" startIcon={<Reload />} onClick={runQueryHandler}>\n Run Query\n </Button>\n )}\n </Box>\n\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <PluginSpecEditor\n pluginSelection={value.selection}\n value={value.spec}\n onChange={onSpecChange}\n isReadonly={isReadonly}\n queryHandlerSettings={queryHandlerSettings}\n />\n </ErrorBoundary>\n </Box>\n );\n});\n\nPluginEditor.displayName = 'PluginEditor';\n"],"names":["Box","Button","Reload","ErrorAlert","ErrorBoundary","forwardRef","useCallback","useImperativeHandle","useMemo","useState","PluginKindSelect","PluginSpecEditor","usePluginEditor","PluginEditor","props","ref","value","withRunQueryButton","pluginTypes","pluginKindLabel","onChange","_","isReadonly","postExecuteRunQuery","refresh","others","pendingSelection","isLoading","error","onSelectionChange","onSpecChange","watchedQuery","setWatchQuery","spec","watchedOtherSpecs","setWatchOtherSpecs","runQueryHandler","query","queryHandlerSettings","runWithOnBlur","watchQueryChanges","otherSpecs","undefined","flushChanges","sx","display","flexDirection","alignItems","justifyContent","gap","mb","fullWidth","minWidth","margin","label","disabled","selection","slotProps","input","readOnly","helperText","message","data-testid","variant","startIcon","onClick","FallbackComponent","pluginSelection","displayName"],"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,GAAG,EAAEC,MAAM,QAAQ,gBAAgB;AAC5C,OAAOC,YAAY,yBAAyB;AAC5C,SAASC,UAAU,EAAEC,aAAa,QAAQ,yBAAyB;AACnE,SAASC,UAAU,EAAgBC,WAAW,EAAEC,mBAAmB,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAEtG,SAASC,gBAAgB,QAAQ,sBAAsB;AACvD,SAASC,gBAAgB,QAAQ,sBAAsB;AACvD,SAA6CC,eAAe,QAAQ,sBAAsB;AAE1F;;;;;;;CAOC,GAED,OAAO,MAAMC,6BAAeR,WAA+C,CAACS,OAAOC;IACjF,MAAM,EACJC,KAAK,EACLC,qBAAqB,IAAI,EACzBC,WAAW,EACXC,eAAe,EACfC,UAAUC,CAAC,EACXC,UAAU,EACVC,qBAAqBC,OAAO,
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PluginEditor/PluginEditor.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 { Box, Button } from '@mui/material';\nimport Reload from 'mdi-material-ui/Reload';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { forwardRef, ReactElement, useCallback, useImperativeHandle, useMemo, useState } from 'react';\nimport { UnknownSpec } from '@perses-dev/core';\nimport { PluginKindSelect } from '../PluginKindSelect';\nimport { PluginSpecEditor } from '../PluginSpecEditor';\nimport { PluginEditorProps, PluginEditorRef, usePluginEditor } from './plugin-editor-api';\n\n/**\n * A combination `PluginKindSelect` and `PluginSpecEditor` component. This is meant for editing the `plugin` property\n * that's common in our JSON specs where a user selects a plugin `kind` and then edits the `spec` via that plugin's\n * editor component. It takes care of transitioning from one plugin kind to another \"all at once\" so that when the\n * plugin's kind changes, the spec is also changed at the same time so those options editor components don't see a\n * previous plugin's spec state. If you just want this behavior, but in a different UI layout from this, try the\n * `usePluginEditor` hook that powers this component.\n */\n\nexport const PluginEditor = forwardRef<PluginEditorRef, PluginEditorProps>((props, ref): ReactElement => {\n const {\n value,\n withRunQueryButton = true,\n pluginTypes,\n pluginKindLabel,\n onChange: _,\n isReadonly,\n postExecuteRunQuery: refresh,\n filteredQueryPlugins,\n ...others\n } = props;\n const { pendingSelection, isLoading, error, onSelectionChange, onSpecChange } = usePluginEditor(props);\n\n /* \n We could technically merge the watchedQuery, watchedOtherSpecs into a single watched-object,\n because at the end of the day, they are all specs.\n However, let's have them separated to keep the code simple and readable.\n Reason: Only Query string field is common between all of them. Other specs may be different\n Example: Legend, and MinSteps\n */\n const [watchedQuery, setWatchQuery] = useState<string>(value.spec['query'] as string);\n const [watchedOtherSpecs, setWatchOtherSpecs] = useState<UnknownSpec>(value.spec);\n\n const runQueryHandler = useCallback((): void => {\n onSpecChange({ ...value.spec, ...watchedOtherSpecs, query: watchedQuery });\n refresh?.();\n }, [value.spec, onSpecChange, watchedQuery, watchedOtherSpecs, refresh]);\n\n const queryHandlerSettings = useMemo(() => {\n return withRunQueryButton\n ? {\n runWithOnBlur: false,\n watchQueryChanges: (query: string): void => {\n setWatchQuery(query);\n },\n setWatchOtherSpecs: (otherSpecs: UnknownSpec): void => {\n setWatchOtherSpecs(otherSpecs);\n },\n }\n : undefined;\n }, [withRunQueryButton]);\n\n useImperativeHandle(ref, () => ({ flushChanges: runQueryHandler }));\n\n return (\n <Box {...others}>\n <Box\n sx={{\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: 1,\n mb: 1,\n }}\n >\n <PluginKindSelect\n fullWidth={false}\n sx={{ minWidth: 120 }}\n margin=\"dense\"\n label={pluginKindLabel}\n pluginTypes={pluginTypes}\n disabled={isLoading}\n value={pendingSelection ? pendingSelection : value.selection}\n slotProps={{ input: { readOnly: isReadonly } }}\n error={!!error}\n helperText={error?.message}\n onChange={onSelectionChange}\n filteredQueryPlugins={filteredQueryPlugins}\n />\n\n {withRunQueryButton && !isLoading && (\n <Button data-testid=\"run_query_button\" variant=\"contained\" startIcon={<Reload />} onClick={runQueryHandler}>\n Run Query\n </Button>\n )}\n </Box>\n\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <PluginSpecEditor\n pluginSelection={value.selection}\n value={value.spec}\n onChange={onSpecChange}\n isReadonly={isReadonly}\n queryHandlerSettings={queryHandlerSettings}\n />\n </ErrorBoundary>\n </Box>\n );\n});\n\nPluginEditor.displayName = 'PluginEditor';\n"],"names":["Box","Button","Reload","ErrorAlert","ErrorBoundary","forwardRef","useCallback","useImperativeHandle","useMemo","useState","PluginKindSelect","PluginSpecEditor","usePluginEditor","PluginEditor","props","ref","value","withRunQueryButton","pluginTypes","pluginKindLabel","onChange","_","isReadonly","postExecuteRunQuery","refresh","filteredQueryPlugins","others","pendingSelection","isLoading","error","onSelectionChange","onSpecChange","watchedQuery","setWatchQuery","spec","watchedOtherSpecs","setWatchOtherSpecs","runQueryHandler","query","queryHandlerSettings","runWithOnBlur","watchQueryChanges","otherSpecs","undefined","flushChanges","sx","display","flexDirection","alignItems","justifyContent","gap","mb","fullWidth","minWidth","margin","label","disabled","selection","slotProps","input","readOnly","helperText","message","data-testid","variant","startIcon","onClick","FallbackComponent","pluginSelection","displayName"],"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,GAAG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B,cAAcP;QAAgB,CAAA;IAEhE,qBACE,MAACrC;QAAK,GAAG0B,MAAM;;0BACb,MAAC1B;gBACC6C,IAAI;oBACFC,SAAS;oBACTC,eAAe;oBACfC,YAAY;oBACZC,gBAAgB;oBAChBC,KAAK;oBACLC,IAAI;gBACN;;kCAEA,KAACzC;wBACC0C,WAAW;wBACXP,IAAI;4BAAEQ,UAAU;wBAAI;wBACpBC,QAAO;wBACPC,OAAOpC;wBACPD,aAAaA;wBACbsC,UAAU5B;wBACVZ,OAAOW,mBAAmBA,mBAAmBX,MAAMyC,SAAS;wBAC5DC,WAAW;4BAAEC,OAAO;gCAAEC,UAAUtC;4BAAW;wBAAE;wBAC7CO,OAAO,CAAC,CAACA;wBACTgC,YAAYhC,OAAOiC;wBACnB1C,UAAUU;wBACVL,sBAAsBA;;oBAGvBR,sBAAsB,CAACW,2BACtB,KAAC3B;wBAAO8D,eAAY;wBAAmBC,SAAQ;wBAAYC,yBAAW,KAAC/D;wBAAWgE,SAAS7B;kCAAiB;;;;0BAMhH,KAACjC;gBAAc+D,mBAAmBhE;0BAChC,cAAA,KAACQ;oBACCyD,iBAAiBpD,MAAMyC,SAAS;oBAChCzC,OAAOA,MAAMkB,IAAI;oBACjBd,UAAUW;oBACVT,YAAYA;oBACZiB,sBAAsBA;;;;;AAKhC,GAAG;AAEH1B,aAAawD,WAAW,GAAG"}
|
|
@@ -16,6 +16,7 @@ export interface PluginEditorProps extends Omit<BoxProps, OmittedMuiProps> {
|
|
|
16
16
|
value: PluginEditorValue;
|
|
17
17
|
isReadonly?: boolean;
|
|
18
18
|
withRunQueryButton?: boolean;
|
|
19
|
+
filteredQueryPlugins?: string[];
|
|
19
20
|
onChange: (next: PluginEditorValue) => void;
|
|
20
21
|
postExecuteRunQuery?: () => void;
|
|
21
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-editor-api.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/plugin-editor-api.ts"],"names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K,IAAI,CAAC;CACvD,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG;IAC5D,gBAAgB,CAAC,EAAE,qBAAqB,CAAC;IACzC,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,iBAAiB,EAAE,CAAC,CAAC,EAAE,qBAAqB,KAAK,IAAI,CAAC;IACtD,YAAY,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;IAC1C,wBAAwB,EAAE,MAAM,IAAI,CAAC;CACtC,CAyHA"}
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { useEvent } from '@perses-dev/core';
|
|
14
13
|
import { useState, useRef, useEffect } from 'react';
|
|
15
14
|
import { produce } from 'immer';
|
|
16
15
|
import { usePlugin, usePluginRegistry } from '../../runtime';
|
|
16
|
+
import { useEvent } from '../../utils';
|
|
17
17
|
/**
|
|
18
18
|
* Returns the state/handlers that power the `PluginEditor` component. Useful for custom components that want to provide
|
|
19
19
|
* a different UI, but want the same behavior of changing `kind` and `spec` together on plugin kind changes. Also
|