@perses-dev/plugin-system 0.33.0 → 0.35.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.
- package/dist/cjs/components/CalculationSelector/CalculationSelector.js +4 -9
- package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +153 -0
- package/dist/cjs/components/LegendOptionsEditor/index.js +28 -0
- package/dist/cjs/components/index.js +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/model/index.js +1 -1
- package/dist/cjs/model/legend.js +73 -0
- package/dist/cjs/runtime/template-variables.js +9 -1
- package/dist/cjs/utils/index.js +28 -0
- package/dist/cjs/utils/variables.js +68 -0
- package/dist/components/CalculationSelector/CalculationSelector.d.ts +1 -1
- package/dist/components/CalculationSelector/CalculationSelector.d.ts.map +1 -1
- package/dist/components/CalculationSelector/CalculationSelector.js +3 -8
- package/dist/components/CalculationSelector/CalculationSelector.js.map +1 -1
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts +8 -0
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -0
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +147 -0
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -0
- package/dist/components/LegendOptionsEditor/index.d.ts +2 -0
- package/dist/components/LegendOptionsEditor/index.d.ts.map +1 -0
- package/dist/components/LegendOptionsEditor/index.js +15 -0
- package/dist/components/LegendOptionsEditor/index.js.map +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -0
- package/dist/components/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/model/index.d.ts +1 -1
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +1 -1
- package/dist/model/index.js.map +1 -1
- package/dist/model/legend.d.ts +15 -0
- package/dist/model/legend.d.ts.map +1 -0
- package/dist/model/legend.js +65 -0
- package/dist/model/legend.js.map +1 -0
- package/dist/runtime/template-variables.d.ts +1 -0
- package/dist/runtime/template-variables.d.ts.map +1 -1
- package/dist/runtime/template-variables.js +8 -0
- package/dist/runtime/template-variables.js.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +15 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/variables.d.ts +9 -0
- package/dist/utils/variables.d.ts.map +1 -0
- package/dist/utils/variables.js +57 -0
- package/dist/utils/variables.js.map +1 -0
- package/package.json +4 -4
- package/dist/cjs/model/calculations.js +0 -82
- package/dist/model/calculations.d.ts +0 -21
- package/dist/model/calculations.d.ts.map +0 -1
- package/dist/model/calculations.js +0 -70
- package/dist/model/calculations.js.map +0 -1
|
@@ -19,10 +19,9 @@ Object.defineProperty(exports, "CalculationSelector", {
|
|
|
19
19
|
get: ()=>CalculationSelector
|
|
20
20
|
});
|
|
21
21
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
-
const _material = require("@mui/material");
|
|
23
22
|
const _components = require("@perses-dev/components");
|
|
24
|
-
const
|
|
25
|
-
const CALC_OPTIONS = Object.entries(
|
|
23
|
+
const _core = require("@perses-dev/core");
|
|
24
|
+
const CALC_OPTIONS = Object.entries(_core.CALCULATIONS_CONFIG).map(([id, config])=>{
|
|
26
25
|
return {
|
|
27
26
|
id: id,
|
|
28
27
|
...config
|
|
@@ -32,19 +31,15 @@ function CalculationSelector({ value , onChange }) {
|
|
|
32
31
|
const handleCalculationChange = (_, newValue)=>{
|
|
33
32
|
onChange(newValue.id);
|
|
34
33
|
};
|
|
35
|
-
const calcConfig =
|
|
34
|
+
const calcConfig = _core.CALCULATIONS_CONFIG[value];
|
|
36
35
|
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.OptionsEditorControl, {
|
|
37
36
|
label: "Calculation",
|
|
38
|
-
control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(
|
|
37
|
+
control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.SettingsAutocomplete, {
|
|
39
38
|
value: {
|
|
40
39
|
...calcConfig,
|
|
41
40
|
id: value
|
|
42
41
|
},
|
|
43
42
|
options: CALC_OPTIONS,
|
|
44
|
-
isOptionEqualToValue: (option, value)=>option.id === value.id,
|
|
45
|
-
renderInput: (params)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
46
|
-
...params
|
|
47
|
-
}),
|
|
48
43
|
onChange: handleCalculationChange,
|
|
49
44
|
disableClearable: true
|
|
50
45
|
})
|
|
@@ -0,0 +1,153 @@
|
|
|
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, "LegendOptionsEditor", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>LegendOptionsEditor
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _material = require("@mui/material");
|
|
23
|
+
const _core = require("@perses-dev/core");
|
|
24
|
+
const _components = require("@perses-dev/components");
|
|
25
|
+
const _model = require("../../model");
|
|
26
|
+
const POSITION_OPTIONS = Object.entries(_model.LEGEND_POSITIONS_CONFIG).map(([id, config])=>{
|
|
27
|
+
return {
|
|
28
|
+
id: id,
|
|
29
|
+
...config
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
const MODE_OPTIONS = Object.entries(_model.LEGEND_MODE_CONFIG).map(([id, config])=>{
|
|
33
|
+
return {
|
|
34
|
+
id: id,
|
|
35
|
+
...config
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
const VALUE_OPTIONS = Object.entries(_model.LEGEND_VALUE_CONFIG).map(([id, config])=>{
|
|
39
|
+
return {
|
|
40
|
+
id: id,
|
|
41
|
+
...config
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
function LegendOptionsEditor({ value , onChange }) {
|
|
45
|
+
const handleLegendShowChange = (_, checked)=>{
|
|
46
|
+
// legend is hidden when legend obj is undefined
|
|
47
|
+
const legendValue = checked === true ? {
|
|
48
|
+
position: _core.DEFAULT_LEGEND.position
|
|
49
|
+
} : undefined;
|
|
50
|
+
onChange(legendValue);
|
|
51
|
+
};
|
|
52
|
+
const handleLegendPositionChange = (_, newValue)=>{
|
|
53
|
+
onChange({
|
|
54
|
+
...value,
|
|
55
|
+
position: newValue.id
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
const handleLegendModeChange = (_, newValue)=>{
|
|
59
|
+
onChange({
|
|
60
|
+
...value,
|
|
61
|
+
position: currentPosition,
|
|
62
|
+
mode: newValue.id
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
const handleLegendValueChange = (_, newValue)=>{
|
|
66
|
+
onChange({
|
|
67
|
+
...value,
|
|
68
|
+
position: currentPosition,
|
|
69
|
+
values: newValue.map((value)=>{
|
|
70
|
+
return value.id;
|
|
71
|
+
})
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
const isValidLegend = (0, _model.validateLegendSpec)(value);
|
|
75
|
+
const currentPosition = (0, _core.getLegendPosition)(value === null || value === void 0 ? void 0 : value.position);
|
|
76
|
+
const legendPositionConfig = _model.LEGEND_POSITIONS_CONFIG[currentPosition];
|
|
77
|
+
const currentMode = (0, _core.getLegendMode)(value === null || value === void 0 ? void 0 : value.mode);
|
|
78
|
+
const legendModeConfig = _model.LEGEND_MODE_CONFIG[currentMode];
|
|
79
|
+
const currentValues = (value === null || value === void 0 ? void 0 : value.values) || [];
|
|
80
|
+
const legendValuesConfig = currentValues.reduce((result, item)=>{
|
|
81
|
+
const config = _model.LEGEND_VALUE_CONFIG[item];
|
|
82
|
+
if (config) {
|
|
83
|
+
result.push({
|
|
84
|
+
...config,
|
|
85
|
+
id: item
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}, []);
|
|
90
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
91
|
+
children: [
|
|
92
|
+
!isValidLegend && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorAlert, {
|
|
93
|
+
error: {
|
|
94
|
+
name: 'invalid-legend',
|
|
95
|
+
message: 'Invalid legend spec'
|
|
96
|
+
}
|
|
97
|
+
}),
|
|
98
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.OptionsEditorControl, {
|
|
99
|
+
label: "Show",
|
|
100
|
+
control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Switch, {
|
|
101
|
+
checked: value !== undefined,
|
|
102
|
+
onChange: handleLegendShowChange
|
|
103
|
+
})
|
|
104
|
+
}),
|
|
105
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.OptionsEditorControl, {
|
|
106
|
+
label: "Position",
|
|
107
|
+
control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.SettingsAutocomplete, {
|
|
108
|
+
value: {
|
|
109
|
+
...legendPositionConfig,
|
|
110
|
+
id: currentPosition
|
|
111
|
+
},
|
|
112
|
+
options: POSITION_OPTIONS,
|
|
113
|
+
onChange: handleLegendPositionChange,
|
|
114
|
+
disabled: value === undefined,
|
|
115
|
+
disableClearable: true
|
|
116
|
+
})
|
|
117
|
+
}),
|
|
118
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.OptionsEditorControl, {
|
|
119
|
+
label: "Mode",
|
|
120
|
+
control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.SettingsAutocomplete, {
|
|
121
|
+
value: {
|
|
122
|
+
...legendModeConfig,
|
|
123
|
+
id: currentMode
|
|
124
|
+
},
|
|
125
|
+
options: MODE_OPTIONS,
|
|
126
|
+
onChange: handleLegendModeChange,
|
|
127
|
+
disabled: value === undefined,
|
|
128
|
+
disableClearable: true
|
|
129
|
+
})
|
|
130
|
+
}),
|
|
131
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.OptionsEditorControl, {
|
|
132
|
+
label: "Values",
|
|
133
|
+
description: "Computed values ignore nulls.",
|
|
134
|
+
control: // For some reason, the inferred option type doesn't always seem to work
|
|
135
|
+
// quite right when `multiple` is true. Explicitly setting the generics
|
|
136
|
+
// to work around this.
|
|
137
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.SettingsAutocomplete, {
|
|
138
|
+
multiple: true,
|
|
139
|
+
disableCloseOnSelect: true,
|
|
140
|
+
disableClearable: true,
|
|
141
|
+
value: legendValuesConfig,
|
|
142
|
+
options: VALUE_OPTIONS,
|
|
143
|
+
onChange: handleLegendValueChange,
|
|
144
|
+
disabled: value === undefined || currentMode !== 'Table',
|
|
145
|
+
limitTags: 1,
|
|
146
|
+
ChipProps: {
|
|
147
|
+
size: 'small'
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
})
|
|
151
|
+
]
|
|
152
|
+
});
|
|
153
|
+
}
|
|
@@ -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("./LegendOptionsEditor"), 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
|
+
}
|
|
@@ -16,6 +16,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
16
16
|
});
|
|
17
17
|
_exportStar(require("./CalculationSelector"), exports);
|
|
18
18
|
_exportStar(require("./DatasourceSelect"), exports);
|
|
19
|
+
_exportStar(require("./LegendOptionsEditor"), exports);
|
|
19
20
|
_exportStar(require("./OptionsEditorTabs"), exports);
|
|
20
21
|
_exportStar(require("./PanelSpecEditor"), exports);
|
|
21
22
|
_exportStar(require("./PluginEditor"), exports);
|
package/dist/cjs/index.js
CHANGED
|
@@ -18,6 +18,7 @@ _exportStar(require("./components"), exports);
|
|
|
18
18
|
_exportStar(require("./model"), exports);
|
|
19
19
|
_exportStar(require("./runtime"), exports);
|
|
20
20
|
_exportStar(require("./test-utils"), exports);
|
|
21
|
+
_exportStar(require("./utils"), exports);
|
|
21
22
|
function _exportStar(from, to) {
|
|
22
23
|
Object.keys(from).forEach(function(k) {
|
|
23
24
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
package/dist/cjs/model/index.js
CHANGED
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
_exportStar(require("./calculations"), exports);
|
|
18
17
|
_exportStar(require("./datasource"), exports);
|
|
18
|
+
_exportStar(require("./legend"), exports);
|
|
19
19
|
_exportStar(require("./panels"), exports);
|
|
20
20
|
_exportStar(require("./plugins"), exports);
|
|
21
21
|
_exportStar(require("./plugin-base"), exports);
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
legendValues: ()=>legendValues,
|
|
25
|
+
LEGEND_POSITIONS_CONFIG: ()=>LEGEND_POSITIONS_CONFIG,
|
|
26
|
+
LEGEND_MODE_CONFIG: ()=>LEGEND_MODE_CONFIG,
|
|
27
|
+
LEGEND_VALUE_CONFIG: ()=>LEGEND_VALUE_CONFIG,
|
|
28
|
+
validateLegendSpec: ()=>validateLegendSpec
|
|
29
|
+
});
|
|
30
|
+
const _core = require("@perses-dev/core");
|
|
31
|
+
const legendValues = [
|
|
32
|
+
'Mean',
|
|
33
|
+
'First',
|
|
34
|
+
'FirstNumber',
|
|
35
|
+
'Last',
|
|
36
|
+
'LastNumber',
|
|
37
|
+
'Min',
|
|
38
|
+
'Max',
|
|
39
|
+
'Sum'
|
|
40
|
+
];
|
|
41
|
+
const LEGEND_POSITIONS_CONFIG = {
|
|
42
|
+
Bottom: {
|
|
43
|
+
label: 'Bottom'
|
|
44
|
+
},
|
|
45
|
+
Right: {
|
|
46
|
+
label: 'Right'
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const LEGEND_MODE_CONFIG = {
|
|
50
|
+
List: {
|
|
51
|
+
label: 'List'
|
|
52
|
+
},
|
|
53
|
+
Table: {
|
|
54
|
+
label: 'Table'
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const LEGEND_VALUE_CONFIG = legendValues.reduce((config, value)=>{
|
|
58
|
+
config[value] = _core.CALCULATIONS_CONFIG[value];
|
|
59
|
+
return config;
|
|
60
|
+
}, {});
|
|
61
|
+
function validateLegendSpec(legend) {
|
|
62
|
+
if (legend === undefined) {
|
|
63
|
+
// undefined is valid since this is how legend is hidden by default
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
if (!(0, _core.isValidLegendPosition)(legend.position)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
if (legend.mode && !(0, _core.isValidLegendMode)(legend.mode)) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
@@ -23,9 +23,11 @@ function _export(target, all) {
|
|
|
23
23
|
_export(exports, {
|
|
24
24
|
DEFAULT_ALL_VALUE: ()=>DEFAULT_ALL_VALUE,
|
|
25
25
|
TemplateVariableContext: ()=>TemplateVariableContext,
|
|
26
|
-
useTemplateVariableValues: ()=>useTemplateVariableValues
|
|
26
|
+
useTemplateVariableValues: ()=>useTemplateVariableValues,
|
|
27
|
+
useReplaceVariablesInString: ()=>useReplaceVariablesInString
|
|
27
28
|
});
|
|
28
29
|
const _react = require("react");
|
|
30
|
+
const _utils = require("../utils");
|
|
29
31
|
const DEFAULT_ALL_VALUE = '$__all';
|
|
30
32
|
const TemplateVariableContext = (0, _react.createContext)(undefined);
|
|
31
33
|
function useTemplateVariableContext() {
|
|
@@ -55,3 +57,9 @@ function useTemplateVariableValues(names) {
|
|
|
55
57
|
}
|
|
56
58
|
return values;
|
|
57
59
|
}
|
|
60
|
+
function useReplaceVariablesInString(str) {
|
|
61
|
+
const variablesInString = str ? (0, _utils.parseTemplateVariables)(str) : [];
|
|
62
|
+
const variableValues = useTemplateVariableValues(variablesInString);
|
|
63
|
+
if (!str) return undefined;
|
|
64
|
+
return (0, _utils.replaceTemplateVariables)(str, variableValues);
|
|
65
|
+
}
|
|
@@ -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("./variables"), 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,68 @@
|
|
|
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
|
+
replaceTemplateVariables: ()=>replaceTemplateVariables,
|
|
25
|
+
replaceTemplateVariable: ()=>replaceTemplateVariable,
|
|
26
|
+
parseTemplateVariables: ()=>parseTemplateVariables
|
|
27
|
+
});
|
|
28
|
+
function replaceTemplateVariables(text, variableState) {
|
|
29
|
+
const variables = parseTemplateVariables(text);
|
|
30
|
+
let finalText = text;
|
|
31
|
+
variables.forEach((v)=>{
|
|
32
|
+
const variable = variableState[v];
|
|
33
|
+
if (variable && (variable === null || variable === void 0 ? void 0 : variable.value)) {
|
|
34
|
+
finalText = replaceTemplateVariable(finalText, v, variable === null || variable === void 0 ? void 0 : variable.value);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return finalText;
|
|
38
|
+
}
|
|
39
|
+
function replaceTemplateVariable(text, varName, templateVariableValue) {
|
|
40
|
+
const variableTemplate = '$' + varName;
|
|
41
|
+
let replaceString = '';
|
|
42
|
+
if (Array.isArray(templateVariableValue)) {
|
|
43
|
+
replaceString = `(${templateVariableValue.join('|')})`; // regex style
|
|
44
|
+
}
|
|
45
|
+
if (typeof templateVariableValue === 'string') {
|
|
46
|
+
replaceString = templateVariableValue;
|
|
47
|
+
}
|
|
48
|
+
return text.replaceAll(variableTemplate, replaceString);
|
|
49
|
+
}
|
|
50
|
+
// This regular expression is designed to identify variable references in a template string.
|
|
51
|
+
// It supports two formats for referencing variables:
|
|
52
|
+
// 1. $variableName - This is a simpler format, and the regular expression captures the variable name (\w+ matches one or more word characters).
|
|
53
|
+
// 2. [COMING SOON] ${variableName:value} - This is a more complex format that allows specifying a format function as well.
|
|
54
|
+
// TODO: Fix this lint error
|
|
55
|
+
// eslint-disable-next-line no-useless-escape
|
|
56
|
+
const TEMPLATE_VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?}/gm;
|
|
57
|
+
const parseTemplateVariables = (text)=>{
|
|
58
|
+
const regex = TEMPLATE_VARIABLE_REGEX;
|
|
59
|
+
const matches = new Set();
|
|
60
|
+
let match;
|
|
61
|
+
while((match = regex.exec(text)) !== null){
|
|
62
|
+
if (match && match.length > 1 && match[1]) {
|
|
63
|
+
matches.add(match[1]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// return unique matches
|
|
67
|
+
return Array.from(matches.values());
|
|
68
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CalculationSelector.d.ts","sourceRoot":"","sources":["../../../src/components/CalculationSelector/CalculationSelector.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"CalculationSelector.d.ts","sourceRoot":"","sources":["../../../src/components/CalculationSelector/CalculationSelector.tsx"],"names":[],"mappings":";AAcA,OAAO,EAA0C,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAU3F,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAC;CAC3C;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,wBAAwB,eAuBhF"}
|
|
@@ -11,9 +11,8 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { CALCULATIONS_CONFIG } from '../../model/calculations';
|
|
14
|
+
import { OptionsEditorControl, SettingsAutocomplete } from '@perses-dev/components';
|
|
15
|
+
import { CALCULATIONS_CONFIG } from '@perses-dev/core';
|
|
17
16
|
const CALC_OPTIONS = Object.entries(CALCULATIONS_CONFIG).map(([id, config])=>{
|
|
18
17
|
return {
|
|
19
18
|
id: id,
|
|
@@ -27,16 +26,12 @@ export function CalculationSelector({ value , onChange }) {
|
|
|
27
26
|
const calcConfig = CALCULATIONS_CONFIG[value];
|
|
28
27
|
return /*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
29
28
|
label: "Calculation",
|
|
30
|
-
control: /*#__PURE__*/ _jsx(
|
|
29
|
+
control: /*#__PURE__*/ _jsx(SettingsAutocomplete, {
|
|
31
30
|
value: {
|
|
32
31
|
...calcConfig,
|
|
33
32
|
id: value
|
|
34
33
|
},
|
|
35
34
|
options: CALC_OPTIONS,
|
|
36
|
-
isOptionEqualToValue: (option, value)=>option.id === value.id,
|
|
37
|
-
renderInput: (params)=>/*#__PURE__*/ _jsx(TextField, {
|
|
38
|
-
...params
|
|
39
|
-
}),
|
|
40
35
|
onChange: handleCalculationChange,
|
|
41
36
|
disableClearable: true
|
|
42
37
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/CalculationSelector/CalculationSelector.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 {
|
|
1
|
+
{"version":3,"sources":["../../../src/components/CalculationSelector/CalculationSelector.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 { OptionsEditorControl, SettingsAutocomplete } from '@perses-dev/components';\nimport { CALCULATIONS_CONFIG, CalculationConfig, CalculationType } from '@perses-dev/core';\n\ntype AutocompleteCalculationOption = CalculationConfig & { id: CalculationType };\nconst CALC_OPTIONS: AutocompleteCalculationOption[] = Object.entries(CALCULATIONS_CONFIG).map(([id, config]) => {\n return {\n id: id as CalculationType,\n ...config,\n };\n});\n\nexport interface CalculationSelectorProps {\n value: CalculationType;\n onChange: (unit: CalculationType) => void;\n}\n\nexport function CalculationSelector({ value, onChange }: CalculationSelectorProps) {\n const handleCalculationChange = (_: unknown, newValue: AutocompleteCalculationOption) => {\n onChange(newValue.id);\n };\n\n const calcConfig = CALCULATIONS_CONFIG[value];\n\n return (\n <OptionsEditorControl\n label=\"Calculation\"\n control={\n <SettingsAutocomplete\n value={{\n ...calcConfig,\n id: value,\n }}\n options={CALC_OPTIONS}\n onChange={handleCalculationChange}\n disableClearable\n ></SettingsAutocomplete>\n }\n />\n );\n}\n"],"names":["OptionsEditorControl","SettingsAutocomplete","CALCULATIONS_CONFIG","CALC_OPTIONS","Object","entries","map","id","config","CalculationSelector","value","onChange","handleCalculationChange","_","newValue","calcConfig","label","control","options","disableClearable"],"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,oBAAoB,EAAEC,oBAAoB,QAAQ,wBAAwB,CAAC;AACpF,SAASC,mBAAmB,QAA4C,kBAAkB,CAAC;AAG3F,MAAMC,YAAY,GAAoCC,MAAM,CAACC,OAAO,CAACH,mBAAmB,CAAC,CAACI,GAAG,CAAC,CAAC,CAACC,EAAE,EAAEC,MAAM,CAAC,GAAK;IAC9G,OAAO;QACLD,EAAE,EAAEA,EAAE;QACN,GAAGC,MAAM;KACV,CAAC;AACJ,CAAC,CAAC,AAAC;AAOH,OAAO,SAASC,mBAAmB,CAAC,EAAEC,KAAK,CAAA,EAAEC,QAAQ,CAAA,EAA4B,EAAE;IACjF,MAAMC,uBAAuB,GAAG,CAACC,CAAU,EAAEC,QAAuC,GAAK;QACvFH,QAAQ,CAACG,QAAQ,CAACP,EAAE,CAAC,CAAC;IACxB,CAAC,AAAC;IAEF,MAAMQ,UAAU,GAAGb,mBAAmB,CAACQ,KAAK,CAAC,AAAC;IAE9C,qBACE,KAACV,oBAAoB;QACnBgB,KAAK,EAAC,aAAa;QACnBC,OAAO,gBACL,KAAChB,oBAAoB;YACnBS,KAAK,EAAE;gBACL,GAAGK,UAAU;gBACbR,EAAE,EAAEG,KAAK;aACV;YACDQ,OAAO,EAAEf,YAAY;YACrBQ,QAAQ,EAAEC,uBAAuB;YACjCO,gBAAgB;UACM;MAE1B,CACF;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { LegendSpecOptions } from '../../model';
|
|
3
|
+
export interface LegendOptionsEditorProps {
|
|
4
|
+
value?: LegendSpecOptions;
|
|
5
|
+
onChange: (legend?: LegendSpecOptions) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function LegendOptionsEditor({ value, onChange }: LegendOptionsEditorProps): JSX.Element;
|
|
8
|
+
//# sourceMappingURL=LegendOptionsEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LegendOptionsEditor.d.ts","sourceRoot":"","sources":["../../../src/components/LegendOptionsEditor/LegendOptionsEditor.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAGL,iBAAiB,EAKlB,MAAM,aAAa,CAAC;AA4BrB,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAChD;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,wBAAwB,eA6GhF"}
|
|
@@ -0,0 +1,147 @@
|
|
|
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
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
+
import { Switch } from '@mui/material';
|
|
15
|
+
import { DEFAULT_LEGEND, getLegendMode, getLegendPosition } from '@perses-dev/core';
|
|
16
|
+
import { ErrorAlert, OptionsEditorControl, SettingsAutocomplete } from '@perses-dev/components';
|
|
17
|
+
import { LEGEND_MODE_CONFIG, LEGEND_POSITIONS_CONFIG, validateLegendSpec, LEGEND_VALUE_CONFIG } from '../../model';
|
|
18
|
+
const POSITION_OPTIONS = Object.entries(LEGEND_POSITIONS_CONFIG).map(([id, config])=>{
|
|
19
|
+
return {
|
|
20
|
+
id: id,
|
|
21
|
+
...config
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
const MODE_OPTIONS = Object.entries(LEGEND_MODE_CONFIG).map(([id, config])=>{
|
|
25
|
+
return {
|
|
26
|
+
id: id,
|
|
27
|
+
...config
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
const VALUE_OPTIONS = Object.entries(LEGEND_VALUE_CONFIG).map(([id, config])=>{
|
|
31
|
+
return {
|
|
32
|
+
id: id,
|
|
33
|
+
...config
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
export function LegendOptionsEditor({ value , onChange }) {
|
|
37
|
+
const handleLegendShowChange = (_, checked)=>{
|
|
38
|
+
// legend is hidden when legend obj is undefined
|
|
39
|
+
const legendValue = checked === true ? {
|
|
40
|
+
position: DEFAULT_LEGEND.position
|
|
41
|
+
} : undefined;
|
|
42
|
+
onChange(legendValue);
|
|
43
|
+
};
|
|
44
|
+
const handleLegendPositionChange = (_, newValue)=>{
|
|
45
|
+
onChange({
|
|
46
|
+
...value,
|
|
47
|
+
position: newValue.id
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
const handleLegendModeChange = (_, newValue)=>{
|
|
51
|
+
onChange({
|
|
52
|
+
...value,
|
|
53
|
+
position: currentPosition,
|
|
54
|
+
mode: newValue.id
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
const handleLegendValueChange = (_, newValue)=>{
|
|
58
|
+
onChange({
|
|
59
|
+
...value,
|
|
60
|
+
position: currentPosition,
|
|
61
|
+
values: newValue.map((value)=>{
|
|
62
|
+
return value.id;
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
const isValidLegend = validateLegendSpec(value);
|
|
67
|
+
const currentPosition = getLegendPosition(value === null || value === void 0 ? void 0 : value.position);
|
|
68
|
+
const legendPositionConfig = LEGEND_POSITIONS_CONFIG[currentPosition];
|
|
69
|
+
const currentMode = getLegendMode(value === null || value === void 0 ? void 0 : value.mode);
|
|
70
|
+
const legendModeConfig = LEGEND_MODE_CONFIG[currentMode];
|
|
71
|
+
const currentValues = (value === null || value === void 0 ? void 0 : value.values) || [];
|
|
72
|
+
const legendValuesConfig = currentValues.reduce((result, item)=>{
|
|
73
|
+
const config = LEGEND_VALUE_CONFIG[item];
|
|
74
|
+
if (config) {
|
|
75
|
+
result.push({
|
|
76
|
+
...config,
|
|
77
|
+
id: item
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}, []);
|
|
82
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
83
|
+
children: [
|
|
84
|
+
!isValidLegend && /*#__PURE__*/ _jsx(ErrorAlert, {
|
|
85
|
+
error: {
|
|
86
|
+
name: 'invalid-legend',
|
|
87
|
+
message: 'Invalid legend spec'
|
|
88
|
+
}
|
|
89
|
+
}),
|
|
90
|
+
/*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
91
|
+
label: "Show",
|
|
92
|
+
control: /*#__PURE__*/ _jsx(Switch, {
|
|
93
|
+
checked: value !== undefined,
|
|
94
|
+
onChange: handleLegendShowChange
|
|
95
|
+
})
|
|
96
|
+
}),
|
|
97
|
+
/*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
98
|
+
label: "Position",
|
|
99
|
+
control: /*#__PURE__*/ _jsx(SettingsAutocomplete, {
|
|
100
|
+
value: {
|
|
101
|
+
...legendPositionConfig,
|
|
102
|
+
id: currentPosition
|
|
103
|
+
},
|
|
104
|
+
options: POSITION_OPTIONS,
|
|
105
|
+
onChange: handleLegendPositionChange,
|
|
106
|
+
disabled: value === undefined,
|
|
107
|
+
disableClearable: true
|
|
108
|
+
})
|
|
109
|
+
}),
|
|
110
|
+
/*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
111
|
+
label: "Mode",
|
|
112
|
+
control: /*#__PURE__*/ _jsx(SettingsAutocomplete, {
|
|
113
|
+
value: {
|
|
114
|
+
...legendModeConfig,
|
|
115
|
+
id: currentMode
|
|
116
|
+
},
|
|
117
|
+
options: MODE_OPTIONS,
|
|
118
|
+
onChange: handleLegendModeChange,
|
|
119
|
+
disabled: value === undefined,
|
|
120
|
+
disableClearable: true
|
|
121
|
+
})
|
|
122
|
+
}),
|
|
123
|
+
/*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
124
|
+
label: "Values",
|
|
125
|
+
description: "Computed values ignore nulls.",
|
|
126
|
+
control: // For some reason, the inferred option type doesn't always seem to work
|
|
127
|
+
// quite right when `multiple` is true. Explicitly setting the generics
|
|
128
|
+
// to work around this.
|
|
129
|
+
/*#__PURE__*/ _jsx(SettingsAutocomplete, {
|
|
130
|
+
multiple: true,
|
|
131
|
+
disableCloseOnSelect: true,
|
|
132
|
+
disableClearable: true,
|
|
133
|
+
value: legendValuesConfig,
|
|
134
|
+
options: VALUE_OPTIONS,
|
|
135
|
+
onChange: handleLegendValueChange,
|
|
136
|
+
disabled: value === undefined || currentMode !== 'Table',
|
|
137
|
+
limitTags: 1,
|
|
138
|
+
ChipProps: {
|
|
139
|
+
size: 'small'
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
]
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
//# sourceMappingURL=LegendOptionsEditor.js.map
|