Skip to content

feat: add configuration screen for Custom query parameters #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## tip

* BUGFIX: fix build annotation from the label field. All labels transforms to the string representation. See [this issue](https://github.com/VictoriaMetrics/victorialogs-datasource/issues/188).
* FEATURE: add configuration screen for Custom query parameters. See [this issue](https://github.com/VictoriaMetrics/victorialogs-datasource/issues/252).

## v0.15.0

Expand Down
4 changes: 4 additions & 0 deletions src/configuration/ConfigEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { HelpfulLinks } from "./HelpfulLinks";
import { LimitsSettings } from "./LimitSettings";
import { QuerySettings } from './QuerySettings';
import { DerivedFields } from "./DerivedFields";
import { LogsSettings } from './LogsSettings';

export type Props = DataSourcePluginOptionsEditorProps<Options>;

Expand Down Expand Up @@ -47,6 +48,9 @@ const ConfigEditor = (props: Props) => {
fields={options.jsonData.derivedFields}
onChange={(value) => onOptionsChange(setDerivedFields(options, value))}
/>

<LogsSettings {...props}/>

<LimitsSettings {...props}/>
</>
);
Expand Down
73 changes: 73 additions & 0 deletions src/configuration/LogsSettings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React, { SyntheticEvent } from 'react';

import {
DataSourcePluginOptionsEditorProps,
SelectableValue,
} from '@grafana/data';
import {
InlineField,
regexValidation,
Input, validate
} from '@grafana/ui';

import { Options } from '../types';

type Props = Pick<DataSourcePluginOptionsEditorProps<Options>, 'options' | 'onOptionsChange'>;

export const LogsSettings = (props: Props) => {
const {options, onOptionsChange} = props;

// We are explicitly adding httpMethod so it is correctly displayed in dropdown. This way, it is more predictable for users.

if (!options.jsonData.httpMethod) {
options.jsonData.httpMethod = 'POST';
}
return (
<>
<h3 className="page-heading">Misc</h3>
<div className="gf-form-group">
<div className="gf-form max-width-30">
<InlineField
label="Custom query parameters"
labelWidth={14}
tooltip="Add Custom parameters to all queries."
interactive={true}
>
<Input
className="width-25"
value={options.jsonData.customQueryParameters}
onChange={onChangeHandler('customQueryParameters', options, onOptionsChange)}
spellCheck={false}
placeholder="Example: max_source_resolution=5m&timeout=10"
/>
</InlineField>
</div>
</div>
</>
);
};

export const getValueFromEventItem = (eventItem: SyntheticEvent<HTMLInputElement> | SelectableValue<string>) => {
if (!eventItem) {
return '';
}

if (eventItem.hasOwnProperty('currentTarget')) {
return eventItem.currentTarget.value;
}

return (eventItem as SelectableValue<string>).value;
};

const onChangeHandler =
(key: keyof Options, options: Props['options'], onOptionsChange: Props['onOptionsChange']) =>
(eventItem: SyntheticEvent<HTMLInputElement> | SelectableValue<string>) => {
onOptionsChange({
...options,
jsonData: {
...options.jsonData,
[key]: getValueFromEventItem(eventItem),
},
});
};