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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dist/cjs/components/LinksEditor/LinksEditor.js +162 -0
  2. package/dist/cjs/components/LinksEditor/index.js +30 -0
  3. package/dist/cjs/components/MultiQueryEditor/MultiQueryEditor.js +2 -2
  4. package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +97 -12
  5. package/dist/cjs/components/MultiQueryEditor/index.js +1 -0
  6. package/dist/cjs/components/MultiQueryEditor/utils.js +36 -0
  7. package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +5 -7
  8. package/dist/cjs/components/index.js +1 -0
  9. package/dist/cjs/context/ValidationProvider.js +3 -2
  10. package/dist/cjs/index.js +1 -0
  11. package/dist/cjs/remote/PluginRuntime.js +12 -12
  12. package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +21 -28
  13. package/dist/cjs/runtime/DataQueriesProvider/model.js +3 -119
  14. package/dist/cjs/runtime/index.js +0 -1
  15. package/dist/cjs/schema/index.js +30 -0
  16. package/dist/cjs/schema/panel.js +42 -0
  17. package/dist/components/LinksEditor/LinksEditor.d.ts +8 -0
  18. package/dist/components/LinksEditor/LinksEditor.d.ts.map +1 -0
  19. package/dist/components/LinksEditor/LinksEditor.js +149 -0
  20. package/dist/components/LinksEditor/LinksEditor.js.map +1 -0
  21. package/dist/components/LinksEditor/index.d.ts +2 -0
  22. package/dist/components/LinksEditor/index.d.ts.map +1 -0
  23. package/dist/components/LinksEditor/index.js +15 -0
  24. package/dist/components/LinksEditor/index.js.map +1 -0
  25. package/dist/components/MultiQueryEditor/MultiQueryEditor.js +2 -2
  26. package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
  27. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts.map +1 -1
  28. package/dist/components/MultiQueryEditor/QueryEditorContainer.js +99 -14
  29. package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
  30. package/dist/components/MultiQueryEditor/index.d.ts +1 -0
  31. package/dist/components/MultiQueryEditor/index.d.ts.map +1 -1
  32. package/dist/components/MultiQueryEditor/index.js +1 -0
  33. package/dist/components/MultiQueryEditor/index.js.map +1 -1
  34. package/dist/components/MultiQueryEditor/utils.d.ts +8 -0
  35. package/dist/components/MultiQueryEditor/utils.d.ts.map +1 -0
  36. package/dist/components/MultiQueryEditor/utils.js +23 -0
  37. package/dist/components/MultiQueryEditor/utils.js.map +1 -0
  38. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts +2 -1
  39. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
  40. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +6 -8
  41. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  42. package/dist/components/index.d.ts +1 -0
  43. package/dist/components/index.d.ts.map +1 -1
  44. package/dist/components/index.js +1 -0
  45. package/dist/components/index.js.map +1 -1
  46. package/dist/context/ValidationProvider.d.ts +2 -1
  47. package/dist/context/ValidationProvider.d.ts.map +1 -1
  48. package/dist/context/ValidationProvider.js +2 -1
  49. package/dist/context/ValidationProvider.js.map +1 -1
  50. package/dist/index.d.ts +1 -0
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +1 -0
  53. package/dist/index.js.map +1 -1
  54. package/dist/model/panels.d.ts +9 -1
  55. package/dist/model/panels.d.ts.map +1 -1
  56. package/dist/model/panels.js +3 -1
  57. package/dist/model/panels.js.map +1 -1
  58. package/dist/remote/PluginRuntime.js +12 -12
  59. package/dist/remote/PluginRuntime.js.map +1 -1
  60. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -1
  61. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +22 -29
  62. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
  63. package/dist/runtime/DataQueriesProvider/model.d.ts +4 -4
  64. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
  65. package/dist/runtime/DataQueriesProvider/model.js +0 -108
  66. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  67. package/dist/runtime/index.d.ts +0 -1
  68. package/dist/runtime/index.d.ts.map +1 -1
  69. package/dist/runtime/index.js +0 -1
  70. package/dist/runtime/index.js.map +1 -1
  71. package/dist/runtime/plugin-registry.d.ts +1 -2
  72. package/dist/runtime/plugin-registry.d.ts.map +1 -1
  73. package/dist/runtime/plugin-registry.js.map +1 -1
  74. package/dist/schema/index.d.ts +2 -0
  75. package/dist/schema/index.d.ts.map +1 -0
  76. package/dist/schema/index.js +15 -0
  77. package/dist/schema/index.js.map +1 -0
  78. package/dist/schema/panel.d.ts +6 -0
  79. package/dist/schema/panel.d.ts.map +1 -0
  80. package/dist/{runtime/QueryCountProvider.js → schema/panel.js} +12 -12
  81. package/dist/schema/panel.js.map +1 -0
  82. package/package.json +5 -5
  83. package/dist/cjs/runtime/QueryCountProvider.js +0 -83
  84. package/dist/runtime/QueryCountProvider.d.ts +0 -9
  85. package/dist/runtime/QueryCountProvider.d.ts.map +0 -1
  86. package/dist/runtime/QueryCountProvider.js.map +0 -1
@@ -14,22 +14,12 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- function _export(target, all) {
18
- for(var name in all)Object.defineProperty(target, name, {
19
- enumerable: true,
20
- get: Object.getOwnPropertyDescriptor(all, name).get
21
- });
22
- }
23
- _export(exports, {
24
- get transformQueryResults () {
17
+ Object.defineProperty(exports, "transformQueryResults", {
18
+ enumerable: true,
19
+ get: function() {
25
20
  return transformQueryResults;
26
- },
27
- get useQueryType () {
28
- return useQueryType;
29
21
  }
30
22
  });
31
- const _react = require("react");
32
- const _pluginregistry = require("../plugin-registry");
33
23
  function transformQueryResults(results, definitions) {
34
24
  return results.map(({ data, isFetching, isLoading, refetch, error }, i)=>{
35
25
  return {
@@ -42,109 +32,3 @@ function transformQueryResults(results, definitions) {
42
32
  };
43
33
  });
44
34
  }
45
- function useQueryType() {
46
- const { data: timeSeriesQueryPlugins, isLoading: isTimeSeriesQueryLoading } = (0, _pluginregistry.useListPluginMetadata)([
47
- 'TimeSeriesQuery'
48
- ]);
49
- const { data: traceQueryPlugins, isLoading: isTraceQueryPluginLoading } = (0, _pluginregistry.useListPluginMetadata)([
50
- 'TraceQuery'
51
- ]);
52
- const { data: profileQueryPlugins, isLoading: isProfileQueryPluginLoading } = (0, _pluginregistry.useListPluginMetadata)([
53
- 'ProfileQuery'
54
- ]);
55
- const { data: logQueries, isLoading: isLogQueryPluginLoading } = (0, _pluginregistry.useListPluginMetadata)([
56
- 'LogQuery'
57
- ]);
58
- const { data: alertsQueryPlugins, isLoading: isAlertsQueryPluginLoading } = (0, _pluginregistry.useListPluginMetadata)([
59
- 'AlertsQuery'
60
- ]);
61
- const { data: silencesQueryPlugins, isLoading: isSilencesQueryPluginLoading } = (0, _pluginregistry.useListPluginMetadata)([
62
- 'SilencesQuery'
63
- ]);
64
- // For example, `map: {"TimeSeriesQuery":["PrometheusTimeSeriesQuery"],"TraceQuery":["TempoTraceQuery"]}`
65
- const queryTypeMap = (0, _react.useMemo)(()=>{
66
- const map = {
67
- TimeSeriesQuery: [],
68
- TraceQuery: [],
69
- ProfileQuery: [],
70
- LogQuery: [],
71
- AlertsQuery: [],
72
- SilencesQuery: []
73
- };
74
- if (timeSeriesQueryPlugins) {
75
- timeSeriesQueryPlugins.forEach((plugin)=>{
76
- map[plugin.kind]?.push(plugin.spec.name);
77
- });
78
- }
79
- if (traceQueryPlugins) {
80
- traceQueryPlugins.forEach((plugin)=>{
81
- map[plugin.kind]?.push(plugin.spec.name);
82
- });
83
- }
84
- if (profileQueryPlugins) {
85
- profileQueryPlugins.forEach((plugin)=>{
86
- map[plugin.kind]?.push(plugin.spec.name);
87
- });
88
- }
89
- if (logQueries) {
90
- logQueries.forEach((plugin)=>{
91
- map[plugin.kind]?.push(plugin.spec.name);
92
- });
93
- }
94
- if (alertsQueryPlugins) {
95
- alertsQueryPlugins.forEach((plugin)=>{
96
- map[plugin.kind]?.push(plugin.spec.name);
97
- });
98
- }
99
- if (silencesQueryPlugins) {
100
- silencesQueryPlugins.forEach((plugin)=>{
101
- map[plugin.kind]?.push(plugin.spec.name);
102
- });
103
- }
104
- return map;
105
- }, [
106
- timeSeriesQueryPlugins,
107
- traceQueryPlugins,
108
- profileQueryPlugins,
109
- logQueries,
110
- alertsQueryPlugins,
111
- silencesQueryPlugins
112
- ]);
113
- const getQueryType = (0, _react.useCallback)((pluginKind)=>{
114
- const isLoading = (pluginKind)=>{
115
- switch(pluginKind){
116
- case 'PrometheusTimeSeriesQuery':
117
- return isTimeSeriesQueryLoading;
118
- case 'TempoTraceQuery':
119
- return isTraceQueryPluginLoading;
120
- case 'PyroscopeProfileQuery':
121
- return isProfileQueryPluginLoading;
122
- case 'LokiLogQuery':
123
- return isLogQueryPluginLoading;
124
- case 'AlertmanagerAlertsQuery':
125
- return isAlertsQueryPluginLoading;
126
- case 'AlertmanagerSilencesQuery':
127
- return isSilencesQueryPluginLoading;
128
- }
129
- return isTraceQueryPluginLoading || isTimeSeriesQueryLoading || isProfileQueryPluginLoading || isLogQueryPluginLoading || isAlertsQueryPluginLoading || isSilencesQueryPluginLoading;
130
- };
131
- if (isLoading(pluginKind)) {
132
- return undefined;
133
- }
134
- for(const queryType in queryTypeMap){
135
- if (queryTypeMap[queryType]?.includes(pluginKind)) {
136
- return queryType;
137
- }
138
- }
139
- throw new Error(`Unable to determine the query type: ${pluginKind}`);
140
- }, [
141
- queryTypeMap,
142
- isTimeSeriesQueryLoading,
143
- isTraceQueryPluginLoading,
144
- isProfileQueryPluginLoading,
145
- isLogQueryPluginLoading,
146
- isAlertsQueryPluginLoading,
147
- isSilencesQueryPluginLoading
148
- ]);
149
- return getQueryType;
150
- }
@@ -27,7 +27,6 @@ _export_star(require("./alerts-queries"), exports);
27
27
  _export_star(require("./silences-queries"), exports);
28
28
  _export_star(require("./item-actions"), exports);
29
29
  _export_star(require("./DataQueriesProvider"), exports);
30
- _export_star(require("./QueryCountProvider"), exports);
31
30
  _export_star(require("./RouterProvider"), exports);
32
31
  _export_star(require("./UsageMetricsProvider"), exports);
33
32
  function _export_star(from, to) {
@@ -0,0 +1,30 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _export_star(require("./panel"), exports);
18
+ function _export_star(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
21
+ Object.defineProperty(to, k, {
22
+ enumerable: true,
23
+ get: function() {
24
+ return from[k];
25
+ }
26
+ });
27
+ }
28
+ });
29
+ return from;
30
+ }
@@ -0,0 +1,42 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: Object.getOwnPropertyDescriptor(all, name).get
21
+ });
22
+ }
23
+ _export(exports, {
24
+ get buildPanelEditorSchema () {
25
+ return buildPanelEditorSchema;
26
+ },
27
+ get panelEditorSchema () {
28
+ return panelEditorSchema;
29
+ }
30
+ });
31
+ const _zod = require("zod");
32
+ const _spec = require("@perses-dev/spec");
33
+ const panelEditorSchema = _zod.z.object({
34
+ groupId: _zod.z.number(),
35
+ panelDefinition: _spec.panelDefinitionSchema
36
+ });
37
+ function buildPanelEditorSchema(pluginSchema) {
38
+ return _zod.z.object({
39
+ groupId: _zod.z.number(),
40
+ panelDefinition: (0, _spec.buildPanelDefinitionSchema)(pluginSchema)
41
+ });
42
+ }
@@ -0,0 +1,8 @@
1
+ import { HTMLAttributes, ReactElement } from 'react';
2
+ import { Control } from 'react-hook-form';
3
+ import { PanelEditorValues } from '../../model';
4
+ export interface LinksEditorProps extends HTMLAttributes<HTMLDivElement> {
5
+ control: Control<PanelEditorValues>;
6
+ }
7
+ export declare function LinksEditor({ control, ...props }: LinksEditorProps): ReactElement;
8
+ //# sourceMappingURL=LinksEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinksEditor.d.ts","sourceRoot":"","sources":["../../../src/components/LinksEditor/LinksEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAY,cAAc,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE/D,OAAO,EAA6B,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAIrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,gBAAiB,SAAQ,cAAc,CAAC,cAAc,CAAC;IACtE,OAAO,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACrC;AAED,wBAAgB,WAAW,CAAC,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,EAAE,gBAAgB,GAAG,YAAY,CAiCjF"}
@@ -0,0 +1,149 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // Copyright The Perses Authors
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { Fragment } from 'react';
15
+ import { Divider, IconButton, Stack, Typography } from '@mui/material';
16
+ import { Controller, useFieldArray } from 'react-hook-form';
17
+ import PlusIcon from 'mdi-material-ui/Plus';
18
+ import MinusIcon from 'mdi-material-ui/Minus';
19
+ import { LinkEditorForm } from '@perses-dev/components';
20
+ export function LinksEditor({ control, ...props }) {
21
+ const { fields, append, remove } = useFieldArray({
22
+ control: control,
23
+ name: 'panelDefinition.spec.links'
24
+ });
25
+ return /*#__PURE__*/ _jsxs(Stack, {
26
+ ...props,
27
+ gap: 3,
28
+ children: [
29
+ fields && fields.length > 0 ? fields.map((field, index)=>/*#__PURE__*/ _jsxs(Fragment, {
30
+ children: [
31
+ /*#__PURE__*/ _jsxs(Stack, {
32
+ direction: "row",
33
+ gap: 1,
34
+ alignItems: "center",
35
+ children: [
36
+ /*#__PURE__*/ _jsx(LinkControl, {
37
+ control: control,
38
+ index: index
39
+ }),
40
+ /*#__PURE__*/ _jsx(IconButton, {
41
+ style: {
42
+ width: 'fit-content',
43
+ height: 'fit-content'
44
+ },
45
+ onClick: ()=>remove(index),
46
+ children: /*#__PURE__*/ _jsx(MinusIcon, {})
47
+ })
48
+ ]
49
+ }),
50
+ /*#__PURE__*/ _jsx(Divider, {})
51
+ ]
52
+ }, field.id)) : /*#__PURE__*/ _jsx(Typography, {
53
+ variant: "subtitle1",
54
+ mb: 2,
55
+ fontStyle: "italic",
56
+ children: "No links defined"
57
+ }),
58
+ /*#__PURE__*/ _jsx(IconButton, {
59
+ style: {
60
+ width: 'fit-content',
61
+ height: 'fit-content'
62
+ },
63
+ onClick: ()=>append({
64
+ url: '',
65
+ name: '',
66
+ tooltip: '',
67
+ renderVariables: false,
68
+ targetBlank: false
69
+ }),
70
+ children: /*#__PURE__*/ _jsx(PlusIcon, {})
71
+ })
72
+ ]
73
+ });
74
+ }
75
+ function LinkControl({ control, index }) {
76
+ const defaultLink = {
77
+ url: '',
78
+ name: '',
79
+ tooltip: '',
80
+ renderVariables: false,
81
+ targetBlank: false
82
+ };
83
+ return /*#__PURE__*/ _jsx(Controller, {
84
+ control: control,
85
+ name: `panelDefinition.spec.links.${index}`,
86
+ render: ({ field, field: { value: link }, fieldState })=>{
87
+ const safeLink = link ?? defaultLink;
88
+ return /*#__PURE__*/ _jsx(LinkEditorForm, {
89
+ mode: "inline",
90
+ url: {
91
+ value: safeLink.url,
92
+ label: 'URL',
93
+ error: {
94
+ hasError: !!fieldState.error,
95
+ helperText: fieldState.error?.message
96
+ },
97
+ onChange: (url)=>{
98
+ field.onChange({
99
+ ...link,
100
+ url
101
+ });
102
+ }
103
+ },
104
+ newTabOpen: {
105
+ value: !!safeLink.targetBlank,
106
+ onChange: (targetBlank)=>{
107
+ field.onChange({
108
+ ...link,
109
+ targetBlank
110
+ });
111
+ },
112
+ label: 'Open in new tab'
113
+ },
114
+ name: {
115
+ value: safeLink.name ?? '',
116
+ label: 'Name',
117
+ onChange: (name)=>{
118
+ field.onChange({
119
+ ...link,
120
+ name
121
+ });
122
+ }
123
+ },
124
+ renderVariables: {
125
+ value: !!safeLink.renderVariables,
126
+ label: 'Render variables',
127
+ onChange: (renderVariables)=>{
128
+ field.onChange({
129
+ ...link,
130
+ renderVariables
131
+ });
132
+ }
133
+ },
134
+ tooltip: {
135
+ value: safeLink.tooltip ?? '',
136
+ label: 'Tooltip',
137
+ onChange: (tooltip)=>{
138
+ field.onChange({
139
+ ...link,
140
+ tooltip
141
+ });
142
+ }
143
+ }
144
+ });
145
+ }
146
+ });
147
+ }
148
+
149
+ //# sourceMappingURL=LinksEditor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/LinksEditor/LinksEditor.tsx"],"sourcesContent":["// Copyright 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 { Fragment, HTMLAttributes, ReactElement } from 'react';\nimport { Divider, IconButton, Stack, Typography } from '@mui/material';\nimport { Controller, useFieldArray, Control } from 'react-hook-form';\nimport PlusIcon from 'mdi-material-ui/Plus';\nimport MinusIcon from 'mdi-material-ui/Minus';\nimport { LinkEditorForm } from '@perses-dev/components';\nimport { PanelEditorValues } from '../../model';\n\nexport interface LinksEditorProps extends HTMLAttributes<HTMLDivElement> {\n control: Control<PanelEditorValues>;\n}\n\nexport function LinksEditor({ control, ...props }: LinksEditorProps): ReactElement {\n const { fields, append, remove } = useFieldArray({\n control: control,\n name: 'panelDefinition.spec.links',\n });\n\n return (\n <Stack {...props} gap={3}>\n {fields && fields.length > 0 ? (\n fields.map((field, index) => (\n <Fragment key={field.id}>\n <Stack direction=\"row\" gap={1} alignItems=\"center\">\n <LinkControl control={control} index={index} />\n <IconButton style={{ width: 'fit-content', height: 'fit-content' }} onClick={() => remove(index)}>\n <MinusIcon />\n </IconButton>\n </Stack>\n <Divider />\n </Fragment>\n ))\n ) : (\n <Typography variant=\"subtitle1\" mb={2} fontStyle=\"italic\">\n No links defined\n </Typography>\n )}\n <IconButton\n style={{ width: 'fit-content', height: 'fit-content' }}\n onClick={() => append({ url: '', name: '', tooltip: '', renderVariables: false, targetBlank: false })}\n >\n <PlusIcon />\n </IconButton>\n </Stack>\n );\n}\n\nfunction LinkControl({ control, index }: { control: Control<PanelEditorValues>; index: number }): ReactElement {\n const defaultLink = { url: '', name: '', tooltip: '', renderVariables: false, targetBlank: false };\n return (\n <Controller\n control={control}\n name={`panelDefinition.spec.links.${index}`}\n render={({ field, field: { value: link }, fieldState }) => {\n const safeLink = link ?? defaultLink;\n return (\n <LinkEditorForm\n mode=\"inline\"\n url={{\n value: safeLink.url,\n label: 'URL',\n error: { hasError: !!fieldState.error, helperText: fieldState.error?.message },\n onChange: (url) => {\n field.onChange({ ...link, url });\n },\n }}\n newTabOpen={{\n value: !!safeLink.targetBlank,\n onChange: (targetBlank) => {\n field.onChange({ ...link, targetBlank });\n },\n label: 'Open in new tab',\n }}\n name={{\n value: safeLink.name ?? '',\n label: 'Name',\n onChange: (name) => {\n field.onChange({ ...link, name });\n },\n }}\n renderVariables={{\n value: !!safeLink.renderVariables,\n label: 'Render variables',\n onChange: (renderVariables) => {\n field.onChange({ ...link, renderVariables });\n },\n }}\n tooltip={{\n value: safeLink.tooltip ?? '',\n label: 'Tooltip',\n onChange: (tooltip) => {\n field.onChange({ ...link, tooltip });\n },\n }}\n />\n );\n }}\n />\n );\n}\n"],"names":["Fragment","Divider","IconButton","Stack","Typography","Controller","useFieldArray","PlusIcon","MinusIcon","LinkEditorForm","LinksEditor","control","props","fields","append","remove","name","gap","length","map","field","index","direction","alignItems","LinkControl","style","width","height","onClick","id","variant","mb","fontStyle","url","tooltip","renderVariables","targetBlank","defaultLink","render","value","link","fieldState","safeLink","mode","label","error","hasError","helperText","message","onChange","newTabOpen"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,QAAQ,QAAsC,QAAQ;AAC/D,SAASC,OAAO,EAAEC,UAAU,EAA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EAAEK,OAAO;QAC3CiB,QAAQ,CAAC,EAAElB,KAAK,EAAEA,OAAO,EAAEmB,OAAOC,IAAI,EAAE,EAAEC,UAAU,EAAE;YACpD,MAAMC,WAAWF,QAAQH;YACzB,qBACE,KAAC5B;gBACCkC,MAAK;gBACLV,KAAK;oBACHM,OAAOG,SAAST,GAAG;oBACnBW,OAAO;oBACPC,OAAO;wBAAEC,UAAU,CAAC,CAACL,WAAWI,KAAK;wBAAEE,YAAYN,WAAWI,KAAK,EAAEG;oBAAQ;oBAC7EC,UAAU,CAAChB;wBACTb,MAAM6B,QAAQ,CAAC;4BAAE,GAAGT,IAAI;4BAAEP;wBAAI;oBAChC;gBACF;gBACAiB,YAAY;oBACVX,OAAO,CAAC,CAACG,SAASN,WAAW;oBAC7Ba,UAAU,CAACb;wBACThB,MAAM6B,QAAQ,CAAC;4BAAE,GAAGT,IAAI;4BAAEJ;wBAAY;oBACxC;oBACAQ,OAAO;gBACT;gBACA5B,MAAM;oBACJuB,OAAOG,SAAS1B,IAAI,IAAI;oBACxB4B,OAAO;oBACPK,UAAU,CAACjC;wBACTI,MAAM6B,QAAQ,CAAC;4BAAE,GAAGT,IAAI;4BAAExB;wBAAK;oBACjC;gBACF;gBACAmB,iBAAiB;oBACfI,OAAO,CAAC,CAACG,SAASP,eAAe;oBACjCS,OAAO;oBACPK,UAAU,CAACd;wBACTf,MAAM6B,QAAQ,CAAC;4BAAE,GAAGT,IAAI;4BAAEL;wBAAgB;oBAC5C;gBACF;gBACAD,SAAS;oBACPK,OAAOG,SAASR,OAAO,IAAI;oBAC3BU,OAAO;oBACPK,UAAU,CAACf;wBACTd,MAAM6B,QAAQ,CAAC;4BAAE,GAAGT,IAAI;4BAAEN;wBAAQ;oBACpC;gBACF;;QAGN;;AAGN"}
@@ -0,0 +1,2 @@
1
+ export * from './LinksEditor';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/LinksEditor/index.ts"],"names":[],"mappings":"AAaA,cAAc,eAAe,CAAC"}
@@ -0,0 +1,15 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export * from './LinksEditor';
14
+
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/LinksEditor/index.ts"],"sourcesContent":["// Copyright 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\nexport * from './LinksEditor';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,gBAAgB"}
@@ -32,7 +32,7 @@ function useDefaultQueryDefinition(queryTypes, filteredQueryPlugins) {
32
32
  } else {
33
33
  defaultQueryKind = defaultPluginKinds?.[defaultQueryType] ?? queryPlugins?.[0]?.spec.name ?? '';
34
34
  }
35
- const { data: defaultQueryPlugin } = usePlugin(defaultQueryType, defaultQueryKind, {
35
+ const { data: defaultQueryPlugin, isLoading: isPluginLoading } = usePlugin(defaultQueryType, defaultQueryKind, {
36
36
  useErrorBoundary: true,
37
37
  enabled: true
38
38
  });
@@ -47,7 +47,7 @@ function useDefaultQueryDefinition(queryTypes, filteredQueryPlugins) {
47
47
  }
48
48
  }
49
49
  },
50
- isLoading
50
+ isLoading: isLoading || isPluginLoading
51
51
  };
52
52
  }
53
53
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/MultiQueryEditor/MultiQueryEditor.tsx"],"sourcesContent":["// Copyright 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/spec';\nimport { QueryData, 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 queryResults?: QueryData[];\n onChange: (queries: QueryDefinition[]) => void;\n onQueryRun: (index: number, query: 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 = [], queryResults, filteredQueryPlugins, onChange, onQueryRun } = 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 handleQueryRun = (index: number, queryDef: QueryDefinition): void => {\n onQueryRun(index, queryDef);\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 queryResult={queryResults?.[i]}\n filteredQueryPlugins={filteredQueryPlugins}\n isCollapsed={!!queriesCollapsed[i]}\n onChange={handleQueryChange}\n onQueryRun={handleQueryRun}\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","filteredQueryPlugins","defaultQueryType","data","queryPlugins","isLoading","defaultPluginKinds","defaultQueryKind","length","find","i","includes","spec","name","defaultQueryPlugin","useErrorBoundary","enabled","defaultInitialQueryDefinition","kind","plugin","createInitialOptions","MultiQueryEditor","props","ref","queries","queryResults","onChange","onQueryRun","queriesCollapsed","setQueriesCollapsed","map","handleQueryChange","index","queryDef","draft","handleQueryRun","handleQueryAdd","push","handleQueryDelete","splice","handleQueryCollapseExpand","queryDefinitions","spacing","query","queryResult","isCollapsed","onDelete","undefined","onCollapseExpand","variant","startIcon","sx","marginTop","onClick","displayName"],"mappings":";AAAA,+BAA+B;AAC/B,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,SAAoBC,qBAAqB,EAAEC,SAAS,EAAEC,iBAAiB,QAAQ,gBAAgB;AAE/F,SAASC,oBAAoB,QAAQ,yBAAyB;AAW9D,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,EAAE,EAAEQ,KAAKC,QAAQ;IAC/F;IAEA,MAAM,EAAEV,MAAMW,kBAAkB,EAAE,GAAGlB,UAAUM,kBAAkBK,kBAAkB;QACjFQ,kBAAkB;QAClBC,SAAS;IACX;IAEA,qGA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;IAEA,MAAMY,4BAA4B,CAACR;QACjCH,oBAAoB,CAACD;YACnBA,gBAAgB,CAACI,MAAM,GAAG,CAACJ,gBAAgB,CAACI,MAAM;YAClD,OAAO;mBAAIJ;aAAiB;QAC9B;IACF;IAEA,2CAA2C;IAC3C,MAAMa,mBAAsCjB,QAAQhB,MAAM,GACtDgB,UACA,CAACnB,YACC;QAACY;KAA8B,GAC/B,EAAE;IAER,qBACE;;0BACE,KAACxB;gBAAMiD,SAAS;0BACbD,iBAAiBX,GAAG,CAAC,CAACa,OAAwBjC,kBAC7C,KAACZ;wBACCyB,KAAKA;wBACLvB,YAAYA;wBAEZgC,OAAOtB;wBACPiC,OAAOA;wBACPC,aAAanB,cAAc,CAACf,EAAE;wBAC9BT,sBAAsBA;wBACtB4C,aAAa,CAAC,CAACjB,gBAAgB,CAAClB,EAAE;wBAClCgB,UAAUK;wBACVJ,YAAYQ;wBACZW,UAAUtB,QAAQhB,MAAM,GAAG,IAAI8B,oBAAoBS;wBACnDC,kBAAkBR;uBATb9B;;0BAaX,KAAClB;gBAAOyD,SAAQ;gBAAYC,yBAAW,KAACxD;gBAAYyD,IAAI;oBAAEC,WAAW;gBAAE;gBAAGC,SAASjB;0BAAgB;;;;AAKzG,GAAG;AAEHf,iBAAiBiC,WAAW,GAAG"}
1
+ {"version":3,"sources":["../../../src/components/MultiQueryEditor/MultiQueryEditor.tsx"],"sourcesContent":["// Copyright 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/spec';\nimport { QueryData, 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 queryResults?: QueryData[];\n onChange: (queries: QueryDefinition[]) => void;\n onQueryRun: (index: number, query: 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, isLoading: isPluginLoading } = 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: isLoading || isPluginLoading,\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 = [], queryResults, filteredQueryPlugins, onChange, onQueryRun } = 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 handleQueryRun = (index: number, queryDef: QueryDefinition): void => {\n onQueryRun(index, queryDef);\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 queryResult={queryResults?.[i]}\n filteredQueryPlugins={filteredQueryPlugins}\n isCollapsed={!!queriesCollapsed[i]}\n onChange={handleQueryChange}\n onQueryRun={handleQueryRun}\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","filteredQueryPlugins","defaultQueryType","data","queryPlugins","isLoading","defaultPluginKinds","defaultQueryKind","length","find","i","includes","spec","name","defaultQueryPlugin","isPluginLoading","useErrorBoundary","enabled","defaultInitialQueryDefinition","kind","plugin","createInitialOptions","MultiQueryEditor","props","ref","queries","queryResults","onChange","onQueryRun","queriesCollapsed","setQueriesCollapsed","map","handleQueryChange","index","queryDef","draft","handleQueryRun","handleQueryAdd","push","handleQueryDelete","splice","handleQueryCollapseExpand","queryDefinitions","spacing","query","queryResult","isCollapsed","onDelete","undefined","onCollapseExpand","variant","startIcon","sx","marginTop","onClick","displayName"],"mappings":";AAAA,+BAA+B;AAC/B,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,SAAoBC,qBAAqB,EAAEC,SAAS,EAAEC,iBAAiB,QAAQ,gBAAgB;AAE/F,SAASC,oBAAoB,QAAQ,yBAAyB;AAW9D,SAASC,0BACPC,UAA6B,EAC7BC,oBAA+B;IAK/B,iCAAiC;IAC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AAG,IAAI+B,oBAAoBS;wBACnDC,kBAAkBR;uBATb/B;;0BAaX,KAAClB;gBAAO0D,SAAQ;gBAAYC,yBAAW,KAACzD;gBAAY0D,IAAI;oBAAEC,WAAW;gBAAE;gBAAGC,SAASjB;0BAAgB;;;;AAKzG,GAAG;AAEHf,iBAAiBiC,WAAW,GAAG"}
@@ -1 +1 @@
1
- {"version":3,"file":"QueryEditorContainer.d.ts","sourceRoot":"","sources":["../../../src/components/MultiQueryEditor/QueryEditorContainer.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAQpE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAmC,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEnF;;GAEG;AACH,UAAU,yBAAyB;IACjC,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,eAAe,CAAC;IACvB,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAC1D,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAC5D,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,oBAAoB,uHAqFhC,CAAC"}
1
+ {"version":3,"file":"QueryEditorContainer.d.ts","sourceRoot":"","sources":["../../../src/components/MultiQueryEditor/QueryEditorContainer.tsx"],"names":[],"mappings":";AAcA,OAAO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