From 9b8f7a091c000794339cc1d3b596ca97aa9a5eda Mon Sep 17 00:00:00 2001 From: Palash Gupta Date: Wed, 28 Jun 2023 15:19:52 +0530 Subject: [PATCH] fix: step size is made dynamic (#2903) * fix: step size is made dynamic * test: get step test is added * chore: alerts step is updated * chore: query is updated * chore: provider query is updated * fix: user input is being take care of * chore: query builder step interval is updated * test: lib/getStep is updated * test: test for getStep is updated * fix: step interval is taken care when we change from top nav * chore: while saving the dashboard query is updated * chore: updated when selected widget is present * chore: getStep is now multiple of 60 and test is updated accordingly * chore: user input is overriden from global step --------- Co-authored-by: Vishal Sharma --- frontend/src/constants/queryBuilder.ts | 2 +- .../src/container/FormAlertRules/index.tsx | 16 +- .../Graph/FullView/index.metricsBuilder.tsx | 11 +- .../container/GridGraphLayout/Graph/index.tsx | 5 +- .../MetricsPageQueriesFactory.ts | 17 +++ .../MetricsApplication/Tabs/DBCall.tsx | 12 +- .../MetricsApplication/Tabs/External.tsx | 16 +- .../MetricsApplication/Tabs/Overview.tsx | 12 +- .../container/MetricsApplication/index.tsx | 7 +- .../LeftContainer/QuerySection/index.tsx | 20 ++- .../filters/AggregateEveryFilter/index.tsx | 54 ++----- .../TopNav/DateTimeSelection/index.tsx | 13 ++ .../queryBuilder/useGetWidgetQueryRange.ts | 10 +- .../src/hooks/queryBuilder/useStepInterval.ts | 37 +++++ frontend/src/lib/__tests__/getStep.test.ts | 7 +- .../getDashboardVariables.ts | 2 +- frontend/src/lib/getStep.test.ts | 137 ++++++++++++++++++ frontend/src/lib/getStep.ts | 10 +- frontend/src/providers/QueryBuilder.tsx | 33 ++++- .../actions/dashboard/getQueryResults.ts | 15 +- .../store/actions/dashboard/saveDashboard.ts | 6 +- frontend/src/types/common/queryBuilder.ts | 1 + 22 files changed, 338 insertions(+), 105 deletions(-) create mode 100644 frontend/src/hooks/queryBuilder/useStepInterval.ts create mode 100644 frontend/src/lib/getStep.test.ts diff --git a/frontend/src/constants/queryBuilder.ts b/frontend/src/constants/queryBuilder.ts index 2ac56af114..52be70442f 100644 --- a/frontend/src/constants/queryBuilder.ts +++ b/frontend/src/constants/queryBuilder.ts @@ -125,7 +125,7 @@ const initialQueryBuilderFormValues: IBuilderQuery = { }), disabled: false, having: [], - stepInterval: 30, + stepInterval: 60, limit: null, orderBy: [], groupBy: [], diff --git a/frontend/src/container/FormAlertRules/index.tsx b/frontend/src/container/FormAlertRules/index.tsx index 26a0830226..59c8333f06 100644 --- a/frontend/src/container/FormAlertRules/index.tsx +++ b/frontend/src/container/FormAlertRules/index.tsx @@ -8,6 +8,7 @@ import QueryTypeTag from 'container/NewWidget/LeftContainer/QueryTypeTag'; import PlotTag from 'container/NewWidget/LeftContainer/WidgetGraph/PlotTag'; import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder'; import { useShareBuilderUrl } from 'hooks/queryBuilder/useShareBuilderUrl'; +import { updateStepInterval } from 'hooks/queryBuilder/useStepInterval'; import { MESSAGE, useIsFeatureDisabled } from 'hooks/useFeatureFlag'; import { useNotifications } from 'hooks/useNotifications'; import history from 'lib/history'; @@ -16,6 +17,8 @@ import { mapQueryDataToApi } from 'lib/newQueryBuilder/queryBuilderMappers/mapQu import { useCallback, useEffect, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useQueryClient } from 'react-query'; +import { useSelector } from 'react-redux'; +import { AppState } from 'store/reducers'; import { AlertTypes } from 'types/api/alerts/alertTypes'; import { AlertDef, @@ -24,6 +27,7 @@ import { } from 'types/api/alerts/def'; import { Query } from 'types/api/queryBuilder/queryBuilderData'; import { EQueryType } from 'types/common/dashboard'; +import { GlobalReducer } from 'types/reducer/globalTime'; import BasicInfo from './BasicInfo'; import ChartPreview from './ChartPreview'; @@ -48,6 +52,10 @@ function FormAlertRules({ // init namespace for translations const { t } = useTranslation('alerts'); + const { minTime, maxTime } = useSelector( + (state) => state.globalTime, + ); + const { currentQuery, stagedQuery, @@ -76,10 +84,6 @@ function FormAlertRules({ setAlertDef(initialValue); }, [initialValue]); - const onRunQuery = (): void => { - handleRunQuery(); - }; - const onCancelHandler = useCallback(() => { history.replace(ROUTES.LIST_ALL_ALERT); }, []); @@ -99,7 +103,7 @@ function FormAlertRules({ } const query: Query = { ...currentQuery, queryType: val }; - redirectWithQueryBuilderData(query); + redirectWithQueryBuilderData(updateStepInterval(query, maxTime, minTime)); }; const { notifications } = useNotifications(); @@ -402,7 +406,7 @@ function FormAlertRules({ queryCategory={currentQuery.queryType} setQueryCategory={onQueryCategoryChange} alertType={alertType || AlertTypes.METRICS_BASED_ALERT} - runQuery={onRunQuery} + runQuery={handleRunQuery} />