Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
c2a6cdb
Implement Grafana Query Builder
archef2000 Jul 4, 2025
201f871
delete unused files
archef2000 Jul 4, 2025
66b3d5b
Make Editors compatible with lower versions
archef2000 Jul 10, 2025
ffac882
Add error handling for unsupported field types in LogsQlLanguageProvider
archef2000 Jul 10, 2025
b96a69c
fix tests
archef2000 Jul 12, 2025
52f4b3e
remove unneeded query rendering
archef2000 Jul 15, 2025
cbc49bb
combine QueryBuilder and QueryEditor
archef2000 Jul 15, 2025
c87894a
fix requested changes
archef2000 Jul 15, 2025
aef6be4
simplify FieldAsFieldEditor updateValue function
archef2000 Jul 15, 2025
111e28c
fix parseFieldMapList function
archef2000 Jul 15, 2025
f28b814
simplify onChange for all editors with a Select component
archef2000 Jul 15, 2025
cd5862d
compare with VictoriaLogsOperationId values
archef2000 Jul 15, 2025
50bc9e5
remove redundant returning of undefined
archef2000 Jul 15, 2025
cd4ca7c
convert value safely
archef2000 Jul 15, 2025
2aef4a9
simplify logic in FieldsEditorWithPrefix
archef2000 Jul 15, 2025
3476058
remove check for empty expr
archef2000 Jul 15, 2025
760a477
simplify to remove all falsy values
archef2000 Jul 15, 2025
b9bbcd6
flatten if block for clarity
archef2000 Jul 15, 2025
92f195f
simplity SortedFieldsEditor
archef2000 Jul 15, 2025
9fd29cf
split state into separate useState calls
archef2000 Jul 15, 2025
c8220f8
improve readability for getFieldName
archef2000 Jul 15, 2025
a1c20cb
use switch case to parse math expresion
archef2000 Jul 15, 2025
a291aec
allow creating values while loading
archef2000 Jul 15, 2025
b2d0fbe
correct wording in getValuesFromBrackets function
archef2000 Jul 15, 2025
838960f
make the logic of parsing the stream filter less complex
archef2000 Jul 15, 2025
8281796
add tests to make shure the parsing is correct
archef2000 Jul 15, 2025
238b3b2
turn onOpenMenu handler into function in ExactValueEditor editor
archef2000 Jul 16, 2025
a5527ae
remove else branch in FieldsEditorWithPrefix editor
archef2000 Jul 16, 2025
12ff850
move menu handlers from components to seperate functions
archef2000 Jul 16, 2025
b6ae599
fix comparison operations
archef2000 Jul 27, 2025
b45858c
improve SortedFieldsEditor
archef2000 Jul 27, 2025
8c2cd63
fix unselection of item in editors using MultiSelect
archef2000 Sep 5, 2025
e265f8e
fix variable generation and option queries
archef2000 Sep 5, 2025
51eb66f
reorder operations for better searching
archef2000 Sep 5, 2025
bd6b7aa
fixed various parsing errors
archef2000 Sep 7, 2025
23af02b
fix disapearing of disabled operations
archef2000 Sep 7, 2025
db33be0
fix disapearing of disabled operations in editors
archef2000 Sep 8, 2025
0e0e0c3
fix math editor and query renderer
archef2000 Sep 24, 2025
bbd152c
add time_add pipe
archef2000 Sep 24, 2025
7d8a171
add missing options
archef2000 Sep 24, 2025
8f1c222
add generate_sequence
archef2000 Sep 24, 2025
6efef10
add query_stats
archef2000 Sep 24, 2025
ed2fee6
add split
archef2000 Sep 24, 2025
7842bc8
add all missing operations
archef2000 Sep 26, 2025
3d9de16
Merge branch 'main' into main
archef2000 Sep 26, 2025
3270538
fix options generation for subqueries
archef2000 Sep 27, 2025
55d2517
fix logic error in subquery editor
archef2000 Sep 29, 2025
7f3d219
Merge branch 'VictoriaMetrics:main' into main
archef2000 Oct 1, 2025
cc26956
fix stream field parsing and field prediction
archef2000 Oct 1, 2025
55f7fbe
remove else
archef2000 Oct 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React, { useState } from 'react';

import { SelectableValue } from '@grafana/data';
import { QueryBuilderOperationParamEditorProps, toOption } from '@grafana/plugin-ui';
import { InlineField, Select } from '@grafana/ui';

import { getFieldValueOptions } from './utils/editorHelper';

export default function ExactValueEditor(props: QueryBuilderOperationParamEditorProps) {
const { onChange, index, value, operation } = props;
const [isLoading, setIsLoading] = useState(false);
const [options, setOptions] = useState<SelectableValue<string>[]>([]);
const handleOpenMenu = async () => {
setIsLoading(true);
setOptions(await getFieldValueOptions(props, operation.params[0] as string));
setIsLoading(false);
};
return (
<InlineField>
<Select<string>
allowCustomValue={true}
allowCreateWhileLoading={true}
isLoading={isLoading}
onOpenMenu={handleOpenMenu}
options={options}
onChange={({ value = "" }) => onChange(index, value)}
value={toOption(String(value || ""))}
width="auto"
/>
</InlineField>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React, { useState } from 'react';

import { SelectableValue } from '@grafana/data';
import { QueryBuilderOperationParamEditorProps, toOption } from '@grafana/plugin-ui';
import { InlineField, Stack, Select } from '@grafana/ui';

import { isValue, quoteString, getValue } from '../utils/stringHandler';
import { splitString } from '../utils/stringSplitter';

import { getFieldNameOptions } from './utils/editorHelper';

export default function FieldAsFieldEditor(props: QueryBuilderOperationParamEditorProps) {
const { value, onChange, index } = props;

const str = splitString(String(value || ""));
let parsedFromField = "";
let parsedToField = "";
if (str.length === 3) {
if (isValue(str[0])) {
parsedFromField = getValue(str[0]);
}
if (str[1].type === "space" && str[1].value === "as") {
if (isValue(str[2])) {
parsedToField = getValue(str[2]);
}
}
}

const [fromField, setFromField] = useState<string>(parsedFromField);
const [toField, setToField] = useState<string>(parsedToField);

const updateValue = (fromField: string, toField: string) => {
const parts = [fromField, toField].map(field => {
const trimmed = field.trim();
return trimmed === "" ? "\"\"" : quoteString(trimmed);
});
const value = parts.join(" as ");
onChange(index, value);
};

const [isLoading, setIsLoading] = useState(false);
const [options, setOptions] = useState<SelectableValue<string>[]>([]);

const handleOpenMenu = async () => {
setIsLoading(true);
setOptions(await getFieldNameOptions(props));
setIsLoading(false);
};

return (
<Stack>
<InlineField>
<Select<string>
allowCustomValue={true}
allowCreateWhileLoading={true}
isLoading={isLoading}
onOpenMenu={handleOpenMenu}
options={options}
onChange={({ value = "" }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is better to move this to separate handler

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is clearer that way

setFromField(value);
updateValue(value, toField);
}}
value={toOption(fromField)}
width="auto"
/>
</InlineField>
<div style={{ padding: '6px 0 8px 0px' }}>as</div>
<InlineField>
<Select<string>
allowCustomValue={true}
allowCreateWhileLoading={true}
isLoading={isLoading}
onOpenMenu={handleOpenMenu}
options={options}
onChange={({ value = "" }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same about the handler

setToField(value);
updateValue(fromField, value);
}}
value={toOption(toField)}
width="auto"
/>
</InlineField>
</Stack>
);
}
34 changes: 34 additions & 0 deletions src/components/QueryEditor/QueryBuilder/Editors/FieldEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { useState } from 'react';

import { SelectableValue } from '@grafana/data';
import { QueryBuilderOperationParamEditorProps, toOption } from '@grafana/plugin-ui';
import { InlineField, Select } from '@grafana/ui';

import { getFieldNameOptions } from './utils/editorHelper';

export default function FieldEditor(props: QueryBuilderOperationParamEditorProps) {
const { value, onChange, index } = props;
const [isLoading, setIsLoading] = useState(false);
const [options, setOptions] = useState<SelectableValue<string>[]>([]);

const handleOpenMenu = async () => {
setIsLoading(true);
setOptions(await getFieldNameOptions(props));
setIsLoading(false);
}

return (
<InlineField>
<Select<string>
allowCustomValue={true}
allowCreateWhileLoading={true}
isLoading={isLoading}
onOpenMenu={handleOpenMenu}
options={options}
onChange={({ value = "" }) => onChange(index, value)}
value={toOption(String(value || ""))}
width="auto"
/>
</InlineField>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React, { useState } from "react";

import { SelectableValue } from "@grafana/data";
import { QueryBuilderOperationParamEditorProps, toOption } from "@grafana/plugin-ui";
import { Select } from "@grafana/ui";

import { getValueTypeOptions } from "./utils/editorHelper";

export default function FieldValueTypeEditor(props: QueryBuilderOperationParamEditorProps) {
const { value, onChange, index } = props;
const [isLoading, setIsLoading] = useState(false);
const [options, setOptions] = useState<SelectableValue<string>[]>([]);

const handleOpenMenu = async () => {
setIsLoading(true);
setOptions(await getValueTypeOptions(props));
setIsLoading(false);
}

return (
<Select<string>
allowCustomValue={true}
allowCreateWhileLoading={true}
isLoading={isLoading}
onOpenMenu={handleOpenMenu}
options={options}
onChange={({ value = "" }) => onChange(index, value)}
value={toOption(String(value || ""))}
width="auto"
/>
)
}
51 changes: 51 additions & 0 deletions src/components/QueryEditor/QueryBuilder/Editors/FieldsEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, { useState } from 'react';

import { SelectableValue } from '@grafana/data';
import { QueryBuilderOperationParamEditorProps } from '@grafana/plugin-ui';
import { ActionMeta, MultiSelect } from '@grafana/ui';

import { getValuesFromBrackets } from '../utils/operationParser';
import { quoteString } from '../utils/stringHandler';
import { splitString } from '../utils/stringSplitter';

import { getFieldNameOptions } from './utils/editorHelper';

export default function FieldsEditor(props: QueryBuilderOperationParamEditorProps) {
const { value, onChange, index } = props;

const setFields = (values: SelectableValue<string>[], action: ActionMeta) => {
let rawValues = values.map(({ value = "" }) => value.trim()).filter(Boolean);
if (action) {
if (action.action === "remove-value") {
const oldValues = getValuesFromBrackets(splitString(String(value || "")));
rawValues = oldValues.filter((v) => v !== (action.removedValue as SelectableValue<string>).value);
}
}
const newValue = rawValues.map((v) => quoteString(v)).join(", ");
onChange(index, newValue);
}

const [isLoading, setIsLoading] = useState(false);
const [options, setOptions] = useState<SelectableValue<string>[]>([]);

const handleOpenMenu = async () => {
setIsLoading(true);
setOptions(await getFieldNameOptions(props));
setIsLoading(false);
}

return (
<MultiSelect<string>
onChange={setFields}
options={options}
value={getValuesFromBrackets(splitString(String(value || "")))}
isLoading={isLoading}
allowCustomValue
allowCreateWhileLoading
noOptionsMessage="No labels found"
loadingMessage="Loading labels"
width={20}
onOpenMenu={handleOpenMenu}
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import React, { useState } from 'react';

import { SelectableValue } from '@grafana/data';
import { QueryBuilderOperationParamEditorProps } from '@grafana/plugin-ui';
import { ActionMeta, FormatOptionLabelMeta, MultiSelect } from '@grafana/ui';

import { quoteString, unquoteString } from '../utils/stringHandler';
import { splitByUnescapedChar, SplitString, splitString } from '../utils/stringSplitter';

import { getFieldNameOptions } from './utils/editorHelper';

interface FieldWithPrefix {
name: string;
isPrefix: boolean;
}

export default function FieldsEditorWithPrefix(props: QueryBuilderOperationParamEditorProps) {
const { value, onChange, index } = props;

const str = splitString(String(value || ""));
const parsedValues = parseInputValues(str);
const [values, setValues] = useState<FieldWithPrefix[]>(parsedValues);

const setFields = (newValues: FieldWithPrefix[], action?: ActionMeta) => {
if (action) {
if (action.action === "remove-value") {
newValues = values.filter((v) => v.name !== (action.removedValue as any).name);
}
}
setValues(newValues);
const newValue = newValues.map((field) => {
if (field.isPrefix !== undefined) {
return field.isPrefix ? `${quoteString(field.name)}*` : `${quoteString(field.name)}`;
}
return quoteString(field as unknown as string);
}).join(', ');
onChange(index, newValue);
}

const togglePrefix = (index: number) => {
const field = values[index];
field.isPrefix = !field.isPrefix;
setFields(values);
};

const [isLoading, setIsLoading] = useState(false);
const [options, setOptions] = useState<SelectableValue<FieldWithPrefix>[]>([]);

const formatOptionLabel = (option: SelectableValue<FieldWithPrefix>, { context }: FormatOptionLabelMeta<FieldWithPrefix>) => {
if (context === 'value') {
const field = option as FieldWithPrefix;
const handleToggle = (e: React.SyntheticEvent) => {
e.stopPropagation();
const idx = values.findIndex((v) => (v).name === field.name);
if (idx !== -1) {
togglePrefix(idx);
}
};
return (
<span
tabIndex={0}
style={{ cursor: 'pointer' }}
onMouseDown={handleToggle}
>
{formatFieldLabel(field)}
</span>
);
}
return <>{option.label}</>;
}

const handleOpenMenu = async () => {
setIsLoading(true);
let options = await getFieldNameOptions(props);
const selectedNames = values.map(v => v.name);
options = options.filter((opt: SelectableValue<string>) => opt.value && !selectedNames.includes(opt.value));
setOptions(options);
setIsLoading(false);
}

const handleChange = (values: SelectableValue<FieldWithPrefix>[], action: ActionMeta) => {
setFields(values.map((v) => v.value || v as FieldWithPrefix), action)
}

return (
<MultiSelect<FieldWithPrefix>
openMenuOnFocus
onOpenMenu={handleOpenMenu}
isLoading={isLoading}
allowCustomValue
allowCreateWhileLoading
noOptionsMessage="No labels found"
loadingMessage="Loading labels"
options={options}
value={values}
onChange={handleChange}
formatOptionLabel={formatOptionLabel}
/>
);
}

const formatFieldLabel = (field: FieldWithPrefix): string => {
return field.isPrefix ? `${field.name} *` : field.name;
};

const parseValue = (value: SplitString[]): FieldWithPrefix => {
if (value.length === 0 || value[0].type === "bracket") {
return { name: '', isPrefix: false };
}

if (value[0].type === "quote") {
const { type, value: secondValue } = value[1] || {};
const isPrefix = type === "space" && secondValue === "*";
return { name: unquoteString(value[0].value), isPrefix };
}

const fieldValue = value[0].value;
const isPrefix = fieldValue.endsWith("*");
return {
name: isPrefix ? fieldValue.slice(0, -1) : fieldValue,
isPrefix,
};
}

const parseInputValues = (str: SplitString[]): FieldWithPrefix[] => {
let fields: FieldWithPrefix[] = [];
for (const field of splitByUnescapedChar(str, ',')) {
if (field.length > 0 && field[0].type !== "bracket") {
fields.push(parseValue(field));
}
}
return fields;
};
Loading