Skip to content

Commit 9824a5f

Browse files
committed
Simplify config editor
1 parent 5ff454f commit 9824a5f

File tree

3 files changed

+28
-36
lines changed

3 files changed

+28
-36
lines changed

src/ConfigEditor.tsx

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
1-
import React from 'react';
2-
import { DataSourceHttpSettings } from '@grafana/ui';
1+
import React, { ChangeEvent } from 'react';
2+
import { InlineFormLabel, Field, Input, Legend } from '@grafana/ui';
33
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
44
import { JsonApiDataSourceOptions } from './types';
5-
import { ConfigSettings } from './ConfigSettings';
5+
import {} from '@emotion/core';
66

77
interface Props extends DataSourcePluginOptionsEditorProps<JsonApiDataSourceOptions> {}
88

99
export const ConfigEditor: React.FC<Props> = ({ options, onOptionsChange }) => {
10+
const onUrlChange = (e: ChangeEvent<HTMLInputElement>) => {
11+
onOptionsChange({ ...options, jsonData: { ...options, url: e.currentTarget.value } });
12+
};
13+
const onParamsChange = (e: ChangeEvent<HTMLInputElement>) => {
14+
onOptionsChange({ ...options, jsonData: { ...options.jsonData, queryParams: e.currentTarget.value } });
15+
};
1016
return (
1117
<>
12-
<DataSourceHttpSettings
13-
defaultUrl="http://localhost:8080"
14-
dataSourceConfig={options}
15-
onChange={onOptionsChange}
16-
/>
17-
18-
<ConfigSettings options={options} onOptionsChange={onOptionsChange} />
18+
<Legend>HTTP</Legend>
19+
<div className="gf-form-group">
20+
<div className="gf-form">
21+
<InlineFormLabel tooltip={<p>URL to an endpoint that returns a JSON response.</p>}>URL</InlineFormLabel>
22+
<Input className="width-25" value={options.url} onChange={onUrlChange} placeholder="page=1&limit=100" />
23+
</div>
24+
<div className="gf-form">
25+
<InlineFormLabel tooltip={<p>Add custom query parameters to your query.</p>}>
26+
Query parameters
27+
</InlineFormLabel>
28+
<Input
29+
className="width-25"
30+
value={options.jsonData.queryParams}
31+
onChange={onParamsChange}
32+
placeholder="page=1&limit=100"
33+
/>
34+
</div>
35+
</div>
1936
</>
2037
);
2138
};

src/ConfigSettings.tsx

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const defaultQuery: Partial<JsonApiQuery> = {
2020
};
2121

2222
export interface JsonApiDataSourceOptions extends DataSourceJsonData {
23+
url: string;
2324
queryParams?: string;
2425
}
2526

0 commit comments

Comments
 (0)