@perses-dev/loki-plugin 0.1.2 → 0.3.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/__mf/css/async/1580.d3010b86.css +1 -0
- package/__mf/css/async/2341.d3010b86.css +1 -0
- package/__mf/css/async/6759.d3010b86.css +1 -0
- package/__mf/js/{Loki.3789d265.js → Loki.2f631825.js} +4 -4
- package/__mf/js/async/1360.2348e2a7.js +10 -0
- package/__mf/js/async/1580.c7d3c3f1.js +2 -0
- package/__mf/js/async/2178.c22bac1c.js +2 -0
- package/__mf/js/async/2226.a056d1a3.js +1 -0
- package/__mf/js/async/2472.75bb97e0.js +22 -0
- package/__mf/js/async/2652.7b7038d2.js +28 -0
- package/__mf/js/async/2708.9651e2da.js +1 -0
- package/__mf/js/async/282.6c4c5a94.js +1 -0
- package/__mf/js/async/{4075.ea5435c6.js → 4075.19dee570.js} +1 -1
- package/__mf/js/async/{4238.ac5f0a30.js → 4238.155e3b8a.js} +1 -1
- package/__mf/js/async/4310.b96a5c66.js +7 -0
- package/__mf/js/async/4421.5adcbc2d.js +1 -0
- package/__mf/js/async/529.f12e49de.js +2 -0
- package/__mf/js/async/6134.f7ee513c.js +38 -0
- package/__mf/js/async/6329.9c3a3698.js +2 -0
- package/__mf/js/async/9563.0375701c.js +2 -0
- package/__mf/js/async/{__federation_expose_LokiDatasource.875ecaed.js → __federation_expose_LokiDatasource.a9871645.js} +2 -2
- package/__mf/js/async/__federation_expose_LokiLogQuery.9b430d01.js +1 -0
- package/__mf/js/async/__federation_expose_LokiTimeSeriesQuery.61feff51.js +1 -0
- package/__mf/js/{main.925fc3bf.js → main.174be1bc.js} +4 -4
- package/lib/cjs/index.js +0 -1
- package/lib/cjs/queries/loki-log-query/LokiLogQueryEditor.js +28 -27
- package/lib/cjs/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.js +27 -27
- package/lib/cjs/queries/query-editor-model.js +53 -0
- package/lib/index.d.ts +0 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/model/loki-data-types.d.ts +3 -13
- package/lib/model/loki-data-types.d.ts.map +1 -1
- package/lib/model/loki-data-types.js.map +1 -1
- package/lib/queries/loki-log-query/LokiLogQueryEditor.d.ts.map +1 -1
- package/lib/queries/loki-log-query/LokiLogQueryEditor.js +30 -29
- package/lib/queries/loki-log-query/LokiLogQueryEditor.js.map +1 -1
- package/lib/queries/loki-log-query/get-loki-log-data.js.map +1 -1
- package/lib/queries/loki-log-query/log-query-plugin-interface.d.ts +2 -3
- package/lib/queries/loki-log-query/log-query-plugin-interface.d.ts.map +1 -1
- package/lib/queries/loki-log-query/log-query-plugin-interface.js.map +1 -1
- package/lib/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.d.ts.map +1 -1
- package/lib/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.js +28 -28
- package/lib/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.js.map +1 -1
- package/lib/queries/query-editor-model.d.ts +20 -0
- package/lib/queries/query-editor-model.d.ts.map +1 -0
- package/lib/queries/query-editor-model.js +50 -0
- package/lib/queries/query-editor-model.js.map +1 -0
- package/mf-manifest.json +62 -125
- package/mf-stats.json +62 -127
- package/package.json +7 -16
- package/__mf/css/async/1320.7ad02b85.css +0 -1
- package/__mf/css/async/2341.7ad02b85.css +0 -1
- package/__mf/css/async/9479.7ad02b85.css +0 -1
- package/__mf/js/async/1320.ca6d65b6.js +0 -2
- package/__mf/js/async/2417.993ba27f.js +0 -2
- package/__mf/js/async/2448.6a132c1c.js +0 -10
- package/__mf/js/async/2470.ba894af3.js +0 -7
- package/__mf/js/async/282.3d82e785.js +0 -1
- package/__mf/js/async/3413.6dd92cfd.js +0 -1
- package/__mf/js/async/3849.c4035be2.js +0 -1
- package/__mf/js/async/4168.645bbaa1.js +0 -2
- package/__mf/js/async/4368.40ff20c1.js +0 -2
- package/__mf/js/async/4421.8aeb683a.js +0 -1
- package/__mf/js/async/4687.1af57d71.js +0 -2
- package/__mf/js/async/4693.ba67a5aa.js +0 -1
- package/__mf/js/async/5035.15709e1b.js +0 -73
- package/__mf/js/async/5713.3b303108.js +0 -1
- package/__mf/js/async/5876.5618763d.js +0 -2
- package/__mf/js/async/592.269748ce.js +0 -1
- package/__mf/js/async/6569.f33ecbef.js +0 -1
- package/__mf/js/async/6664.078084ff.js +0 -28
- package/__mf/js/async/9479.f74b4605.js +0 -1
- package/__mf/js/async/9654.575f5449.js +0 -37
- package/__mf/js/async/__federation_expose_LogsTable.0bf7a331.js +0 -2
- package/__mf/js/async/__federation_expose_LokiDatasource.875ecaed.js.LICENSE.txt +0 -9
- package/__mf/js/async/__federation_expose_LokiLogQuery.b5fd8404.js +0 -1
- package/__mf/js/async/__federation_expose_LokiTimeSeriesQuery.8e1af800.js +0 -1
- package/lib/cjs/panels/index.js +0 -30
- package/lib/cjs/panels/logstable/LogsTable.js +0 -41
- package/lib/cjs/panels/logstable/LogsTableComponent.js +0 -43
- package/lib/cjs/panels/logstable/LogsTableSettingsEditor.js +0 -70
- package/lib/cjs/panels/logstable/components/EmptyLogsState.js +0 -49
- package/lib/cjs/panels/logstable/components/LogRow/LogRow.js +0 -158
- package/lib/cjs/panels/logstable/components/LogRow/LogTimestamp.js +0 -44
- package/lib/cjs/panels/logstable/components/LogRow/LogsLabelsTable.js +0 -74
- package/lib/cjs/panels/logstable/components/LogRow/LogsStyles.js +0 -77
- package/lib/cjs/panels/logstable/components/LogRow/index.js +0 -37
- package/lib/cjs/panels/logstable/components/LogsList.js +0 -44
- package/lib/cjs/panels/logstable/components/VirtualizedLogsList.js +0 -63
- package/lib/cjs/panels/logstable/components/index.js +0 -23
- package/lib/cjs/panels/logstable/components/utils.js +0 -39
- package/lib/cjs/panels/logstable/hooks/useExpandedRows.js +0 -45
- package/lib/cjs/panels/logstable/hooks/useSeverity.js +0 -43
- package/lib/cjs/panels/logstable/index.js +0 -33
- package/lib/cjs/panels/logstable/logs-types.js +0 -16
- package/lib/panels/index.d.ts +0 -2
- package/lib/panels/index.d.ts.map +0 -1
- package/lib/panels/index.js +0 -15
- package/lib/panels/index.js.map +0 -1
- package/lib/panels/logstable/LogsTable.d.ts +0 -4
- package/lib/panels/logstable/LogsTable.d.ts.map +0 -1
- package/lib/panels/logstable/LogsTable.js +0 -33
- package/lib/panels/logstable/LogsTable.js.map +0 -1
- package/lib/panels/logstable/LogsTableComponent.d.ts +0 -4
- package/lib/panels/logstable/LogsTableComponent.d.ts.map +0 -1
- package/lib/panels/logstable/LogsTableComponent.js +0 -35
- package/lib/panels/logstable/LogsTableComponent.js.map +0 -1
- package/lib/panels/logstable/LogsTableSettingsEditor.d.ts +0 -7
- package/lib/panels/logstable/LogsTableSettingsEditor.d.ts.map +0 -1
- package/lib/panels/logstable/LogsTableSettingsEditor.js +0 -62
- package/lib/panels/logstable/LogsTableSettingsEditor.js.map +0 -1
- package/lib/panels/logstable/components/EmptyLogsState.d.ts +0 -7
- package/lib/panels/logstable/components/EmptyLogsState.d.ts.map +0 -1
- package/lib/panels/logstable/components/EmptyLogsState.js +0 -36
- package/lib/panels/logstable/components/EmptyLogsState.js.map +0 -1
- package/lib/panels/logstable/components/LogRow/LogRow.d.ts +0 -14
- package/lib/panels/logstable/components/LogRow/LogRow.d.ts.map +0 -1
- package/lib/panels/logstable/components/LogRow/LogRow.js +0 -104
- package/lib/panels/logstable/components/LogRow/LogRow.js.map +0 -1
- package/lib/panels/logstable/components/LogRow/LogTimestamp.d.ts +0 -7
- package/lib/panels/logstable/components/LogRow/LogTimestamp.d.ts.map +0 -1
- package/lib/panels/logstable/components/LogRow/LogTimestamp.js +0 -31
- package/lib/panels/logstable/components/LogRow/LogTimestamp.js.map +0 -1
- package/lib/panels/logstable/components/LogRow/LogsLabelsTable.d.ts +0 -7
- package/lib/panels/logstable/components/LogRow/LogsLabelsTable.d.ts.map +0 -1
- package/lib/panels/logstable/components/LogRow/LogsLabelsTable.js +0 -61
- package/lib/panels/logstable/components/LogRow/LogsLabelsTable.js.map +0 -1
- package/lib/panels/logstable/components/LogRow/LogsStyles.d.ts +0 -22
- package/lib/panels/logstable/components/LogRow/LogsStyles.d.ts.map +0 -1
- package/lib/panels/logstable/components/LogRow/LogsStyles.js +0 -55
- package/lib/panels/logstable/components/LogRow/LogsStyles.js.map +0 -1
- package/lib/panels/logstable/components/LogRow/index.d.ts +0 -3
- package/lib/panels/logstable/components/LogRow/index.d.ts.map +0 -1
- package/lib/panels/logstable/components/LogRow/index.js +0 -16
- package/lib/panels/logstable/components/LogRow/index.js.map +0 -1
- package/lib/panels/logstable/components/LogsList.d.ts +0 -10
- package/lib/panels/logstable/components/LogsList.d.ts.map +0 -1
- package/lib/panels/logstable/components/LogsList.js +0 -31
- package/lib/panels/logstable/components/LogsList.js.map +0 -1
- package/lib/panels/logstable/components/VirtualizedLogsList.d.ts +0 -12
- package/lib/panels/logstable/components/VirtualizedLogsList.d.ts.map +0 -1
- package/lib/panels/logstable/components/VirtualizedLogsList.js +0 -50
- package/lib/panels/logstable/components/VirtualizedLogsList.js.map +0 -1
- package/lib/panels/logstable/components/index.d.ts +0 -2
- package/lib/panels/logstable/components/index.d.ts.map +0 -1
- package/lib/panels/logstable/components/index.js +0 -15
- package/lib/panels/logstable/components/index.js.map +0 -1
- package/lib/panels/logstable/components/utils.d.ts +0 -3
- package/lib/panels/logstable/components/utils.d.ts.map +0 -1
- package/lib/panels/logstable/components/utils.js +0 -31
- package/lib/panels/logstable/components/utils.js.map +0 -1
- package/lib/panels/logstable/hooks/useExpandedRows.d.ts +0 -6
- package/lib/panels/logstable/hooks/useExpandedRows.d.ts.map +0 -1
- package/lib/panels/logstable/hooks/useExpandedRows.js +0 -37
- package/lib/panels/logstable/hooks/useExpandedRows.js.map +0 -1
- package/lib/panels/logstable/hooks/useSeverity.d.ts +0 -3
- package/lib/panels/logstable/hooks/useSeverity.d.ts.map +0 -1
- package/lib/panels/logstable/hooks/useSeverity.js +0 -35
- package/lib/panels/logstable/hooks/useSeverity.js.map +0 -1
- package/lib/panels/logstable/index.d.ts +0 -5
- package/lib/panels/logstable/index.d.ts.map +0 -1
- package/lib/panels/logstable/index.js +0 -18
- package/lib/panels/logstable/index.js.map +0 -1
- package/lib/panels/logstable/logs-types.d.ts +0 -11
- package/lib/panels/logstable/logs-types.d.ts.map +0 -1
- package/lib/panels/logstable/logs-types.js +0 -15
- package/lib/panels/logstable/logs-types.js.map +0 -1
- /package/__mf/js/async/{2448.6a132c1c.js.LICENSE.txt → 1360.2348e2a7.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{1320.ca6d65b6.js.LICENSE.txt → 1580.c7d3c3f1.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{4368.40ff20c1.js.LICENSE.txt → 2178.c22bac1c.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{5035.15709e1b.js.LICENSE.txt → 2472.75bb97e0.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{2470.ba894af3.js.LICENSE.txt → 4310.b96a5c66.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{5876.5618763d.js.LICENSE.txt → 529.f12e49de.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{2417.993ba27f.js.LICENSE.txt → 6329.9c3a3698.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{4687.1af57d71.js.LICENSE.txt → 9563.0375701c.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{__federation_expose_LogsTable.0bf7a331.js.LICENSE.txt → __federation_expose_LokiDatasource.a9871645.js.LICENSE.txt} +0 -0
|
@@ -24,27 +24,23 @@ const _jsxruntime = require("react/jsx-runtime");
|
|
|
24
24
|
const _pluginsystem = require("@perses-dev/plugin-system");
|
|
25
25
|
const _material = require("@mui/material");
|
|
26
26
|
const _react = require("react");
|
|
27
|
+
const _immer = require("immer");
|
|
27
28
|
const _logqleditor = require("../../components/logql-editor");
|
|
28
29
|
const _model = require("../../model");
|
|
29
30
|
const _constants = require("../constants");
|
|
31
|
+
const _queryeditormodel = require("../query-editor-model");
|
|
30
32
|
function LokiQueryEditor(props) {
|
|
31
|
-
const { onChange, value } = props;
|
|
33
|
+
const { onChange, value, queryHandlerSettings } = props;
|
|
32
34
|
const { datasource } = value;
|
|
33
35
|
const datasourceSelectValue = datasource ?? _constants.DEFAULT_DATASOURCE;
|
|
34
36
|
const selectedDatasource = (0, _pluginsystem.useDatasourceSelectValueToSelector)(datasourceSelectValue, _model.LOKI_DATASOURCE_KIND);
|
|
35
|
-
|
|
36
|
-
// const lokiURL = client?.options.datasourceUrl;
|
|
37
|
-
// Local state for editor value to prevent query_range calls on every keystroke
|
|
38
|
-
const [localQuery, setLocalQuery] = (0, _react.useState)(value.query);
|
|
39
|
-
// Update local state when prop changes
|
|
40
|
-
(0, _react.useEffect)(()=>{
|
|
41
|
-
setLocalQuery(value.query);
|
|
42
|
-
}, [
|
|
43
|
-
value.query
|
|
44
|
-
]);
|
|
37
|
+
const { query, handleQueryChange, handleQueryBlur } = (0, _queryeditormodel.useQueryState)(props);
|
|
45
38
|
const handleDatasourceChange = (newDatasourceSelection)=>{
|
|
46
39
|
if (!(0, _pluginsystem.isVariableDatasource)(newDatasourceSelection) && newDatasourceSelection.kind === _constants.DATASOURCE_KIND) {
|
|
47
|
-
onChange({
|
|
40
|
+
onChange((0, _immer.produce)(value, (draft)=>{
|
|
41
|
+
draft.datasource = newDatasourceSelection;
|
|
42
|
+
}));
|
|
43
|
+
if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
|
|
48
44
|
...value,
|
|
49
45
|
datasource: newDatasourceSelection
|
|
50
46
|
});
|
|
@@ -52,19 +48,23 @@ function LokiQueryEditor(props) {
|
|
|
52
48
|
}
|
|
53
49
|
throw new Error('Got unexpected non LokiQuery datasource selection');
|
|
54
50
|
};
|
|
55
|
-
// Debounced query change handler to prevent excessive query_range calls
|
|
56
|
-
const handleQueryChange = (0, _react.useCallback)((newQuery)=>{
|
|
57
|
-
setLocalQuery(newQuery);
|
|
58
|
-
}, []);
|
|
59
51
|
// Immediate query execution on Enter or blur
|
|
60
|
-
const handleQueryExecute = (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
const handleQueryExecute = (query)=>{
|
|
53
|
+
if (queryHandlerSettings?.watchQueryChanges) {
|
|
54
|
+
queryHandlerSettings.watchQueryChanges(query);
|
|
55
|
+
}
|
|
56
|
+
onChange((0, _immer.produce)(value, (draft)=>{
|
|
57
|
+
draft.query = query;
|
|
58
|
+
}));
|
|
59
|
+
};
|
|
60
|
+
const handleLogsQueryChange = (0, _react.useCallback)((e)=>{
|
|
61
|
+
handleQueryChange(e);
|
|
62
|
+
if (queryHandlerSettings?.watchQueryChanges) {
|
|
63
|
+
queryHandlerSettings.watchQueryChanges(e);
|
|
64
|
+
}
|
|
65
65
|
}, [
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
handleQueryChange,
|
|
67
|
+
queryHandlerSettings
|
|
68
68
|
]);
|
|
69
69
|
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
|
|
70
70
|
spacing: 1.5,
|
|
@@ -100,13 +100,13 @@ function LokiQueryEditor(props) {
|
|
|
100
100
|
children: "LogQL Query"
|
|
101
101
|
}),
|
|
102
102
|
/*#__PURE__*/ (0, _jsxruntime.jsx)(_logqleditor.LogQLEditor, {
|
|
103
|
-
value:
|
|
104
|
-
onChange:
|
|
105
|
-
onBlur:
|
|
103
|
+
value: query,
|
|
104
|
+
onChange: handleLogsQueryChange,
|
|
105
|
+
onBlur: queryHandlerSettings?.runWithOnBlur ? handleQueryBlur : undefined,
|
|
106
106
|
onKeyDown: (event)=>{
|
|
107
107
|
if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {
|
|
108
108
|
event.preventDefault();
|
|
109
|
-
handleQueryExecute(
|
|
109
|
+
handleQueryExecute(query);
|
|
110
110
|
}
|
|
111
111
|
},
|
|
112
112
|
placeholder: 'Enter LogQL query (e.g. {job="mysql"} |= "error")'
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Copyright 2025 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, "useQueryState", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return useQueryState;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const _react = require("react");
|
|
24
|
+
const _immer = require("immer");
|
|
25
|
+
function useQueryState(props) {
|
|
26
|
+
const { onChange, value } = props;
|
|
27
|
+
// Local copy of the query's value
|
|
28
|
+
const [query, setQuery] = (0, _react.useState)(value.query);
|
|
29
|
+
// This is basically "getDerivedStateFromProps" to make sure if spec's value changes external to this component,
|
|
30
|
+
// we render with the latest value
|
|
31
|
+
const [lastSyncedQuery, setLastSyncedQuery] = (0, _react.useState)(value.query);
|
|
32
|
+
if (value.query !== lastSyncedQuery) {
|
|
33
|
+
setQuery(value.query);
|
|
34
|
+
setLastSyncedQuery(value.query);
|
|
35
|
+
}
|
|
36
|
+
// Update our local state's copy as the user types
|
|
37
|
+
const handleQueryChange = (e)=>{
|
|
38
|
+
setQuery(e);
|
|
39
|
+
};
|
|
40
|
+
// Propagate changes to the query's value when the input is blurred to avoid constantly re-running queries in the
|
|
41
|
+
// PanelPreview
|
|
42
|
+
const handleQueryBlur = ()=>{
|
|
43
|
+
setLastSyncedQuery(query);
|
|
44
|
+
onChange((0, _immer.produce)(value, (draft)=>{
|
|
45
|
+
draft.query = query;
|
|
46
|
+
}));
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
query,
|
|
50
|
+
handleQueryChange,
|
|
51
|
+
handleQueryBlur
|
|
52
|
+
};
|
|
53
|
+
}
|
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,cAAc,SAAS,CAAC;AACxB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC"}
|
package/lib/index.js
CHANGED
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { getPluginModule } from './getPluginModule';\nexport * from './model';\nexport * from './
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { getPluginModule } from './getPluginModule';\nexport * from './model';\nexport * from './queries';\nexport * from './datasources';\n"],"names":["getPluginModule"],"mappings":"AAAA,SAASA,eAAe,QAAQ,oBAAoB;AACpD,cAAc,UAAU;AACxB,cAAc,YAAY;AAC1B,cAAc,gBAAgB"}
|
|
@@ -1,23 +1,13 @@
|
|
|
1
|
-
import { AbsoluteTimeRange, TimeSeries, TimeSeriesData, TimeSeriesMetadata } from '@perses-dev/core';
|
|
2
|
-
export interface LogEntry {
|
|
3
|
-
timestamp: number;
|
|
4
|
-
line: string;
|
|
5
|
-
labels: Record<string, string>;
|
|
6
|
-
}
|
|
7
|
-
export interface LogsData {
|
|
8
|
-
entries: LogEntry[];
|
|
9
|
-
totalCount: number;
|
|
10
|
-
hasMore?: boolean;
|
|
11
|
-
}
|
|
1
|
+
import { LogData, AbsoluteTimeRange, TimeSeries, TimeSeriesData, TimeSeriesMetadata } from '@perses-dev/core';
|
|
12
2
|
export interface LokiTimeSeriesData extends TimeSeriesData {
|
|
13
|
-
logs?:
|
|
3
|
+
logs?: LogData;
|
|
14
4
|
resultType?: 'matrix' | 'streams';
|
|
15
5
|
}
|
|
16
6
|
export interface LokiQueryResult {
|
|
17
7
|
timeRange?: AbsoluteTimeRange;
|
|
18
8
|
stepMs?: number;
|
|
19
9
|
series: TimeSeries[];
|
|
20
|
-
logs?:
|
|
10
|
+
logs?: LogData;
|
|
21
11
|
resultType: 'matrix' | 'streams';
|
|
22
12
|
metadata?: TimeSeriesMetadata;
|
|
23
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loki-data-types.d.ts","sourceRoot":"","sources":["../../../src/model/loki-data-types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"loki-data-types.d.ts","sourceRoot":"","sources":["../../../src/model/loki-data-types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE9G,MAAM,WAAW,kBAAmB,SAAQ,cAAc;IACxD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;CACnC;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,UAAU,EAAE,QAAQ,GAAG,SAAS,CAAC;IACjC,QAAQ,CAAC,EAAE,kBAAkB,CAAC;CAC/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/loki-data-types.ts"],"sourcesContent":["// Copyright 2025 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 { AbsoluteTimeRange, TimeSeries, TimeSeriesData, TimeSeriesMetadata } from '@perses-dev/core';\n\nexport interface
|
|
1
|
+
{"version":3,"sources":["../../../src/model/loki-data-types.ts"],"sourcesContent":["// Copyright 2025 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, AbsoluteTimeRange, TimeSeries, TimeSeriesData, TimeSeriesMetadata } from '@perses-dev/core';\n\nexport interface LokiTimeSeriesData extends TimeSeriesData {\n logs?: LogData;\n resultType?: 'matrix' | 'streams';\n}\n\nexport interface LokiQueryResult {\n timeRange?: AbsoluteTimeRange;\n stepMs?: number;\n series: TimeSeries[];\n logs?: LogData;\n resultType: 'matrix' | 'streams';\n metadata?: TimeSeriesMetadata;\n}\n"],"names":[],"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;AASjC,WAOC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LokiLogQueryEditor.d.ts","sourceRoot":"","sources":["../../../../src/queries/loki-log-query/LokiLogQueryEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAIL,kBAAkB,EAEnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAoC,MAAM,OAAO,CAAC;AAMvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"LokiLogQueryEditor.d.ts","sourceRoot":"","sources":["../../../../src/queries/loki-log-query/LokiLogQueryEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAIL,kBAAkB,EAEnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAoC,MAAM,OAAO,CAAC;AAMvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D,KAAK,oBAAoB,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;AAEjE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,oBAAoB,GAAG,YAAY,CA6H5E"}
|
|
@@ -13,30 +13,27 @@
|
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
import { DatasourceSelect, isVariableDatasource, useDatasourceSelectValueToSelector } from '@perses-dev/plugin-system';
|
|
15
15
|
import { InputLabel, Stack, ToggleButton, ToggleButtonGroup } from '@mui/material';
|
|
16
|
-
import { useCallback
|
|
16
|
+
import { useCallback } from 'react';
|
|
17
17
|
import { produce } from 'immer';
|
|
18
18
|
import { OptionsEditorControl } from '@perses-dev/components';
|
|
19
19
|
import { LogQLEditor } from '../../components/logql-editor';
|
|
20
|
-
import { LOKI_DATASOURCE_KIND } from '../../model';
|
|
20
|
+
import { isDefaultLokiSelector, LOKI_DATASOURCE_KIND } from '../../model';
|
|
21
21
|
import { DATASOURCE_KIND, DEFAULT_DATASOURCE } from '../constants';
|
|
22
|
+
import { useQueryState } from '../query-editor-model';
|
|
22
23
|
export function LokiLogQueryEditor(props) {
|
|
23
|
-
const { onChange, value } = props;
|
|
24
|
+
const { onChange, value, queryHandlerSettings } = props;
|
|
24
25
|
const { datasource } = value;
|
|
25
26
|
const datasourceSelectValue = datasource ?? DEFAULT_DATASOURCE;
|
|
26
27
|
const selectedDatasource = useDatasourceSelectValueToSelector(datasourceSelectValue, LOKI_DATASOURCE_KIND);
|
|
27
|
-
|
|
28
|
-
// const lokiURL = client?.options.datasourceUrl;
|
|
29
|
-
// Local state for editor value to prevent query_range calls on every keystroke
|
|
30
|
-
const [localQuery, setLocalQuery] = useState(value.query);
|
|
31
|
-
// Update local state when prop changes
|
|
32
|
-
useEffect(()=>{
|
|
33
|
-
setLocalQuery(value.query);
|
|
34
|
-
}, [
|
|
35
|
-
value.query
|
|
36
|
-
]);
|
|
28
|
+
const { query, handleQueryChange, handleQueryBlur } = useQueryState(props);
|
|
37
29
|
const handleDatasourceChange = (newDatasourceSelection)=>{
|
|
38
30
|
if (!isVariableDatasource(newDatasourceSelection) && newDatasourceSelection.kind === DATASOURCE_KIND) {
|
|
39
|
-
onChange({
|
|
31
|
+
onChange(produce(value, (draft)=>{
|
|
32
|
+
// If they're using the default, just omit the datasource prop (i.e. set to undefined)
|
|
33
|
+
const nextDatasource = isDefaultLokiSelector(newDatasourceSelection) ? undefined : newDatasourceSelection;
|
|
34
|
+
draft.datasource = nextDatasource;
|
|
35
|
+
}));
|
|
36
|
+
if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
|
|
40
37
|
...value,
|
|
41
38
|
datasource: newDatasourceSelection
|
|
42
39
|
});
|
|
@@ -44,22 +41,26 @@ export function LokiLogQueryEditor(props) {
|
|
|
44
41
|
}
|
|
45
42
|
throw new Error('Got unexpected non LokiQuery datasource selection');
|
|
46
43
|
};
|
|
47
|
-
// Debounced query change handler to prevent excessive query_range calls
|
|
48
|
-
const handleQueryChange = useCallback((newQuery)=>{
|
|
49
|
-
setLocalQuery(newQuery);
|
|
50
|
-
}, []);
|
|
51
44
|
const handleLogsDirection = (_, v)=>onChange(produce(value, (draft)=>{
|
|
52
45
|
draft.direction = v;
|
|
53
46
|
}));
|
|
54
47
|
// Immediate query execution on Enter or blur
|
|
55
|
-
const handleQueryExecute =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
48
|
+
const handleQueryExecute = (query)=>{
|
|
49
|
+
if (queryHandlerSettings?.watchQueryChanges) {
|
|
50
|
+
queryHandlerSettings.watchQueryChanges(query);
|
|
51
|
+
}
|
|
52
|
+
onChange(produce(value, (draft)=>{
|
|
53
|
+
draft.query = query;
|
|
54
|
+
}));
|
|
55
|
+
};
|
|
56
|
+
const handleLogsQueryChange = useCallback((e)=>{
|
|
57
|
+
handleQueryChange(e);
|
|
58
|
+
if (queryHandlerSettings?.watchQueryChanges) {
|
|
59
|
+
queryHandlerSettings.watchQueryChanges(e);
|
|
60
|
+
}
|
|
60
61
|
}, [
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
handleQueryChange,
|
|
63
|
+
queryHandlerSettings
|
|
63
64
|
]);
|
|
64
65
|
return /*#__PURE__*/ _jsxs(Stack, {
|
|
65
66
|
spacing: 1.5,
|
|
@@ -95,13 +96,13 @@ export function LokiLogQueryEditor(props) {
|
|
|
95
96
|
children: "LogQL Query"
|
|
96
97
|
}),
|
|
97
98
|
/*#__PURE__*/ _jsx(LogQLEditor, {
|
|
98
|
-
value:
|
|
99
|
-
onChange:
|
|
100
|
-
onBlur:
|
|
99
|
+
value: query,
|
|
100
|
+
onChange: handleLogsQueryChange,
|
|
101
|
+
onBlur: queryHandlerSettings?.runWithOnBlur ? handleQueryBlur : undefined,
|
|
101
102
|
onKeyDown: (event)=>{
|
|
102
103
|
if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {
|
|
103
104
|
event.preventDefault();
|
|
104
|
-
handleQueryExecute(
|
|
105
|
+
handleQueryExecute(query);
|
|
105
106
|
}
|
|
106
107
|
},
|
|
107
108
|
placeholder: 'Enter LogQL query (e.g. {job="mysql"} |= "error")'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/queries/loki-log-query/LokiLogQueryEditor.tsx"],"sourcesContent":["// Copyright 2025 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 {\n DatasourceSelect,\n DatasourceSelectProps,\n isVariableDatasource,\n OptionsEditorProps,\n useDatasourceSelectValueToSelector,\n} from '@perses-dev/plugin-system';\nimport { InputLabel, Stack, ToggleButton, ToggleButtonGroup } from '@mui/material';\nimport { ReactElement, useCallback, useState, useEffect } from 'react';\nimport { produce } from 'immer';\nimport { OptionsEditorControl } from '@perses-dev/components';\nimport { LogQLEditor } from '../../components/logql-editor';\nimport { LOKI_DATASOURCE_KIND, LokiDatasourceSelector } from '../../model';\nimport { DATASOURCE_KIND, DEFAULT_DATASOURCE } from '../constants';\nimport { LokiLogQuerySpec } from './loki-log-query-types';\n\ntype LokiQueryEditorProps = OptionsEditorProps<LokiLogQuerySpec>;\n\nexport function LokiLogQueryEditor(props: LokiQueryEditorProps): ReactElement {\n const { onChange, value } = props;\n const { datasource } = value;\n const datasourceSelectValue = datasource ?? DEFAULT_DATASOURCE;\n const selectedDatasource = useDatasourceSelectValueToSelector(\n datasourceSelectValue,\n LOKI_DATASOURCE_KIND\n ) as LokiDatasourceSelector;\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/queries/loki-log-query/LokiLogQueryEditor.tsx"],"sourcesContent":["// Copyright 2025 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 {\n DatasourceSelect,\n DatasourceSelectProps,\n isVariableDatasource,\n OptionsEditorProps,\n useDatasourceSelectValueToSelector,\n} from '@perses-dev/plugin-system';\nimport { InputLabel, Stack, ToggleButton, ToggleButtonGroup } from '@mui/material';\nimport { ReactElement, useCallback, useState, useEffect } from 'react';\nimport { produce } from 'immer';\nimport { OptionsEditorControl } from '@perses-dev/components';\nimport { LogQLEditor } from '../../components/logql-editor';\nimport { isDefaultLokiSelector, LOKI_DATASOURCE_KIND, LokiDatasourceSelector } from '../../model';\nimport { DATASOURCE_KIND, DEFAULT_DATASOURCE } from '../constants';\nimport { LokiLogQuerySpec } from './loki-log-query-types';\nimport { useQueryState } from '../query-editor-model';\n\ntype LokiQueryEditorProps = OptionsEditorProps<LokiLogQuerySpec>;\n\nexport function LokiLogQueryEditor(props: LokiQueryEditorProps): ReactElement {\n const { onChange, value, queryHandlerSettings } = props;\n const { datasource } = value;\n const datasourceSelectValue = datasource ?? DEFAULT_DATASOURCE;\n const selectedDatasource = useDatasourceSelectValueToSelector(\n datasourceSelectValue,\n LOKI_DATASOURCE_KIND\n ) as LokiDatasourceSelector;\n const { query, handleQueryChange, handleQueryBlur } = useQueryState(props);\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (newDatasourceSelection) => {\n if (!isVariableDatasource(newDatasourceSelection) && newDatasourceSelection.kind === DATASOURCE_KIND) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n const nextDatasource = isDefaultLokiSelector(newDatasourceSelection) ? undefined : newDatasourceSelection;\n draft.datasource = nextDatasource;\n })\n );\n\n if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings.setWatchOtherSpecs({ ...value, datasource: newDatasourceSelection });\n return;\n }\n\n throw new Error('Got unexpected non LokiQuery datasource selection');\n };\n\n const handleLogsDirection = (_: React.MouseEvent, v: 'backward' | 'forward') =>\n onChange(\n produce(value, (draft: LokiLogQuerySpec) => {\n draft.direction = v;\n })\n );\n\n // Immediate query execution on Enter or blur\n const handleQueryExecute = (query: string) => {\n if (queryHandlerSettings?.watchQueryChanges) {\n queryHandlerSettings.watchQueryChanges(query);\n }\n onChange(\n produce(value, (draft) => {\n draft.query = query;\n })\n );\n };\n\n const handleLogsQueryChange = useCallback(\n (e: string) => {\n handleQueryChange(e);\n if (queryHandlerSettings?.watchQueryChanges) {\n queryHandlerSettings.watchQueryChanges(e);\n }\n },\n [handleQueryChange, queryHandlerSettings]\n );\n\n return (\n <Stack spacing={1.5} paddingBottom={1}>\n <div>\n <InputLabel\n sx={{\n display: 'block',\n marginBottom: '4px',\n fontWeight: 500,\n }}\n >\n Datasource\n </InputLabel>\n <DatasourceSelect\n datasourcePluginKind={DATASOURCE_KIND}\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n label=\"Loki Datasource\"\n notched\n />\n </div>\n\n <div>\n <InputLabel\n sx={{\n display: 'block',\n marginBottom: '4px',\n fontWeight: 500,\n }}\n >\n LogQL Query\n </InputLabel>\n <LogQLEditor\n value={query}\n onChange={handleLogsQueryChange}\n onBlur={queryHandlerSettings?.runWithOnBlur ? handleQueryBlur : undefined}\n onKeyDown={(event) => {\n if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {\n event.preventDefault();\n handleQueryExecute(query);\n }\n }}\n placeholder='Enter LogQL query (e.g. {job=\"mysql\"} |= \"error\")'\n // height=\"120px\"\n />\n </div>\n <div>\n <OptionsEditorControl\n label=\"Order\"\n // description=\"Percentage means thresholds relative to min & max\"\n control={\n <ToggleButtonGroup\n exclusive\n value={value?.direction ?? 'backward'}\n onChange={handleLogsDirection}\n sx={{ height: '36px', marginLeft: '10px', width: 'max-content' }}\n >\n <ToggleButton aria-label=\"backward\" value=\"backward\" sx={{ fontWeight: 500 }}>\n Newest first\n </ToggleButton>\n <ToggleButton aria-label=\"forward\" value=\"forward\" sx={{ fontWeight: 500 }}>\n Oldest first\n </ToggleButton>\n </ToggleButtonGroup>\n }\n />\n </div>\n </Stack>\n );\n}\n"],"names":["DatasourceSelect","isVariableDatasource","useDatasourceSelectValueToSelector","InputLabel","Stack","ToggleButton","ToggleButtonGroup","useCallback","produce","OptionsEditorControl","LogQLEditor","isDefaultLokiSelector","LOKI_DATASOURCE_KIND","DATASOURCE_KIND","DEFAULT_DATASOURCE","useQueryState","LokiLogQueryEditor","props","onChange","value","queryHandlerSettings","datasource","datasourceSelectValue","selectedDatasource","query","handleQueryChange","handleQueryBlur","handleDatasourceChange","newDatasourceSelection","kind","draft","nextDatasource","undefined","setWatchOtherSpecs","Error","handleLogsDirection","_","v","direction","handleQueryExecute","watchQueryChanges","handleLogsQueryChange","e","spacing","paddingBottom","div","sx","display","marginBottom","fontWeight","datasourcePluginKind","label","notched","onBlur","runWithOnBlur","onKeyDown","event","key","ctrlKey","metaKey","preventDefault","placeholder","control","exclusive","height","marginLeft","width","aria-label"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/queries/loki-log-query/get-loki-log-data.ts"],"sourcesContent":["import { replaceVariables } from '@perses-dev/plugin-system';\nimport { LokiStreamResult } from '../../model/loki-client-types';\nimport { LokiClient } from '../../model/loki-client';\nimport { LogEntry,
|
|
1
|
+
{"version":3,"sources":["../../../../src/queries/loki-log-query/get-loki-log-data.ts"],"sourcesContent":["import { replaceVariables } from '@perses-dev/plugin-system';\nimport { LokiStreamResult } from '../../model/loki-client-types';\nimport { LokiClient } from '../../model/loki-client';\nimport { LogEntry, LogData } from '@perses-dev/core';\nimport { DEFAULT_DATASOURCE } from '../constants';\nimport { LokiLogQuerySpec, LokiLogQueryResponse } from './loki-log-query-types';\nimport { LogQueryPlugin, LogQueryContext } from './log-query-plugin-interface';\n\nfunction convertStreamsToLogs(streams: LokiStreamResult[]): LogData {\n const entries: LogEntry[] = [];\n\n streams.forEach((stream) => {\n stream.values.forEach(([timestamp, logLine]: [string, string]) => {\n entries.push({\n timestamp: Number(timestamp) / 1000000000,\n line: logLine,\n labels: stream.stream,\n });\n });\n });\n\n return {\n entries,\n totalCount: entries.length,\n };\n}\n\nexport const getLokiLogData: LogQueryPlugin<LokiLogQuerySpec>['getLogData'] = async (\n spec: LokiLogQuerySpec,\n context: LogQueryContext\n) => {\n if (!spec.query) {\n return {\n logs: { entries: [], totalCount: 0 },\n timeRange: { start: context.timeRange.start, end: context.timeRange.end },\n };\n }\n\n const query = replaceVariables(spec.query, context.variableState);\n const client = (await context.datasourceStore.getDatasourceClient<LokiClient>(\n spec.datasource ?? DEFAULT_DATASOURCE\n )) as LokiClient;\n\n const { start, end } = context.timeRange;\n\n const response: LokiLogQueryResponse = await client.queryRange({\n query,\n start: start.getTime().toString(),\n end: end.getTime().toString(),\n direction: spec.direction,\n });\n\n if (response.data.resultType === 'streams') {\n const logs = convertStreamsToLogs(response.data.result);\n return {\n logs,\n timeRange: { start, end },\n metadata: {\n executedQueryString: query,\n },\n };\n }\n\n return {\n logs: { entries: [], totalCount: 0 },\n timeRange: { start, end },\n };\n};\n"],"names":["replaceVariables","DEFAULT_DATASOURCE","convertStreamsToLogs","streams","entries","forEach","stream","values","timestamp","logLine","push","Number","line","labels","totalCount","length","getLokiLogData","spec","context","query","logs","timeRange","start","end","variableState","client","datasourceStore","getDatasourceClient","datasource","response","queryRange","getTime","toString","direction","data","resultType","result","metadata","executedQueryString"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,4BAA4B;AAI7D,SAASC,kBAAkB,QAAQ,eAAe;AAIlD,SAASC,qBAAqBC,OAA2B;IACvD,MAAMC,UAAsB,EAAE;IAE9BD,QAAQE,OAAO,CAAC,CAACC;QACfA,OAAOC,MAAM,CAACF,OAAO,CAAC,CAAC,CAACG,WAAWC,QAA0B;YAC3DL,QAAQM,IAAI,CAAC;gBACXF,WAAWG,OAAOH,aAAa;gBAC/BI,MAAMH;gBACNI,QAAQP,OAAOA,MAAM;YACvB;QACF;IACF;IAEA,OAAO;QACLF;QACAU,YAAYV,QAAQW,MAAM;IAC5B;AACF;AAEA,OAAO,MAAMC,iBAAiE,OAC5EC,MACAC;IAEA,IAAI,CAACD,KAAKE,KAAK,EAAE;QACf,OAAO;YACLC,MAAM;gBAAEhB,SAAS,EAAE;gBAAEU,YAAY;YAAE;YACnCO,WAAW;gBAAEC,OAAOJ,QAAQG,SAAS,CAACC,KAAK;gBAAEC,KAAKL,QAAQG,SAAS,CAACE,GAAG;YAAC;QAC1E;IACF;IAEA,MAAMJ,QAAQnB,iBAAiBiB,KAAKE,KAAK,EAAED,QAAQM,aAAa;IAChE,MAAMC,SAAU,MAAMP,QAAQQ,eAAe,CAACC,mBAAmB,CAC/DV,KAAKW,UAAU,IAAI3B;IAGrB,MAAM,EAAEqB,KAAK,EAAEC,GAAG,EAAE,GAAGL,QAAQG,SAAS;IAExC,MAAMQ,WAAiC,MAAMJ,OAAOK,UAAU,CAAC;QAC7DX;QACAG,OAAOA,MAAMS,OAAO,GAAGC,QAAQ;QAC/BT,KAAKA,IAAIQ,OAAO,GAAGC,QAAQ;QAC3BC,WAAWhB,KAAKgB,SAAS;IAC3B;IAEA,IAAIJ,SAASK,IAAI,CAACC,UAAU,KAAK,WAAW;QAC1C,MAAMf,OAAOlB,qBAAqB2B,SAASK,IAAI,CAACE,MAAM;QACtD,OAAO;YACLhB;YACAC,WAAW;gBAAEC;gBAAOC;YAAI;YACxBc,UAAU;gBACRC,qBAAqBnB;YACvB;QACF;IACF;IAEA,OAAO;QACLC,MAAM;YAAEhB,SAAS,EAAE;YAAEU,YAAY;QAAE;QACnCO,WAAW;YAAEC;YAAOC;QAAI;IAC1B;AACF,EAAE"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { AbsoluteTimeRange, UnknownSpec } from '@perses-dev/core';
|
|
1
|
+
import { LogData, AbsoluteTimeRange, UnknownSpec } from '@perses-dev/core';
|
|
2
2
|
import { DatasourceStore, Plugin, VariableStateMap } from '@perses-dev/plugin-system';
|
|
3
|
-
import { LogsData } from '../../model/loki-data-types';
|
|
4
3
|
export interface LogQueryResult {
|
|
5
|
-
logs:
|
|
4
|
+
logs: LogData;
|
|
6
5
|
timeRange: AbsoluteTimeRange;
|
|
7
6
|
metadata?: {
|
|
8
7
|
executedQueryString: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log-query-plugin-interface.d.ts","sourceRoot":"","sources":["../../../../src/queries/loki-log-query/log-query-plugin-interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"log-query-plugin-interface.d.ts","sourceRoot":"","sources":["../../../../src/queries/loki-log-query/log-query-plugin-interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAEtF,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,iBAAiB,CAAC;IAC7B,QAAQ,CAAC,EAAE;QACT,mBAAmB,EAAE,MAAM,CAAC;KAC7B,CAAC;CACH;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,iBAAiB,CAAC;IAC7B,aAAa,EAAE,gBAAgB,CAAC;IAChC,eAAe,EAAE,eAAe,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,KAAK,0BAA0B,GAAG;IAChC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAEF,MAAM,WAAW,cAAc,CAAC,IAAI,GAAG,WAAW,CAAE,SAAQ,MAAM,CAAC,IAAI,CAAC;IACtE,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IAC1E,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,eAAe,KAAK,0BAA0B,CAAC;CAC9E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/queries/loki-log-query/log-query-plugin-interface.ts"],"sourcesContent":["import { AbsoluteTimeRange, UnknownSpec } from '@perses-dev/core';\nimport { DatasourceStore, Plugin, VariableStateMap } from '@perses-dev/plugin-system';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/queries/loki-log-query/log-query-plugin-interface.ts"],"sourcesContent":["import { LogData, AbsoluteTimeRange, UnknownSpec } from '@perses-dev/core';\nimport { DatasourceStore, Plugin, VariableStateMap } from '@perses-dev/plugin-system';\n\nexport interface LogQueryResult {\n logs: LogData;\n timeRange: AbsoluteTimeRange;\n metadata?: {\n executedQueryString: string;\n };\n}\n\nexport interface LogQueryContext {\n timeRange: AbsoluteTimeRange;\n variableState: VariableStateMap;\n datasourceStore: DatasourceStore;\n refreshKey: string;\n}\n\ntype LogQueryPluginDependencies = {\n variables?: string[];\n};\n\nexport interface LogQueryPlugin<Spec = UnknownSpec> extends Plugin<Spec> {\n getLogData: (spec: Spec, ctx: LogQueryContext) => Promise<LogQueryResult>;\n dependsOn?: (spec: Spec, ctx: LogQueryContext) => LogQueryPluginDependencies;\n}\n"],"names":[],"mappings":"AAsBA,WAGC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LokiTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../../src/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAIL,kBAAkB,EAEnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"LokiTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../../src/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAIL,kBAAkB,EAEnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAe,MAAM,OAAO,CAAC;AAKlD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAGzE,KAAK,oBAAoB,GAAG,kBAAkB,CAAC,uBAAuB,CAAC,CAAC;AAExE,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,YAAY,CA+FzE"}
|
|
@@ -13,28 +13,24 @@
|
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
import { DatasourceSelect, isVariableDatasource, useDatasourceSelectValueToSelector } from '@perses-dev/plugin-system';
|
|
15
15
|
import { InputLabel, Stack } from '@mui/material';
|
|
16
|
-
import { useCallback
|
|
16
|
+
import { useCallback } from 'react';
|
|
17
|
+
import { produce } from 'immer';
|
|
17
18
|
import { LogQLEditor } from '../../components/logql-editor';
|
|
18
19
|
import { LOKI_DATASOURCE_KIND } from '../../model';
|
|
19
20
|
import { DATASOURCE_KIND, DEFAULT_DATASOURCE } from '../constants';
|
|
21
|
+
import { useQueryState } from '../query-editor-model';
|
|
20
22
|
export function LokiQueryEditor(props) {
|
|
21
|
-
const { onChange, value } = props;
|
|
23
|
+
const { onChange, value, queryHandlerSettings } = props;
|
|
22
24
|
const { datasource } = value;
|
|
23
25
|
const datasourceSelectValue = datasource ?? DEFAULT_DATASOURCE;
|
|
24
26
|
const selectedDatasource = useDatasourceSelectValueToSelector(datasourceSelectValue, LOKI_DATASOURCE_KIND);
|
|
25
|
-
|
|
26
|
-
// const lokiURL = client?.options.datasourceUrl;
|
|
27
|
-
// Local state for editor value to prevent query_range calls on every keystroke
|
|
28
|
-
const [localQuery, setLocalQuery] = useState(value.query);
|
|
29
|
-
// Update local state when prop changes
|
|
30
|
-
useEffect(()=>{
|
|
31
|
-
setLocalQuery(value.query);
|
|
32
|
-
}, [
|
|
33
|
-
value.query
|
|
34
|
-
]);
|
|
27
|
+
const { query, handleQueryChange, handleQueryBlur } = useQueryState(props);
|
|
35
28
|
const handleDatasourceChange = (newDatasourceSelection)=>{
|
|
36
29
|
if (!isVariableDatasource(newDatasourceSelection) && newDatasourceSelection.kind === DATASOURCE_KIND) {
|
|
37
|
-
onChange({
|
|
30
|
+
onChange(produce(value, (draft)=>{
|
|
31
|
+
draft.datasource = newDatasourceSelection;
|
|
32
|
+
}));
|
|
33
|
+
if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
|
|
38
34
|
...value,
|
|
39
35
|
datasource: newDatasourceSelection
|
|
40
36
|
});
|
|
@@ -42,19 +38,23 @@ export function LokiQueryEditor(props) {
|
|
|
42
38
|
}
|
|
43
39
|
throw new Error('Got unexpected non LokiQuery datasource selection');
|
|
44
40
|
};
|
|
45
|
-
// Debounced query change handler to prevent excessive query_range calls
|
|
46
|
-
const handleQueryChange = useCallback((newQuery)=>{
|
|
47
|
-
setLocalQuery(newQuery);
|
|
48
|
-
}, []);
|
|
49
41
|
// Immediate query execution on Enter or blur
|
|
50
|
-
const handleQueryExecute =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
const handleQueryExecute = (query)=>{
|
|
43
|
+
if (queryHandlerSettings?.watchQueryChanges) {
|
|
44
|
+
queryHandlerSettings.watchQueryChanges(query);
|
|
45
|
+
}
|
|
46
|
+
onChange(produce(value, (draft)=>{
|
|
47
|
+
draft.query = query;
|
|
48
|
+
}));
|
|
49
|
+
};
|
|
50
|
+
const handleLogsQueryChange = useCallback((e)=>{
|
|
51
|
+
handleQueryChange(e);
|
|
52
|
+
if (queryHandlerSettings?.watchQueryChanges) {
|
|
53
|
+
queryHandlerSettings.watchQueryChanges(e);
|
|
54
|
+
}
|
|
55
55
|
}, [
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
handleQueryChange,
|
|
57
|
+
queryHandlerSettings
|
|
58
58
|
]);
|
|
59
59
|
return /*#__PURE__*/ _jsxs(Stack, {
|
|
60
60
|
spacing: 1.5,
|
|
@@ -90,13 +90,13 @@ export function LokiQueryEditor(props) {
|
|
|
90
90
|
children: "LogQL Query"
|
|
91
91
|
}),
|
|
92
92
|
/*#__PURE__*/ _jsx(LogQLEditor, {
|
|
93
|
-
value:
|
|
94
|
-
onChange:
|
|
95
|
-
onBlur:
|
|
93
|
+
value: query,
|
|
94
|
+
onChange: handleLogsQueryChange,
|
|
95
|
+
onBlur: queryHandlerSettings?.runWithOnBlur ? handleQueryBlur : undefined,
|
|
96
96
|
onKeyDown: (event)=>{
|
|
97
97
|
if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {
|
|
98
98
|
event.preventDefault();
|
|
99
|
-
handleQueryExecute(
|
|
99
|
+
handleQueryExecute(query);
|
|
100
100
|
}
|
|
101
101
|
},
|
|
102
102
|
placeholder: 'Enter LogQL query (e.g. {job="mysql"} |= "error")'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.tsx"],"sourcesContent":["// Copyright 2025 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 {\n DatasourceSelect,\n DatasourceSelectProps,\n isVariableDatasource,\n OptionsEditorProps,\n useDatasourceSelectValueToSelector,\n} from '@perses-dev/plugin-system';\nimport { InputLabel, Stack } from '@mui/material';\nimport { ReactElement, useCallback
|
|
1
|
+
{"version":3,"sources":["../../../../src/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.tsx"],"sourcesContent":["// Copyright 2025 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 {\n DatasourceSelect,\n DatasourceSelectProps,\n isVariableDatasource,\n OptionsEditorProps,\n useDatasourceSelectValueToSelector,\n} from '@perses-dev/plugin-system';\nimport { InputLabel, Stack } from '@mui/material';\nimport { ReactElement, useCallback } from 'react';\nimport { produce } from 'immer';\nimport { LogQLEditor } from '../../components/logql-editor';\nimport { LOKI_DATASOURCE_KIND, LokiDatasourceSelector } from '../../model';\nimport { DATASOURCE_KIND, DEFAULT_DATASOURCE } from '../constants';\nimport { LokiTimeSeriesQuerySpec } from './loki-time-series-query-types';\nimport { useQueryState } from '../query-editor-model';\n\ntype LokiQueryEditorProps = OptionsEditorProps<LokiTimeSeriesQuerySpec>;\n\nexport function LokiQueryEditor(props: LokiQueryEditorProps): ReactElement {\n const { onChange, value, queryHandlerSettings } = props;\n const { datasource } = value;\n const datasourceSelectValue = datasource ?? DEFAULT_DATASOURCE;\n const selectedDatasource = useDatasourceSelectValueToSelector(\n datasourceSelectValue,\n LOKI_DATASOURCE_KIND\n ) as LokiDatasourceSelector;\n const { query, handleQueryChange, handleQueryBlur } = useQueryState(props);\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (newDatasourceSelection) => {\n if (!isVariableDatasource(newDatasourceSelection) && newDatasourceSelection.kind === DATASOURCE_KIND) {\n onChange(\n produce(value, (draft) => {\n draft.datasource = newDatasourceSelection;\n })\n );\n\n if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings.setWatchOtherSpecs({ ...value, datasource: newDatasourceSelection });\n return;\n }\n\n throw new Error('Got unexpected non LokiQuery datasource selection');\n };\n\n // Immediate query execution on Enter or blur\n const handleQueryExecute = (query: string) => {\n if (queryHandlerSettings?.watchQueryChanges) {\n queryHandlerSettings.watchQueryChanges(query);\n }\n onChange(\n produce(value, (draft) => {\n draft.query = query;\n })\n );\n };\n\n const handleLogsQueryChange = useCallback(\n (e: string) => {\n handleQueryChange(e);\n if (queryHandlerSettings?.watchQueryChanges) {\n queryHandlerSettings.watchQueryChanges(e);\n }\n },\n [handleQueryChange, queryHandlerSettings]\n );\n\n return (\n <Stack spacing={1.5} paddingBottom={1}>\n <div>\n <InputLabel\n sx={{\n display: 'block',\n marginBottom: '4px',\n fontWeight: 500,\n }}\n >\n Datasource\n </InputLabel>\n <DatasourceSelect\n datasourcePluginKind={DATASOURCE_KIND}\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n label=\"Loki Datasource\"\n notched\n />\n </div>\n\n <div>\n <InputLabel\n sx={{\n display: 'block',\n marginBottom: '4px',\n fontWeight: 500,\n }}\n >\n LogQL Query\n </InputLabel>\n <LogQLEditor\n value={query}\n onChange={handleLogsQueryChange}\n onBlur={queryHandlerSettings?.runWithOnBlur ? handleQueryBlur : undefined}\n onKeyDown={(event) => {\n if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {\n event.preventDefault();\n handleQueryExecute(query);\n }\n }}\n placeholder='Enter LogQL query (e.g. {job=\"mysql\"} |= \"error\")'\n // height=\"120px\"\n />\n </div>\n </Stack>\n );\n}\n"],"names":["DatasourceSelect","isVariableDatasource","useDatasourceSelectValueToSelector","InputLabel","Stack","useCallback","produce","LogQLEditor","LOKI_DATASOURCE_KIND","DATASOURCE_KIND","DEFAULT_DATASOURCE","useQueryState","LokiQueryEditor","props","onChange","value","queryHandlerSettings","datasource","datasourceSelectValue","selectedDatasource","query","handleQueryChange","handleQueryBlur","handleDatasourceChange","newDatasourceSelection","kind","draft","setWatchOtherSpecs","Error","handleQueryExecute","watchQueryChanges","handleLogsQueryChange","e","spacing","paddingBottom","div","sx","display","marginBottom","fontWeight","datasourcePluginKind","label","notched","onBlur","runWithOnBlur","undefined","onKeyDown","event","key","ctrlKey","metaKey","preventDefault","placeholder"],"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,SACEA,gBAAgB,EAEhBC,oBAAoB,EAEpBC,kCAAkC,QAC7B,4BAA4B;AACnC,SAASC,UAAU,EAAEC,KAAK,QAAQ,gBAAgB;AAClD,SAAuBC,WAAW,QAAQ,QAAQ;AAClD,SAASC,OAAO,QAAQ,QAAQ;AAChC,SAASC,WAAW,QAAQ,gCAAgC;AAC5D,SAASC,oBAAoB,QAAgC,cAAc;AAC3E,SAASC,eAAe,EAAEC,kBAAkB,QAAQ,eAAe;AAEnE,SAASC,aAAa,QAAQ,wBAAwB;AAItD,OAAO,SAASC,gBAAgBC,KAA2B;IACzD,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,oBAAoB,EAAE,GAAGH;IAClD,MAAM,EAAEI,UAAU,EAAE,GAAGF;IACvB,MAAMG,wBAAwBD,cAAcP;IAC5C,MAAMS,qBAAqBjB,mCACzBgB,uBACAV;IAEF,MAAM,EAAEY,KAAK,EAAEC,iBAAiB,EAAEC,eAAe,EAAE,GAAGX,cAAcE;IAEpE,MAAMU,yBAA4D,CAACC;QACjE,IAAI,CAACvB,qBAAqBuB,2BAA2BA,uBAAuBC,IAAI,KAAKhB,iBAAiB;YACpGK,SACER,QAAQS,OAAO,CAACW;gBACdA,MAAMT,UAAU,GAAGO;YACrB;YAGF,IAAIR,sBAAsBW,oBACxBX,qBAAqBW,kBAAkB,CAAC;gBAAE,GAAGZ,KAAK;gBAAEE,YAAYO;YAAuB;YACzF;QACF;QAEA,MAAM,IAAII,MAAM;IAClB;IAEA,6CAA6C;IAC7C,MAAMC,qBAAqB,CAACT;QAC1B,IAAIJ,sBAAsBc,mBAAmB;YAC3Cd,qBAAqBc,iBAAiB,CAACV;QACzC;QACAN,SACER,QAAQS,OAAO,CAACW;YACdA,MAAMN,KAAK,GAAGA;QAChB;IAEJ;IAEA,MAAMW,wBAAwB1B,YAC5B,CAAC2B;QACCX,kBAAkBW;QAClB,IAAIhB,sBAAsBc,mBAAmB;YAC3Cd,qBAAqBc,iBAAiB,CAACE;QACzC;IACF,GACA;QAACX;QAAmBL;KAAqB;IAG3C,qBACE,MAACZ;QAAM6B,SAAS;QAAKC,eAAe;;0BAClC,MAACC;;kCACC,KAAChC;wBACCiC,IAAI;4BACFC,SAAS;4BACTC,cAAc;4BACdC,YAAY;wBACd;kCACD;;kCAGD,KAACvC;wBACCwC,sBAAsB/B;wBACtBM,OAAOI;wBACPL,UAAUS;wBACVkB,OAAM;wBACNC,OAAO;;;;0BAIX,MAACP;;kCACC,KAAChC;wBACCiC,IAAI;4BACFC,SAAS;4BACTC,cAAc;4BACdC,YAAY;wBACd;kCACD;;kCAGD,KAAChC;wBACCQ,OAAOK;wBACPN,UAAUiB;wBACVY,QAAQ3B,sBAAsB4B,gBAAgBtB,kBAAkBuB;wBAChEC,WAAW,CAACC;4BACV,IAAIA,MAAMC,GAAG,KAAK,WAAYD,CAAAA,MAAME,OAAO,IAAIF,MAAMG,OAAO,AAAD,GAAI;gCAC7DH,MAAMI,cAAc;gCACpBtB,mBAAmBT;4BACrB;wBACF;wBACAgC,aAAY;;;;;;AAMtB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { OptionsEditorProps } from '@perses-dev/plugin-system';
|
|
2
|
+
/**
|
|
3
|
+
* Generic type for any Loki query spec that has a query field
|
|
4
|
+
*/
|
|
5
|
+
type LokiQuerySpec = {
|
|
6
|
+
query: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A hook for managing the `query` state in Loki query specs. Returns the `query` value, along with
|
|
10
|
+
* `onChange` and `onBlur` event handlers to the input. Keeps a local copy of the user's input and only syncs those
|
|
11
|
+
* changes with the overall spec value once the input is blurred to prevent re-running queries in the panel's preview
|
|
12
|
+
* every time the user types.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useQueryState<T extends LokiQuerySpec>(props: OptionsEditorProps<T>): {
|
|
15
|
+
query: string;
|
|
16
|
+
handleQueryChange: (e: string) => void;
|
|
17
|
+
handleQueryBlur: () => void;
|
|
18
|
+
};
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=query-editor-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-editor-model.d.ts","sourceRoot":"","sources":["../../../src/queries/query-editor-model.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D;;GAEG;AACH,KAAK,aAAa,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,aAAa,EACnD,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAC3B;IACD,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,eAAe,EAAE,MAAM,IAAI,CAAC;CAC7B,CA+BA"}
|