Skip to content

Commit

Permalink
Merge pull request #104 from questdb/update-query-builder-settings
Browse files Browse the repository at this point in the history
Update query builder settings
  • Loading branch information
insmac authored Jun 25, 2024
2 parents c95cec7 + 74aff81 commit 5087340
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 122 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ data from within Grafana.
For detailed instructions on how to install the plugin on Grafana Cloud or
locally, please check out the [Plugin installation docs](https://grafana.com/docs/grafana/latest/plugins/installation/).

Read the guide on QuestDB website: [Third-party Tools - Grafana](https://questdb.io/docs/third-party-tools/grafana/).

## Configuration

### QuestDB user for the data source
Expand Down Expand Up @@ -179,3 +181,4 @@ You may choose to hide this variable from view as it serves no further purpose.
- Configure and use [Templates and variables](https://grafana.com/docs/grafana/latest/variables/).
- Add [Transformations](https://grafana.com/docs/grafana/latest/panels/transformations/).
- Set up alerting; refer to [Alerts overview](https://grafana.com/docs/grafana/latest/alerting/).
- Read the [Plugin guide](https://questdb.io/docs/third-party-tools/grafana/) on QuestDB website
12 changes: 10 additions & 2 deletions src/components/queryBuilder/GroupBy.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import React from 'react';
import { render } from '@testing-library/react';
import { GroupByEditor } from './GroupBy';
import {selectors} from "../../selectors";
import { selectors } from '../../selectors';

describe('GroupByEditor', () => {
it('renders correctly', () => {
const result = render(<GroupByEditor fieldsList={[]} groupBy={[]} onGroupByChange={() => {}} labelAndTooltip={selectors.components.QueryEditor.QueryBuilder.SAMPLE_BY} />);
const result = render(
<GroupByEditor
fieldsList={[]}
groupBy={[]}
onGroupByChange={() => {}}
isDisabled={false}
labelAndTooltip={selectors.components.QueryEditor.QueryBuilder.SAMPLE_BY}
/>
);
expect(result.container.firstChild).not.toBeNull();
});
});
4 changes: 3 additions & 1 deletion src/components/queryBuilder/GroupBy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface GroupByEditorProps {
groupBy: string[];
onGroupByChange: (groupBy: string[]) => void;
labelAndTooltip: typeof selectors.components.QueryEditor.QueryBuilder.GROUP_BY;
isDisabled: boolean;
}
export const GroupByEditor = (props: GroupByEditorProps) => {
const columns: SelectableValue[] = (props.fieldsList || []).map((f) => ({ label: f.label, value: f.name }));
Expand All @@ -34,7 +35,7 @@ export const GroupByEditor = (props: GroupByEditorProps) => {
<EditorField tooltip={tooltip} label={label}>
<MultiSelect
options={columns}
placeholder="Choose"
placeholder={props.isDisabled ? 'Table is missing designated timestamp' : 'Choose'}
isOpen={isOpen}
onOpenMenu={() => setIsOpen(true)}
onCloseMenu={() => setIsOpen(false)}
Expand All @@ -43,6 +44,7 @@ export const GroupByEditor = (props: GroupByEditorProps) => {
value={groupBy}
allowCustomValue={true}
width={50}
disabled={props.isDisabled}
/>
</EditorField>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/queryBuilder/Limit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface LimitEditorProps {
onLimitChange: (limit: string) => void;
}
export const LimitEditor = (props: LimitEditorProps) => {
const [limit, setLimit] = useState(props.limit || '100');
const [limit, setLimit] = useState(props.limit);
const { label, tooltip } = selectors.components.QueryEditor.QueryBuilder.LIMIT;

return (
Expand Down
10 changes: 8 additions & 2 deletions src/components/queryBuilder/QueryBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export const QueryBuilder = (props: QueryBuilderProps) => {
onGroupByChange={onGroupByChange}
fieldsList={fieldsList}
labelAndTooltip={selectors.components.QueryEditor.QueryBuilder.SAMPLE_BY}
isDisabled={builder.timeField.length === 0}
/>
</EditorRow>
)}
Expand Down Expand Up @@ -264,7 +265,11 @@ export const QueryBuilder = (props: QueryBuilderProps) => {

{builder.mode === BuilderMode.Trend && (
<EditorRow>
<SampleByFillEditor fills={builder.sampleByFill || []} onFillsChange={onFillChange} />
<SampleByFillEditor
fills={builder.sampleByFill || []}
onFillsChange={onFillChange}
isDisabled={builder.timeField.length === 0}
/>
</EditorRow>
)}

Expand All @@ -275,6 +280,7 @@ export const QueryBuilder = (props: QueryBuilderProps) => {
onGroupByChange={onGroupByChange}
fieldsList={fieldsList}
labelAndTooltip={selectors.components.QueryEditor.QueryBuilder.GROUP_BY}
isDisabled={builder.timeField.length === 0}
/>
</EditorRow>
)}
Expand All @@ -295,7 +301,7 @@ export const QueryBuilder = (props: QueryBuilderProps) => {
fieldsList={getOrderByFields(builder, fieldsList)}
/>
<EditorRow>
<LimitEditor limit={builder.limit || 100} onLimitChange={onLimitChange} />
<LimitEditor limit={builder.limit} onLimitChange={onLimitChange} />
</EditorRow>
</EditorRows>
) : null;
Expand Down
3 changes: 3 additions & 0 deletions src/components/queryBuilder/SampleByFillEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { GroupBase, OptionsOrGroups } from 'react-select';
interface FillEditorProps {
fills: string[];
onFillsChange: (fills: string[]) => void;
isDisabled: boolean;
}

const fillModes: SelectableValue[] = [];
Expand Down Expand Up @@ -85,6 +86,8 @@ export const SampleByFillEditor = (props: FillEditorProps) => {
width={50}
isClearable={true}
hideSelectedOptions={true}
placeholder={props.isDisabled ? 'Table is missing designated timestamp' : 'Choose'}
disabled={props.isDisabled}
/>
</EditorField>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/queryBuilder/TableSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const TableSelect = (props: Props) => {

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

0 comments on commit 5087340

Please sign in to comment.