Skip to content

Commit 66d5f95

Browse files
feature: Improves query editor UI spacing
Uses Form to standardize element spacing
1 parent 37f6ce8 commit 66d5f95

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

src/components/QueryEditor.tsx

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { ChangeEvent, ReactNode } from 'react';
2-
import { Button, Form, Icon, InlineField, Input, Select } from '@grafana/ui';
2+
import { Button, Field, Form, Icon, InlineField, Input, Select } from '@grafana/ui';
33
import { QueryEditorProps, SelectableValue } from '@grafana/data';
44
import { DataSource } from '../datasource';
55
import { DEFAULT_QUERY, MyDataSourceOptions, MyQuery } from '../types';
@@ -29,6 +29,7 @@ export function QueryEditor({ query, onChange, onRunQuery }: Props) {
2929

3030
const SelectComponent = () => {
3131
return (
32+
<Field>
3233
<Select
3334
options={queryTypes}
3435
value={queryTypeFromLabel(query.type)}
@@ -38,34 +39,49 @@ export function QueryEditor({ query, onChange, onRunQuery }: Props) {
3839
onTypeChange(queryType);
3940
}}
4041
/>
42+
</Field>
4143
);
4244
};
4345

4446
function renderQuery(): ReactNode {
4547
let queryType = queryTypeFromLabel(query.type);
4648
switch(queryType.value) {
4749
case 0: // Eval
48-
return <InlineField label="Axon" labelWidth="auto" tooltip="An Axon expression to evaluate on the Haystack server">
49-
<Input width={100} prefix={<Icon name="angle-right" />} onChange={onEvalChange} value={query.eval} placeholder={DEFAULT_QUERY.eval} />
50-
</InlineField>
50+
return (
51+
<Field>
52+
<InlineField label="Axon" labelWidth="auto" tooltip="An Axon expression to evaluate on the Haystack server">
53+
<Input width={100} prefix={<Icon name="angle-right" />} onChange={onEvalChange} value={query.eval} placeholder={DEFAULT_QUERY.eval} />
54+
</InlineField>
55+
</Field>
56+
);
5157
case 1: // HisRead
52-
return <InlineField label="Point ID" labelWidth="auto" tooltip="The ID of the point to read">
53-
<Input width={100} prefix={<Icon name="angle-right" />} onChange={onHisReadChange} value={query.hisRead} placeholder={DEFAULT_QUERY.hisRead} />
54-
</InlineField>
58+
return (
59+
<Field>
60+
<InlineField label="Point ID" labelWidth="auto" tooltip="The ID of the point to read">
61+
<Input width={100} prefix={<Icon name="angle-right" />} onChange={onHisReadChange} value={query.hisRead} placeholder={DEFAULT_QUERY.hisRead} />
62+
</InlineField>
63+
</Field>
64+
);
5565
}
5666
return <p>Select a query type</p>
5767
}
5868

69+
function onSubmit(newQuery: Partial<MyQuery>) {
70+
query = { ...query, ...newQuery }
71+
onRunQuery();
72+
}
73+
5974
return (
6075
<div className="gf-form">
6176
<Form
62-
onSubmit={(newQuery: Partial<MyQuery>) => query = { ...query, ...newQuery }}
77+
onSubmit={onSubmit}
6378
>{({register, errors}) => {
79+
let queryComponent = renderQuery();
6480
return (
6581
<div>
6682
<SelectComponent/>
67-
{renderQuery()}
68-
<Button type="submit" onClick={onRunQuery}>Run</Button>
83+
{queryComponent}
84+
<Button type="submit">Run</Button>
6985
</div>
7086
)
7187
}}</Form>

0 commit comments

Comments
 (0)