@perses-dev/plugin-system 0.37.1 → 0.38.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 (61) hide show
  1. package/dist/cjs/components/PluginEditor/PluginEditor.js +4 -2
  2. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +459 -0
  3. package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +178 -0
  4. package/dist/cjs/components/Variables/VariableEditorForm/index.js +29 -0
  5. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +102 -0
  6. package/dist/cjs/components/Variables/index.js +29 -0
  7. package/dist/cjs/components/Variables/variable-model.js +117 -0
  8. package/dist/cjs/components/index.js +1 -0
  9. package/dist/cjs/constants/index.js +28 -0
  10. package/dist/cjs/constants/user-interface-text.js +25 -0
  11. package/dist/cjs/index.js +1 -0
  12. package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
  13. package/dist/components/PluginEditor/PluginEditor.js +4 -2
  14. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  15. package/dist/components/PluginEditor/plugin-editor-api.d.ts +1 -0
  16. package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
  17. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  18. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +12 -0
  19. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -0
  20. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +414 -0
  21. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -0
  22. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +16 -0
  23. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -0
  24. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +122 -0
  25. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -0
  26. package/dist/components/Variables/VariableEditorForm/index.d.ts +3 -0
  27. package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -0
  28. package/dist/components/Variables/VariableEditorForm/index.js +16 -0
  29. package/dist/components/Variables/VariableEditorForm/index.js.map +1 -0
  30. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +23 -0
  31. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -0
  32. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +90 -0
  33. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -0
  34. package/dist/components/Variables/index.d.ts +3 -0
  35. package/dist/components/Variables/index.d.ts.map +1 -0
  36. package/dist/components/Variables/index.js +16 -0
  37. package/dist/components/Variables/index.js.map +1 -0
  38. package/dist/components/Variables/variable-model.d.ts +17 -0
  39. package/dist/components/Variables/variable-model.d.ts.map +1 -0
  40. package/dist/components/Variables/variable-model.js +105 -0
  41. package/dist/components/Variables/variable-model.js.map +1 -0
  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/constants/index.d.ts +2 -0
  47. package/dist/constants/index.d.ts.map +1 -0
  48. package/dist/constants/index.js +15 -0
  49. package/dist/constants/index.js.map +1 -0
  50. package/dist/constants/user-interface-text.d.ts +5 -0
  51. package/dist/constants/user-interface-text.d.ts.map +1 -0
  52. package/dist/constants/user-interface-text.js +19 -0
  53. package/dist/constants/user-interface-text.js.map +1 -0
  54. package/dist/index.d.ts +1 -0
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +1 -0
  57. package/dist/index.js.map +1 -1
  58. package/dist/model/plugin-base.d.ts +1 -0
  59. package/dist/model/plugin-base.d.ts.map +1 -1
  60. package/dist/model/plugin-base.js.map +1 -1
  61. package/package.json +4 -4
@@ -0,0 +1,29 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _exportStar(require("./VariableEditorForm"), exports);
18
+ _exportStar(require("./VariablePreview"), exports);
19
+ function _exportStar(from, to) {
20
+ Object.keys(from).forEach(function(k) {
21
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
22
+ enumerable: true,
23
+ get: function() {
24
+ return from[k];
25
+ }
26
+ });
27
+ });
28
+ return from;
29
+ }
@@ -0,0 +1,102 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ getInitialState: ()=>getInitialState,
25
+ getVariableDefinitionFromState: ()=>getVariableDefinitionFromState
26
+ });
27
+ function getInitialState(initialVariableDefinition) {
28
+ var ref, ref1;
29
+ var _value;
30
+ const textVariableFields = {
31
+ value: (_value = initialVariableDefinition.spec.value) !== null && _value !== void 0 ? _value : ''
32
+ };
33
+ const listVariableFields = {
34
+ allowMultiple: false,
35
+ allowAll: false,
36
+ capturing_regexp: undefined,
37
+ plugin: {
38
+ kind: '',
39
+ spec: {}
40
+ },
41
+ customAllValue: undefined
42
+ };
43
+ if (initialVariableDefinition.kind === 'ListVariable') {
44
+ var _allow_all_value;
45
+ listVariableFields.allowMultiple = (_allow_all_value = initialVariableDefinition.spec.allow_all_value) !== null && _allow_all_value !== void 0 ? _allow_all_value : false;
46
+ var _allow_all_value1;
47
+ listVariableFields.allowAll = (_allow_all_value1 = initialVariableDefinition.spec.allow_all_value) !== null && _allow_all_value1 !== void 0 ? _allow_all_value1 : false;
48
+ listVariableFields.capturing_regexp = initialVariableDefinition.spec.capturing_regexp;
49
+ listVariableFields.plugin = initialVariableDefinition.spec.plugin;
50
+ listVariableFields.customAllValue = initialVariableDefinition.spec.custom_all_value;
51
+ }
52
+ return {
53
+ name: initialVariableDefinition.spec.name,
54
+ title: (ref = initialVariableDefinition.spec.display) === null || ref === void 0 ? void 0 : ref.name,
55
+ kind: initialVariableDefinition.kind,
56
+ description: (ref1 = initialVariableDefinition.spec.display) === null || ref1 === void 0 ? void 0 : ref1.description,
57
+ listVariableFields,
58
+ textVariableFields
59
+ };
60
+ }
61
+ function getVariableDefinitionFromState(state) {
62
+ const { name , title , kind , description } = state;
63
+ let display = title ? {
64
+ name: title
65
+ } : undefined;
66
+ if (description) {
67
+ if (display) {
68
+ display.description = description;
69
+ } else {
70
+ // Name is mandatory if you want to add a description, autofilled by the metadata name if undefined
71
+ display = {
72
+ name: name,
73
+ description: description
74
+ };
75
+ }
76
+ }
77
+ if (kind === 'TextVariable') {
78
+ return {
79
+ kind,
80
+ spec: {
81
+ name,
82
+ display,
83
+ ...state.textVariableFields
84
+ }
85
+ };
86
+ }
87
+ if (kind === 'ListVariable') {
88
+ return {
89
+ kind,
90
+ spec: {
91
+ name,
92
+ display,
93
+ allow_multiple: state.listVariableFields.allowMultiple,
94
+ allow_all_value: state.listVariableFields.allowAll,
95
+ capturing_regexp: state.listVariableFields.capturing_regexp,
96
+ plugin: state.listVariableFields.plugin,
97
+ custom_all_value: state.listVariableFields.customAllValue
98
+ }
99
+ };
100
+ }
101
+ throw new Error(`Unknown variable kind: ${kind}`);
102
+ }
@@ -0,0 +1,29 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _exportStar(require("./variable-model"), exports);
18
+ _exportStar(require("./VariableEditorForm"), exports);
19
+ function _exportStar(from, to) {
20
+ Object.keys(from).forEach(function(k) {
21
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
22
+ enumerable: true,
23
+ get: function() {
24
+ return from[k];
25
+ }
26
+ });
27
+ });
28
+ return from;
29
+ }
@@ -0,0 +1,117 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name1 in all)Object.defineProperty(target, name1, {
19
+ enumerable: true,
20
+ get: all[name1]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ filterVariableList: ()=>filterVariableList,
25
+ useListVariablePluginValues: ()=>useListVariablePluginValues,
26
+ getVariableValuesKey: ()=>getVariableValuesKey,
27
+ VARIABLE_TYPES: ()=>VARIABLE_TYPES
28
+ });
29
+ const _reactQuery = require("@tanstack/react-query");
30
+ const _runtime = require("../../runtime");
31
+ function filterVariableList(data, capturedRegexp) {
32
+ const result = [];
33
+ const filteredSet = new Set();
34
+ for (const variableValue of data){
35
+ const matches = variableValue.value.matchAll(capturedRegexp);
36
+ let concat = '';
37
+ for (const match of matches){
38
+ for(let i = 1; i < match.length; i++){
39
+ const m = match[i];
40
+ if (m !== undefined) {
41
+ concat = `${concat}${m}`;
42
+ }
43
+ }
44
+ }
45
+ if (concat !== '' && !filteredSet.has(concat)) {
46
+ // like that we are avoiding to have duplicating variable value
47
+ filteredSet.add(concat);
48
+ result.push({
49
+ label: variableValue.label,
50
+ value: concat
51
+ });
52
+ }
53
+ }
54
+ return result;
55
+ }
56
+ function useListVariablePluginValues(definition) {
57
+ const { data: variablePlugin } = (0, _runtime.usePlugin)('Variable', definition.spec.plugin.kind);
58
+ const datasourceStore = (0, _runtime.useDatasourceStore)();
59
+ const allVariables = (0, _runtime.useTemplateVariableValues)();
60
+ const { absoluteTimeRange: timeRange , refreshKey } = (0, _runtime.useTimeRange)();
61
+ const variablePluginCtx = {
62
+ timeRange,
63
+ datasourceStore,
64
+ variables: allVariables
65
+ };
66
+ const spec = definition.spec.plugin.spec;
67
+ const capturingRegexp = definition.spec.capturing_regexp !== undefined ? new RegExp(definition.spec.capturing_regexp, 'g') : undefined;
68
+ let dependsOnVariables;
69
+ if (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.dependsOn) {
70
+ const dependencies = variablePlugin.dependsOn(spec, variablePluginCtx);
71
+ dependsOnVariables = dependencies.variables;
72
+ }
73
+ const variables = (0, _runtime.useTemplateVariableValues)(dependsOnVariables);
74
+ let waitToLoad = false;
75
+ if (dependsOnVariables) {
76
+ waitToLoad = dependsOnVariables.some((v)=>{
77
+ var ref;
78
+ return (ref = variables[v]) === null || ref === void 0 ? void 0 : ref.loading;
79
+ });
80
+ }
81
+ const variablesValueKey = getVariableValuesKey(variables);
82
+ return (0, _reactQuery.useQuery)([
83
+ name,
84
+ definition,
85
+ variablesValueKey,
86
+ timeRange,
87
+ refreshKey
88
+ ], async ()=>{
89
+ const resp = await (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.getVariableOptions(spec, {
90
+ datasourceStore,
91
+ variables,
92
+ timeRange
93
+ }));
94
+ if (resp === undefined) {
95
+ return [];
96
+ }
97
+ if (capturingRegexp === undefined) {
98
+ return resp.data;
99
+ }
100
+ return filterVariableList(resp.data, capturingRegexp);
101
+ }, {
102
+ enabled: !!variablePlugin || waitToLoad
103
+ });
104
+ }
105
+ function getVariableValuesKey(v) {
106
+ return Object.values(v).map((v)=>JSON.stringify(v.value)).join(',');
107
+ }
108
+ const VARIABLE_TYPES = [
109
+ {
110
+ label: 'List',
111
+ kind: 'ListVariable'
112
+ },
113
+ {
114
+ label: 'Text',
115
+ kind: 'TextVariable'
116
+ }
117
+ ];
@@ -24,6 +24,7 @@ _exportStar(require("./PluginKindSelect"), exports);
24
24
  _exportStar(require("./PluginRegistry"), exports);
25
25
  _exportStar(require("./PluginSpecEditor"), exports);
26
26
  _exportStar(require("./TimeSeriesQueryEditor"), exports);
27
+ _exportStar(require("./Variables"), exports);
27
28
  function _exportStar(from, to) {
28
29
  Object.keys(from).forEach(function(k) {
29
30
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
@@ -0,0 +1,28 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _exportStar(require("./user-interface-text"), exports);
18
+ function _exportStar(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
21
+ enumerable: true,
22
+ get: function() {
23
+ return from[k];
24
+ }
25
+ });
26
+ });
27
+ return from;
28
+ }
@@ -0,0 +1,25 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "TOOLTIP_TEXT", {
18
+ enumerable: true,
19
+ get: ()=>TOOLTIP_TEXT
20
+ });
21
+ const TOOLTIP_TEXT = {
22
+ // Variable editor buttons
23
+ refreshVariableValues: 'Refresh values',
24
+ copyVariableValues: 'Copy values to clipboard'
25
+ };
package/dist/cjs/index.js CHANGED
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
17
  _exportStar(require("./components"), exports);
18
+ _exportStar(require("./constants"), exports);
18
19
  _exportStar(require("./model"), exports);
19
20
  _exportStar(require("./runtime"), exports);
20
21
  _exportStar(require("./test-utils"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"PluginEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,iBAAiB,EAAmB,MAAM,qBAAqB,CAAC;AAEzE;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,eAqBpD"}
1
+ {"version":3,"file":"PluginEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,iBAAiB,EAAmB,MAAM,qBAAqB,CAAC;AAEzE;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,eA4BpD"}
@@ -24,7 +24,7 @@ import { usePluginEditor } from './plugin-editor-api';
24
24
  * `usePluginEditor` hook that powers this component.
25
25
  */ export function PluginEditor(props) {
26
26
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
27
- const { value , pluginType , pluginKindLabel , onChange: _ , ...others } = props;
27
+ const { value , pluginType , pluginKindLabel , onChange: _ , isReadonly , ...others } = props;
28
28
  const { pendingKind , isLoading , error , onKindChange , onSpecChange } = usePluginEditor(props);
29
29
  var ref;
30
30
  return /*#__PURE__*/ _jsxs(Box, {
@@ -48,6 +48,7 @@ import { usePluginEditor } from './plugin-editor-api';
48
48
  label: pluginKindLabel,
49
49
  pluginType: pluginType,
50
50
  value: pendingKind !== '' ? pendingKind : value.kind,
51
+ readOnly: isReadonly,
51
52
  onChange: onKindChange
52
53
  }),
53
54
  /*#__PURE__*/ _jsx(FormHelperText, {
@@ -59,7 +60,8 @@ import { usePluginEditor } from './plugin-editor-api';
59
60
  pluginType: pluginType,
60
61
  pluginKind: value.kind,
61
62
  value: value.spec,
62
- onChange: onSpecChange
63
+ onChange: onSpecChange,
64
+ isReadonly: isReadonly
63
65
  })
64
66
  ]
65
67
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box, FormControl, FormHelperText, InputLabel } from '@mui/material';\nimport { PluginKindSelect } from '../PluginKindSelect';\nimport { PluginSpecEditor } from '../PluginSpecEditor';\nimport { PluginEditorProps, usePluginEditor } from './plugin-editor-api';\n\n/**\n * A combination `PluginKindSelect` and `PluginSpecEditor` component. This is meant for editing the `plugin` property\n * that's common in our JSON specs where a user selects a plugin `kind` and then edits the `spec` via that plugin's\n * editor component. It takes care of transitioning from one plugin kind to another \"all at once\" so that when the\n * plugin's kind changes, the spec is also changed at the same time so those options editor components don't see a\n * previous plugin's spec state. If you just want this behavior, but in a different UI layout from this, try the\n * `usePluginEditor` hook that powers this component.\n */\nexport function PluginEditor(props: PluginEditorProps) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { value, pluginType, pluginKindLabel, onChange: _, ...others } = props;\n const { pendingKind, isLoading, error, onKindChange, onSpecChange } = usePluginEditor(props);\n return (\n <Box {...others}>\n <FormControl margin=\"dense\" fullWidth={false} disabled={isLoading} error={error !== null} sx={{ mb: 1 }}>\n {/* TODO: How to ensure ids are unique? */}\n <InputLabel id=\"plugin-kind-label\">{pluginKindLabel}</InputLabel>\n <PluginKindSelect\n labelId=\"plugin-kind-label\"\n label={pluginKindLabel}\n pluginType={pluginType}\n value={pendingKind !== '' ? pendingKind : value.kind}\n onChange={onKindChange}\n />\n <FormHelperText>{error?.message ?? ''}</FormHelperText>\n </FormControl>\n <PluginSpecEditor pluginType={pluginType} pluginKind={value.kind} value={value.spec} onChange={onSpecChange} />\n </Box>\n );\n}\n"],"names":["Box","FormControl","FormHelperText","InputLabel","PluginKindSelect","PluginSpecEditor","usePluginEditor","PluginEditor","props","value","pluginType","pluginKindLabel","onChange","_","others","pendingKind","isLoading","error","onKindChange","onSpecChange","margin","fullWidth","disabled","sx","mb","id","labelId","label","kind","message","pluginKind","spec"],"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;AAAA,SAASA,GAAG,EAAEC,WAAW,EAAEC,cAAc,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAC7E,SAASC,gBAAgB,QAAQ,qBAAqB,CAAC;AACvD,SAASC,gBAAgB,QAAQ,qBAAqB,CAAC;AACvD,SAA4BC,eAAe,QAAQ,qBAAqB,CAAC;AAEzE;;;;;;;CAOC,GACD,OAAO,SAASC,YAAY,CAACC,KAAwB,EAAE;IACrD,6DAA6D;IAC7D,MAAM,EAAEC,KAAK,CAAA,EAAEC,UAAU,CAAA,EAAEC,eAAe,CAAA,EAAEC,QAAQ,EAAEC,CAAC,CAAA,EAAE,GAAGC,MAAM,EAAE,GAAGN,KAAK,AAAC;IAC7E,MAAM,EAAEO,WAAW,CAAA,EAAEC,SAAS,CAAA,EAAEC,KAAK,CAAA,EAAEC,YAAY,CAAA,EAAEC,YAAY,CAAA,EAAE,GAAGb,eAAe,CAACE,KAAK,CAAC,AAAC;QAatES,GAAc;IAZrC,qBACE,MAACjB,GAAG;QAAE,GAAGc,MAAM;;0BACb,MAACb,WAAW;gBAACmB,MAAM,EAAC,OAAO;gBAACC,SAAS,EAAE,KAAK;gBAAEC,QAAQ,EAAEN,SAAS;gBAAEC,KAAK,EAAEA,KAAK,KAAK,IAAI;gBAAEM,EAAE,EAAE;oBAAEC,EAAE,EAAE,CAAC;iBAAE;;kCAErG,KAACrB,UAAU;wBAACsB,EAAE,EAAC,mBAAmB;kCAAEd,eAAe;sBAAc;kCACjE,KAACP,gBAAgB;wBACfsB,OAAO,EAAC,mBAAmB;wBAC3BC,KAAK,EAAEhB,eAAe;wBACtBD,UAAU,EAAEA,UAAU;wBACtBD,KAAK,EAAEM,WAAW,KAAK,EAAE,GAAGA,WAAW,GAAGN,KAAK,CAACmB,IAAI;wBACpDhB,QAAQ,EAAEM,YAAY;sBACtB;kCACF,KAAChB,cAAc;kCAAEe,CAAAA,GAAc,GAAdA,KAAK,aAALA,KAAK,WAAS,GAAdA,KAAAA,CAAc,GAAdA,KAAK,CAAEY,OAAO,cAAdZ,GAAc,cAAdA,GAAc,GAAI,EAAE;sBAAkB;;cAC3C;0BACd,KAACZ,gBAAgB;gBAACK,UAAU,EAAEA,UAAU;gBAAEoB,UAAU,EAAErB,KAAK,CAACmB,IAAI;gBAAEnB,KAAK,EAAEA,KAAK,CAACsB,IAAI;gBAAEnB,QAAQ,EAAEO,YAAY;cAAI;;MAC3G,CACN;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box, FormControl, FormHelperText, InputLabel } from '@mui/material';\nimport { PluginKindSelect } from '../PluginKindSelect';\nimport { PluginSpecEditor } from '../PluginSpecEditor';\nimport { PluginEditorProps, usePluginEditor } from './plugin-editor-api';\n\n/**\n * A combination `PluginKindSelect` and `PluginSpecEditor` component. This is meant for editing the `plugin` property\n * that's common in our JSON specs where a user selects a plugin `kind` and then edits the `spec` via that plugin's\n * editor component. It takes care of transitioning from one plugin kind to another \"all at once\" so that when the\n * plugin's kind changes, the spec is also changed at the same time so those options editor components don't see a\n * previous plugin's spec state. If you just want this behavior, but in a different UI layout from this, try the\n * `usePluginEditor` hook that powers this component.\n */\nexport function PluginEditor(props: PluginEditorProps) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { value, pluginType, pluginKindLabel, onChange: _, isReadonly, ...others } = props;\n const { pendingKind, isLoading, error, onKindChange, onSpecChange } = usePluginEditor(props);\n return (\n <Box {...others}>\n <FormControl margin=\"dense\" fullWidth={false} disabled={isLoading} error={error !== null} sx={{ mb: 1 }}>\n {/* TODO: How to ensure ids are unique? */}\n <InputLabel id=\"plugin-kind-label\">{pluginKindLabel}</InputLabel>\n <PluginKindSelect\n labelId=\"plugin-kind-label\"\n label={pluginKindLabel}\n pluginType={pluginType}\n value={pendingKind !== '' ? pendingKind : value.kind}\n readOnly={isReadonly}\n onChange={onKindChange}\n />\n <FormHelperText>{error?.message ?? ''}</FormHelperText>\n </FormControl>\n <PluginSpecEditor\n pluginType={pluginType}\n pluginKind={value.kind}\n value={value.spec}\n onChange={onSpecChange}\n isReadonly={isReadonly}\n />\n </Box>\n );\n}\n"],"names":["Box","FormControl","FormHelperText","InputLabel","PluginKindSelect","PluginSpecEditor","usePluginEditor","PluginEditor","props","value","pluginType","pluginKindLabel","onChange","_","isReadonly","others","pendingKind","isLoading","error","onKindChange","onSpecChange","margin","fullWidth","disabled","sx","mb","id","labelId","label","kind","readOnly","message","pluginKind","spec"],"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;AAAA,SAASA,GAAG,EAAEC,WAAW,EAAEC,cAAc,EAAEC,UAAU,QAAQ,eAAe,CAA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,GAAc,cAAdA,GAAc,GAAI,EAAE;sBAAkB;;cAC3C;0BACd,KAACb,gBAAgB;gBACfK,UAAU,EAAEA,UAAU;gBACtBsB,UAAU,EAAEvB,KAAK,CAACoB,IAAI;gBACtBpB,KAAK,EAAEA,KAAK,CAACwB,IAAI;gBACjBrB,QAAQ,EAAEQ,YAAY;gBACtBN,UAAU,EAAEA,UAAU;cACtB;;MACE,CACN;AACJ,CAAC"}
@@ -7,6 +7,7 @@ export interface PluginEditorProps extends Omit<BoxProps, OmittedMuiProps> {
7
7
  pluginType: PluginType;
8
8
  pluginKindLabel: string;
9
9
  value: Definition<UnknownSpec>;
10
+ isReadonly?: boolean;
10
11
  onChange: (next: Definition<UnknownSpec>) => void;
11
12
  }
12
13
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-editor-api.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/plugin-editor-api.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAY,MAAM,kBAAkB,CAAC;AAGrE,OAAO,EAAe,UAAU,EAAE,MAAM,aAAa,CAAC;AAOtD,aAAK,eAAe,GAAG,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC;AAEzD,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,QAAQ,EAAE,eAAe,CAAC;IACxE,UAAU,EAAE,UAAU,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IAC/B,QAAQ,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;CACnD;AAKD;;GAEG;AACH,oBAAY,oBAAoB,GAAG,IAAI,CAAC,iBAAiB,EAAE,YAAY,GAAG,OAAO,GAAG,UAAU,CAAC,GAAG;IAChG,uBAAuB,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;CACvD,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB;;;;;;;EAqG1D"}
1
+ {"version":3,"file":"plugin-editor-api.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/plugin-editor-api.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAY,MAAM,kBAAkB,CAAC;AAGrE,OAAO,EAAe,UAAU,EAAE,MAAM,aAAa,CAAC;AAOtD,aAAK,eAAe,GAAG,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC;AAEzD,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,QAAQ,EAAE,eAAe,CAAC;IACxE,UAAU,EAAE,UAAU,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;CACnD;AAKD;;GAEG;AACH,oBAAY,oBAAoB,GAAG,IAAI,CAAC,iBAAiB,EAAE,YAAY,GAAG,OAAO,GAAG,UAAU,CAAC,GAAG;IAChG,uBAAuB,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;CACvD,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB;;;;;;;EAqG1D"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/PluginEditor/plugin-editor-api.ts"],"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 { BoxProps } from '@mui/material';\nimport { Definition, UnknownSpec, useEvent } from '@perses-dev/core';\nimport { useState, useRef, useEffect } from 'react';\nimport { produce } from 'immer';\nimport { PanelPlugin, PluginType } from '../../model';\nimport { PluginKindSelectProps } from '../PluginKindSelect/PluginKindSelect';\nimport { PluginSpecEditorProps } from '../PluginSpecEditor/PluginSpecEditor';\nimport { usePlugin, usePluginRegistry } from '../../runtime';\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';\n\nexport interface PluginEditorProps extends Omit<BoxProps, OmittedMuiProps> {\n pluginType: PluginType;\n pluginKindLabel: string;\n value: Definition<UnknownSpec>;\n onChange: (next: Definition<UnknownSpec>) => void;\n}\n\ntype PreviousSpecState = Record<string, Record<string, UnknownSpec>>;\ntype HideQueryEditorState = Record<string, boolean>;\n\n/**\n * Props needed by the usePluginEditor hook.\n */\nexport type UsePluginEditorProps = Pick<PluginEditorProps, 'pluginType' | 'value' | 'onChange'> & {\n onHideQueryEditorChange?: (isHidden: boolean) => void;\n};\n\n/**\n * Returns the state/handlers that power the `PluginEditor` component. Useful for custom components that want to provide\n * a different UI, but want the same behavior of changing `kind` and `spec` together on plugin kind changes. Also\n * remembers previous `spec` values that it's seen, allowing and restores those values if a user switches the plugin\n * kind back.\n */\nexport function usePluginEditor(props: UsePluginEditorProps) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const { pluginType, value, onHideQueryEditorChange = () => {} } = props; // setting onHideQueryEditorChange to empty function here because useEvent requires a function\n\n // Keep a stable reference so we don't run the effect below when we don't need to\n const onChange = useEvent(props.onChange);\n const onHideQuery = useEvent(onHideQueryEditorChange);\n\n // The previous spec state for PluginType and kind and a helper function for remembering current values\n const prevSpecState = useRef<PreviousSpecState>({\n [pluginType]: { [value.kind]: value.spec },\n });\n const rememberCurrentSpecState = useEvent(() => {\n let byPluginType = prevSpecState.current[pluginType];\n if (byPluginType === undefined) {\n byPluginType = {};\n prevSpecState.current[pluginType] = byPluginType;\n }\n byPluginType[value.kind] = value.spec;\n });\n\n // The previous hide query state for each panel kind\n const hideQueryState = useRef<HideQueryEditorState>({\n [value.kind]: false,\n });\n\n const { defaultPluginKinds } = usePluginRegistry();\n const defaultPluginKind = defaultPluginKinds?.[pluginType];\n const initPendingKind = !value.kind && defaultPluginKind ? defaultPluginKind : '';\n\n // When kind changes and we haven't loaded that plugin before, we will need to enter a \"pending\" state so that we\n // can generate proper initial spec values that match the new plugin kind\n const [pendingKind, setPendingKind] = useState(initPendingKind);\n const { data: plugin, isFetching, error } = usePlugin(pluginType, pendingKind);\n\n useEffect(() => {\n // Nothing to do if no new plugin kind is pending\n if (pendingKind === '') return;\n\n // Can't get spec value until we have a plugin\n if (plugin === undefined) return;\n\n // Fire an onChange to change to the pending kind with initial values from the plugin\n rememberCurrentSpecState();\n onChange({\n kind: pendingKind,\n spec: plugin.createInitialOptions(),\n });\n\n if (pluginType === 'Panel') {\n const panelPlugin = plugin as PanelPlugin;\n hideQueryState.current[pendingKind] = !!panelPlugin.hideQueryEditor;\n if (!!panelPlugin.hideQueryEditor !== hideQueryState.current[value.kind]) {\n onHideQuery(!!panelPlugin.hideQueryEditor);\n }\n }\n\n setPendingKind('');\n }, [pendingKind, plugin, rememberCurrentSpecState, onChange, onHideQuery, hideQueryState, pluginType, value.kind]);\n\n /**\n * When the user tries to change the plugin kind, make sure we have the correct spec for that plugin kind before we\n * make the switch.\n */\n const onKindChange: PluginKindSelectProps['onChange'] = (e) => {\n const nextKind = e.target.value;\n\n // If we already have state for this plugin type/kind from a previous selection, just use it\n const previousState = prevSpecState.current[pluginType]?.[nextKind];\n if (previousState !== undefined) {\n rememberCurrentSpecState();\n onChange({\n kind: nextKind,\n spec: previousState,\n });\n } else {\n // Otherwise, kick off the async loading process\n setPendingKind(nextKind);\n }\n\n if (\n pluginType === 'Panel' &&\n hideQueryState.current[nextKind] !== undefined &&\n hideQueryState.current[value.kind] !== hideQueryState.current[nextKind]\n ) {\n onHideQuery(!!hideQueryState.current[nextKind]);\n }\n };\n\n /**\n * Spec changes are independent and always just set the spec state.\n */\n const onSpecChange: PluginSpecEditorProps['onChange'] = (next) => {\n onChange(\n produce(value, (draft) => {\n draft.spec = next;\n })\n );\n };\n\n return { pendingKind, isLoading: isFetching, error, onKindChange, onSpecChange, rememberCurrentSpecState };\n}\n"],"names":["useEvent","useState","useRef","useEffect","produce","usePlugin","usePluginRegistry","usePluginEditor","props","pluginType","value","onHideQueryEditorChange","onChange","onHideQuery","prevSpecState","kind","spec","rememberCurrentSpecState","byPluginType","current","undefined","hideQueryState","defaultPluginKinds","defaultPluginKind","initPendingKind","pendingKind","setPendingKind","data","plugin","isFetching","error","createInitialOptions","panelPlugin","hideQueryEditor","onKindChange","e","nextKind","target","previousState","onSpecChange","next","draft","isLoading"],"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;AAGjC,SAAkCA,QAAQ,QAAQ,kBAAkB,CAAC;AACrE,SAASC,QAAQ,EAAEC,MAAM,EAAEC,SAAS,QAAQ,OAAO,CAAC;AACpD,SAASC,OAAO,QAAQ,OAAO,CAAC;AAIhC,SAASC,SAAS,EAAEC,iBAAiB,QAAQ,eAAe,CAAC;AAuB7D;;;;;CAKC,GACD,OAAO,SAASC,eAAe,CAACC,KAA2B,EAAE;IAC3D,gEAAgE;IAChE,MAAM,EAAEC,UAAU,CAAA,EAAEC,KAAK,CAAA,EAAEC,uBAAuB,EAAG,IAAM,CAAC,CAAC,CAAA,EAAE,GAAGH,KAAK,AAAC,EAAC,8FAA8F;I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AACV,UAAU,CAAC,cAAjCK,GAAiC,WAAY,GAA7CA,KAAAA,CAA6C,GAA7CA,GAAiC,AAAE,CAACsB,QAAQ,CAAC,AAAC;QACpE,IAAIE,aAAa,KAAKlB,SAAS,EAAE;YAC/BH,wBAAwB,EAAE,CAAC;YAC3BL,QAAQ,CAAC;gBACPG,IAAI,EAAEqB,QAAQ;gBACdpB,IAAI,EAAEsB,aAAa;aACpB,CAAC,CAAC;QACL,OAAO;YACL,gDAAgD;YAChDZ,cAAc,CAACU,QAAQ,CAAC,CAAC;QAC3B,CAAC;QAED,IACE3B,UAAU,KAAK,OAAO,IACtBY,cAAc,CAACF,OAAO,CAACiB,QAAQ,CAAC,KAAKhB,SAAS,IAC9CC,cAAc,CAACF,OAAO,CAACT,KAAK,CAACK,IAAI,CAAC,KAAKM,cAAc,CAACF,OAAO,CAACiB,QAAQ,CAAC,EACvE;YACAvB,WAAW,CAAC,CAAC,CAACQ,cAAc,CAACF,OAAO,CAACiB,QAAQ,CAAC,CAAC,CAAC;QAClD,CAAC;IACH,CAAC,AAAC;IAEF;;GAEC,GACD,MAAMG,YAAY,GAAsC,CAACC,IAAI,GAAK;QAChE5B,QAAQ,CACNR,OAAO,CAACM,KAAK,EAAE,CAAC+B,KAAK,GAAK;YACxBA,KAAK,CAACzB,IAAI,GAAGwB,IAAI,CAAC;QACpB,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,AAAC;IAEF,OAAO;QAAEf,WAAW;QAAEiB,SAAS,EAAEb,UAAU;QAAEC,KAAK;QAAEI,YAAY;QAAEK,YAAY;QAAEtB,wBAAwB;KAAE,CAAC;AAC7G,CAAC"}
1
+ {"version":3,"sources":["../../../src/components/PluginEditor/plugin-editor-api.ts"],"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 { BoxProps } from '@mui/material';\nimport { Definition, UnknownSpec, useEvent } from '@perses-dev/core';\nimport { useState, useRef, useEffect } from 'react';\nimport { produce } from 'immer';\nimport { PanelPlugin, PluginType } from '../../model';\nimport { PluginKindSelectProps } from '../PluginKindSelect/PluginKindSelect';\nimport { PluginSpecEditorProps } from '../PluginSpecEditor/PluginSpecEditor';\nimport { usePlugin, usePluginRegistry } from '../../runtime';\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';\n\nexport interface PluginEditorProps extends Omit<BoxProps, OmittedMuiProps> {\n pluginType: PluginType;\n pluginKindLabel: string;\n value: Definition<UnknownSpec>;\n isReadonly?: boolean;\n onChange: (next: Definition<UnknownSpec>) => void;\n}\n\ntype PreviousSpecState = Record<string, Record<string, UnknownSpec>>;\ntype HideQueryEditorState = Record<string, boolean>;\n\n/**\n * Props needed by the usePluginEditor hook.\n */\nexport type UsePluginEditorProps = Pick<PluginEditorProps, 'pluginType' | 'value' | 'onChange'> & {\n onHideQueryEditorChange?: (isHidden: boolean) => void;\n};\n\n/**\n * Returns the state/handlers that power the `PluginEditor` component. Useful for custom components that want to provide\n * a different UI, but want the same behavior of changing `kind` and `spec` together on plugin kind changes. Also\n * remembers previous `spec` values that it's seen, allowing and restores those values if a user switches the plugin\n * kind back.\n */\nexport function usePluginEditor(props: UsePluginEditorProps) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const { pluginType, value, onHideQueryEditorChange = () => {} } = props; // setting onHideQueryEditorChange to empty function here because useEvent requires a function\n\n // Keep a stable reference so we don't run the effect below when we don't need to\n const onChange = useEvent(props.onChange);\n const onHideQuery = useEvent(onHideQueryEditorChange);\n\n // The previous spec state for PluginType and kind and a helper function for remembering current values\n const prevSpecState = useRef<PreviousSpecState>({\n [pluginType]: { [value.kind]: value.spec },\n });\n const rememberCurrentSpecState = useEvent(() => {\n let byPluginType = prevSpecState.current[pluginType];\n if (byPluginType === undefined) {\n byPluginType = {};\n prevSpecState.current[pluginType] = byPluginType;\n }\n byPluginType[value.kind] = value.spec;\n });\n\n // The previous hide query state for each panel kind\n const hideQueryState = useRef<HideQueryEditorState>({\n [value.kind]: false,\n });\n\n const { defaultPluginKinds } = usePluginRegistry();\n const defaultPluginKind = defaultPluginKinds?.[pluginType];\n const initPendingKind = !value.kind && defaultPluginKind ? defaultPluginKind : '';\n\n // When kind changes and we haven't loaded that plugin before, we will need to enter a \"pending\" state so that we\n // can generate proper initial spec values that match the new plugin kind\n const [pendingKind, setPendingKind] = useState(initPendingKind);\n const { data: plugin, isFetching, error } = usePlugin(pluginType, pendingKind);\n\n useEffect(() => {\n // Nothing to do if no new plugin kind is pending\n if (pendingKind === '') return;\n\n // Can't get spec value until we have a plugin\n if (plugin === undefined) return;\n\n // Fire an onChange to change to the pending kind with initial values from the plugin\n rememberCurrentSpecState();\n onChange({\n kind: pendingKind,\n spec: plugin.createInitialOptions(),\n });\n\n if (pluginType === 'Panel') {\n const panelPlugin = plugin as PanelPlugin;\n hideQueryState.current[pendingKind] = !!panelPlugin.hideQueryEditor;\n if (!!panelPlugin.hideQueryEditor !== hideQueryState.current[value.kind]) {\n onHideQuery(!!panelPlugin.hideQueryEditor);\n }\n }\n\n setPendingKind('');\n }, [pendingKind, plugin, rememberCurrentSpecState, onChange, onHideQuery, hideQueryState, pluginType, value.kind]);\n\n /**\n * When the user tries to change the plugin kind, make sure we have the correct spec for that plugin kind before we\n * make the switch.\n */\n const onKindChange: PluginKindSelectProps['onChange'] = (e) => {\n const nextKind = e.target.value;\n\n // If we already have state for this plugin type/kind from a previous selection, just use it\n const previousState = prevSpecState.current[pluginType]?.[nextKind];\n if (previousState !== undefined) {\n rememberCurrentSpecState();\n onChange({\n kind: nextKind,\n spec: previousState,\n });\n } else {\n // Otherwise, kick off the async loading process\n setPendingKind(nextKind);\n }\n\n if (\n pluginType === 'Panel' &&\n hideQueryState.current[nextKind] !== undefined &&\n hideQueryState.current[value.kind] !== hideQueryState.current[nextKind]\n ) {\n onHideQuery(!!hideQueryState.current[nextKind]);\n }\n };\n\n /**\n * Spec changes are independent and always just set the spec state.\n */\n const onSpecChange: PluginSpecEditorProps['onChange'] = (next) => {\n onChange(\n produce(value, (draft) => {\n draft.spec = next;\n })\n );\n };\n\n return { pendingKind, isLoading: isFetching, error, onKindChange, onSpecChange, rememberCurrentSpecState };\n}\n"],"names":["useEvent","useState","useRef","useEffect","produce","usePlugin","usePluginRegistry","usePluginEditor","props","pluginType","value","onHideQueryEditorChange","onChange","onHideQuery","prevSpecState","kind","spec","rememberCurrentSpecState","byPluginType","current","undefined","hideQueryState","defaultPluginKinds","defaultPluginKind","initPendingKind","pendingKind","setPendingKind","data","plugin","isFetching","error","createInitialOptions","panelPlugin","hideQueryEditor","onKindChange","e","nextKind","target","previousState","onSpecChange","next","draft","isLoading"],"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;AAGjC,SAAkCA,QAAQ,QAAQ,kBAAkB,CAAC;AACrE,SAASC,QAAQ,EAAEC,MAAM,EAAEC,SAAS,QAAQ,OAAO,CAAC;AACpD,SAASC,OAAO,QAAQ,OAAO,CAAC;AAIhC,SAASC,SAAS,EAAEC,iBAAiB,QAAQ,eAAe,CAAC;AAwB7D;;;;;CAKC,GACD,OAAO,SAASC,eAAe,CAACC,KAA2B,EAAE;IAC3D,gEAAgE;IAChE,MAAM,EAAEC,UAAU,CAAA,EAAEC,KAAK,CAAA,EAAEC,uBAAuB,EAAG,IAAM,CAAC,CAAC,CAAA,EAAE,GAAGH,KAAK,A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,aAAa,CAACK,OAAO,CAACV,UAAU,CAAC,cAAjCK,GAAiC,WAAY,GAA7CA,KAAAA,CAA6C,GAA7CA,GAAiC,AAAE,CAACsB,QAAQ,CAAC,AAAC;QACpE,IAAIE,aAAa,KAAKlB,SAAS,EAAE;YAC/BH,wBAAwB,EAAE,CAAC;YAC3BL,QAAQ,CAAC;gBACPG,IAAI,EAAEqB,QAAQ;gBACdpB,IAAI,EAAEsB,aAAa;aACpB,CAAC,CAAC;QACL,OAAO;YACL,gDAAgD;YAChDZ,cAAc,CAACU,QAAQ,CAAC,CAAC;QAC3B,CAAC;QAED,IACE3B,UAAU,KAAK,OAAO,IACtBY,cAAc,CAACF,OAAO,CAACiB,QAAQ,CAAC,KAAKhB,SAAS,IAC9CC,cAAc,CAACF,OAAO,CAACT,KAAK,CAACK,IAAI,CAAC,KAAKM,cAAc,CAACF,OAAO,CAACiB,QAAQ,CAAC,EACvE;YACAvB,WAAW,CAAC,CAAC,CAACQ,cAAc,CAACF,OAAO,CAACiB,QAAQ,CAAC,CAAC,CAAC;QAClD,CAAC;IACH,CAAC,AAAC;IAEF;;GAEC,GACD,MAAMG,YAAY,GAAsC,CAACC,IAAI,GAAK;QAChE5B,QAAQ,CACNR,OAAO,CAACM,KAAK,EAAE,CAAC+B,KAAK,GAAK;YACxBA,KAAK,CAACzB,IAAI,GAAGwB,IAAI,CAAC;QACpB,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,AAAC;IAEF,OAAO;QAAEf,WAAW;QAAEiB,SAAS,EAAEb,UAAU;QAAEC,KAAK;QAAEI,YAAY;QAAEK,YAAY;QAAEtB,wBAAwB;KAAE,CAAC;AAC7G,CAAC"}
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { VariableDefinition } from '@perses-dev/core';
3
+ export declare type Action = 'create' | 'read' | 'update';
4
+ interface VariableEditFormProps {
5
+ initialVariableDefinition: VariableDefinition;
6
+ onChange: (def: VariableDefinition) => void;
7
+ onCancel: () => void;
8
+ action?: Action;
9
+ }
10
+ export declare function VariableEditForm(props: VariableEditFormProps): JSX.Element;
11
+ export {};
12
+ //# sourceMappingURL=VariableEditorForm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VariableEditorForm.d.ts","sourceRoot":"","sources":["../../../../src/components/Variables/VariableEditorForm/VariableEditorForm.tsx"],"names":[],"mappings":";AAgCA,OAAO,EAAE,kBAAkB,EAA0B,MAAM,kBAAkB,CAAC;AA6B9E,oBAAY,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAC;AAElD,UAAU,qBAAqB;IAC7B,yBAAyB,EAAE,kBAAkB,CAAC;IAC9C,QAAQ,EAAE,CAAC,GAAG,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC5C,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,eAoT5D"}