Skip to content

Commit 093337f

Browse files
committed
Extract PathEditor
1 parent 60d5d58 commit 093337f

File tree

2 files changed

+48
-37
lines changed

2 files changed

+48
-37
lines changed

src/components/PathEditor.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react';
2+
import { InlineFieldRow, InlineField, Input, Select } from '@grafana/ui';
3+
import {} from '@emotion/core';
4+
5+
interface Props {
6+
method: string;
7+
onMethodChange: (method: string) => void;
8+
path: string;
9+
onPathChange: (path: string) => void;
10+
}
11+
12+
export const PathEditor = ({ method, onMethodChange, path, onPathChange }: Props) => {
13+
return (
14+
<InlineFieldRow>
15+
<InlineField>
16+
<Select
17+
value={method}
18+
options={[
19+
{ label: 'GET', value: 'GET' },
20+
{ label: 'POST', value: 'POST' },
21+
]}
22+
onChange={(v) => onMethodChange(v.value ?? 'GET')}
23+
/>
24+
</InlineField>
25+
<InlineField grow>
26+
<Input placeholder="/orders/${orderId}" value={path} onChange={(e) => onPathChange(e.currentTarget.value)} />
27+
</InlineField>
28+
</InlineFieldRow>
29+
);
30+
};

src/components/QueryEditor.tsx

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
import defaults from 'lodash/defaults';
22
import React, { useState } from 'react';
3-
import {
4-
InlineFieldRow,
5-
InlineField,
6-
Segment,
7-
Input,
8-
Select,
9-
RadioButtonGroup,
10-
CodeEditor,
11-
useTheme,
12-
InfoBox,
13-
} from '@grafana/ui';
3+
import { InlineFieldRow, InlineField, Segment, RadioButtonGroup, CodeEditor, useTheme, InfoBox } from '@grafana/ui';
144
import { QueryEditorProps } from '@grafana/data';
155
import { JsonApiQuery, JsonApiDataSourceOptions, defaultQuery } from '../types';
166
import { KeyValueEditor } from './KeyValueEditor';
@@ -19,6 +9,7 @@ import { css } from 'emotion';
199
import { Pair } from '../types';
2010
import { JsonDataSource } from 'datasource';
2111
import { FieldEditor } from './FieldEditor';
12+
import { PathEditor } from './PathEditor';
2213

2314
// Display a warning message when user adds any of the following headers.
2415
const sensitiveHeaders = ['authorization', 'proxy-authorization', 'x-api-key'];
@@ -34,10 +25,10 @@ export const QueryEditor: React.FC<Props> = ({ onRunQuery, onChange, limitFields
3425

3526
const query = defaults(props.query, defaultQuery);
3627

37-
const onMethodChange = (method: string) => {
38-
onChange({ ...query, method });
39-
onRunQuery();
40-
};
28+
// const onMethodChange = (method: string) => {
29+
// onChange({ ...query, method });
30+
// onRunQuery();
31+
// };
4132

4233
const onBodyChange = (body: string) => {
4334
onChange({ ...query, body });
@@ -72,25 +63,18 @@ export const QueryEditor: React.FC<Props> = ({ onRunQuery, onChange, limitFields
7263
{
7364
title: 'Path',
7465
content: (
75-
<InlineFieldRow>
76-
<InlineField>
77-
<Select
78-
value={query.method}
79-
options={[
80-
{ label: 'GET', value: 'GET' },
81-
{ label: 'POST', value: 'POST' },
82-
]}
83-
onChange={(v) => onMethodChange(v.value ?? 'GET')}
84-
/>
85-
</InlineField>
86-
<InlineField grow>
87-
<Input
88-
placeholder="/orders/${orderId}"
89-
value={query.urlPath}
90-
onChange={(e) => onChange({ ...query, urlPath: e.currentTarget.value })}
91-
/>
92-
</InlineField>
93-
</InlineFieldRow>
66+
<PathEditor
67+
method={query.method ?? 'GET'}
68+
onMethodChange={(method) => {
69+
onChange({ ...query, method });
70+
onRunQuery();
71+
}}
72+
path={query.urlPath ?? ''}
73+
onPathChange={(path) => {
74+
onChange({ ...query, urlPath: path });
75+
onRunQuery();
76+
}}
77+
/>
9478
),
9579
},
9680
{
@@ -153,9 +137,6 @@ export const QueryEditor: React.FC<Props> = ({ onRunQuery, onChange, limitFields
153137
/>
154138
)}
155139
</AutoSizer>
156-
{/* <InlineField label="Body" tooltip="foo" grow>
157-
<JsonQueryField value={body || ''} onChange={} />
158-
</InlineField> */}
159140
</InlineFieldRow>
160141
</>
161142
),

0 commit comments

Comments
 (0)