@perses-dev/loki-plugin 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/__mf/js/{Loki.e3bb11f6.js → Loki.b0aaf34e.js} +5 -6
  2. package/__mf/js/async/2417.993ba27f.js +2 -0
  3. package/__mf/js/async/{2470.32c642b9.js → 2470.ba894af3.js} +2 -2
  4. package/__mf/js/async/4368.40ff20c1.js +2 -0
  5. package/__mf/js/async/4421.8aeb683a.js +1 -0
  6. package/__mf/js/async/5035.15709e1b.js +73 -0
  7. package/__mf/js/async/5713.3b303108.js +1 -0
  8. package/__mf/js/async/{__federation_expose_LogsTable.3952e904.js → __federation_expose_LogsTable.0bf7a331.js} +2 -2
  9. package/__mf/js/async/{__federation_expose_LokiDatasource.5fbd8f68.js → __federation_expose_LokiDatasource.875ecaed.js} +2 -2
  10. package/__mf/js/async/__federation_expose_LokiLogQuery.ab63332a.js +1 -0
  11. package/__mf/js/async/__federation_expose_LokiTimeSeriesQuery.9789679e.js +1 -0
  12. package/__mf/js/main.7a86e12b.js +5 -0
  13. package/lib/cjs/queries/loki-log-query/LokiLogQueryEditor.js +28 -27
  14. package/lib/cjs/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.js +27 -27
  15. package/lib/cjs/queries/query-editor-model.js +53 -0
  16. package/lib/panels/logstable/components/LogRow/LogsStyles.d.ts +2 -2
  17. package/lib/queries/loki-log-query/LokiLogQueryEditor.d.ts.map +1 -1
  18. package/lib/queries/loki-log-query/LokiLogQueryEditor.js +30 -29
  19. package/lib/queries/loki-log-query/LokiLogQueryEditor.js.map +1 -1
  20. package/lib/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.d.ts.map +1 -1
  21. package/lib/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.js +28 -28
  22. package/lib/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.js.map +1 -1
  23. package/lib/queries/query-editor-model.d.ts +20 -0
  24. package/lib/queries/query-editor-model.d.ts.map +1 -0
  25. package/lib/queries/query-editor-model.js +50 -0
  26. package/lib/queries/query-editor-model.js.map +1 -0
  27. package/mf-manifest.json +44 -46
  28. package/mf-stats.json +44 -46
  29. package/package.json +6 -6
  30. package/__mf/js/async/3246.240e9404.js +0 -1
  31. package/__mf/js/async/3413.6dd92cfd.js +0 -1
  32. package/__mf/js/async/3869.4e06bfcb.js +0 -2
  33. package/__mf/js/async/4368.438b431f.js +0 -2
  34. package/__mf/js/async/4421.fef63995.js +0 -1
  35. package/__mf/js/async/7152.e8100fb6.js +0 -73
  36. package/__mf/js/async/__federation_expose_LokiLogQuery.0720038a.js +0 -1
  37. package/__mf/js/async/__federation_expose_LokiTimeSeriesQuery.8c7f7602.js +0 -1
  38. package/__mf/js/main.a5b9ede8.js +0 -6
  39. /package/__mf/js/async/{3869.4e06bfcb.js.LICENSE.txt → 2417.993ba27f.js.LICENSE.txt} +0 -0
  40. /package/__mf/js/async/{2470.32c642b9.js.LICENSE.txt → 2470.ba894af3.js.LICENSE.txt} +0 -0
  41. /package/__mf/js/async/{4368.438b431f.js.LICENSE.txt → 4368.40ff20c1.js.LICENSE.txt} +0 -0
  42. /package/__mf/js/async/{7152.e8100fb6.js.LICENSE.txt → 5035.15709e1b.js.LICENSE.txt} +0 -0
  43. /package/__mf/js/async/{__federation_expose_LogsTable.3952e904.js.LICENSE.txt → __federation_expose_LogsTable.0bf7a331.js.LICENSE.txt} +0 -0
  44. /package/__mf/js/async/{__federation_expose_LokiDatasource.5fbd8f68.js.LICENSE.txt → __federation_expose_LokiDatasource.875ecaed.js.LICENSE.txt} +0 -0
@@ -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
+ }
@@ -11,12 +11,12 @@ export declare const LogRowContent: import("@emotion/styled").StyledComponent<im
11
11
  }, {}, {}>;
12
12
  export declare const ExpandButton: import("@emotion/styled").StyledComponent<import("@mui/material").IconButtonOwnProps & Omit<import("@mui/material").ButtonBaseOwnProps, "classes"> & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
13
13
  ref?: ((instance: HTMLButtonElement | null) => void | import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | import("react").RefObject<HTMLButtonElement> | null | undefined;
14
- }, "className" | "style" | "tabIndex" | "color" | "children" | "sx" | "disabled" | "action" | "loading" | "size" | "classes" | "centerRipple" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "onFocusVisible" | "TouchRippleProps" | "touchRippleRef" | "disableFocusRipple" | "edge" | "loadingIndicator"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & {
14
+ }, "color" | "children" | "sx" | "style" | "className" | "tabIndex" | "disabled" | "action" | "loading" | "size" | "classes" | "centerRipple" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "onFocusVisible" | "TouchRippleProps" | "touchRippleRef" | "disableFocusRipple" | "edge" | "loadingIndicator"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & {
15
15
  isExpanded: boolean;
16
16
  }, {}, {}>;
17
17
  export declare const LogText: import("@emotion/styled").StyledComponent<import("@mui/material").TypographyOwnProps & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
18
18
  ref?: ((instance: HTMLSpanElement | null) => void | import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | import("react").RefObject<HTMLSpanElement> | null | undefined;
19
- }, "className" | "style" | "color" | "children" | "height" | "minHeight" | "maxHeight" | "width" | "minWidth" | "maxWidth" | "border" | "borderTop" | "borderRight" | "borderBottom" | "borderLeft" | "borderColor" | "borderRadius" | "display" | "displayPrint" | "overflow" | "textOverflow" | "visibility" | "whiteSpace" | "flexBasis" | "flexDirection" | "flexWrap" | "justifyContent" | "alignItems" | "alignContent" | "order" | "flex" | "flexGrow" | "flexShrink" | "alignSelf" | "justifyItems" | "justifySelf" | "gap" | "columnGap" | "rowGap" | "gridColumn" | "gridRow" | "gridAutoFlow" | "gridAutoColumns" | "gridAutoRows" | "gridTemplateColumns" | "gridTemplateRows" | "gridTemplateAreas" | "gridArea" | "bgcolor" | "zIndex" | "position" | "top" | "right" | "bottom" | "left" | "boxShadow" | "boxSizing" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "my" | "p" | "pt" | "pr" | "pb" | "pl" | "px" | "py" | "margin" | "marginTop" | "marginRight" | "marginBottom" | "marginLeft" | "marginX" | "marginY" | "marginInline" | "marginInlineStart" | "marginInlineEnd" | "marginBlock" | "marginBlockStart" | "marginBlockEnd" | "padding" | "paddingTop" | "paddingRight" | "paddingBottom" | "paddingLeft" | "paddingX" | "paddingY" | "paddingInline" | "paddingInlineStart" | "paddingInlineEnd" | "paddingBlock" | "paddingBlockStart" | "paddingBlockEnd" | "typography" | "fontFamily" | "fontSize" | "fontStyle" | "fontWeight" | "letterSpacing" | "lineHeight" | "textAlign" | "textTransform" | "sx" | "align" | "classes" | "gutterBottom" | "noWrap" | "paragraph" | "variant" | "variantMapping"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & {
19
+ }, "border" | "borderTop" | "borderRight" | "borderBottom" | "borderLeft" | "borderColor" | "borderRadius" | "display" | "displayPrint" | "overflow" | "textOverflow" | "visibility" | "whiteSpace" | "flexBasis" | "flexDirection" | "flexWrap" | "justifyContent" | "alignItems" | "alignContent" | "order" | "flex" | "flexGrow" | "flexShrink" | "alignSelf" | "justifyItems" | "justifySelf" | "gap" | "columnGap" | "rowGap" | "gridColumn" | "gridRow" | "gridAutoFlow" | "gridAutoColumns" | "gridAutoRows" | "gridTemplateColumns" | "gridTemplateRows" | "gridTemplateAreas" | "gridArea" | "bgcolor" | "color" | "zIndex" | "position" | "top" | "right" | "bottom" | "left" | "boxShadow" | "width" | "maxWidth" | "minWidth" | "height" | "maxHeight" | "minHeight" | "boxSizing" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "my" | "p" | "pt" | "pr" | "pb" | "pl" | "px" | "py" | "margin" | "marginTop" | "marginRight" | "marginBottom" | "marginLeft" | "marginX" | "marginY" | "marginInline" | "marginInlineStart" | "marginInlineEnd" | "marginBlock" | "marginBlockStart" | "marginBlockEnd" | "padding" | "paddingTop" | "paddingRight" | "paddingBottom" | "paddingLeft" | "paddingX" | "paddingY" | "paddingInline" | "paddingInlineStart" | "paddingInlineEnd" | "paddingBlock" | "paddingBlockStart" | "paddingBlockEnd" | "typography" | "fontFamily" | "fontSize" | "fontStyle" | "fontWeight" | "letterSpacing" | "lineHeight" | "textAlign" | "textTransform" | "children" | "sx" | "style" | "className" | "align" | "classes" | "gutterBottom" | "noWrap" | "paragraph" | "variant" | "variantMapping"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & {
20
20
  wrap: boolean;
21
21
  }, {}, {}>;
22
22
  //# sourceMappingURL=LogsStyles.d.ts.map
@@ -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;AAE1D,KAAK,oBAAoB,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;AAEjE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,oBAAoB,GAAG,YAAY,CAqH5E"}
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, useState, useEffect } from 'react';
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
- // const { data: client } = useDatasourceClient<LokiClient>(selectedDatasource);
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 = useCallback((query)=>{
56
- onChange({
57
- ...value,
58
- query
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
- onChange,
62
- value
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: localQuery,
99
- onChange: handleQueryChange,
100
- onBlur: ()=>handleQueryExecute(localQuery),
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(localQuery);
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\n // const { data: client } = useDatasourceClient<LokiClient>(selectedDatasource);\n // const lokiURL = client?.options.datasourceUrl;\n\n // Local state for editor value to prevent query_range calls on every keystroke\n const [localQuery, setLocalQuery] = useState(value.query);\n\n // Update local state when prop changes\n useEffect(() => {\n setLocalQuery(value.query);\n }, [value.query]);\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (newDatasourceSelection) => {\n if (!isVariableDatasource(newDatasourceSelection) && newDatasourceSelection.kind === DATASOURCE_KIND) {\n onChange({ ...value, datasource: newDatasourceSelection });\n return;\n }\n\n throw new Error('Got unexpected non LokiQuery datasource selection');\n };\n\n // Debounced query change handler to prevent excessive query_range calls\n const handleQueryChange = useCallback((newQuery: string) => {\n setLocalQuery(newQuery);\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 = useCallback(\n (query: string) => {\n onChange({ ...value, query });\n },\n [onChange, value]\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={localQuery}\n onChange={handleQueryChange}\n onBlur={() => handleQueryExecute(localQuery)}\n onKeyDown={(event) => {\n if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {\n event.preventDefault();\n handleQueryExecute(localQuery);\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","useState","useEffect","produce","OptionsEditorControl","LogQLEditor","LOKI_DATASOURCE_KIND","DATASOURCE_KIND","DEFAULT_DATASOURCE","LokiLogQueryEditor","props","onChange","value","datasource","datasourceSelectValue","selectedDatasource","localQuery","setLocalQuery","query","handleDatasourceChange","newDatasourceSelection","kind","Error","handleQueryChange","newQuery","handleLogsDirection","_","v","draft","direction","handleQueryExecute","spacing","paddingBottom","div","sx","display","marginBottom","fontWeight","datasourcePluginKind","label","notched","onBlur","onKeyDown","event","key","ctrlKey","metaKey","preventDefault","placeholder","control","exclusive","height","marginLeft","width","aria-label"],"mappings":"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"}
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,"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,EAAoC,MAAM,OAAO,CAAC;AAIvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,KAAK,oBAAoB,GAAG,kBAAkB,CAAC,uBAAuB,CAAC,CAAC;AAExE,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,YAAY,CAyFzE"}
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, useState, useEffect } from 'react';
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
- // const { data: client } = useDatasourceClient<LokiClient>(selectedDatasource);
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 = useCallback((query)=>{
51
- onChange({
52
- ...value,
53
- query
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
- onChange,
57
- value
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: localQuery,
94
- onChange: handleQueryChange,
95
- onBlur: ()=>handleQueryExecute(localQuery),
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(localQuery);
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, useState, useEffect } from 'react';\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';\n\ntype LokiQueryEditorProps = OptionsEditorProps<LokiTimeSeriesQuerySpec>;\n\nexport function LokiQueryEditor(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\n // const { data: client } = useDatasourceClient<LokiClient>(selectedDatasource);\n // const lokiURL = client?.options.datasourceUrl;\n\n // Local state for editor value to prevent query_range calls on every keystroke\n const [localQuery, setLocalQuery] = useState(value.query);\n\n // Update local state when prop changes\n useEffect(() => {\n setLocalQuery(value.query);\n }, [value.query]);\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (newDatasourceSelection) => {\n if (!isVariableDatasource(newDatasourceSelection) && newDatasourceSelection.kind === DATASOURCE_KIND) {\n onChange({ ...value, datasource: newDatasourceSelection });\n return;\n }\n\n throw new Error('Got unexpected non LokiQuery datasource selection');\n };\n\n // Debounced query change handler to prevent excessive query_range calls\n const handleQueryChange = useCallback((newQuery: string) => {\n setLocalQuery(newQuery);\n }, []);\n\n // Immediate query execution on Enter or blur\n const handleQueryExecute = useCallback(\n (query: string) => {\n onChange({ ...value, query });\n },\n [onChange, value]\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={localQuery}\n onChange={handleQueryChange}\n onBlur={() => handleQueryExecute(localQuery)}\n onKeyDown={(event) => {\n if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {\n event.preventDefault();\n handleQueryExecute(localQuery);\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","useState","useEffect","LogQLEditor","LOKI_DATASOURCE_KIND","DATASOURCE_KIND","DEFAULT_DATASOURCE","LokiQueryEditor","props","onChange","value","datasource","datasourceSelectValue","selectedDatasource","localQuery","setLocalQuery","query","handleDatasourceChange","newDatasourceSelection","kind","Error","handleQueryChange","newQuery","handleQueryExecute","spacing","paddingBottom","div","sx","display","marginBottom","fontWeight","datasourcePluginKind","label","notched","onBlur","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,EAAEC,QAAQ,EAAEC,SAAS,QAAQ,QAAQ;AACvE,SAASC,WAAW,QAAQ,gCAAgC;AAC5D,SAASC,oBAAoB,QAAgC,cAAc;AAC3E,SAASC,eAAe,EAAEC,kBAAkB,QAAQ,eAAe;AAKnE,OAAO,SAASC,gBAAgBC,KAA2B;IACzD,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAE,GAAGF;IAC5B,MAAM,EAAEG,UAAU,EAAE,GAAGD;IACvB,MAAME,wBAAwBD,cAAcL;IAC5C,MAAMO,qBAAqBhB,mCACzBe,uBACAR;IAGF,gFAAgF;IAChF,iDAAiD;IAEjD,+EAA+E;IAC/E,MAAM,CAACU,YAAYC,cAAc,GAAGd,SAASS,MAAMM,KAAK;IAExD,uCAAuC;IACvCd,UAAU;QACRa,cAAcL,MAAMM,KAAK;IAC3B,GAAG;QAACN,MAAMM,KAAK;KAAC;IAEhB,MAAMC,yBAA4D,CAACC;QACjE,IAAI,CAACtB,qBAAqBsB,2BAA2BA,uBAAuBC,IAAI,KAAKd,iBAAiB;YACpGI,SAAS;gBAAE,GAAGC,KAAK;gBAAEC,YAAYO;YAAuB;YACxD;QACF;QAEA,MAAM,IAAIE,MAAM;IAClB;IAEA,wEAAwE;IACxE,MAAMC,oBAAoBrB,YAAY,CAACsB;QACrCP,cAAcO;IAChB,GAAG,EAAE;IAEL,6CAA6C;IAC7C,MAAMC,qBAAqBvB,YACzB,CAACgB;QACCP,SAAS;YAAE,GAAGC,KAAK;YAAEM;QAAM;IAC7B,GACA;QAACP;QAAUC;KAAM;IAGnB,qBACE,MAACX;QAAMyB,SAAS;QAAKC,eAAe;;0BAClC,MAACC;;kCACC,KAAC5B;wBACC6B,IAAI;4BACFC,SAAS;4BACTC,cAAc;4BACdC,YAAY;wBACd;kCACD;;kCAGD,KAACnC;wBACCoC,sBAAsB1B;wBACtBK,OAAOG;wBACPJ,UAAUQ;wBACVe,OAAM;wBACNC,OAAO;;;;0BAIX,MAACP;;kCACC,KAAC5B;wBACC6B,IAAI;4BACFC,SAAS;4BACTC,cAAc;4BACdC,YAAY;wBACd;kCACD;;kCAGD,KAAC3B;wBACCO,OAAOI;wBACPL,UAAUY;wBACVa,QAAQ,IAAMX,mBAAmBT;wBACjCqB,WAAW,CAACC;4BACV,IAAIA,MAAMC,GAAG,KAAK,WAAYD,CAAAA,MAAME,OAAO,IAAIF,MAAMG,OAAO,AAAD,GAAI;gCAC7DH,MAAMI,cAAc;gCACpBjB,mBAAmBT;4BACrB;wBACF;wBACA2B,aAAY;;;;;;AAMtB"}
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"}
@@ -0,0 +1,50 @@
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
+ import { useState } from 'react';
14
+ import { produce } from 'immer';
15
+ /**
16
+ * A hook for managing the `query` state in Loki query specs. Returns the `query` value, along with
17
+ * `onChange` and `onBlur` event handlers to the input. Keeps a local copy of the user's input and only syncs those
18
+ * changes with the overall spec value once the input is blurred to prevent re-running queries in the panel's preview
19
+ * every time the user types.
20
+ */ export function useQueryState(props) {
21
+ const { onChange, value } = props;
22
+ // Local copy of the query's value
23
+ const [query, setQuery] = useState(value.query);
24
+ // This is basically "getDerivedStateFromProps" to make sure if spec's value changes external to this component,
25
+ // we render with the latest value
26
+ const [lastSyncedQuery, setLastSyncedQuery] = useState(value.query);
27
+ if (value.query !== lastSyncedQuery) {
28
+ setQuery(value.query);
29
+ setLastSyncedQuery(value.query);
30
+ }
31
+ // Update our local state's copy as the user types
32
+ const handleQueryChange = (e)=>{
33
+ setQuery(e);
34
+ };
35
+ // Propagate changes to the query's value when the input is blurred to avoid constantly re-running queries in the
36
+ // PanelPreview
37
+ const handleQueryBlur = ()=>{
38
+ setLastSyncedQuery(query);
39
+ onChange(produce(value, (draft)=>{
40
+ draft.query = query;
41
+ }));
42
+ };
43
+ return {
44
+ query,
45
+ handleQueryChange,
46
+ handleQueryBlur
47
+ };
48
+ }
49
+
50
+ //# sourceMappingURL=query-editor-model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/queries/query-editor-model.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 { useState } from 'react';\nimport { produce } from 'immer';\nimport { OptionsEditorProps } from '@perses-dev/plugin-system';\n\n/**\n * Generic type for any Loki query spec that has a query field\n */\ntype LokiQuerySpec = {\n query: string;\n};\n\n/**\n * A hook for managing the `query` state in Loki query specs. Returns the `query` value, along with\n * `onChange` and `onBlur` event handlers to the input. Keeps a local copy of the user's input and only syncs those\n * changes with the overall spec value once the input is blurred to prevent re-running queries in the panel's preview\n * every time the user types.\n */\nexport function useQueryState<T extends LokiQuerySpec>(\n props: OptionsEditorProps<T>\n): {\n query: string;\n handleQueryChange: (e: string) => void;\n handleQueryBlur: () => void;\n} {\n const { onChange, value } = props;\n\n // Local copy of the query's value\n const [query, setQuery] = useState(value.query);\n\n // This is basically \"getDerivedStateFromProps\" to make sure if spec's value changes external to this component,\n // we render with the latest value\n const [lastSyncedQuery, setLastSyncedQuery] = useState(value.query);\n if (value.query !== lastSyncedQuery) {\n setQuery(value.query);\n setLastSyncedQuery(value.query);\n }\n\n // Update our local state's copy as the user types\n const handleQueryChange = (e: string): void => {\n setQuery(e);\n };\n\n // Propagate changes to the query's value when the input is blurred to avoid constantly re-running queries in the\n // PanelPreview\n const handleQueryBlur = (): void => {\n setLastSyncedQuery(query);\n onChange(\n produce(value, (draft) => {\n draft.query = query;\n })\n );\n };\n\n return { query, handleQueryChange, handleQueryBlur };\n}\n"],"names":["useState","produce","useQueryState","props","onChange","value","query","setQuery","lastSyncedQuery","setLastSyncedQuery","handleQueryChange","e","handleQueryBlur","draft"],"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,QAAQ,QAAQ,QAAQ;AACjC,SAASC,OAAO,QAAQ,QAAQ;AAUhC;;;;;CAKC,GACD,OAAO,SAASC,cACdC,KAA4B;IAM5B,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAE,GAAGF;IAE5B,kCAAkC;IAClC,MAAM,CAACG,OAAOC,SAAS,GAAGP,SAASK,MAAMC,KAAK;IAE9C,gHAAgH;IAChH,kCAAkC;IAClC,MAAM,CAACE,iBAAiBC,mBAAmB,GAAGT,SAASK,MAAMC,KAAK;IAClE,IAAID,MAAMC,KAAK,KAAKE,iBAAiB;QACnCD,SAASF,MAAMC,KAAK;QACpBG,mBAAmBJ,MAAMC,KAAK;IAChC;IAEA,kDAAkD;IAClD,MAAMI,oBAAoB,CAACC;QACzBJ,SAASI;IACX;IAEA,iHAAiH;IACjH,eAAe;IACf,MAAMC,kBAAkB;QACtBH,mBAAmBH;QACnBF,SACEH,QAAQI,OAAO,CAACQ;YACdA,MAAMP,KAAK,GAAGA;QAChB;IAEJ;IAEA,OAAO;QAAEA;QAAOI;QAAmBE;IAAgB;AACrD"}