@perses-dev/plugin-system 0.52.0-beta.5 → 0.52.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/MultiQueryEditor/MultiQueryEditor.js +5 -2
- package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +13 -4
- package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +7 -5
- package/dist/cjs/components/PluginEditor/PluginEditor.js +16 -11
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +37 -87
- package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +12 -17
- package/dist/cjs/context/query-params.js +4 -4
- package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +6 -1
- package/dist/cjs/runtime/TimeRangeProvider/query-params.js +27 -27
- package/dist/cjs/test/utils.js +17 -8
- package/dist/cjs/utils/variables.js +109 -14
- package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts +3 -2
- package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js +6 -3
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts +3 -2
- package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts.map +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.js +13 -4
- package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts +3 -2
- package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js +7 -5
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.d.ts +3 -3
- package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.js +17 -12
- package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts +4 -0
- package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +38 -47
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +0 -2
- package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js +13 -18
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
- package/dist/context/query-params.js +4 -4
- package/dist/context/query-params.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +6 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/query-params.d.ts +7 -12
- package/dist/runtime/TimeRangeProvider/query-params.d.ts.map +1 -1
- package/dist/runtime/TimeRangeProvider/query-params.js +20 -23
- package/dist/runtime/TimeRangeProvider/query-params.js.map +1 -1
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +17 -8
- package/dist/test/utils.js.map +1 -1
- package/dist/utils/variables.d.ts +24 -2
- package/dist/utils/variables.d.ts.map +1 -1
- package/dist/utils/variables.js +102 -14
- package/dist/utils/variables.js.map +1 -1
- package/package.json +4 -4
|
@@ -21,9 +21,18 @@ function _export(target, all) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
|
+
InterpolationFormat: function() {
|
|
25
|
+
return InterpolationFormat;
|
|
26
|
+
},
|
|
27
|
+
interpolate: function() {
|
|
28
|
+
return interpolate;
|
|
29
|
+
},
|
|
24
30
|
parseVariables: function() {
|
|
25
31
|
return parseVariables;
|
|
26
32
|
},
|
|
33
|
+
parseVariablesAndFormat: function() {
|
|
34
|
+
return parseVariablesAndFormat;
|
|
35
|
+
},
|
|
27
36
|
replaceVariable: function() {
|
|
28
37
|
return replaceVariable;
|
|
29
38
|
},
|
|
@@ -32,7 +41,8 @@ _export(exports, {
|
|
|
32
41
|
}
|
|
33
42
|
});
|
|
34
43
|
function replaceVariables(text, variableState) {
|
|
35
|
-
const
|
|
44
|
+
const variablesMap = parseVariablesAndFormat(text);
|
|
45
|
+
const variables = Array.from(variablesMap.keys());
|
|
36
46
|
let finalText = text;
|
|
37
47
|
variables// Sorting variables by their length.
|
|
38
48
|
// In order to not have a variable name have contained in another variable name.
|
|
@@ -40,20 +50,88 @@ function replaceVariables(text, variableState) {
|
|
|
40
50
|
.sort((a, b)=>b.length - a.length).forEach((v)=>{
|
|
41
51
|
const variable = variableState[v];
|
|
42
52
|
if (variable && variable.value !== undefined) {
|
|
43
|
-
finalText = replaceVariable(finalText, v, variable?.value);
|
|
53
|
+
finalText = replaceVariable(finalText, v, variable?.value, variablesMap.get(v));
|
|
44
54
|
}
|
|
45
55
|
});
|
|
46
56
|
return finalText;
|
|
47
57
|
}
|
|
48
|
-
|
|
58
|
+
var InterpolationFormat = /*#__PURE__*/ function(InterpolationFormat) {
|
|
59
|
+
InterpolationFormat["CSV"] = "csv";
|
|
60
|
+
InterpolationFormat["DISTRIBUTED"] = "distributed";
|
|
61
|
+
InterpolationFormat["DOUBLEQUOTE"] = "doublequote";
|
|
62
|
+
InterpolationFormat["GLOB"] = "glob";
|
|
63
|
+
InterpolationFormat["JSON"] = "json";
|
|
64
|
+
InterpolationFormat["LUCENE"] = "lucene";
|
|
65
|
+
InterpolationFormat["PERCENTENCODE"] = "percentencode";
|
|
66
|
+
InterpolationFormat["PIPE"] = "pipe";
|
|
67
|
+
InterpolationFormat["PROMETHEUS"] = "prometheus";
|
|
68
|
+
InterpolationFormat["RAW"] = "raw";
|
|
69
|
+
InterpolationFormat["REGEX"] = "regex";
|
|
70
|
+
InterpolationFormat["SINGLEQUOTE"] = "singlequote";
|
|
71
|
+
InterpolationFormat["SQLSTRING"] = "sqlstring";
|
|
72
|
+
InterpolationFormat["TEXT"] = "text";
|
|
73
|
+
InterpolationFormat["QUERYPARAM"] = "queryparam";
|
|
74
|
+
return InterpolationFormat;
|
|
75
|
+
}({});
|
|
76
|
+
function stringToFormat(val) {
|
|
77
|
+
if (!val) return undefined;
|
|
78
|
+
const lowerVal = val.toLowerCase();
|
|
79
|
+
return Object.values(InterpolationFormat).find((format)=>format === lowerVal) || undefined;
|
|
80
|
+
}
|
|
81
|
+
function interpolate(values, name, format) {
|
|
82
|
+
switch(format){
|
|
83
|
+
case "csv":
|
|
84
|
+
case "raw":
|
|
85
|
+
return values.join(',');
|
|
86
|
+
case "distributed":
|
|
87
|
+
{
|
|
88
|
+
const [first, ...rest] = values;
|
|
89
|
+
return `${[
|
|
90
|
+
first,
|
|
91
|
+
...rest.map((v)=>`${name}=${v}`)
|
|
92
|
+
].join(',')}`;
|
|
93
|
+
}
|
|
94
|
+
case "doublequote":
|
|
95
|
+
return values.map((v)=>`"${v}"`).join(',');
|
|
96
|
+
case "glob":
|
|
97
|
+
return `{${values.join(',')}}`;
|
|
98
|
+
case "json":
|
|
99
|
+
return JSON.stringify(values);
|
|
100
|
+
case "lucene":
|
|
101
|
+
return `(${values.map((v)=>`"${v}"`).join(' OR ')})`;
|
|
102
|
+
case "percentencode":
|
|
103
|
+
return encodeURIComponent(values.join(','));
|
|
104
|
+
case "pipe":
|
|
105
|
+
return values.join('|');
|
|
106
|
+
case "regex":
|
|
107
|
+
{
|
|
108
|
+
const escapedRegex = values.map((v)=>v.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'));
|
|
109
|
+
return `(${escapedRegex.join('|')})`;
|
|
110
|
+
}
|
|
111
|
+
case "singlequote":
|
|
112
|
+
return values.map((v)=>`'${v}'`).join(',');
|
|
113
|
+
case "sqlstring":
|
|
114
|
+
return values.map((v)=>`'${v.replace(/'/g, "''")}'`).join(',');
|
|
115
|
+
case "text":
|
|
116
|
+
return values.join(' + ');
|
|
117
|
+
case "queryparam":
|
|
118
|
+
return values.map((v)=>`${name}=${encodeURIComponent(v)}`).join('&');
|
|
119
|
+
case "prometheus":
|
|
120
|
+
default:
|
|
121
|
+
return `(${values.join('|')})`;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function replaceVariable(text, varName, variableValue, varFormat) {
|
|
49
125
|
const variableSyntax = '$' + varName;
|
|
50
|
-
const alternativeVariableSyntax = '${' + varName + '}';
|
|
126
|
+
const alternativeVariableSyntax = '${' + varName + (varFormat ? ':' + varFormat : '') + '}';
|
|
51
127
|
let replaceString = '';
|
|
52
128
|
if (Array.isArray(variableValue)) {
|
|
53
|
-
replaceString =
|
|
129
|
+
replaceString = interpolate(variableValue, varName, varFormat || "prometheus");
|
|
54
130
|
}
|
|
55
131
|
if (typeof variableValue === 'string') {
|
|
56
|
-
replaceString =
|
|
132
|
+
replaceString = interpolate([
|
|
133
|
+
variableValue
|
|
134
|
+
], varName, varFormat || "raw");
|
|
57
135
|
}
|
|
58
136
|
text = text.replaceAll(variableSyntax, replaceString);
|
|
59
137
|
return text.replaceAll(alternativeVariableSyntax, replaceString);
|
|
@@ -62,15 +140,12 @@ function replaceVariable(text, varName, variableValue) {
|
|
|
62
140
|
// It supports two formats for referencing variables:
|
|
63
141
|
// 1. $variableName - This is a simpler format, and the regular expression captures the variable name (\w+ matches one or more word characters).
|
|
64
142
|
// 2. ${variableName} - This is a more complex format and the regular expression captures the variable name (\w+ matches one or more word characters) in the curly braces.
|
|
65
|
-
// 3.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?}/gm;
|
|
69
|
-
const parseVariables = (text)=>{
|
|
70
|
-
const regex = VARIABLE_REGEX;
|
|
143
|
+
// 3. ${variableName:format} - This is a more complex format that allows specifying a format interpolation.
|
|
144
|
+
const VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^}]+))?(?::([^}]+))?}/gm;
|
|
145
|
+
function parseVariables(text) {
|
|
71
146
|
const matches = new Set();
|
|
72
147
|
let match;
|
|
73
|
-
while((match =
|
|
148
|
+
while((match = VARIABLE_REGEX.exec(text)) !== null){
|
|
74
149
|
if (match) {
|
|
75
150
|
if (match[1]) {
|
|
76
151
|
// \$(\w+)\
|
|
@@ -83,4 +158,24 @@ const parseVariables = (text)=>{
|
|
|
83
158
|
}
|
|
84
159
|
// return unique matches
|
|
85
160
|
return Array.from(matches.values());
|
|
86
|
-
}
|
|
161
|
+
}
|
|
162
|
+
function parseVariablesAndFormat(text) {
|
|
163
|
+
const matches = new Map();
|
|
164
|
+
let match;
|
|
165
|
+
while((match = VARIABLE_REGEX.exec(text)) !== null){
|
|
166
|
+
if (match) {
|
|
167
|
+
let format = undefined;
|
|
168
|
+
if (match[4]) {
|
|
169
|
+
format = match[4];
|
|
170
|
+
}
|
|
171
|
+
if (match[1]) {
|
|
172
|
+
// \$(\w+)\
|
|
173
|
+
matches.set(match[1], stringToFormat(format));
|
|
174
|
+
} else if (match[2]) {
|
|
175
|
+
// \${(\w+)}\
|
|
176
|
+
matches.set(match[2], stringToFormat(format));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return matches;
|
|
181
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { QueryDefinition, QueryPluginType } from '@perses-dev/core';
|
|
3
|
+
import { PluginEditorRef } from '../PluginEditor';
|
|
3
4
|
export interface MultiQueryEditorProps {
|
|
4
5
|
queryTypes: QueryPluginType[];
|
|
5
6
|
queries?: QueryDefinition[];
|
|
@@ -13,5 +14,5 @@ export interface MultiQueryEditorProps {
|
|
|
13
14
|
* @param onChange The callback to call when the queries are modified
|
|
14
15
|
* @constructor
|
|
15
16
|
*/
|
|
16
|
-
export declare
|
|
17
|
+
export declare const MultiQueryEditor: import("react").ForwardRefExoticComponent<MultiQueryEditorProps & import("react").RefAttributes<PluginEditorRef>>;
|
|
17
18
|
//# sourceMappingURL=MultiQueryEditor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiQueryEditor.d.ts","sourceRoot":"","sources":["../../../src/components/MultiQueryEditor/MultiQueryEditor.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MultiQueryEditor.d.ts","sourceRoot":"","sources":["../../../src/components/MultiQueryEditor/MultiQueryEditor.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,OAAO,CAAC,EAAE,eAAe,EAAE,CAAC;IAC5B,QAAQ,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,IAAI,CAAC;CAChD;AAmCD;;;;;;;GAOG;AAEH,eAAO,MAAM,gBAAgB,mHAmF3B,CAAC"}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
-
import { useState } from 'react';
|
|
14
|
+
import { forwardRef, useState } from 'react';
|
|
15
15
|
import { produce } from 'immer';
|
|
16
16
|
import { Button, Stack } from '@mui/material';
|
|
17
17
|
import AddIcon from 'mdi-material-ui/Plus';
|
|
@@ -52,7 +52,8 @@ function useDefaultQueryDefinition(queryTypes) {
|
|
|
52
52
|
* @param queries The list of query definitions to render
|
|
53
53
|
* @param onChange The callback to call when the queries are modified
|
|
54
54
|
* @constructor
|
|
55
|
-
*/ export
|
|
55
|
+
*/ export const MultiQueryEditor = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
56
|
+
const { queryTypes, queries = [], onChange } = props;
|
|
56
57
|
const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes);
|
|
57
58
|
// State for which queries are collapsed
|
|
58
59
|
const [queriesCollapsed, setQueriesCollapsed] = useState(queries.map(()=>false));
|
|
@@ -114,6 +115,7 @@ function useDefaultQueryDefinition(queryTypes) {
|
|
|
114
115
|
/*#__PURE__*/ _jsx(Stack, {
|
|
115
116
|
spacing: 1,
|
|
116
117
|
children: queryDefinitions.map((query, i)=>/*#__PURE__*/ _jsx(QueryEditorContainer, {
|
|
118
|
+
ref: ref,
|
|
117
119
|
queryTypes: queryTypes,
|
|
118
120
|
index: i,
|
|
119
121
|
query: query,
|
|
@@ -134,6 +136,7 @@ function useDefaultQueryDefinition(queryTypes) {
|
|
|
134
136
|
})
|
|
135
137
|
]
|
|
136
138
|
});
|
|
137
|
-
}
|
|
139
|
+
});
|
|
140
|
+
MultiQueryEditor.displayName = 'MultiQueryEditor';
|
|
138
141
|
|
|
139
142
|
//# sourceMappingURL=MultiQueryEditor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/MultiQueryEditor/MultiQueryEditor.tsx"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ReactElement, useState } from 'react';\nimport { produce } from 'immer';\nimport { Button, Stack } from '@mui/material';\nimport AddIcon from 'mdi-material-ui/Plus';\nimport { QueryDefinition, QueryPluginType } from '@perses-dev/core';\nimport { useListPluginMetadata, usePlugin, usePluginRegistry } from '../../runtime';\nimport { QueryEditorContainer } from './QueryEditorContainer';\n\nexport interface MultiQueryEditorProps {\n queryTypes: QueryPluginType[];\n queries?: QueryDefinition[];\n onChange: (queries: QueryDefinition[]) => void;\n}\n\nfunction useDefaultQueryDefinition(queryTypes: QueryPluginType[]): {\n defaultInitialQueryDefinition: QueryDefinition;\n isLoading: boolean;\n} {\n // Build the default query plugin\n // This will be used only if the queries are empty, to open a starting query\n\n // Firs the default query type\n const defaultQueryType = queryTypes[0]!;\n\n // Then the default plugin kind\n // Use as default the plugin kind explicitly set as default or the first in the list\n const { data: queryPlugins, isLoading } = useListPluginMetadata(queryTypes);\n const { defaultPluginKinds } = usePluginRegistry();\n const defaultQueryKind = defaultPluginKinds?.[defaultQueryType] ?? queryPlugins?.[0]?.spec.name ?? '';\n\n const { data: defaultQueryPlugin } = usePlugin(defaultQueryType, defaultQueryKind, {\n useErrorBoundary: true,\n enabled: true,\n });\n\n // This default query definition is used if no query is provided initially or when we add a new query\n return {\n defaultInitialQueryDefinition: {\n kind: defaultQueryType,\n spec: {\n plugin: { kind: defaultQueryKind, spec: defaultQueryPlugin?.createInitialOptions() || {} },\n },\n },\n isLoading,\n };\n}\n\n/**\n * A component render a list of {@link QueryEditorContainer} for the given query definitions.\n * It allows adding, removing and editing queries.\n * @param queryTypes The list of query types that the underlying editor will propose\n * @param queries The list of query definitions to render\n * @param onChange The callback to call when the queries are modified\n * @constructor\n */\nexport
|
|
1
|
+
{"version":3,"sources":["../../../src/components/MultiQueryEditor/MultiQueryEditor.tsx"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { forwardRef, ReactElement, useState } from 'react';\nimport { produce } from 'immer';\nimport { Button, Stack } from '@mui/material';\nimport AddIcon from 'mdi-material-ui/Plus';\nimport { QueryDefinition, QueryPluginType } from '@perses-dev/core';\nimport { useListPluginMetadata, usePlugin, usePluginRegistry } from '../../runtime';\nimport { PluginEditorRef } from '../PluginEditor';\nimport { QueryEditorContainer } from './QueryEditorContainer';\n\nexport interface MultiQueryEditorProps {\n queryTypes: QueryPluginType[];\n queries?: QueryDefinition[];\n onChange: (queries: QueryDefinition[]) => void;\n}\n\nfunction useDefaultQueryDefinition(queryTypes: QueryPluginType[]): {\n defaultInitialQueryDefinition: QueryDefinition;\n isLoading: boolean;\n} {\n // Build the default query plugin\n // This will be used only if the queries are empty, to open a starting query\n\n // Firs the default query type\n const defaultQueryType = queryTypes[0]!;\n\n // Then the default plugin kind\n // Use as default the plugin kind explicitly set as default or the first in the list\n const { data: queryPlugins, isLoading } = useListPluginMetadata(queryTypes);\n const { defaultPluginKinds } = usePluginRegistry();\n const defaultQueryKind = defaultPluginKinds?.[defaultQueryType] ?? queryPlugins?.[0]?.spec.name ?? '';\n\n const { data: defaultQueryPlugin } = usePlugin(defaultQueryType, defaultQueryKind, {\n useErrorBoundary: true,\n enabled: true,\n });\n\n // This default query definition is used if no query is provided initially or when we add a new query\n return {\n defaultInitialQueryDefinition: {\n kind: defaultQueryType,\n spec: {\n plugin: { kind: defaultQueryKind, spec: defaultQueryPlugin?.createInitialOptions() || {} },\n },\n },\n isLoading,\n };\n}\n\n/**\n * A component render a list of {@link QueryEditorContainer} for the given query definitions.\n * It allows adding, removing and editing queries.\n * @param queryTypes The list of query types that the underlying editor will propose\n * @param queries The list of query definitions to render\n * @param onChange The callback to call when the queries are modified\n * @constructor\n */\n\nexport const MultiQueryEditor = forwardRef<PluginEditorRef, MultiQueryEditorProps>((props, ref): ReactElement => {\n const { queryTypes, queries = [], onChange } = props;\n const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes);\n // State for which queries are collapsed\n const [queriesCollapsed, setQueriesCollapsed] = useState(queries.map(() => false));\n\n // Query handlers\n const handleQueryChange = (index: number, queryDef: QueryDefinition): void => {\n onChange(\n produce(queries, (draft) => {\n if (draft) {\n draft[index] = queryDef;\n } else {\n draft = [queryDef];\n }\n })\n );\n };\n\n const handleQueryAdd = (): void => {\n onChange(\n produce(queries, (draft) => {\n if (draft) {\n draft.push(defaultInitialQueryDefinition);\n } else {\n draft = [...queries, defaultInitialQueryDefinition];\n }\n })\n );\n setQueriesCollapsed((queriesCollapsed) => {\n queriesCollapsed.push(false);\n return [...queriesCollapsed];\n });\n };\n\n const handleQueryDelete = (index: number): void => {\n onChange(\n produce(queries, (draft) => {\n draft.splice(index, 1);\n })\n );\n setQueriesCollapsed((queriesCollapsed) => {\n queriesCollapsed.splice(index, 1);\n return [...queriesCollapsed];\n });\n };\n\n const handleQueryCollapseExpand = (index: number): void => {\n setQueriesCollapsed((queriesCollapsed) => {\n queriesCollapsed[index] = !queriesCollapsed[index];\n return [...queriesCollapsed];\n });\n };\n\n // show one query input if queries is empty\n const queryDefinitions: QueryDefinition[] = queries.length\n ? queries\n : !isLoading\n ? [defaultInitialQueryDefinition]\n : [];\n\n return (\n <>\n <Stack spacing={1}>\n {queryDefinitions.map((query: QueryDefinition, i: number) => (\n <QueryEditorContainer\n ref={ref}\n queryTypes={queryTypes}\n key={i}\n index={i}\n query={query}\n isCollapsed={!!queriesCollapsed[i]}\n onChange={handleQueryChange}\n onDelete={queries.length > 1 ? handleQueryDelete : undefined}\n onCollapseExpand={handleQueryCollapseExpand}\n />\n ))}\n </Stack>\n <Button variant=\"contained\" startIcon={<AddIcon />} sx={{ marginTop: 1 }} onClick={handleQueryAdd}>\n Add Query\n </Button>\n </>\n );\n});\n\nMultiQueryEditor.displayName = 'MultiQueryEditor';\n"],"names":["forwardRef","useState","produce","Button","Stack","AddIcon","useListPluginMetadata","usePlugin","usePluginRegistry","QueryEditorContainer","useDefaultQueryDefinition","queryTypes","defaultQueryType","data","queryPlugins","isLoading","defaultPluginKinds","defaultQueryKind","spec","name","defaultQueryPlugin","useErrorBoundary","enabled","defaultInitialQueryDefinition","kind","plugin","createInitialOptions","MultiQueryEditor","props","ref","queries","onChange","queriesCollapsed","setQueriesCollapsed","map","handleQueryChange","index","queryDef","draft","handleQueryAdd","push","handleQueryDelete","splice","handleQueryCollapseExpand","queryDefinitions","length","spacing","query","i","isCollapsed","onDelete","undefined","onCollapseExpand","variant","startIcon","sx","marginTop","onClick","displayName"],"mappings":"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"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { QueryDefinition, QueryPluginType } from '@perses-dev/core';
|
|
2
|
-
import {
|
|
3
|
+
import { PluginEditorRef } from '../PluginEditor';
|
|
3
4
|
/**
|
|
4
5
|
* Properties for {@link QueryEditorContainer}
|
|
5
6
|
*/
|
|
@@ -24,6 +25,6 @@ interface QueryEditorContainerProps {
|
|
|
24
25
|
* @param onCollapseExpand callback when the query is collapsed or expanded
|
|
25
26
|
* @constructor
|
|
26
27
|
*/
|
|
27
|
-
export declare const QueryEditorContainer: (
|
|
28
|
+
export declare const QueryEditorContainer: import("react").ForwardRefExoticComponent<QueryEditorContainerProps & import("react").RefAttributes<PluginEditorRef>>;
|
|
28
29
|
export {};
|
|
29
30
|
//# sourceMappingURL=QueryEditorContainer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryEditorContainer.d.ts","sourceRoot":"","sources":["../../../src/components/MultiQueryEditor/QueryEditorContainer.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"QueryEditorContainer.d.ts","sourceRoot":"","sources":["../../../src/components/MultiQueryEditor/QueryEditorContainer.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAMpE,OAAO,EAAmC,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGnF;;GAEG;AACH,UAAU,yBAAyB;IACjC,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAC1D,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,oBAAoB,uHA2BhC,CAAC"}
|
|
@@ -16,7 +16,9 @@ import { Stack, IconButton, Typography, Box } from '@mui/material';
|
|
|
16
16
|
import DeleteIcon from 'mdi-material-ui/DeleteOutline';
|
|
17
17
|
import ChevronDown from 'mdi-material-ui/ChevronDown';
|
|
18
18
|
import ChevronRight from 'mdi-material-ui/ChevronRight';
|
|
19
|
+
import { forwardRef } from 'react';
|
|
19
20
|
import { PluginEditor } from '../PluginEditor';
|
|
21
|
+
import { useTimeRange } from '../../runtime';
|
|
20
22
|
/**
|
|
21
23
|
* Container for a query editor. This component is responsible for rendering the query editor, and make it collapsible
|
|
22
24
|
* to not take too much space.
|
|
@@ -28,7 +30,8 @@ import { PluginEditor } from '../PluginEditor';
|
|
|
28
30
|
* @param onChange callback when the query is changed
|
|
29
31
|
* @param onCollapseExpand callback when the query is collapsed or expanded
|
|
30
32
|
* @constructor
|
|
31
|
-
*/ export const QueryEditorContainer = (
|
|
33
|
+
*/ export const QueryEditorContainer = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
34
|
+
const { queryTypes, index, query, isCollapsed, onDelete, onChange, onCollapseExpand } = props;
|
|
32
35
|
return /*#__PURE__*/ _jsxs(Stack, {
|
|
33
36
|
spacing: 1,
|
|
34
37
|
children: [
|
|
@@ -64,21 +67,24 @@ import { PluginEditor } from '../PluginEditor';
|
|
|
64
67
|
]
|
|
65
68
|
}),
|
|
66
69
|
!isCollapsed && /*#__PURE__*/ _jsx(QueryEditor, {
|
|
70
|
+
ref: ref,
|
|
67
71
|
queryTypes: queryTypes,
|
|
68
72
|
value: query,
|
|
69
73
|
onChange: (next)=>onChange(index, next)
|
|
70
74
|
})
|
|
71
75
|
]
|
|
72
76
|
}, index);
|
|
73
|
-
};
|
|
77
|
+
});
|
|
78
|
+
QueryEditorContainer.displayName = 'QueryEditorContainer';
|
|
74
79
|
/**
|
|
75
80
|
* Editor for a query definition. This component is responsible for rendering the plugin editor for the given query.
|
|
76
81
|
* This will allow user to select a plugin extending from the given supported query types, and then edit the plugin
|
|
77
82
|
* spec for this plugin.
|
|
78
83
|
* @param props
|
|
79
84
|
* @constructor
|
|
80
|
-
*/
|
|
85
|
+
*/ const QueryEditor = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
81
86
|
const { value, onChange, queryTypes, ...others } = props;
|
|
87
|
+
const { refresh } = useTimeRange();
|
|
82
88
|
const handlePluginChange = (next)=>{
|
|
83
89
|
onChange(produce(value, (draft)=>{
|
|
84
90
|
draft.kind = next.selection.type;
|
|
@@ -89,6 +95,8 @@ import { PluginEditor } from '../PluginEditor';
|
|
|
89
95
|
return /*#__PURE__*/ _jsx(Box, {
|
|
90
96
|
...others,
|
|
91
97
|
children: /*#__PURE__*/ _jsx(PluginEditor, {
|
|
98
|
+
postExecuteRunQuery: refresh,
|
|
99
|
+
ref: ref,
|
|
92
100
|
withRunQueryButton: true,
|
|
93
101
|
pluginTypes: queryTypes,
|
|
94
102
|
pluginKindLabel: "Query Type",
|
|
@@ -102,6 +110,7 @@ import { PluginEditor } from '../PluginEditor';
|
|
|
102
110
|
onChange: handlePluginChange
|
|
103
111
|
})
|
|
104
112
|
});
|
|
105
|
-
}
|
|
113
|
+
});
|
|
114
|
+
QueryEditor.displayName = 'QueryEditor';
|
|
106
115
|
|
|
107
116
|
//# sourceMappingURL=QueryEditorContainer.js.map
|
|
@@ -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 = (
|
|
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 ref={ref} queryTypes={queryTypes} value={query} onChange={(next) => onChange(index, next)} />\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 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, ...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 />\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","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;AACvD,OAAOC,iBAAiB,8BAA8B;AACtD,OAAOC,kBAAkB,+BAA+B;AACxD,SAASC,UAAU,QAAsB,QAAQ;AACjD,SAASC,YAAY,QAA4C,kBAAkB;AACnF,SAASC,YAAY,QAAQ,gBAAgB;AAe7C;;;;;;;;;;;CAWC,GAED,OAAO,MAAMC,qCAAuBH,WAClC,CAACI,OAAOC;IACN,MAAM,EAAEC,UAAU,EAAEC,KAAK,EAAEC,KAAK,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,gBAAgB,EAAE,GAAGR;IACxF,qBACE,MAACX;QAAkBoB,SAAS;;0BAC1B,MAACpB;gBAAMqB,WAAU;gBAAMC,YAAW;gBAASC,cAAc;gBAAGC,aAAa,CAACC,QAAUA,MAAMC,OAAO,CAACC,OAAO;;kCACvG,KAAC1B;wBAAW2B,MAAK;wBAAQC,SAAS,IAAMV,iBAAiBL;kCACtDE,4BAAc,KAACV,kCAAkB,KAACD;;kCAErC,MAACH;wBAAW4B,SAAQ;wBAAWC,WAAU;;4BAAK;4BACpCjB,QAAQ;;;kCAElB,KAACb;wBACC2B,MAAK;wBACL,2GAA2G;wBAC3GI,IAAI;4BAAEC,YAAY;4BAAQC,YAAY,GAAGjB,WAAW,YAAY,UAAU;wBAAC;wBAC3EY,SAAS,IAAMZ,YAAYA,SAASH;kCAEpC,cAAA,KAACV;;;;YAGJ,CAACY,6BACA,KAACmB;gBAAYvB,KAAKA;gBAAKC,YAAYA;gBAAYuB,OAAOrB;gBAAOG,UAAU,CAACmB,OAASnB,SAASJ,OAAOuB;;;OAlBzFvB;AAsBhB,GACA;AAEFJ,qBAAqB4B,WAAW,GAAG;AAWnC;;;;;;CAMC,GAED,MAAMH,4BAAc5B,WAA8C,CAACI,OAAOC;IACxE,MAAM,EAAEwB,KAAK,EAAElB,QAAQ,EAAEL,UAAU,EAAE,GAAG0B,QAAQ,GAAG5B;IACnD,MAAM,EAAE6B,OAAO,EAAE,GAAG/B;IACpB,MAAMgC,qBAAoD,CAACJ;QACzDnB,SACEnB,QAAQqC,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,KAAC3C;QAAK,GAAGoC,MAAM;kBACb,cAAA,KAAC/B;YACCwC,qBAAqBR;YACrB5B,KAAKA;YACLqC,kBAAkB;YAClBC,aAAarC;YACbsC,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;;;AAIlB;AAEAN,YAAYG,WAAW,GAAG"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { PanelDefinition, PanelEditorValues, QueryDefinition, UnknownSpec } from '@perses-dev/core';
|
|
2
3
|
import { Control } from 'react-hook-form';
|
|
3
|
-
import {
|
|
4
|
+
import { PluginEditorRef } from '../PluginEditor';
|
|
4
5
|
export interface PanelSpecEditorProps {
|
|
5
6
|
control: Control<PanelEditorValues>;
|
|
6
7
|
panelDefinition: PanelDefinition;
|
|
@@ -8,5 +9,5 @@ export interface PanelSpecEditorProps {
|
|
|
8
9
|
onPluginSpecChange: (spec: UnknownSpec) => void;
|
|
9
10
|
onJSONChange: (panelDefinitionStr: string) => void;
|
|
10
11
|
}
|
|
11
|
-
export declare
|
|
12
|
+
export declare const PanelSpecEditor: import("react").ForwardRefExoticComponent<PanelSpecEditorProps & import("react").RefAttributes<PluginEditorRef>>;
|
|
12
13
|
//# sourceMappingURL=PanelSpecEditor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PanelSpecEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PanelSpecEditor/PanelSpecEditor.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpG,OAAO,EAAE,OAAO,EAAc,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"PanelSpecEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PanelSpecEditor/PanelSpecEditor.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpG,OAAO,EAAE,OAAO,EAAc,MAAM,iBAAiB,CAAC;AAMtD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACpC,eAAe,EAAE,eAAe,CAAC;IACjC,eAAe,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,IAAI,CAAC;IACtD,kBAAkB,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;IAChD,YAAY,EAAE,CAAC,kBAAkB,EAAE,MAAM,KAAK,IAAI,CAAC;CACpD;AAED,eAAO,MAAM,eAAe,kHAgG1B,CAAC"}
|
|
@@ -13,10 +13,11 @@
|
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { ErrorAlert, JSONEditor, LinksEditor } from '@perses-dev/components';
|
|
15
15
|
import { Controller } from 'react-hook-form';
|
|
16
|
+
import { forwardRef } from 'react';
|
|
16
17
|
import { QueryCountProvider, usePlugin } from '../../runtime';
|
|
17
18
|
import { OptionsEditorTabs } from '../OptionsEditorTabs';
|
|
18
19
|
import { MultiQueryEditor } from '../MultiQueryEditor';
|
|
19
|
-
export
|
|
20
|
+
export const PanelSpecEditor = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
20
21
|
const { control, panelDefinition, onJSONChange, onQueriesChange, onPluginSpecChange } = props;
|
|
21
22
|
const { kind } = panelDefinition.spec.plugin;
|
|
22
23
|
const { data: plugin, isLoading, error } = usePlugin('Panel', kind);
|
|
@@ -25,11 +26,10 @@ export function PanelSpecEditor(props) {
|
|
|
25
26
|
error: error
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
|
-
// TODO: Proper loading indicator
|
|
29
29
|
if (isLoading) {
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
32
|
-
if (plugin
|
|
32
|
+
if (!plugin) {
|
|
33
33
|
throw new Error(`Missing implementation for panel plugin with kind '${kind}'`);
|
|
34
34
|
}
|
|
35
35
|
const { panelOptionsEditorComponents, hideQueryEditor } = plugin;
|
|
@@ -41,6 +41,7 @@ export function PanelSpecEditor(props) {
|
|
|
41
41
|
control: control,
|
|
42
42
|
name: "panelDefinition.spec.queries",
|
|
43
43
|
render: ({ field })=>/*#__PURE__*/ _jsx(MultiQueryEditor, {
|
|
44
|
+
ref: ref,
|
|
44
45
|
queryTypes: plugin.supportedQueryTypes ?? [],
|
|
45
46
|
queries: panelDefinition.spec.queries ?? [],
|
|
46
47
|
onChange: (queries)=>{
|
|
@@ -51,7 +52,7 @@ export function PanelSpecEditor(props) {
|
|
|
51
52
|
})
|
|
52
53
|
});
|
|
53
54
|
}
|
|
54
|
-
if (panelOptionsEditorComponents
|
|
55
|
+
if (panelOptionsEditorComponents) {
|
|
55
56
|
tabs = tabs.concat(panelOptionsEditorComponents.map(({ label, content: OptionsEditorComponent })=>({
|
|
56
57
|
label,
|
|
57
58
|
content: /*#__PURE__*/ _jsx(Controller, {
|
|
@@ -95,6 +96,7 @@ export function PanelSpecEditor(props) {
|
|
|
95
96
|
tabs: tabs
|
|
96
97
|
}, tabs.length)
|
|
97
98
|
});
|
|
98
|
-
}
|
|
99
|
+
});
|
|
100
|
+
PanelSpecEditor.displayName = 'PanelSpecEditor';
|
|
99
101
|
|
|
100
102
|
//# sourceMappingURL=PanelSpecEditor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/PanelSpecEditor/PanelSpecEditor.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 { ErrorAlert, JSONEditor, LinksEditor } from '@perses-dev/components';\nimport { PanelDefinition, PanelEditorValues, QueryDefinition, UnknownSpec } from '@perses-dev/core';\nimport { Control, Controller } from 'react-hook-form';\nimport { ReactElement } from 'react';\nimport { QueryCountProvider, usePlugin } from '../../runtime';\nimport { PanelPlugin } from '../../model';\nimport { OptionsEditorTabsProps, OptionsEditorTabs } from '../OptionsEditorTabs';\nimport { MultiQueryEditor } from '../MultiQueryEditor';\n\nexport interface PanelSpecEditorProps {\n control: Control<PanelEditorValues>;\n panelDefinition: PanelDefinition;\n onQueriesChange: (queries: QueryDefinition[]) => void;\n onPluginSpecChange: (spec: UnknownSpec) => void;\n onJSONChange: (panelDefinitionStr: string) => void;\n}\n\nexport
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PanelSpecEditor/PanelSpecEditor.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 { ErrorAlert, JSONEditor, LinksEditor } from '@perses-dev/components';\nimport { PanelDefinition, PanelEditorValues, QueryDefinition, UnknownSpec } from '@perses-dev/core';\nimport { Control, Controller } from 'react-hook-form';\nimport { forwardRef, ReactElement } from 'react';\nimport { QueryCountProvider, usePlugin } from '../../runtime';\nimport { PanelPlugin } from '../../model';\nimport { OptionsEditorTabsProps, OptionsEditorTabs } from '../OptionsEditorTabs';\nimport { MultiQueryEditor } from '../MultiQueryEditor';\nimport { PluginEditorRef } from '../PluginEditor';\n\nexport interface PanelSpecEditorProps {\n control: Control<PanelEditorValues>;\n panelDefinition: PanelDefinition;\n onQueriesChange: (queries: QueryDefinition[]) => void;\n onPluginSpecChange: (spec: UnknownSpec) => void;\n onJSONChange: (panelDefinitionStr: string) => void;\n}\n\nexport const PanelSpecEditor = forwardRef<PluginEditorRef, PanelSpecEditorProps>((props, ref): ReactElement | null => {\n const { control, panelDefinition, onJSONChange, onQueriesChange, onPluginSpecChange } = props;\n const { kind } = panelDefinition.spec.plugin;\n const { data: plugin, isLoading, error } = usePlugin('Panel', kind);\n\n if (error) {\n return <ErrorAlert error={error} />;\n }\n\n if (isLoading) {\n return null;\n }\n\n if (!plugin) {\n throw new Error(`Missing implementation for panel plugin with kind '${kind}'`);\n }\n\n const { panelOptionsEditorComponents, hideQueryEditor } = plugin as PanelPlugin;\n let tabs: OptionsEditorTabsProps['tabs'] = [];\n\n if (!hideQueryEditor) {\n tabs.push({\n label: 'Query',\n content: (\n <Controller\n control={control}\n name=\"panelDefinition.spec.queries\"\n render={({ field }) => (\n <MultiQueryEditor\n ref={ref}\n queryTypes={plugin.supportedQueryTypes ?? []}\n queries={panelDefinition.spec.queries ?? []}\n onChange={(queries) => {\n field.onChange(queries);\n onQueriesChange(queries);\n }}\n />\n )}\n />\n ),\n });\n }\n\n if (panelOptionsEditorComponents) {\n tabs = tabs.concat(\n panelOptionsEditorComponents.map(({ label, content: OptionsEditorComponent }) => ({\n label,\n content: (\n <Controller\n control={control}\n name=\"panelDefinition.spec.plugin.spec\"\n render={({ field }) => (\n <OptionsEditorComponent\n value={panelDefinition.spec.plugin.spec}\n onChange={(spec) => {\n field.onChange(spec);\n onPluginSpecChange(spec);\n }}\n />\n )}\n />\n ),\n }))\n );\n }\n\n // always show json editor and links editor by default\n tabs.push({\n label: 'Links',\n content: <LinksEditor control={control} />,\n });\n tabs.push({\n label: 'JSON',\n content: (\n <Controller\n control={control}\n name=\"panelDefinition\"\n render={({ field }) => (\n <JSONEditor\n maxHeight=\"80vh\"\n value={panelDefinition}\n onChange={(json) => {\n field.onChange(JSON.parse(json));\n onJSONChange(json);\n }}\n />\n )}\n />\n ),\n });\n\n return (\n <QueryCountProvider queryCount={(panelDefinition.spec.queries ?? []).length}>\n <OptionsEditorTabs key={tabs.length} tabs={tabs} />\n </QueryCountProvider>\n );\n});\n\nPanelSpecEditor.displayName = 'PanelSpecEditor';\n"],"names":["ErrorAlert","JSONEditor","LinksEditor","Controller","forwardRef","QueryCountProvider","usePlugin","OptionsEditorTabs","MultiQueryEditor","PanelSpecEditor","props","ref","control","panelDefinition","onJSONChange","onQueriesChange","onPluginSpecChange","kind","spec","plugin","data","isLoading","error","Error","panelOptionsEditorComponents","hideQueryEditor","tabs","push","label","content","name","render","field","queryTypes","supportedQueryTypes","queries","onChange","concat","map","OptionsEditorComponent","value","maxHeight","json","JSON","parse","queryCount","length","displayName"],"mappings":"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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import { PluginEditorProps } from './plugin-editor-api';
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { PluginEditorProps, PluginEditorRef } from './plugin-editor-api';
|
|
3
3
|
/**
|
|
4
4
|
* A combination `PluginKindSelect` and `PluginSpecEditor` component. This is meant for editing the `plugin` property
|
|
5
5
|
* that's common in our JSON specs where a user selects a plugin `kind` and then edits the `spec` via that plugin's
|
|
@@ -8,5 +8,5 @@ import { PluginEditorProps } from './plugin-editor-api';
|
|
|
8
8
|
* previous plugin's spec state. If you just want this behavior, but in a different UI layout from this, try the
|
|
9
9
|
* `usePluginEditor` hook that powers this component.
|
|
10
10
|
*/
|
|
11
|
-
export declare
|
|
11
|
+
export declare const PluginEditor: import("react").ForwardRefExoticComponent<Omit<PluginEditorProps, "ref"> & import("react").RefAttributes<PluginEditorRef>>;
|
|
12
12
|
//# sourceMappingURL=PluginEditor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"names":[],"mappings":"
|
|
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,4HAqFvB,CAAC"}
|
|
@@ -14,7 +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, useMemo, useState } from 'react';
|
|
17
|
+
import { forwardRef, useCallback, useImperativeHandle, useMemo, useState } from 'react';
|
|
18
18
|
import { PluginKindSelect } from '../PluginKindSelect';
|
|
19
19
|
import { PluginSpecEditor } from '../PluginSpecEditor';
|
|
20
20
|
import { usePluginEditor } from './plugin-editor-api';
|
|
@@ -25,17 +25,16 @@ import { usePluginEditor } from './plugin-editor-api';
|
|
|
25
25
|
* plugin's kind changes, the spec is also changed at the same time so those options editor components don't see a
|
|
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
|
-
*/ export
|
|
29
|
-
|
|
30
|
-
const { value, withRunQueryButton = true, pluginTypes, pluginKindLabel, onChange: _, isReadonly, ...others } = props;
|
|
28
|
+
*/ export const PluginEditor = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
29
|
+
const { value, withRunQueryButton = true, pluginTypes, pluginKindLabel, onChange: _, isReadonly, postExecuteRunQuery: refresh, ...others } = props;
|
|
31
30
|
const { pendingSelection, isLoading, error, onSelectionChange, onSpecChange } = usePluginEditor(props);
|
|
32
31
|
/*
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
We could technically merge the watchedQuery, watchedOtherSpecs into a single watched-object,
|
|
33
|
+
because at the end of the day, they are all specs.
|
|
34
|
+
However, let's have them separated to keep the code simple and readable.
|
|
35
|
+
Reason: Only Query string field is common between all of them. Other specs may be different
|
|
36
|
+
Example: Legend, and MinSteps
|
|
37
|
+
*/ const [watchedQuery, setWatchQuery] = useState(value.spec['query']);
|
|
39
38
|
const [watchedOtherSpecs, setWatchOtherSpecs] = useState(value.spec);
|
|
40
39
|
const runQueryHandler = useCallback(()=>{
|
|
41
40
|
onSpecChange({
|
|
@@ -43,11 +42,13 @@ import { usePluginEditor } from './plugin-editor-api';
|
|
|
43
42
|
...watchedOtherSpecs,
|
|
44
43
|
query: watchedQuery
|
|
45
44
|
});
|
|
45
|
+
refresh?.();
|
|
46
46
|
}, [
|
|
47
47
|
value.spec,
|
|
48
48
|
onSpecChange,
|
|
49
49
|
watchedQuery,
|
|
50
|
-
watchedOtherSpecs
|
|
50
|
+
watchedOtherSpecs,
|
|
51
|
+
refresh
|
|
51
52
|
]);
|
|
52
53
|
const queryHandlerSettings = useMemo(()=>{
|
|
53
54
|
return withRunQueryButton ? {
|
|
@@ -62,6 +63,9 @@ import { usePluginEditor } from './plugin-editor-api';
|
|
|
62
63
|
}, [
|
|
63
64
|
withRunQueryButton
|
|
64
65
|
]);
|
|
66
|
+
useImperativeHandle(ref, ()=>({
|
|
67
|
+
flushChanges: runQueryHandler
|
|
68
|
+
}));
|
|
65
69
|
return /*#__PURE__*/ _jsxs(Box, {
|
|
66
70
|
...others,
|
|
67
71
|
children: [
|
|
@@ -116,6 +120,7 @@ import { usePluginEditor } from './plugin-editor-api';
|
|
|
116
120
|
})
|
|
117
121
|
]
|
|
118
122
|
});
|
|
119
|
-
}
|
|
123
|
+
});
|
|
124
|
+
PluginEditor.displayName = 'PluginEditor';
|
|
120
125
|
|
|
121
126
|
//# sourceMappingURL=PluginEditor.js.map
|