@perses-dev/plugin-system 0.0.0-snapshot-time-chart-rewrite-4667058 → 0.0.0-snapshot-panel-extra-content-3-17f9c42

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 (97) hide show
  1. package/dist/cjs/components/OptionsEditorRadios/OptionsEditorRadios.js +74 -0
  2. package/dist/cjs/components/OptionsEditorRadios/index.js +28 -0
  3. package/dist/cjs/components/{OptionsEditorTabs/TabPanel.js → OptionsEditorTabPanel/OptionsEditorTabPanel.js} +3 -3
  4. package/dist/cjs/components/OptionsEditorTabPanel/index.js +28 -0
  5. package/dist/cjs/components/OptionsEditorTabs/OptionsEditorTabs.js +2 -2
  6. package/dist/cjs/components/PluginEditor/PluginEditor.js +4 -2
  7. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +459 -0
  8. package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +178 -0
  9. package/dist/cjs/components/Variables/VariableEditorForm/index.js +29 -0
  10. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +102 -0
  11. package/dist/cjs/components/Variables/index.js +29 -0
  12. package/dist/cjs/components/Variables/variable-model.js +117 -0
  13. package/dist/cjs/components/index.js +2 -0
  14. package/dist/cjs/constants/index.js +28 -0
  15. package/dist/cjs/constants/user-interface-text.js +25 -0
  16. package/dist/cjs/index.js +1 -0
  17. package/dist/cjs/runtime/template-variables.js +62 -0
  18. package/dist/cjs/runtime/time-series-queries.js +1 -1
  19. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.d.ts +16 -0
  20. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.d.ts.map +1 -0
  21. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js +68 -0
  22. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js.map +1 -0
  23. package/dist/components/OptionsEditorRadios/index.d.ts +2 -0
  24. package/dist/components/OptionsEditorRadios/index.d.ts.map +1 -0
  25. package/dist/components/OptionsEditorRadios/index.js +15 -0
  26. package/dist/components/OptionsEditorRadios/index.js.map +1 -0
  27. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.d.ts +9 -0
  28. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.d.ts.map +1 -0
  29. package/dist/components/{OptionsEditorTabs/TabPanel.js → OptionsEditorTabPanel/OptionsEditorTabPanel.js} +2 -2
  30. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js.map +1 -0
  31. package/dist/components/OptionsEditorTabPanel/index.d.ts +2 -0
  32. package/dist/components/OptionsEditorTabPanel/index.d.ts.map +1 -0
  33. package/dist/components/OptionsEditorTabPanel/index.js +15 -0
  34. package/dist/components/OptionsEditorTabPanel/index.js.map +1 -0
  35. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js +2 -2
  36. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js.map +1 -1
  37. package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
  38. package/dist/components/PluginEditor/PluginEditor.js +4 -2
  39. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  40. package/dist/components/PluginEditor/plugin-editor-api.d.ts +1 -0
  41. package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
  42. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  43. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +12 -0
  44. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -0
  45. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +414 -0
  46. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -0
  47. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +16 -0
  48. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -0
  49. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +122 -0
  50. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -0
  51. package/dist/components/Variables/VariableEditorForm/index.d.ts +3 -0
  52. package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -0
  53. package/dist/components/Variables/VariableEditorForm/index.js +16 -0
  54. package/dist/components/Variables/VariableEditorForm/index.js.map +1 -0
  55. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +23 -0
  56. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -0
  57. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +90 -0
  58. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -0
  59. package/dist/components/Variables/index.d.ts +3 -0
  60. package/dist/components/Variables/index.d.ts.map +1 -0
  61. package/dist/components/Variables/index.js +16 -0
  62. package/dist/components/Variables/index.js.map +1 -0
  63. package/dist/components/Variables/variable-model.d.ts +17 -0
  64. package/dist/components/Variables/variable-model.d.ts.map +1 -0
  65. package/dist/components/Variables/variable-model.js +105 -0
  66. package/dist/components/Variables/variable-model.js.map +1 -0
  67. package/dist/components/index.d.ts +2 -0
  68. package/dist/components/index.d.ts.map +1 -1
  69. package/dist/components/index.js +2 -0
  70. package/dist/components/index.js.map +1 -1
  71. package/dist/constants/index.d.ts +2 -0
  72. package/dist/constants/index.d.ts.map +1 -0
  73. package/dist/constants/index.js +15 -0
  74. package/dist/constants/index.js.map +1 -0
  75. package/dist/constants/user-interface-text.d.ts +5 -0
  76. package/dist/constants/user-interface-text.d.ts.map +1 -0
  77. package/dist/constants/user-interface-text.js +19 -0
  78. package/dist/constants/user-interface-text.js.map +1 -0
  79. package/dist/index.d.ts +1 -0
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +1 -0
  82. package/dist/index.js.map +1 -1
  83. package/dist/model/plugin-base.d.ts +1 -0
  84. package/dist/model/plugin-base.d.ts.map +1 -1
  85. package/dist/model/plugin-base.js.map +1 -1
  86. package/dist/runtime/template-variables.d.ts +61 -2
  87. package/dist/runtime/template-variables.d.ts.map +1 -1
  88. package/dist/runtime/template-variables.js +63 -0
  89. package/dist/runtime/template-variables.js.map +1 -1
  90. package/dist/runtime/time-series-queries.d.ts +1 -1
  91. package/dist/runtime/time-series-queries.d.ts.map +1 -1
  92. package/dist/runtime/time-series-queries.js +1 -1
  93. package/dist/runtime/time-series-queries.js.map +1 -1
  94. package/package.json +4 -4
  95. package/dist/components/OptionsEditorTabs/TabPanel.d.ts +0 -9
  96. package/dist/components/OptionsEditorTabs/TabPanel.d.ts.map +0 -1
  97. package/dist/components/OptionsEditorTabs/TabPanel.js.map +0 -1
@@ -0,0 +1,178 @@
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
+ VariablePreview: ()=>VariablePreview,
25
+ VariableListPreview: ()=>VariableListPreview
26
+ });
27
+ const _jsxRuntime = require("react/jsx-runtime");
28
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
29
+ const _material = require("@mui/material");
30
+ const _components = require("@perses-dev/components");
31
+ const _refresh = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Refresh"));
32
+ const _clipboardOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/ClipboardOutline"));
33
+ const _constants = require("../../../constants");
34
+ const _variableModel = require("../variable-model");
35
+ function _interopRequireDefault(obj) {
36
+ return obj && obj.__esModule ? obj : {
37
+ default: obj
38
+ };
39
+ }
40
+ function _getRequireWildcardCache(nodeInterop) {
41
+ if (typeof WeakMap !== "function") return null;
42
+ var cacheBabelInterop = new WeakMap();
43
+ var cacheNodeInterop = new WeakMap();
44
+ return (_getRequireWildcardCache = function(nodeInterop) {
45
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
46
+ })(nodeInterop);
47
+ }
48
+ function _interopRequireWildcard(obj, nodeInterop) {
49
+ if (!nodeInterop && obj && obj.__esModule) {
50
+ return obj;
51
+ }
52
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
53
+ return {
54
+ default: obj
55
+ };
56
+ }
57
+ var cache = _getRequireWildcardCache(nodeInterop);
58
+ if (cache && cache.has(obj)) {
59
+ return cache.get(obj);
60
+ }
61
+ var newObj = {};
62
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
63
+ for(var key in obj){
64
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
65
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
66
+ if (desc && (desc.get || desc.set)) {
67
+ Object.defineProperty(newObj, key, desc);
68
+ } else {
69
+ newObj[key] = obj[key];
70
+ }
71
+ }
72
+ }
73
+ newObj.default = obj;
74
+ if (cache) {
75
+ cache.set(obj, newObj);
76
+ }
77
+ return newObj;
78
+ }
79
+ const DEFAULT_MAX_PREVIEW_VALUES = 50;
80
+ function VariablePreview(props) {
81
+ const { values , onRefresh , isLoading , error } = props;
82
+ const [maxValues, setMaxValues] = (0, _react.useState)(DEFAULT_MAX_PREVIEW_VALUES);
83
+ const { infoSnackbar } = (0, _components.useSnackbar)();
84
+ const showAll = ()=>{
85
+ setMaxValues(undefined);
86
+ };
87
+ let notShown = 0;
88
+ if (values && (values === null || values === void 0 ? void 0 : values.length) > 0 && maxValues) {
89
+ notShown = values.length - maxValues;
90
+ }
91
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
92
+ children: [
93
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
94
+ direction: "row",
95
+ spacing: 1,
96
+ alignItems: "center",
97
+ mb: 1,
98
+ children: [
99
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
100
+ variant: "h4",
101
+ children: "Preview Values"
102
+ }),
103
+ onRefresh && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.InfoTooltip, {
104
+ description: _constants.TOOLTIP_TEXT.refreshVariableValues,
105
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
106
+ onClick: onRefresh,
107
+ size: "small",
108
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_refresh.default, {})
109
+ })
110
+ }),
111
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.InfoTooltip, {
112
+ description: _constants.TOOLTIP_TEXT.copyVariableValues,
113
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
114
+ onClick: async ()=>{
115
+ if (values === null || values === void 0 ? void 0 : values.length) {
116
+ await navigator.clipboard.writeText(values.map((value)=>value).join(', '));
117
+ infoSnackbar('Preview values copied to clipboard!');
118
+ }
119
+ },
120
+ size: "small",
121
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_clipboardOutline.default, {})
122
+ })
123
+ })
124
+ ]
125
+ }),
126
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Card, {
127
+ variant: "outlined",
128
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
129
+ sx: {
130
+ display: 'flex',
131
+ flexWrap: 'wrap',
132
+ gap: 1,
133
+ m: 2
134
+ },
135
+ children: [
136
+ error && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Alert, {
137
+ severity: "error",
138
+ children: error
139
+ }),
140
+ (values === null || values === void 0 ? void 0 : values.length) === 0 && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Alert, {
141
+ severity: "info",
142
+ children: "No results"
143
+ }),
144
+ isLoading && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Stack, {
145
+ width: "100%",
146
+ sx: {
147
+ alignItems: 'center',
148
+ justifyContent: 'center'
149
+ },
150
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.CircularProgress, {})
151
+ }),
152
+ values === null || values === void 0 ? void 0 : values.slice(0, maxValues).map((val)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Chip, {
153
+ size: "small",
154
+ label: val
155
+ }, val)),
156
+ notShown > 0 && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Chip, {
157
+ onClick: showAll,
158
+ variant: "outlined",
159
+ size: "small",
160
+ label: `+${notShown} more`
161
+ })
162
+ ]
163
+ })
164
+ })
165
+ ]
166
+ });
167
+ }
168
+ function VariableListPreview(props) {
169
+ const { definition , onRefresh } = props;
170
+ const { data , isFetching , error } = (0, _variableModel.useListVariablePluginValues)(definition);
171
+ const errorMessage = error === null || error === void 0 ? void 0 : error.message;
172
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(VariablePreview, {
173
+ values: (data === null || data === void 0 ? void 0 : data.map((val)=>val.value)) || [],
174
+ onRefresh: onRefresh,
175
+ isLoading: isFetching,
176
+ error: errorMessage
177
+ });
178
+ }
@@ -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
+ ];
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", {
17
17
  _exportStar(require("./CalculationSelector"), exports);
18
18
  _exportStar(require("./DatasourceSelect"), exports);
19
19
  _exportStar(require("./LegendOptionsEditor"), exports);
20
+ _exportStar(require("./OptionsEditorRadios"), exports);
20
21
  _exportStar(require("./OptionsEditorTabs"), exports);
21
22
  _exportStar(require("./PanelSpecEditor"), exports);
22
23
  _exportStar(require("./PluginEditor"), exports);
@@ -24,6 +25,7 @@ _exportStar(require("./PluginKindSelect"), exports);
24
25
  _exportStar(require("./PluginRegistry"), exports);
25
26
  _exportStar(require("./PluginSpecEditor"), exports);
26
27
  _exportStar(require("./TimeSeriesQueryEditor"), exports);
28
+ _exportStar(require("./Variables"), exports);
27
29
  function _exportStar(from, to) {
28
30
  Object.keys(from).forEach(function(k) {
29
31
  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);
@@ -21,12 +21,74 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
+ VariableStoreStateMap: ()=>VariableStoreStateMap,
24
25
  TemplateVariableContext: ()=>TemplateVariableContext,
25
26
  useTemplateVariableValues: ()=>useTemplateVariableValues,
26
27
  useReplaceVariablesInString: ()=>useReplaceVariablesInString
27
28
  });
28
29
  const _react = require("react");
30
+ const _immer = require("immer");
29
31
  const _utils = require("../utils");
32
+ let _immerable = _immer.immerable;
33
+ class VariableStoreStateMap {
34
+ /**
35
+ * Get variable state by key.
36
+ * @param key
37
+ */ get(key) {
38
+ return this._sourceStatesOrEmpty(key.source)[key.name];
39
+ }
40
+ /**
41
+ * Set variable state by key.
42
+ * @param key
43
+ * @param value
44
+ */ set(key, value) {
45
+ const sourceName = this._sourceName(key.source);
46
+ if (!this._state[sourceName]) {
47
+ this._state[sourceName] = {};
48
+ }
49
+ this._sourceStatesOrEmpty(key.source)[key.name] = value;
50
+ return value;
51
+ }
52
+ /**
53
+ * Check presence of variable state by key.
54
+ * @param key
55
+ */ has(key) {
56
+ return this._sourceStatesOrEmpty(key.source)[key.name] !== undefined;
57
+ }
58
+ /**
59
+ * Delete variable state by key.
60
+ * @param key
61
+ */ delete(key) {
62
+ var ref;
63
+ const result = this.has(key);
64
+ const sourceName = this._sourceName(key.source);
65
+ const sourceStates = this._state[sourceName];
66
+ // Delete var from source state
67
+ if (sourceStates) {
68
+ delete sourceStates[key.name];
69
+ }
70
+ // Delete source state from state if empty
71
+ if (((ref = Object.keys(sourceStates !== null && sourceStates !== void 0 ? sourceStates : {})) === null || ref === void 0 ? void 0 : ref.length) === 0) {
72
+ delete this._state[sourceName];
73
+ }
74
+ return result;
75
+ }
76
+ _sourceName(source) {
77
+ return source !== null && source !== void 0 ? source : this.DEFAULT_LOCAL_SOURCE_NAME;
78
+ }
79
+ _sourceStatesOrEmpty(source) {
80
+ var ref;
81
+ return (ref = this._state[this._sourceName(source)]) !== null && ref !== void 0 ? ref : {};
82
+ }
83
+ constructor(){
84
+ /**
85
+ * "Immerable" is mandatory to be able to use this class in an immer context.
86
+ * Ref: https://docs.pmnd.rs/zustand/integrations/immer-middleware#gotchas
87
+ */ this[_immerable] = true;
88
+ this.DEFAULT_LOCAL_SOURCE_NAME = '';
89
+ this._state = {};
90
+ }
91
+ }
30
92
  const TemplateVariableContext = (0, _react.createContext)(undefined);
31
93
  function useTemplateVariableContext() {
32
94
  const ctx = (0, _react.useContext)(TemplateVariableContext);
@@ -117,7 +117,7 @@ function useTimeSeriesQueries(definitions, options) {
117
117
  return {
118
118
  enabled: queryEnabled,
119
119
  queryKey: queryKey,
120
- refetchInterval: context.refreshIntervalInMs > 0 ? context.refreshIntervalInMs : false,
120
+ refetchInterval: context.refreshIntervalInMs > 0 ? context.refreshIntervalInMs : undefined,
121
121
  queryFn: async ()=>{
122
122
  // Keep options out of query key so we don't re-run queries because suggested step changes
123
123
  const ctx = {
@@ -0,0 +1,16 @@
1
+ /// <reference types="react" />
2
+ export declare type OptionsEditorRadio = {
3
+ label: string;
4
+ /**
5
+ * Content rendered when the tab is active.
6
+ */
7
+ content: React.ReactNode;
8
+ };
9
+ export declare type OptionsEditorRadiosProps = {
10
+ tabs: OptionsEditorRadio[];
11
+ defaultTab: number;
12
+ onModeChange: (value: number) => void;
13
+ isReadonly?: boolean;
14
+ };
15
+ export declare const OptionsEditorRadios: (props: OptionsEditorRadiosProps) => JSX.Element;
16
+ //# sourceMappingURL=OptionsEditorRadios.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OptionsEditorRadios.d.ts","sourceRoot":"","sources":["../../../src/components/OptionsEditorRadios/OptionsEditorRadios.tsx"],"names":[],"mappings":";AAiBA,oBAAY,kBAAkB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC;CAC1B,CAAC;AAEF,oBAAY,wBAAwB,GAAG;IACrC,IAAI,EAAE,kBAAkB,EAAE,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,mBAAmB,UAAW,wBAAwB,gBAuClE,CAAC"}