Skip to content

Commit

Permalink
Fixes removing URL in the config. Fixes #120
Browse files Browse the repository at this point in the history
  • Loading branch information
yesoreyeram committed Aug 13, 2021
1 parent 3cfe542 commit de201ab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
3 changes: 3 additions & 0 deletions pkg/infinity/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ type InfinitySettingsJson struct {

func LoadSettings(config backend.DataSourceInstanceSettings) (settings InfinitySettings, err error) {
settings.URL = config.URL
if config.URL == "__IGNORE_URL__" {
settings.URL = ""
}
settings.BasicAuthEnabled = config.BasicAuthEnabled
settings.UserName = config.BasicAuthUser
infJson := InfinitySettingsJson{}
Expand Down
19 changes: 10 additions & 9 deletions src/editors/config/URL.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import React from 'react';
import React, { useState } from 'react';
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
import { LegacyForms } from '@grafana/ui';
import { InfinityDataSourceJSONOptions } from '../../types';
import { InfinityDataSourceJSONOptions, IGNORE_URL } from '../../types';

export type Props = DataSourcePluginOptionsEditorProps<InfinityDataSourceJSONOptions>;

export const URLEditor = (props: Props) => {
const { FormField } = LegacyForms;
const onURLChange = (url: string) => {
props.onOptionsChange({
...props.options,
url,
});
const { options, onOptionsChange } = props;
const [url, setUrl] = useState(options.url || '');
const onURLChange = () => {
onOptionsChange({ ...options, url: url || IGNORE_URL });
};
return (
<div className="gf-form">
Expand All @@ -20,9 +19,11 @@ export const URLEditor = (props: Props) => {
labelWidth={11}
tooltip="Base URL of the query. Leave blank if you want to handle it in the query editor."
placeholder="Leave blank and you can specify full URL in the query."
value={props.options.url}
onChange={(e) => onURLChange(e.currentTarget.value)}
value={url === IGNORE_URL ? '' : url}
onChange={(e) => setUrl(e.currentTarget.value || '')}
onBlur={onURLChange}
/>
<div className="gf-form-label text-warning">Deprecated field. Use URL in the query editor instead.</div>
</div>
);
};
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DataQuery, SelectableValue, DataSourceJsonData, DataSourceInstanceSettings } from '@grafana/data';

export const IGNORE_URL = '__IGNORE_URL__';
export interface MetricFindValue {
text: string;
value: string | number;
Expand Down

0 comments on commit de201ab

Please sign in to comment.