From 821471f4ab66e0615389cbb00c3c4461c872b6f2 Mon Sep 17 00:00:00 2001 From: Palash Gupta Date: Wed, 27 Sep 2023 12:04:47 +0000 Subject: [PATCH] feat(query-builder): add limit, order by and having clause to formula (#3623) * feat: query builder formula is updated * feat: formula is updated for having and limit * feat: orderBy is updated * feat: formula is added * chore: add query-service support for formula limit and order by * feat: enable more filters is displayed when all data source is metrics * chore: feedback is updated * chore: feedback is updated --------- Co-authored-by: Srikanth Chekuri Co-authored-by: Rajat Dabade --- frontend/src/constants/queryBuilder.ts | 20 +- frontend/src/container/LiveLogs/constants.ts | 4 +- .../container/LogsContextList/ShowButton.tsx | 4 +- .../src/container/LogsContextList/index.tsx | 12 +- .../container/LogsExplorerContext/index.tsx | 6 +- .../container/QueryBuilder/QueryBuilder.tsx | 27 ++- .../AdditionalFiltersToggler.tsx | 4 +- .../components/Formula/Formula.interfaces.ts | 14 +- .../components/Formula/Formula.tsx | 117 ++++++++++- .../QueryBuilder/components/Query/Query.tsx | 2 +- .../filters/Formula/Having/HavingFilter.tsx | 198 ++++++++++++++++++ .../filters/Formula/Having/types.ts | 12 ++ .../filters/Formula/Limit/Limit.tsx | 20 ++ .../filters/Formula/Limit/types.ts | 6 + .../filters/Formula/OrderBy/OrderByFilter.tsx | 84 ++++++++ .../filters/Formula/OrderBy/types.ts | 12 ++ .../OrderBy/useOrderByFormulaFilter.tsx | 127 +++++++++++ .../filters/Formula/OrderBy/utils.ts | 26 +++ .../filters/HavingFilter/HavingFilter.tsx | 37 +--- .../filters/LimitFilter/LimitFilter.tsx | 24 +-- .../OrderByFilter/OrderByFilter.interfaces.ts | 4 +- .../filters/OrderByFilter/OrderByFilter.tsx | 14 +- .../filters/OrderByFilter/config.ts | 2 +- .../filters/OrderByFilter/useOrderByFilter.ts | 77 ++----- .../filters/OrderByFilter/utils.ts | 12 +- .../container/QueryBuilder/filters/utils.ts | 94 +++++++++ ...ations.ts => useQueryBuilderOperations.ts} | 103 ++++++--- .../getOperatorsBySourceAndPanelType.ts | 6 +- .../newQueryBuilder/getPaginationQueryData.ts | 8 +- .../api/queryBuilder/queryBuilderData.ts | 5 +- frontend/src/types/common/operations.types.ts | 19 +- frontend/src/utils/selectPopupContainer.ts | 6 +- pkg/query-service/app/http_handler.go | 4 +- .../app/queryBuilder/query_builder.go | 17 +- 34 files changed, 916 insertions(+), 211 deletions(-) create mode 100644 frontend/src/container/QueryBuilder/filters/Formula/Having/HavingFilter.tsx create mode 100644 frontend/src/container/QueryBuilder/filters/Formula/Having/types.ts create mode 100644 frontend/src/container/QueryBuilder/filters/Formula/Limit/Limit.tsx create mode 100644 frontend/src/container/QueryBuilder/filters/Formula/Limit/types.ts create mode 100644 frontend/src/container/QueryBuilder/filters/Formula/OrderBy/OrderByFilter.tsx create mode 100644 frontend/src/container/QueryBuilder/filters/Formula/OrderBy/types.ts create mode 100644 frontend/src/container/QueryBuilder/filters/Formula/OrderBy/useOrderByFormulaFilter.tsx create mode 100644 frontend/src/container/QueryBuilder/filters/Formula/OrderBy/utils.ts create mode 100644 frontend/src/container/QueryBuilder/filters/utils.ts rename frontend/src/hooks/queryBuilder/{useQueryOperations.ts => useQueryBuilderOperations.ts} (79%) diff --git a/frontend/src/constants/queryBuilder.ts b/frontend/src/constants/queryBuilder.ts index c04005afa6..c53873bc5c 100644 --- a/frontend/src/constants/queryBuilder.ts +++ b/frontend/src/constants/queryBuilder.ts @@ -74,7 +74,7 @@ export const mapOfOperators = { traces: tracesAggregateOperatorOptions, }; -export const mapOfFilters: Record = { +export const mapOfQueryFilters: Record = { metrics: [ // eslint-disable-next-line sonarjs/no-duplicate-string { text: 'Aggregation interval', field: 'stepInterval' }, @@ -94,6 +94,24 @@ export const mapOfFilters: Record = { ], }; +const commonFormulaFilters: QueryAdditionalFilter[] = [ + { + text: 'Having', + field: 'having', + }, + { text: 'Order by', field: 'orderBy' }, + { text: 'Limit', field: 'limit' }, +]; + +export const mapOfFormulaToFilters: Record< + DataSource, + QueryAdditionalFilter[] +> = { + metrics: commonFormulaFilters, + logs: commonFormulaFilters, + traces: commonFormulaFilters, +}; + export const REDUCE_TO_VALUES: SelectOption[] = [ { value: 'last', label: 'Latest of values in timeframe' }, { value: 'sum', label: 'Sum of values in timeframe' }, diff --git a/frontend/src/container/LiveLogs/constants.ts b/frontend/src/container/LiveLogs/constants.ts index f2c5ca1c97..83df3759ee 100644 --- a/frontend/src/container/LiveLogs/constants.ts +++ b/frontend/src/container/LiveLogs/constants.ts @@ -2,7 +2,7 @@ import { initialQueriesMap, initialQueryBuilderFormValuesMap, } from 'constants/queryBuilder'; -import { FILTERS } from 'container/QueryBuilder/filters/OrderByFilter/config'; +import { ORDERBY_FILTERS } from 'container/QueryBuilder/filters/OrderByFilter/config'; import { BaseAutocompleteData, DataTypes, @@ -14,7 +14,7 @@ export const defaultLiveQueryDataConfig: Partial = { aggregateOperator: LogsAggregatorOperator.NOOP, disabled: true, pageSize: 10, - orderBy: [{ columnName: 'timestamp', order: FILTERS.DESC }], + orderBy: [{ columnName: 'timestamp', order: ORDERBY_FILTERS.DESC }], }; type GetDefaultCompositeQueryParams = { diff --git a/frontend/src/container/LogsContextList/ShowButton.tsx b/frontend/src/container/LogsContextList/ShowButton.tsx index 26fbadaf30..7240800af7 100644 --- a/frontend/src/container/LogsContextList/ShowButton.tsx +++ b/frontend/src/container/LogsContextList/ShowButton.tsx @@ -1,5 +1,5 @@ import { Button, Typography } from 'antd'; -import { FILTERS } from 'container/QueryBuilder/filters/OrderByFilter/config'; +import { ORDERBY_FILTERS } from 'container/QueryBuilder/filters/OrderByFilter/config'; import { ShowButtonWrapper } from './styles'; @@ -19,7 +19,7 @@ function ShowButton({ return ( - Showing 10 lines {order === FILTERS.ASC ? 'after' : 'before'} match + Showing 10 lines {order === ORDERBY_FILTERS.ASC ? 'after' : 'before'} match