@perses-dev/plugin-system 0.0.0-snapshot-ts-panel-actions-90e9ef0 → 0.0.0-snapshot-reverse-proxy-75afbd7
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/DatasourceEditorForm/DatasourceEditorForm.js +1 -0
- package/dist/cjs/components/{DatasourceSelect.js → DatasourceSelect/DatasourceSelect.js} +4 -3
- package/dist/cjs/components/DatasourceSelect/index.js +30 -0
- package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +117 -90
- package/dist/cjs/components/MultiQueryEditor/MultiQueryEditor.js +5 -2
- package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +14 -4
- package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +7 -5
- package/dist/cjs/components/PluginEditor/PluginEditor.js +57 -17
- package/dist/cjs/components/PluginKindSelect/PluginKindSelect.js +6 -3
- package/dist/cjs/components/PluginSpecEditor/PluginSpecEditor.js +13 -9
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +62 -120
- package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +42 -33
- package/dist/cjs/components/Variables/VariableEditorForm/index.js +1 -0
- package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +47 -0
- package/dist/cjs/components/Variables/variable-model.js +3 -3
- package/dist/cjs/components/index.js +0 -1
- package/dist/cjs/context/index.js +0 -1
- package/dist/cjs/model/legend.js +13 -0
- package/dist/cjs/model/log-queries.js +16 -0
- package/dist/cjs/remote/PluginRuntime.js +3 -2
- package/dist/cjs/remote/remotePluginLoader.js +19 -4
- package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +10 -2
- package/dist/cjs/runtime/DataQueriesProvider/model.js +17 -4
- package/dist/cjs/runtime/RouterProvider.js +114 -0
- package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +6 -1
- package/dist/cjs/runtime/UsageMetricsProvider.js +4 -3
- package/dist/cjs/runtime/index.js +1 -0
- package/dist/cjs/runtime/log-queries.js +68 -0
- package/dist/cjs/runtime/time-series-queries.js +4 -4
- package/dist/cjs/runtime/variables.js +15 -0
- package/dist/cjs/test/mock-data.js +182 -0
- package/dist/cjs/test/utils.js +17 -8
- package/dist/cjs/utils/variables.js +109 -14
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +1 -0
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
- package/dist/components/{DatasourceSelect.d.ts → DatasourceSelect/DatasourceSelect.d.ts} +1 -1
- package/dist/components/DatasourceSelect/DatasourceSelect.d.ts.map +1 -0
- package/dist/components/{DatasourceSelect.js → DatasourceSelect/DatasourceSelect.js} +4 -3
- package/dist/components/DatasourceSelect/DatasourceSelect.js.map +1 -0
- package/dist/components/DatasourceSelect/index.d.ts +2 -0
- package/dist/components/DatasourceSelect/index.d.ts.map +1 -0
- package/dist/components/DatasourceSelect/index.js +15 -0
- package/dist/components/DatasourceSelect/index.js.map +1 -0
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts +2 -1
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -1
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +120 -93
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts +3 -2
- package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js +6 -3
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts +3 -2
- package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts.map +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.js +14 -4
- package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts +3 -2
- package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js +7 -5
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.d.ts +3 -3
- package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.js +57 -17
- package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts +5 -0
- package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.js +7 -4
- package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.js +13 -9
- package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +63 -80
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +2 -2
- package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js +43 -34
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/index.d.ts +1 -0
- package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/index.js +1 -0
- package/dist/components/Variables/VariableEditorForm/index.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +6 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +44 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
- package/dist/components/Variables/variable-model.js +3 -3
- package/dist/components/Variables/variable-model.js.map +1 -1
- package/dist/components/index.d.ts +0 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +0 -1
- package/dist/components/index.js.map +1 -1
- package/dist/context/index.d.ts +0 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +0 -1
- package/dist/context/index.js.map +1 -1
- package/dist/model/legend.d.ts +3 -1
- package/dist/model/legend.d.ts.map +1 -1
- package/dist/model/legend.js +10 -0
- package/dist/model/legend.js.map +1 -1
- package/dist/model/log-queries.d.ts +24 -0
- package/dist/model/log-queries.d.ts.map +1 -0
- package/dist/model/log-queries.js +15 -0
- package/dist/model/log-queries.js.map +1 -0
- package/dist/model/panels.d.ts +8 -0
- package/dist/model/panels.d.ts.map +1 -1
- package/dist/model/panels.js.map +1 -1
- package/dist/model/plugin-base.d.ts +6 -1
- package/dist/model/plugin-base.d.ts.map +1 -1
- package/dist/model/plugin-base.js.map +1 -1
- package/dist/model/plugins.d.ts +2 -0
- package/dist/model/plugins.d.ts.map +1 -1
- package/dist/model/plugins.js.map +1 -1
- package/dist/model/time-series-queries.d.ts +1 -1
- package/dist/model/time-series-queries.d.ts.map +1 -1
- package/dist/model/time-series-queries.js.map +1 -1
- package/dist/model/variables.d.ts +1 -1
- package/dist/model/variables.d.ts.map +1 -1
- package/dist/model/variables.js.map +1 -1
- package/dist/remote/PluginRuntime.d.ts +2 -2
- package/dist/remote/PluginRuntime.d.ts.map +1 -1
- package/dist/remote/PluginRuntime.js +4 -3
- package/dist/remote/PluginRuntime.js.map +1 -1
- package/dist/remote/remotePluginLoader.d.ts +18 -1
- package/dist/remote/remotePluginLoader.d.ts.map +1 -1
- package/dist/remote/remotePluginLoader.js +22 -4
- package/dist/remote/remotePluginLoader.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -1
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +10 -2
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.js +17 -4
- package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
- package/dist/runtime/RouterProvider.d.ts +32 -0
- package/dist/runtime/RouterProvider.d.ts.map +1 -0
- package/dist/runtime/RouterProvider.js +59 -0
- package/dist/runtime/RouterProvider.js.map +1 -0
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +6 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/query-params.d.ts.map +1 -1
- package/dist/runtime/TimeRangeProvider/query-params.js.map +1 -1
- package/dist/runtime/UsageMetricsProvider.d.ts +3 -1
- package/dist/runtime/UsageMetricsProvider.d.ts.map +1 -1
- package/dist/runtime/UsageMetricsProvider.js +4 -3
- package/dist/runtime/UsageMetricsProvider.js.map +1 -1
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/log-queries.d.ts +7 -0
- package/dist/runtime/log-queries.d.ts.map +1 -0
- package/dist/runtime/log-queries.js +52 -0
- package/dist/runtime/log-queries.js.map +1 -0
- package/dist/runtime/time-series-queries.d.ts.map +1 -1
- package/dist/runtime/time-series-queries.js +4 -4
- package/dist/runtime/time-series-queries.js.map +1 -1
- package/dist/runtime/variables.d.ts +1 -0
- package/dist/runtime/variables.d.ts.map +1 -1
- package/dist/runtime/variables.js +13 -0
- package/dist/runtime/variables.js.map +1 -1
- package/dist/test/mock-data.d.ts +136 -1
- package/dist/test/mock-data.d.ts.map +1 -1
- package/dist/test/mock-data.js +156 -0
- package/dist/test/mock-data.js.map +1 -1
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +17 -8
- package/dist/test/utils.js.map +1 -1
- package/dist/utils/variables.d.ts +24 -2
- package/dist/utils/variables.d.ts.map +1 -1
- package/dist/utils/variables.js +102 -14
- package/dist/utils/variables.js.map +1 -1
- package/package.json +7 -7
- package/dist/cjs/components/ProjectSelect.js +0 -96
- package/dist/cjs/context/ProjectStoreProvider.js +0 -81
- package/dist/cjs/context/query-params.js +0 -49
- package/dist/components/DatasourceSelect.d.ts.map +0 -1
- package/dist/components/DatasourceSelect.js.map +0 -1
- package/dist/components/ProjectSelect.d.ts +0 -15
- package/dist/components/ProjectSelect.d.ts.map +0 -1
- package/dist/components/ProjectSelect.js +0 -91
- package/dist/components/ProjectSelect.js.map +0 -1
- package/dist/context/ProjectStoreProvider.d.ts +0 -16
- package/dist/context/ProjectStoreProvider.d.ts.map +0 -1
- package/dist/context/ProjectStoreProvider.js +0 -59
- package/dist/context/ProjectStoreProvider.js.map +0 -1
- package/dist/context/query-params.d.ts +0 -5
- package/dist/context/query-params.d.ts.map +0 -1
- package/dist/context/query-params.js +0 -41
- package/dist/context/query-params.js.map +0 -1
package/dist/test/mock-data.js
CHANGED
|
@@ -81,6 +81,27 @@ export const MOCK_TRACE_DATA = {
|
|
|
81
81
|
executedQueryString: '{ duration > 1000ms }'
|
|
82
82
|
}
|
|
83
83
|
};
|
|
84
|
+
export const MOCK_LOG_DATA = {
|
|
85
|
+
totalCount: 2,
|
|
86
|
+
entries: [
|
|
87
|
+
{
|
|
88
|
+
timestamp: 1666479357903,
|
|
89
|
+
line: 'Error: Something went wrong',
|
|
90
|
+
labels: {
|
|
91
|
+
level: 'error',
|
|
92
|
+
service: 'backend'
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
timestamp: 1666479382282,
|
|
97
|
+
line: 'Info: Request processed successfully',
|
|
98
|
+
labels: {
|
|
99
|
+
level: 'info',
|
|
100
|
+
service: 'frontend'
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
};
|
|
84
105
|
export const MOCK_PROFILE_DATA = {
|
|
85
106
|
profile: {
|
|
86
107
|
stackTrace: {
|
|
@@ -101,5 +122,140 @@ export const MOCK_PROFILE_DATA = {
|
|
|
101
122
|
name: 'cpu'
|
|
102
123
|
}
|
|
103
124
|
};
|
|
125
|
+
// Remote Plugin Loader Test Fixtures
|
|
126
|
+
export const MOCK_VALID_PLUGIN_METADATA = {
|
|
127
|
+
kind: 'Panel',
|
|
128
|
+
spec: {
|
|
129
|
+
name: 'testPlugin',
|
|
130
|
+
display: {
|
|
131
|
+
name: 'Test Plugin',
|
|
132
|
+
description: 'A test plugin for unit testing'
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
export const MOCK_VALID_PLUGIN_MODULE_RESOURCE = {
|
|
137
|
+
kind: 'PluginModule',
|
|
138
|
+
metadata: {
|
|
139
|
+
name: 'test-module',
|
|
140
|
+
version: '1.0.0'
|
|
141
|
+
},
|
|
142
|
+
spec: {
|
|
143
|
+
plugins: [
|
|
144
|
+
MOCK_VALID_PLUGIN_METADATA
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
export const MOCK_INVALID_PLUGIN_MODULE = {
|
|
149
|
+
// Missing required fields
|
|
150
|
+
metadata: {
|
|
151
|
+
name: 'invalid-module'
|
|
152
|
+
},
|
|
153
|
+
spec: {
|
|
154
|
+
plugins: [
|
|
155
|
+
{
|
|
156
|
+
// Missing required fields
|
|
157
|
+
kind: 'Panel'
|
|
158
|
+
}
|
|
159
|
+
]
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
export const MOCK_MIXED_VALIDITY_PLUGIN_MODULES = [
|
|
163
|
+
MOCK_VALID_PLUGIN_MODULE_RESOURCE,
|
|
164
|
+
MOCK_INVALID_PLUGIN_MODULE,
|
|
165
|
+
{
|
|
166
|
+
kind: 'PluginModule',
|
|
167
|
+
metadata: {
|
|
168
|
+
name: 'another-valid-module',
|
|
169
|
+
version: '2.0.0'
|
|
170
|
+
},
|
|
171
|
+
spec: {
|
|
172
|
+
plugins: [
|
|
173
|
+
{
|
|
174
|
+
kind: 'Variable',
|
|
175
|
+
spec: {
|
|
176
|
+
name: 'anotherPlugin',
|
|
177
|
+
display: {
|
|
178
|
+
name: 'Another Plugin'
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
]
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
];
|
|
186
|
+
export const MOCK_REMOTE_PLUGIN_MODULE = {
|
|
187
|
+
testPlugin: {
|
|
188
|
+
component: ()=>null,
|
|
189
|
+
createDefaultOptions: ()=>({})
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
export const MOCK_MULTI_PLUGIN_MODULE = {
|
|
193
|
+
kind: 'PluginModule',
|
|
194
|
+
metadata: {
|
|
195
|
+
name: 'multi-plugin-module',
|
|
196
|
+
version: '1.0.0'
|
|
197
|
+
},
|
|
198
|
+
spec: {
|
|
199
|
+
plugins: [
|
|
200
|
+
{
|
|
201
|
+
kind: 'Panel',
|
|
202
|
+
spec: {
|
|
203
|
+
name: 'plugin1',
|
|
204
|
+
display: {
|
|
205
|
+
name: 'Plugin 1'
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
kind: 'Variable',
|
|
211
|
+
spec: {
|
|
212
|
+
name: 'plugin2',
|
|
213
|
+
display: {
|
|
214
|
+
name: 'Plugin 2'
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
]
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
export const MOCK_PARTIAL_FAILURE_MODULE = {
|
|
222
|
+
kind: 'PluginModule',
|
|
223
|
+
metadata: {
|
|
224
|
+
name: 'partial-failure-module',
|
|
225
|
+
version: '1.0.0'
|
|
226
|
+
},
|
|
227
|
+
spec: {
|
|
228
|
+
plugins: [
|
|
229
|
+
{
|
|
230
|
+
kind: 'Panel',
|
|
231
|
+
spec: {
|
|
232
|
+
name: 'workingPlugin',
|
|
233
|
+
display: {
|
|
234
|
+
name: 'Working Plugin'
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
kind: 'Variable',
|
|
240
|
+
spec: {
|
|
241
|
+
name: 'failingPlugin',
|
|
242
|
+
display: {
|
|
243
|
+
name: 'Failing Plugin'
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
]
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
export const MOCK_EMPTY_PLUGIN_MODULE = {
|
|
251
|
+
kind: 'PluginModule',
|
|
252
|
+
metadata: {
|
|
253
|
+
name: 'empty-module',
|
|
254
|
+
version: '1.0.0'
|
|
255
|
+
},
|
|
256
|
+
spec: {
|
|
257
|
+
plugins: []
|
|
258
|
+
}
|
|
259
|
+
};
|
|
104
260
|
|
|
105
261
|
//# sourceMappingURL=mock-data.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/test/mock-data.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 { ProfileData, TimeSeriesData, TraceData } from '@perses-dev/core';\n\nexport const MOCK_TIME_SERIES_DATA: TimeSeriesData = {\n timeRange: {\n start: new Date(1666625490000),\n end: new Date(1666625535000),\n },\n stepMs: 24379,\n series: [\n {\n name: 'device=\"/dev/vda1\", env=\"demo\", fstype=\"ext4\", instance=\"demo.do.prometheus.io:9100\", job=\"node\", mountpoint=\"/\"',\n values: [\n [1666479357903, 0.27700745551584494],\n [1666479382282, 0.27701284657366565],\n ],\n },\n {\n name: 'device=\"/dev/vda15\", env=\"demo\", fstype=\"vfat\", instance=\"demo.do.prometheus.io:9100\", job=\"node\", mountpoint=\"/boot/efi\"',\n values: [\n [1666479357903, 0.08486496097624885],\n [1666479382282, 0.08486496097624885],\n ],\n },\n ],\n};\n\nexport const MOCK_TRACE_DATA: TraceData = {\n searchResult: [\n {\n durationMs: 1120,\n serviceStats: {\n 'shop-backend': {\n spanCount: 4,\n errorCount: 0,\n },\n 'cart-service': {\n spanCount: 2,\n errorCount: 0,\n },\n 'article-service': {\n spanCount: 2,\n errorCount: 0,\n },\n 'auth-service': {\n spanCount: 1,\n errorCount: 0,\n },\n postgres: {\n spanCount: 1,\n errorCount: 0,\n },\n },\n startTimeUnixMs: 1699916103945861,\n traceId: '95ba9202315c29c801b5aa41452aa775',\n rootServiceName: 'shop-backend',\n rootTraceName: 'article-to-cart',\n },\n ],\n metadata: {\n executedQueryString: '{ duration > 1000ms }',\n },\n};\n\nexport const MOCK_PROFILE_DATA: ProfileData = {\n profile: {\n stackTrace: {\n id: 0,\n name: 'root',\n level: 0,\n start: 1699916103945861,\n end: 1699916105065861,\n total: 1000,\n self: 500,\n children: [],\n },\n },\n metadata: {\n spyName: '',\n sampleRate: 1000000000,\n units: 'samples',\n name: 'cpu',\n },\n};\n"],"names":["MOCK_TIME_SERIES_DATA","timeRange","start","Date","end","stepMs","series","name","values","MOCK_TRACE_DATA","searchResult","durationMs","serviceStats","spanCount","errorCount","postgres","startTimeUnixMs","traceId","rootServiceName","rootTraceName","metadata","executedQueryString","MOCK_PROFILE_DATA","profile","stackTrace","id","
|
|
1
|
+
{"version":3,"sources":["../../src/test/mock-data.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 { LogData, ProfileData, TimeSeriesData, TraceData } from '@perses-dev/core';\n\nexport const MOCK_TIME_SERIES_DATA: TimeSeriesData = {\n timeRange: {\n start: new Date(1666625490000),\n end: new Date(1666625535000),\n },\n stepMs: 24379,\n series: [\n {\n name: 'device=\"/dev/vda1\", env=\"demo\", fstype=\"ext4\", instance=\"demo.do.prometheus.io:9100\", job=\"node\", mountpoint=\"/\"',\n values: [\n [1666479357903, 0.27700745551584494],\n [1666479382282, 0.27701284657366565],\n ],\n },\n {\n name: 'device=\"/dev/vda15\", env=\"demo\", fstype=\"vfat\", instance=\"demo.do.prometheus.io:9100\", job=\"node\", mountpoint=\"/boot/efi\"',\n values: [\n [1666479357903, 0.08486496097624885],\n [1666479382282, 0.08486496097624885],\n ],\n },\n ],\n};\n\nexport const MOCK_TRACE_DATA: TraceData = {\n searchResult: [\n {\n durationMs: 1120,\n serviceStats: {\n 'shop-backend': {\n spanCount: 4,\n errorCount: 0,\n },\n 'cart-service': {\n spanCount: 2,\n errorCount: 0,\n },\n 'article-service': {\n spanCount: 2,\n errorCount: 0,\n },\n 'auth-service': {\n spanCount: 1,\n errorCount: 0,\n },\n postgres: {\n spanCount: 1,\n errorCount: 0,\n },\n },\n startTimeUnixMs: 1699916103945861,\n traceId: '95ba9202315c29c801b5aa41452aa775',\n rootServiceName: 'shop-backend',\n rootTraceName: 'article-to-cart',\n },\n ],\n metadata: {\n executedQueryString: '{ duration > 1000ms }',\n },\n};\n\nexport const MOCK_LOG_DATA: LogData = {\n totalCount: 2,\n entries: [\n {\n timestamp: 1666479357903,\n line: 'Error: Something went wrong',\n labels: {\n level: 'error',\n service: 'backend',\n },\n },\n {\n timestamp: 1666479382282,\n line: 'Info: Request processed successfully',\n labels: {\n level: 'info',\n service: 'frontend',\n },\n },\n ],\n};\n\nexport const MOCK_PROFILE_DATA: ProfileData = {\n profile: {\n stackTrace: {\n id: 0,\n name: 'root',\n level: 0,\n start: 1699916103945861,\n end: 1699916105065861,\n total: 1000,\n self: 500,\n children: [],\n },\n },\n metadata: {\n spyName: '',\n sampleRate: 1000000000,\n units: 'samples',\n name: 'cpu',\n },\n};\n\n// Remote Plugin Loader Test Fixtures\nexport const MOCK_VALID_PLUGIN_METADATA = {\n kind: 'Panel' as const,\n spec: {\n name: 'testPlugin',\n display: {\n name: 'Test Plugin',\n description: 'A test plugin for unit testing',\n },\n },\n};\n\nexport const MOCK_VALID_PLUGIN_MODULE_RESOURCE = {\n kind: 'PluginModule' as const,\n metadata: {\n name: 'test-module',\n version: '1.0.0',\n },\n spec: {\n plugins: [MOCK_VALID_PLUGIN_METADATA],\n },\n};\n\nexport const MOCK_INVALID_PLUGIN_MODULE = {\n // Missing required fields\n metadata: {\n name: 'invalid-module',\n },\n spec: {\n plugins: [\n {\n // Missing required fields\n kind: 'Panel',\n },\n ],\n },\n};\n\nexport const MOCK_MIXED_VALIDITY_PLUGIN_MODULES = [\n MOCK_VALID_PLUGIN_MODULE_RESOURCE,\n MOCK_INVALID_PLUGIN_MODULE,\n {\n kind: 'PluginModule' as const,\n metadata: {\n name: 'another-valid-module',\n version: '2.0.0',\n },\n spec: {\n plugins: [\n {\n kind: 'Variable' as const,\n spec: {\n name: 'anotherPlugin',\n display: {\n name: 'Another Plugin',\n },\n },\n },\n ],\n },\n },\n];\n\nexport const MOCK_REMOTE_PLUGIN_MODULE = {\n testPlugin: {\n component: (): null => null,\n createDefaultOptions: (): Record<string, unknown> => ({}),\n },\n};\n\nexport const MOCK_MULTI_PLUGIN_MODULE = {\n kind: 'PluginModule' as const,\n metadata: {\n name: 'multi-plugin-module',\n version: '1.0.0',\n },\n spec: {\n plugins: [\n {\n kind: 'Panel' as const,\n spec: {\n name: 'plugin1',\n display: { name: 'Plugin 1' },\n },\n },\n {\n kind: 'Variable' as const,\n spec: {\n name: 'plugin2',\n display: { name: 'Plugin 2' },\n },\n },\n ],\n },\n};\n\nexport const MOCK_PARTIAL_FAILURE_MODULE = {\n kind: 'PluginModule' as const,\n metadata: {\n name: 'partial-failure-module',\n version: '1.0.0',\n },\n spec: {\n plugins: [\n {\n kind: 'Panel' as const,\n spec: {\n name: 'workingPlugin',\n display: { name: 'Working Plugin' },\n },\n },\n {\n kind: 'Variable' as const,\n spec: {\n name: 'failingPlugin',\n display: { name: 'Failing Plugin' },\n },\n },\n ],\n },\n};\n\nexport const MOCK_EMPTY_PLUGIN_MODULE = {\n kind: 'PluginModule' as const,\n metadata: {\n name: 'empty-module',\n version: '1.0.0',\n },\n spec: {\n plugins: [],\n },\n};\n"],"names":["MOCK_TIME_SERIES_DATA","timeRange","start","Date","end","stepMs","series","name","values","MOCK_TRACE_DATA","searchResult","durationMs","serviceStats","spanCount","errorCount","postgres","startTimeUnixMs","traceId","rootServiceName","rootTraceName","metadata","executedQueryString","MOCK_LOG_DATA","totalCount","entries","timestamp","line","labels","level","service","MOCK_PROFILE_DATA","profile","stackTrace","id","total","self","children","spyName","sampleRate","units","MOCK_VALID_PLUGIN_METADATA","kind","spec","display","description","MOCK_VALID_PLUGIN_MODULE_RESOURCE","version","plugins","MOCK_INVALID_PLUGIN_MODULE","MOCK_MIXED_VALIDITY_PLUGIN_MODULES","MOCK_REMOTE_PLUGIN_MODULE","testPlugin","component","createDefaultOptions","MOCK_MULTI_PLUGIN_MODULE","MOCK_PARTIAL_FAILURE_MODULE","MOCK_EMPTY_PLUGIN_MODULE"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,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M;oBAAW;gBAC9B;YACF;SACD;IACH;AACF,EAAE;AAEF,OAAO,MAAMgD,8BAA8B;IACzCd,MAAM;IACNrB,UAAU;QACRb,MAAM;QACNuC,SAAS;IACX;IACAJ,MAAM;QACJK,SAAS;YACP;gBACEN,MAAM;gBACNC,MAAM;oBACJnC,MAAM;oBACNoC,SAAS;wBAAEpC,MAAM;oBAAiB;gBACpC;YACF;YACA;gBACEkC,MAAM;gBACNC,MAAM;oBACJnC,MAAM;oBACNoC,SAAS;wBAAEpC,MAAM;oBAAiB;gBACpC;YACF;SACD;IACH;AACF,EAAE;AAEF,OAAO,MAAMiD,2BAA2B;IACtCf,MAAM;IACNrB,UAAU;QACRb,MAAM;QACNuC,SAAS;IACX;IACAJ,MAAM;QACJK,SAAS,EAAE;IACb;AACF,EAAE"}
|
package/dist/test/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/test/utils.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/test/utils.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAI9C,MAAM,MAAM,cAAc,GAAG;IAC3B,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,cAAc,CAAC,EAAE,cAAc,kBAO7B;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,KAAG,SAAS,CAkB1E"}
|
package/dist/test/utils.js
CHANGED
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
15
|
+
import { DEFAULT_DASHBOARD_DURATION } from '@perses-dev/core';
|
|
15
16
|
import { PluginRegistry } from '../components';
|
|
17
|
+
import { TimeRangeProvider } from '../runtime';
|
|
16
18
|
import { testPluginLoader } from './test-plugins';
|
|
17
19
|
export function getTestContextWrapper(contextOptions) {
|
|
18
20
|
// Create a new QueryClient for each test to avoid caching issues
|
|
@@ -24,15 +26,22 @@ export function getTestContextWrapper(contextOptions) {
|
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
});
|
|
29
|
+
const timeRange = {
|
|
30
|
+
start: new Date(Date.now() - Number(DEFAULT_DASHBOARD_DURATION)),
|
|
31
|
+
end: new Date()
|
|
32
|
+
};
|
|
27
33
|
return function Wrapper({ children }) {
|
|
28
|
-
return /*#__PURE__*/ _jsx(
|
|
29
|
-
|
|
30
|
-
children: /*#__PURE__*/ _jsx(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
return /*#__PURE__*/ _jsx(TimeRangeProvider, {
|
|
35
|
+
timeRange: timeRange,
|
|
36
|
+
children: /*#__PURE__*/ _jsx(QueryClientProvider, {
|
|
37
|
+
client: queryClient,
|
|
38
|
+
children: /*#__PURE__*/ _jsx(PluginRegistry, {
|
|
39
|
+
pluginLoader: testPluginLoader,
|
|
40
|
+
defaultPluginKinds: contextOptions?.defaultPluginKinds ?? {
|
|
41
|
+
TimeSeriesQuery: 'PrometheusTimeSeriesQuery'
|
|
42
|
+
},
|
|
43
|
+
children: children
|
|
44
|
+
})
|
|
36
45
|
})
|
|
37
46
|
});
|
|
38
47
|
};
|
package/dist/test/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/test/utils.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 { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { ReactNode } from 'react';\nimport { PluginRegistry } from '../components';\nimport { DefaultPluginKinds } from '../model';\nimport { testPluginLoader } from './test-plugins';\n\nexport type ContextOptions = {\n defaultPluginKinds?: DefaultPluginKinds;\n};\n\nexport function getTestContextWrapper(contextOptions?: ContextOptions) {\n // Create a new QueryClient for each test to avoid caching issues\n const queryClient = new QueryClient({\n defaultOptions: { queries: { refetchOnWindowFocus: false, retry: false } },\n });\n\n return function Wrapper({ children }: { children: ReactNode }): ReactNode {\n return (\n <QueryClientProvider client={queryClient}>\n
|
|
1
|
+
{"version":3,"sources":["../../src/test/utils.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 { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { ReactNode } from 'react';\nimport { DEFAULT_DASHBOARD_DURATION } from '@perses-dev/core';\nimport { PluginRegistry } from '../components';\nimport { DefaultPluginKinds } from '../model';\nimport { TimeRangeProvider } from '../runtime';\nimport { testPluginLoader } from './test-plugins';\n\nexport type ContextOptions = {\n defaultPluginKinds?: DefaultPluginKinds;\n};\n\nexport function getTestContextWrapper(contextOptions?: ContextOptions) {\n // Create a new QueryClient for each test to avoid caching issues\n const queryClient = new QueryClient({\n defaultOptions: { queries: { refetchOnWindowFocus: false, retry: false } },\n });\n\n const timeRange = { start: new Date(Date.now() - Number(DEFAULT_DASHBOARD_DURATION)), end: new Date() };\n return function Wrapper({ children }: { children: ReactNode }): ReactNode {\n return (\n <TimeRangeProvider timeRange={timeRange}>\n <QueryClientProvider client={queryClient}>\n <PluginRegistry\n pluginLoader={testPluginLoader}\n defaultPluginKinds={\n contextOptions?.defaultPluginKinds ?? {\n TimeSeriesQuery: 'PrometheusTimeSeriesQuery',\n }\n }\n >\n {children}\n </PluginRegistry>\n </QueryClientProvider>\n </TimeRangeProvider>\n );\n };\n}\n"],"names":["QueryClient","QueryClientProvider","DEFAULT_DASHBOARD_DURATION","PluginRegistry","TimeRangeProvider","testPluginLoader","getTestContextWrapper","contextOptions","queryClient","defaultOptions","queries","refetchOnWindowFocus","retry","timeRange","start","Date","now","Number","end","Wrapper","children","client","pluginLoader","defaultPluginKinds","TimeSeriesQuery"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,WAAW,EAAEC,mBAAmB,QAAQ,wBAAwB;AAEzE,SAASC,0BAA0B,QAAQ,mBAAmB;AAC9D,SAASC,cAAc,QAAQ,gBAAgB;AAE/C,SAASC,iBAAiB,QAAQ,aAAa;AAC/C,SAASC,gBAAgB,QAAQ,iBAAiB;AAMlD,OAAO,SAASC,sBAAsBC,cAA+B;IACnE,iEAAiE;IACjE,MAAMC,cAAc,IAAIR,YAAY;QAClCS,gBAAgB;YAAEC,SAAS;gBAAEC,sBAAsB;gBAAOC,OAAO;YAAM;QAAE;IAC3E;IAEA,MAAMC,YAAY;QAAEC,OAAO,IAAIC,KAAKA,KAAKC,GAAG,KAAKC,OAAOf;QAA8BgB,KAAK,IAAIH;IAAO;IACtG,OAAO,SAASI,QAAQ,EAAEC,QAAQ,EAA2B;QAC3D,qBACE,KAAChB;YAAkBS,WAAWA;sBAC5B,cAAA,KAACZ;gBAAoBoB,QAAQb;0BAC3B,cAAA,KAACL;oBACCmB,cAAcjB;oBACdkB,oBACEhB,gBAAgBgB,sBAAsB;wBACpCC,iBAAiB;oBACnB;8BAGDJ;;;;IAKX;AACF"}
|
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
import { VariableValue } from '@perses-dev/core';
|
|
2
2
|
import { VariableStateMap } from '@perses-dev/plugin-system';
|
|
3
3
|
export declare function replaceVariables(text: string, variableState: VariableStateMap): string;
|
|
4
|
-
export declare
|
|
4
|
+
export declare enum InterpolationFormat {
|
|
5
|
+
CSV = "csv",
|
|
6
|
+
DISTRIBUTED = "distributed",
|
|
7
|
+
DOUBLEQUOTE = "doublequote",
|
|
8
|
+
GLOB = "glob",
|
|
9
|
+
JSON = "json",
|
|
10
|
+
LUCENE = "lucene",
|
|
11
|
+
PERCENTENCODE = "percentencode",
|
|
12
|
+
PIPE = "pipe",
|
|
13
|
+
PROMETHEUS = "prometheus",
|
|
14
|
+
RAW = "raw",
|
|
15
|
+
REGEX = "regex",
|
|
16
|
+
SINGLEQUOTE = "singlequote",
|
|
17
|
+
SQLSTRING = "sqlstring",
|
|
18
|
+
TEXT = "text",
|
|
19
|
+
QUERYPARAM = "queryparam"
|
|
20
|
+
}
|
|
21
|
+
export declare function interpolate(values: string[], name: string, format: InterpolationFormat): string;
|
|
22
|
+
export declare function replaceVariable(text: string, varName: string, variableValue: VariableValue, varFormat?: InterpolationFormat): string;
|
|
5
23
|
/**
|
|
6
24
|
* Returns a list of variables
|
|
7
25
|
*/
|
|
8
|
-
export declare
|
|
26
|
+
export declare function parseVariables(text: string): string[];
|
|
27
|
+
/**
|
|
28
|
+
* Returns a map of variable names and its format. If no format is specified, it will be undefined.
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseVariablesAndFormat(text: string): Map<string, InterpolationFormat | undefined>;
|
|
9
31
|
//# sourceMappingURL=variables.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../../src/utils/variables.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,gBAAgB,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../../src/utils/variables.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,gBAAgB,GAAG,MAAM,CAiBtF;AAED,oBAAY,mBAAmB;IAC7B,GAAG,QAAQ;IACX,WAAW,gBAAgB;IAC3B,WAAW,gBAAgB;IAC3B,IAAI,SAAS;IACb,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,aAAa,kBAAkB;IAC/B,IAAI,SAAS;IACb,UAAU,eAAe;IACzB,GAAG,QAAQ;IACX,KAAK,UAAU;IACf,WAAW,gBAAgB;IAC3B,SAAS,cAAc;IACvB,IAAI,SAAS;IACb,UAAU,eAAe;CAC1B;AASD,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAqC/F;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,aAAa,EAC5B,SAAS,CAAC,EAAE,mBAAmB,GAC9B,MAAM,CAcR;AAUD;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAiBrD;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,mBAAmB,GAAG,SAAS,CAAC,CAoBlG"}
|
package/dist/utils/variables.js
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
export function replaceVariables(text, variableState) {
|
|
14
|
-
const
|
|
14
|
+
const variablesMap = parseVariablesAndFormat(text);
|
|
15
|
+
const variables = Array.from(variablesMap.keys());
|
|
15
16
|
let finalText = text;
|
|
16
17
|
variables// Sorting variables by their length.
|
|
17
18
|
// In order to not have a variable name have contained in another variable name.
|
|
@@ -19,20 +20,88 @@ export function replaceVariables(text, variableState) {
|
|
|
19
20
|
.sort((a, b)=>b.length - a.length).forEach((v)=>{
|
|
20
21
|
const variable = variableState[v];
|
|
21
22
|
if (variable && variable.value !== undefined) {
|
|
22
|
-
finalText = replaceVariable(finalText, v, variable?.value);
|
|
23
|
+
finalText = replaceVariable(finalText, v, variable?.value, variablesMap.get(v));
|
|
23
24
|
}
|
|
24
25
|
});
|
|
25
26
|
return finalText;
|
|
26
27
|
}
|
|
27
|
-
export
|
|
28
|
+
export var InterpolationFormat = /*#__PURE__*/ function(InterpolationFormat) {
|
|
29
|
+
InterpolationFormat["CSV"] = "csv";
|
|
30
|
+
InterpolationFormat["DISTRIBUTED"] = "distributed";
|
|
31
|
+
InterpolationFormat["DOUBLEQUOTE"] = "doublequote";
|
|
32
|
+
InterpolationFormat["GLOB"] = "glob";
|
|
33
|
+
InterpolationFormat["JSON"] = "json";
|
|
34
|
+
InterpolationFormat["LUCENE"] = "lucene";
|
|
35
|
+
InterpolationFormat["PERCENTENCODE"] = "percentencode";
|
|
36
|
+
InterpolationFormat["PIPE"] = "pipe";
|
|
37
|
+
InterpolationFormat["PROMETHEUS"] = "prometheus";
|
|
38
|
+
InterpolationFormat["RAW"] = "raw";
|
|
39
|
+
InterpolationFormat["REGEX"] = "regex";
|
|
40
|
+
InterpolationFormat["SINGLEQUOTE"] = "singlequote";
|
|
41
|
+
InterpolationFormat["SQLSTRING"] = "sqlstring";
|
|
42
|
+
InterpolationFormat["TEXT"] = "text";
|
|
43
|
+
InterpolationFormat["QUERYPARAM"] = "queryparam";
|
|
44
|
+
return InterpolationFormat;
|
|
45
|
+
}({});
|
|
46
|
+
function stringToFormat(val) {
|
|
47
|
+
if (!val) return undefined;
|
|
48
|
+
const lowerVal = val.toLowerCase();
|
|
49
|
+
return Object.values(InterpolationFormat).find((format)=>format === lowerVal) || undefined;
|
|
50
|
+
}
|
|
51
|
+
export function interpolate(values, name, format) {
|
|
52
|
+
switch(format){
|
|
53
|
+
case "csv":
|
|
54
|
+
case "raw":
|
|
55
|
+
return values.join(',');
|
|
56
|
+
case "distributed":
|
|
57
|
+
{
|
|
58
|
+
const [first, ...rest] = values;
|
|
59
|
+
return `${[
|
|
60
|
+
first,
|
|
61
|
+
...rest.map((v)=>`${name}=${v}`)
|
|
62
|
+
].join(',')}`;
|
|
63
|
+
}
|
|
64
|
+
case "doublequote":
|
|
65
|
+
return values.map((v)=>`"${v}"`).join(',');
|
|
66
|
+
case "glob":
|
|
67
|
+
return `{${values.join(',')}}`;
|
|
68
|
+
case "json":
|
|
69
|
+
return JSON.stringify(values);
|
|
70
|
+
case "lucene":
|
|
71
|
+
return `(${values.map((v)=>`"${v}"`).join(' OR ')})`;
|
|
72
|
+
case "percentencode":
|
|
73
|
+
return encodeURIComponent(values.join(','));
|
|
74
|
+
case "pipe":
|
|
75
|
+
return values.join('|');
|
|
76
|
+
case "regex":
|
|
77
|
+
{
|
|
78
|
+
const escapedRegex = values.map((v)=>v.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'));
|
|
79
|
+
return `(${escapedRegex.join('|')})`;
|
|
80
|
+
}
|
|
81
|
+
case "singlequote":
|
|
82
|
+
return values.map((v)=>`'${v}'`).join(',');
|
|
83
|
+
case "sqlstring":
|
|
84
|
+
return values.map((v)=>`'${v.replace(/'/g, "''")}'`).join(',');
|
|
85
|
+
case "text":
|
|
86
|
+
return values.join(' + ');
|
|
87
|
+
case "queryparam":
|
|
88
|
+
return values.map((v)=>`${name}=${encodeURIComponent(v)}`).join('&');
|
|
89
|
+
case "prometheus":
|
|
90
|
+
default:
|
|
91
|
+
return `(${values.join('|')})`;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export function replaceVariable(text, varName, variableValue, varFormat) {
|
|
28
95
|
const variableSyntax = '$' + varName;
|
|
29
|
-
const alternativeVariableSyntax = '${' + varName + '}';
|
|
96
|
+
const alternativeVariableSyntax = '${' + varName + (varFormat ? ':' + varFormat : '') + '}';
|
|
30
97
|
let replaceString = '';
|
|
31
98
|
if (Array.isArray(variableValue)) {
|
|
32
|
-
replaceString =
|
|
99
|
+
replaceString = interpolate(variableValue, varName, varFormat || "prometheus");
|
|
33
100
|
}
|
|
34
101
|
if (typeof variableValue === 'string') {
|
|
35
|
-
replaceString =
|
|
102
|
+
replaceString = interpolate([
|
|
103
|
+
variableValue
|
|
104
|
+
], varName, varFormat || "raw");
|
|
36
105
|
}
|
|
37
106
|
text = text.replaceAll(variableSyntax, replaceString);
|
|
38
107
|
return text.replaceAll(alternativeVariableSyntax, replaceString);
|
|
@@ -41,17 +110,14 @@ export function replaceVariable(text, varName, variableValue) {
|
|
|
41
110
|
// It supports two formats for referencing variables:
|
|
42
111
|
// 1. $variableName - This is a simpler format, and the regular expression captures the variable name (\w+ matches one or more word characters).
|
|
43
112
|
// 2. ${variableName} - This is a more complex format and the regular expression captures the variable name (\w+ matches one or more word characters) in the curly braces.
|
|
44
|
-
// 3.
|
|
45
|
-
|
|
46
|
-
// eslint-disable-next-line no-useless-escape
|
|
47
|
-
const VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?}/gm;
|
|
113
|
+
// 3. ${variableName:format} - This is a more complex format that allows specifying a format interpolation.
|
|
114
|
+
const VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^}]+))?(?::([^}]+))?}/gm;
|
|
48
115
|
/**
|
|
49
116
|
* Returns a list of variables
|
|
50
|
-
*/ export
|
|
51
|
-
const regex = VARIABLE_REGEX;
|
|
117
|
+
*/ export function parseVariables(text) {
|
|
52
118
|
const matches = new Set();
|
|
53
119
|
let match;
|
|
54
|
-
while((match =
|
|
120
|
+
while((match = VARIABLE_REGEX.exec(text)) !== null){
|
|
55
121
|
if (match) {
|
|
56
122
|
if (match[1]) {
|
|
57
123
|
// \$(\w+)\
|
|
@@ -64,6 +130,28 @@ const VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?}/gm;
|
|
|
64
130
|
}
|
|
65
131
|
// return unique matches
|
|
66
132
|
return Array.from(matches.values());
|
|
67
|
-
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Returns a map of variable names and its format. If no format is specified, it will be undefined.
|
|
136
|
+
*/ export function parseVariablesAndFormat(text) {
|
|
137
|
+
const matches = new Map();
|
|
138
|
+
let match;
|
|
139
|
+
while((match = VARIABLE_REGEX.exec(text)) !== null){
|
|
140
|
+
if (match) {
|
|
141
|
+
let format = undefined;
|
|
142
|
+
if (match[4]) {
|
|
143
|
+
format = match[4];
|
|
144
|
+
}
|
|
145
|
+
if (match[1]) {
|
|
146
|
+
// \$(\w+)\
|
|
147
|
+
matches.set(match[1], stringToFormat(format));
|
|
148
|
+
} else if (match[2]) {
|
|
149
|
+
// \${(\w+)}\
|
|
150
|
+
matches.set(match[2], stringToFormat(format));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return matches;
|
|
155
|
+
}
|
|
68
156
|
|
|
69
157
|
//# sourceMappingURL=variables.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/variables.ts"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { VariableValue } from '@perses-dev/core';\nimport { VariableStateMap } from '@perses-dev/plugin-system';\n\nexport function replaceVariables(text: string, variableState: VariableStateMap): string {\n const variables = parseVariables(text);\n let finalText = text;\n variables\n // Sorting variables by their length.\n // In order to not have a variable name have contained in another variable name.\n // i.e.: $__range replacing $__range_ms => '3600_ms' instead of '3600000'\n .sort((a, b) => b.length - a.length)\n .forEach((v) => {\n const variable = variableState[v];\n if (variable && variable.value !== undefined) {\n finalText = replaceVariable(finalText, v, variable?.value);\n }\n });\n\n return finalText;\n}\n\nexport function replaceVariable(text: string, varName: string, variableValue: VariableValue): string {\n const variableSyntax = '$' + varName;\n const alternativeVariableSyntax = '${' + varName + '}';\n\n let replaceString = '';\n if (Array.isArray(variableValue)) {\n replaceString = `(${variableValue.join('|')})`; // regex style\n }\n if (typeof variableValue === 'string') {\n replaceString = variableValue;\n }\n\n text = text.replaceAll(variableSyntax, replaceString);\n return text.replaceAll(alternativeVariableSyntax, replaceString);\n}\n\n// This regular expression is designed to identify variable references in a string.\n// It supports two formats for referencing variables:\n// 1. $variableName - This is a simpler format, and the regular expression captures the variable name (\\w+ matches one or more word characters).\n// 2. ${variableName} - This is a more complex format and the regular expression captures the variable name (\\w+ matches one or more word characters) in the curly braces.\n// 3. [COMING SOON] ${variableName:value} - This is a more complex format that allows specifying a format function as well.\n// TODO: Fix this lint error\n// eslint-disable-next-line no-useless-escape\nconst VARIABLE_REGEX = /\\$(\\w+)|\\${(\\w+)(?:\\.([^:^\\}]+))?(?::([^\\}]+))?}/gm;\n\n/**\n * Returns a list of variables\n */\nexport const parseVariables = (text: string): string[] => {\n const regex = VARIABLE_REGEX;\n const matches = new Set<string>();\n let match;\n\n while ((match = regex.exec(text)) !== null) {\n if (match) {\n if (match[1]) {\n // \\$(\\w+)\\\n matches.add(match[1]);\n } else if (match[2]) {\n // \\${(\\w+)}\\\n matches.add(match[2]);\n }\n }\n }\n // return unique matches\n return Array.from(matches.values());\n};\n"],"names":["replaceVariables","text","variableState","variables","parseVariables","finalText","sort","a","b","length","forEach","v","variable","value","undefined","replaceVariable","varName","variableValue","variableSyntax","alternativeVariableSyntax","replaceString","Array","isArray","join","replaceAll","VARIABLE_REGEX","regex","matches","Set","match","exec","add","from","values"],"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;AAKjC,OAAO,SAASA,iBAAiBC,IAAY,EAAEC,aAA+B;IAC5E,MAAMC,YAAYC,eAAeH;IACjC,IAAII,YAAYJ;IAChBE,SACE,qCAAqC;IACrC,gFAAgF;IAChF,yEAAyE;KACxEG,IAAI,CAAC,CAACC,GAAGC,IAAMA,EAAEC,MAAM,GAAGF,EAAEE,MAAM,EAClCC,OAAO,CAAC,CAACC;QACR,MAAMC,WAAWV,aAAa,CAACS,EAAE;QACjC,IAAIC,YAAYA,SAASC,KAAK,KAAKC,WAAW;YAC5CT,YAAYU,gBAAgBV,WAAWM,GAAGC,UAAUC;QACtD;IACF;IAEF,OAAOR;AACT;AAEA,OAAO,SAASU,gBAAgBd,IAAY,EAAEe,OAAe,EAAEC,aAA4B;IACzF,MAAMC,iBAAiB,MAAMF;IAC7B,MAAMG,4BAA4B,OAAOH,UAAU;IAEnD,IAAII,gBAAgB;IACpB,IAAIC,MAAMC,OAAO,CAACL,gBAAgB;QAChCG,gBAAgB,CAAC,CAAC,EAAEH,cAAcM,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc;IAChE;IACA,IAAI,OAAON,kBAAkB,UAAU;QACrCG,gBAAgBH;IAClB;IAEAhB,OAAOA,KAAKuB,UAAU,CAACN,gBAAgBE;IACvC,OAAOnB,KAAKuB,UAAU,CAACL,2BAA2BC;AACpD;AAEA,mFAAmF;AACnF,qDAAqD;AACrD,gJAAgJ;AAChJ,0KAA0K;AAC1K,2HAA2H;AAC3H,4BAA4B;AAC5B,6CAA6C;AAC7C,MAAMK,iBAAiB;AAEvB;;CAEC,GACD,OAAO,MAAMrB,iBAAiB,CAACH;IAC7B,MAAMyB,QAAQD;IACd,MAAME,UAAU,IAAIC;IACpB,IAAIC;IAEJ,MAAO,AAACA,CAAAA,QAAQH,MAAMI,IAAI,CAAC7B,KAAI,MAAO,KAAM;QAC1C,IAAI4B,OAAO;YACT,IAAIA,KAAK,CAAC,EAAE,EAAE;gBACZ,WAAW;gBACXF,QAAQI,GAAG,CAACF,KAAK,CAAC,EAAE;YACtB,OAAO,IAAIA,KAAK,CAAC,EAAE,EAAE;gBACnB,aAAa;gBACbF,QAAQI,GAAG,CAACF,KAAK,CAAC,EAAE;YACtB;QACF;IACF;IACA,wBAAwB;IACxB,OAAOR,MAAMW,IAAI,CAACL,QAAQM,MAAM;AAClC,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/variables.ts"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { VariableValue } from '@perses-dev/core';\nimport { VariableStateMap } from '@perses-dev/plugin-system';\n\nexport function replaceVariables(text: string, variableState: VariableStateMap): string {\n const variablesMap = parseVariablesAndFormat(text);\n const variables = Array.from(variablesMap.keys());\n let finalText = text;\n variables\n // Sorting variables by their length.\n // In order to not have a variable name have contained in another variable name.\n // i.e.: $__range replacing $__range_ms => '3600_ms' instead of '3600000'\n .sort((a, b) => b.length - a.length)\n .forEach((v) => {\n const variable = variableState[v];\n if (variable && variable.value !== undefined) {\n finalText = replaceVariable(finalText, v, variable?.value, variablesMap.get(v));\n }\n });\n\n return finalText;\n}\n\nexport enum InterpolationFormat {\n CSV = 'csv',\n DISTRIBUTED = 'distributed',\n DOUBLEQUOTE = 'doublequote',\n GLOB = 'glob',\n JSON = 'json',\n LUCENE = 'lucene',\n PERCENTENCODE = 'percentencode',\n PIPE = 'pipe',\n PROMETHEUS = 'prometheus',\n RAW = 'raw',\n REGEX = 'regex',\n SINGLEQUOTE = 'singlequote',\n SQLSTRING = 'sqlstring',\n TEXT = 'text',\n QUERYPARAM = 'queryparam',\n}\n\nfunction stringToFormat(val: string | undefined): InterpolationFormat | undefined {\n if (!val) return undefined;\n\n const lowerVal = val.toLowerCase();\n return Object.values(InterpolationFormat).find((format) => format === lowerVal) || undefined;\n}\n\nexport function interpolate(values: string[], name: string, format: InterpolationFormat): string {\n switch (format) {\n case InterpolationFormat.CSV:\n case InterpolationFormat.RAW:\n return values.join(',');\n case InterpolationFormat.DISTRIBUTED: {\n const [first, ...rest] = values;\n return `${[first, ...rest.map((v) => `${name}=${v}`)].join(',')}`;\n }\n case InterpolationFormat.DOUBLEQUOTE:\n return values.map((v) => `\"${v}\"`).join(',');\n case InterpolationFormat.GLOB:\n return `{${values.join(',')}}`;\n case InterpolationFormat.JSON:\n return JSON.stringify(values);\n case InterpolationFormat.LUCENE:\n return `(${values.map((v) => `\"${v}\"`).join(' OR ')})`;\n case InterpolationFormat.PERCENTENCODE:\n return encodeURIComponent(values.join(','));\n case InterpolationFormat.PIPE:\n return values.join('|');\n case InterpolationFormat.REGEX: {\n const escapedRegex = values.map((v) => v.replace(/[-/\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'));\n return `(${escapedRegex.join('|')})`;\n }\n case InterpolationFormat.SINGLEQUOTE:\n return values.map((v) => `'${v}'`).join(',');\n case InterpolationFormat.SQLSTRING:\n return values.map((v) => `'${v.replace(/'/g, \"''\")}'`).join(',');\n case InterpolationFormat.TEXT:\n return values.join(' + ');\n case InterpolationFormat.QUERYPARAM:\n return values.map((v) => `${name}=${encodeURIComponent(v)}`).join('&');\n case InterpolationFormat.PROMETHEUS:\n default:\n return `(${values.join('|')})`;\n }\n}\n\nexport function replaceVariable(\n text: string,\n varName: string,\n variableValue: VariableValue,\n varFormat?: InterpolationFormat\n): string {\n const variableSyntax = '$' + varName;\n const alternativeVariableSyntax = '${' + varName + (varFormat ? ':' + varFormat : '') + '}';\n\n let replaceString = '';\n if (Array.isArray(variableValue)) {\n replaceString = interpolate(variableValue, varName, varFormat || InterpolationFormat.PROMETHEUS);\n }\n if (typeof variableValue === 'string') {\n replaceString = interpolate([variableValue], varName, varFormat || InterpolationFormat.RAW);\n }\n\n text = text.replaceAll(variableSyntax, replaceString);\n return text.replaceAll(alternativeVariableSyntax, replaceString);\n}\n\n// This regular expression is designed to identify variable references in a string.\n// It supports two formats for referencing variables:\n// 1. $variableName - This is a simpler format, and the regular expression captures the variable name (\\w+ matches one or more word characters).\n// 2. ${variableName} - This is a more complex format and the regular expression captures the variable name (\\w+ matches one or more word characters) in the curly braces.\n// 3. ${variableName:format} - This is a more complex format that allows specifying a format interpolation.\n\nconst VARIABLE_REGEX = /\\$(\\w+)|\\${(\\w+)(?:\\.([^:^}]+))?(?::([^}]+))?}/gm;\n\n/**\n * Returns a list of variables\n */\nexport function parseVariables(text: string): string[] {\n const matches = new Set<string>();\n let match;\n\n while ((match = VARIABLE_REGEX.exec(text)) !== null) {\n if (match) {\n if (match[1]) {\n // \\$(\\w+)\\\n matches.add(match[1]);\n } else if (match[2]) {\n // \\${(\\w+)}\\\n matches.add(match[2]);\n }\n }\n }\n // return unique matches\n return Array.from(matches.values());\n}\n\n/**\n * Returns a map of variable names and its format. If no format is specified, it will be undefined.\n */\nexport function parseVariablesAndFormat(text: string): Map<string, InterpolationFormat | undefined> {\n const matches = new Map<string, InterpolationFormat | undefined>();\n let match;\n\n while ((match = VARIABLE_REGEX.exec(text)) !== null) {\n if (match) {\n let format = undefined;\n if (match[4]) {\n format = match[4];\n }\n if (match[1]) {\n // \\$(\\w+)\\\n matches.set(match[1], stringToFormat(format));\n } else if (match[2]) {\n // \\${(\\w+)}\\\n matches.set(match[2], stringToFormat(format));\n }\n }\n }\n return matches;\n}\n"],"names":["replaceVariables","text","variableState","variablesMap","parseVariablesAndFormat","variables","Array","from","keys","finalText","sort","a","b","length","forEach","v","variable","value","undefined","replaceVariable","get","InterpolationFormat","stringToFormat","val","lowerVal","toLowerCase","Object","values","find","format","interpolate","name","join","first","rest","map","JSON","stringify","encodeURIComponent","escapedRegex","replace","varName","variableValue","varFormat","variableSyntax","alternativeVariableSyntax","replaceString","isArray","replaceAll","VARIABLE_REGEX","parseVariables","matches","Set","match","exec","add","Map","set"],"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;AAKjC,OAAO,SAASA,iBAAiBC,IAAY,EAAEC,aAA+B;IAC5E,MAAMC,eAAeC,wBAAwBH;IAC7C,MAAMI,YAAYC,MAAMC,IAAI,CAACJ,aAAaK,IAAI;IAC9C,IAAIC,YAAYR;IAChBI,SACE,qCAAqC;IACrC,gFAAgF;IAChF,yEAAyE;KACxEK,IAAI,CAAC,CAACC,GAAGC,IAAMA,EAAEC,MAAM,GAAGF,EAAEE,MAAM,EAClCC,OAAO,CAAC,CAACC;QACR,MAAMC,WAAWd,aAAa,CAACa,EAAE;QACjC,IAAIC,YAAYA,SAASC,KAAK,KAAKC,WAAW;YAC5CT,YAAYU,gB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AAI,CAACrD,KAAI,MAAO,KAAM;QACnD,IAAIoD,OAAO;YACT,IAAIA,KAAK,CAAC,EAAE,EAAE;gBACZ,WAAW;gBACXF,QAAQI,GAAG,CAACF,KAAK,CAAC,EAAE;YACtB,OAAO,IAAIA,KAAK,CAAC,EAAE,EAAE;gBACnB,aAAa;gBACbF,QAAQI,GAAG,CAACF,KAAK,CAAC,EAAE;YACtB;QACF;IACF;IACA,wBAAwB;IACxB,OAAO/C,MAAMC,IAAI,CAAC4C,QAAQxB,MAAM;AAClC;AAEA;;CAEC,GACD,OAAO,SAASvB,wBAAwBH,IAAY;IAClD,MAAMkD,UAAU,IAAIK;IACpB,IAAIH;IAEJ,MAAO,AAACA,CAAAA,QAAQJ,eAAeK,IAAI,CAACrD,KAAI,MAAO,KAAM;QACnD,IAAIoD,OAAO;YACT,IAAIxB,SAASX;YACb,IAAImC,KAAK,CAAC,EAAE,EAAE;gBACZxB,SAASwB,KAAK,CAAC,EAAE;YACnB;YACA,IAAIA,KAAK,CAAC,EAAE,EAAE;gBACZ,WAAW;gBACXF,QAAQM,GAAG,CAACJ,KAAK,CAAC,EAAE,EAAE/B,eAAeO;YACvC,OAAO,IAAIwB,KAAK,CAAC,EAAE,EAAE;gBACnB,aAAa;gBACbF,QAAQM,GAAG,CAACJ,KAAK,CAAC,EAAE,EAAE/B,eAAeO;YACvC;QACF;IACF;IACA,OAAOsB;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/plugin-system",
|
|
3
|
-
"version": "0.0.0-snapshot-
|
|
3
|
+
"version": "0.0.0-snapshot-reverse-proxy-75afbd7",
|
|
4
4
|
"description": "The plugin feature in Pereses",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"clean": "rimraf dist/",
|
|
20
20
|
"build": "concurrently \"npm:build:*\"",
|
|
21
|
-
"build:cjs": "swc ./src -d dist/cjs --config-file ../.cjs.swcrc",
|
|
22
|
-
"build:esm": "swc ./src -d dist --config-file ../.swcrc",
|
|
21
|
+
"build:cjs": "swc ./src -d dist/cjs --strip-leading-paths --config-file ../.cjs.swcrc",
|
|
22
|
+
"build:esm": "swc ./src -d dist --strip-leading-paths --config-file ../.swcrc",
|
|
23
23
|
"build:types": "tsc --project tsconfig.build.json",
|
|
24
24
|
"type-check": "tsc --noEmit",
|
|
25
25
|
"start": "concurrently -P \"npm:build:* -- {*}\" -- --watch",
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
"lint:fix": "eslint --fix src --ext .ts,.tsx"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@module-federation/enhanced": "^0.
|
|
32
|
-
"@perses-dev/components": "0.0.0-snapshot-
|
|
33
|
-
"@perses-dev/core": "0.0.0-snapshot-
|
|
31
|
+
"@module-federation/enhanced": "^0.19.1",
|
|
32
|
+
"@perses-dev/components": "0.0.0-snapshot-reverse-proxy-75afbd7",
|
|
33
|
+
"@perses-dev/core": "0.0.0-snapshot-reverse-proxy-75afbd7",
|
|
34
34
|
"date-fns": "^4.1.0",
|
|
35
35
|
"date-fns-tz": "^3.2.0",
|
|
36
36
|
"immer": "^10.1.1",
|
|
37
37
|
"react-hook-form": "^7.46.1",
|
|
38
38
|
"use-immer": "^0.11.0",
|
|
39
|
-
"use-query-params": "^2.1
|
|
39
|
+
"use-query-params": "^2.2.1",
|
|
40
40
|
"zod": "^3.22.2"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
@@ -1,96 +0,0 @@
|
|
|
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, "ProjectSelect", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function() {
|
|
20
|
-
return ProjectSelect;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
const _jsxruntime = require("react/jsx-runtime");
|
|
24
|
-
const _material = require("@mui/material");
|
|
25
|
-
const _context = require("../context");
|
|
26
|
-
function ProjectSelect(props) {
|
|
27
|
-
const { onChange, value, ...others } = props;
|
|
28
|
-
const { data, isLoading } = (0, _context.useProjectList)();
|
|
29
|
-
// While loading available values, just use an empty string so MUI select doesn't warn about values out of range
|
|
30
|
-
const optionValue = isLoading ? '' : projectToOptionValue(value);
|
|
31
|
-
// When the user makes a selection, convert the string option value back to a DatasourceSelector
|
|
32
|
-
const handleChange = (e)=>{
|
|
33
|
-
const next = optionValueToSelector(e.target.value);
|
|
34
|
-
onChange(next);
|
|
35
|
-
};
|
|
36
|
-
// TODO:
|
|
37
|
-
// - Does this need a loading indicator of some kind?
|
|
38
|
-
// - The group's edit link is not clickable once selected.
|
|
39
|
-
// - The group's edit link is disabled if datasource is overridden.
|
|
40
|
-
// Ref: https://github.com/mui/material-ui/issues/36572
|
|
41
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Select, {
|
|
42
|
-
...others,
|
|
43
|
-
value: optionValue,
|
|
44
|
-
onChange: handleChange,
|
|
45
|
-
children: [
|
|
46
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
|
|
47
|
-
value: "none",
|
|
48
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
|
|
49
|
-
direction: "row",
|
|
50
|
-
alignItems: "center",
|
|
51
|
-
justifyContent: "space-between",
|
|
52
|
-
width: "100%",
|
|
53
|
-
height: 32,
|
|
54
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.ListItemText, {
|
|
55
|
-
children: "None"
|
|
56
|
-
})
|
|
57
|
-
})
|
|
58
|
-
}),
|
|
59
|
-
data?.map((project)=>[
|
|
60
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
|
|
61
|
-
value: project.metadata.name,
|
|
62
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
|
|
63
|
-
direction: "row",
|
|
64
|
-
alignItems: "center",
|
|
65
|
-
justifyContent: "space-between",
|
|
66
|
-
width: "100%",
|
|
67
|
-
height: 32,
|
|
68
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.ListItemText, {
|
|
69
|
-
children: project.metadata.name
|
|
70
|
-
})
|
|
71
|
-
})
|
|
72
|
-
}, project.metadata.name)
|
|
73
|
-
])
|
|
74
|
-
]
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Given a ProjectSelectItemSelector,
|
|
79
|
-
* returns a string value that can be used as a Select input value.
|
|
80
|
-
* @param selector
|
|
81
|
-
*/ function projectToOptionValue(project) {
|
|
82
|
-
return project.metadata.name ?? 'none';
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Given an option value name,
|
|
86
|
-
* returns a ProjectResource to be used by the query data model.
|
|
87
|
-
* @param optionValue
|
|
88
|
-
*/ function optionValueToSelector(optionValue) {
|
|
89
|
-
return {
|
|
90
|
-
kind: 'Project',
|
|
91
|
-
metadata: {
|
|
92
|
-
name: optionValue
|
|
93
|
-
},
|
|
94
|
-
spec: {}
|
|
95
|
-
};
|
|
96
|
-
}
|