Skip to content

Commit 5087340

Browse files
authored
Merge pull request #104 from questdb/update-query-builder-settings
Update query builder settings
2 parents c95cec7 + 74aff81 commit 5087340

9 files changed

+169
-122
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ data from within Grafana.
1010
For detailed instructions on how to install the plugin on Grafana Cloud or
1111
locally, please check out the [Plugin installation docs](https://grafana.com/docs/grafana/latest/plugins/installation/).
1212

13+
Read the guide on QuestDB website: [Third-party Tools - Grafana](https://questdb.io/docs/third-party-tools/grafana/).
14+
1315
## Configuration
1416

1517
### QuestDB user for the data source
@@ -179,3 +181,4 @@ You may choose to hide this variable from view as it serves no further purpose.
179181
- Configure and use [Templates and variables](https://grafana.com/docs/grafana/latest/variables/).
180182
- Add [Transformations](https://grafana.com/docs/grafana/latest/panels/transformations/).
181183
- Set up alerting; refer to [Alerts overview](https://grafana.com/docs/grafana/latest/alerting/).
184+
- Read the [Plugin guide](https://questdb.io/docs/third-party-tools/grafana/) on QuestDB website
+10-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import React from 'react';
22
import { render } from '@testing-library/react';
33
import { GroupByEditor } from './GroupBy';
4-
import {selectors} from "../../selectors";
4+
import { selectors } from '../../selectors';
55

66
describe('GroupByEditor', () => {
77
it('renders correctly', () => {
8-
const result = render(<GroupByEditor fieldsList={[]} groupBy={[]} onGroupByChange={() => {}} labelAndTooltip={selectors.components.QueryEditor.QueryBuilder.SAMPLE_BY} />);
8+
const result = render(
9+
<GroupByEditor
10+
fieldsList={[]}
11+
groupBy={[]}
12+
onGroupByChange={() => {}}
13+
isDisabled={false}
14+
labelAndTooltip={selectors.components.QueryEditor.QueryBuilder.SAMPLE_BY}
15+
/>
16+
);
917
expect(result.container.firstChild).not.toBeNull();
1018
});
1119
});

src/components/queryBuilder/GroupBy.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface GroupByEditorProps {
1010
groupBy: string[];
1111
onGroupByChange: (groupBy: string[]) => void;
1212
labelAndTooltip: typeof selectors.components.QueryEditor.QueryBuilder.GROUP_BY;
13+
isDisabled: boolean;
1314
}
1415
export const GroupByEditor = (props: GroupByEditorProps) => {
1516
const columns: SelectableValue[] = (props.fieldsList || []).map((f) => ({ label: f.label, value: f.name }));
@@ -34,7 +35,7 @@ export const GroupByEditor = (props: GroupByEditorProps) => {
3435
<EditorField tooltip={tooltip} label={label}>
3536
<MultiSelect
3637
options={columns}
37-
placeholder="Choose"
38+
placeholder={props.isDisabled ? 'Table is missing designated timestamp' : 'Choose'}
3839
isOpen={isOpen}
3940
onOpenMenu={() => setIsOpen(true)}
4041
onCloseMenu={() => setIsOpen(false)}
@@ -43,6 +44,7 @@ export const GroupByEditor = (props: GroupByEditorProps) => {
4344
value={groupBy}
4445
allowCustomValue={true}
4546
width={50}
47+
disabled={props.isDisabled}
4648
/>
4749
</EditorField>
4850
);

src/components/queryBuilder/Limit.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface LimitEditorProps {
88
onLimitChange: (limit: string) => void;
99
}
1010
export const LimitEditor = (props: LimitEditorProps) => {
11-
const [limit, setLimit] = useState(props.limit || '100');
11+
const [limit, setLimit] = useState(props.limit);
1212
const { label, tooltip } = selectors.components.QueryEditor.QueryBuilder.LIMIT;
1313

1414
return (

src/components/queryBuilder/QueryBuilder.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ export const QueryBuilder = (props: QueryBuilderProps) => {
230230
onGroupByChange={onGroupByChange}
231231
fieldsList={fieldsList}
232232
labelAndTooltip={selectors.components.QueryEditor.QueryBuilder.SAMPLE_BY}
233+
isDisabled={builder.timeField.length === 0}
233234
/>
234235
</EditorRow>
235236
)}
@@ -264,7 +265,11 @@ export const QueryBuilder = (props: QueryBuilderProps) => {
264265

265266
{builder.mode === BuilderMode.Trend && (
266267
<EditorRow>
267-
<SampleByFillEditor fills={builder.sampleByFill || []} onFillsChange={onFillChange} />
268+
<SampleByFillEditor
269+
fills={builder.sampleByFill || []}
270+
onFillsChange={onFillChange}
271+
isDisabled={builder.timeField.length === 0}
272+
/>
268273
</EditorRow>
269274
)}
270275

@@ -275,6 +280,7 @@ export const QueryBuilder = (props: QueryBuilderProps) => {
275280
onGroupByChange={onGroupByChange}
276281
fieldsList={fieldsList}
277282
labelAndTooltip={selectors.components.QueryEditor.QueryBuilder.GROUP_BY}
283+
isDisabled={builder.timeField.length === 0}
278284
/>
279285
</EditorRow>
280286
)}
@@ -295,7 +301,7 @@ export const QueryBuilder = (props: QueryBuilderProps) => {
295301
fieldsList={getOrderByFields(builder, fieldsList)}
296302
/>
297303
<EditorRow>
298-
<LimitEditor limit={builder.limit || 100} onLimitChange={onLimitChange} />
304+
<LimitEditor limit={builder.limit} onLimitChange={onLimitChange} />
299305
</EditorRow>
300306
</EditorRows>
301307
) : null;

src/components/queryBuilder/SampleByFillEditor.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { GroupBase, OptionsOrGroups } from 'react-select';
99
interface FillEditorProps {
1010
fills: string[];
1111
onFillsChange: (fills: string[]) => void;
12+
isDisabled: boolean;
1213
}
1314

1415
const fillModes: SelectableValue[] = [];
@@ -85,6 +86,8 @@ export const SampleByFillEditor = (props: FillEditorProps) => {
8586
width={50}
8687
isClearable={true}
8788
hideSelectedOptions={true}
89+
placeholder={props.isDisabled ? 'Table is missing designated timestamp' : 'Choose'}
90+
disabled={props.isDisabled}
8891
/>
8992
</EditorField>
9093
);

src/components/queryBuilder/TableSelect.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const TableSelect = (props: Props) => {
2121

2222
useEffect(() => {
2323
async function fetchTables() {
24-
const tables = await datasource.fetchTables();
24+
const tables = (await datasource.fetchTables()).sort((a, b) => a.tableName.localeCompare(b.tableName));
2525
const values = tables.map((t) => ({ label: t.tableName, value: t.tableName }));
2626
// Add selected value to the list if it does not exist.
2727
if (table && !tables.find((x) => x.tableName === table) && props.mode !== BuilderMode.Trend) {

0 commit comments

Comments
 (0)