From e880fbfd74f126b3e746bc23fff466bb45554576 Mon Sep 17 00:00:00 2001 From: Spencer Torres Date: Thu, 16 Nov 2023 14:09:31 -0500 Subject: [PATCH] revert some field/test changes --- .../queryBuilder/FilterEditor.test.tsx | 10 +- src/components/queryBuilder/FilterEditor.tsx | 103 ++++++++++++------ src/components/queryBuilder/LimitEditor.tsx | 12 +- src/components/queryBuilder/SqlPreview.tsx | 13 ++- src/data/sqlGenerator.ts | 7 +- 5 files changed, 93 insertions(+), 52 deletions(-) diff --git a/src/components/queryBuilder/FilterEditor.test.tsx b/src/components/queryBuilder/FilterEditor.test.tsx index 7c092cdf..b87e8d66 100644 --- a/src/components/queryBuilder/FilterEditor.test.tsx +++ b/src/components/queryBuilder/FilterEditor.test.tsx @@ -38,7 +38,9 @@ describe('FilterEditor', () => { const result = render( {}} />); expect(result.container.firstChild).not.toBeNull(); expect(result.getAllByText(selectors.components.QueryEditor.QueryBuilder.WHERE.label).length).toBe(1); - expect(result.getByTestId('query-builder-filters-add-button')).toBeInTheDocument(); + expect(result.queryByTestId('query-builder-filters-add-button')).not.toBeInTheDocument(); + expect(result.getByTestId('query-builder-filters-inline-add-button')).toBeInTheDocument(); + expect(result.getAllByTestId('query-builder-filters-inline-add-button').length).toBe(1); expect(result.getAllByTestId('query-builder-filters-remove-button').length).toBe(filters.length); }); it('should call the onFiltersChange with correct args', async () => { @@ -62,9 +64,11 @@ describe('FilterEditor', () => { const result = render(); expect(result.container.firstChild).not.toBeNull(); expect(result.getAllByText(selectors.components.QueryEditor.QueryBuilder.WHERE.label).length).toBe(1); - expect(result.getByTestId('query-builder-filters-add-button')).toBeInTheDocument(); + expect(result.queryByTestId('query-builder-filters-add-button')).not.toBeInTheDocument(); + expect(result.getByTestId('query-builder-filters-inline-add-button')).toBeInTheDocument(); + expect(result.getAllByTestId('query-builder-filters-inline-add-button').length).toBe(1); expect(result.getAllByTestId('query-builder-filters-remove-button').length).toBe(filters.length); - await userEvent.click(result.getByTestId('query-builder-filters-add-button')); + await userEvent.click(result.getByTestId('query-builder-filters-inline-add-button')); expect(onFiltersChange).toBeCalledTimes(1); expect(onFiltersChange).toHaveBeenNthCalledWith(1, [...filters, defaultNewFilter]); await userEvent.click(result.getAllByTestId('query-builder-filters-remove-button')[0]); diff --git a/src/components/queryBuilder/FilterEditor.tsx b/src/components/queryBuilder/FilterEditor.tsx index 57edfca6..944b43f4 100644 --- a/src/components/queryBuilder/FilterEditor.tsx +++ b/src/components/queryBuilder/FilterEditor.tsx @@ -1,11 +1,10 @@ import React, { useState } from 'react'; import { SelectableValue } from '@grafana/data'; -import { Button, Input, MultiSelect, RadioButtonGroup, Select } from '@grafana/ui'; +import { Button, InlineFormLabel, Input, MultiSelect, RadioButtonGroup, Select } from '@grafana/ui'; import { Filter, FilterOperator, TableColumn, NullFilter } from 'types/queryBuilder'; import * as utils from 'components/queryBuilder/utils'; import labels from 'labels'; import { styles } from 'styles'; -import { EditorField, EditorFieldGroup } from '@grafana/experimental'; const boolValues: Array> = [ { value: true, label: 'True' }, @@ -67,7 +66,11 @@ const FilterValueNumberItem = (props: { value: number; onChange: (value: number) const FilterValueSingleStringItem = (props: { value: string; onChange: (value: string) => void }) => { return (
- props.onChange(e.currentTarget.value)} /> + props.onChange(e.currentTarget.value)} + />
); }; @@ -329,7 +332,7 @@ export const FilterEditor = (props: { onFilterChange(index, filter); }; return ( - + <> {index !== 0 && ( onFilterConditionChange(e!)} /> )} @@ -337,13 +340,15 @@ export const FilterEditor = (props: { disabled={Boolean(filter.hint)} placeholder={filter.hint || undefined} value={filter.key} - width={30} + width={40} + className={styles.Common.inlineSelect} options={getFields()} isOpen={isOpen} onOpenMenu={() => setIsOpen(true)} onCloseMenu={() => setIsOpen(false)} onChange={(e) => onFilterNameChange(e.value!)} allowCustomValue={true} + menuPlacement={'bottom'} /> { onChange={e => setLimit(e.currentTarget.valueAsNumber)} onBlur={() => props.onLimitChange(limit)} /> - + ); }; diff --git a/src/components/queryBuilder/SqlPreview.tsx b/src/components/queryBuilder/SqlPreview.tsx index e613d3b0..1bffd7e6 100644 --- a/src/components/queryBuilder/SqlPreview.tsx +++ b/src/components/queryBuilder/SqlPreview.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { EditorField, EditorRow } from '@grafana/experimental'; +import { InlineFormLabel } from '@grafana/ui'; import labels from 'labels'; interface SqlPreviewProps { @@ -11,10 +11,11 @@ export const SqlPreview = (props: SqlPreviewProps) => { const { label, tooltip } = labels.components.SqlPreview; return ( - - -
{sql}
-
-
+
+ + {label} + +
{sql}
+
); }; diff --git a/src/data/sqlGenerator.ts b/src/data/sqlGenerator.ts index 69a2b3eb..2d79d55a 100644 --- a/src/data/sqlGenerator.ts +++ b/src/data/sqlGenerator.ts @@ -234,11 +234,12 @@ const getTraceDurationSelectSql = (columnIdentifier: string, timeUnit?: TimeUnit } const getLimit = (limit?: number | undefined): string => { - if (limit === undefined) { - return ''; + limit = Math.max(0, limit || 0); + if (limit > 0) { + return 'LIMIT ' + limit; } - return 'LIMIT ' + Math.max(0, limit || 1000); + return ''; }; const getFilters = (options: QueryBuilderOptions): string => {