fix: ch queries sending builder as query type in query range api for exceptions alerts (#4941)

* fix: ch queries sending builder as query type in query range api for exceptions alerts

* fix: ch queries sending builder as query type in query range api for exceptions alerts

* fix: alerts routing from logs explorer and dashboards
This commit is contained in:
Vikrant Gupta 2024-05-01 14:39:39 +05:30 committed by GitHub
parent b85b9f42ed
commit b3d5831574
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 12 deletions

View File

@ -30,4 +30,5 @@ export enum QueryParams {
integration = 'integration', integration = 'integration',
pagination = 'pagination', pagination = 'pagination',
relativeTime = 'relativeTime', relativeTime = 'relativeTime',
alertType = 'alertType',
} }

View File

@ -1,8 +1,9 @@
import { Form, Row } from 'antd'; import { Form, Row } from 'antd';
import { ENTITY_VERSION_V4 } from 'constants/app'; import { ENTITY_VERSION_V4 } from 'constants/app';
import { QueryParams } from 'constants/query';
import FormAlertRules from 'container/FormAlertRules'; import FormAlertRules from 'container/FormAlertRules';
import { useGetCompositeQueryParam } from 'hooks/queryBuilder/useGetCompositeQueryParam'; import { useGetCompositeQueryParam } from 'hooks/queryBuilder/useGetCompositeQueryParam';
import { isEqual } from 'lodash-es'; import history from 'lib/history';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom'; import { useLocation } from 'react-router-dom';
import { AlertTypes } from 'types/api/alerts/alertTypes'; import { AlertTypes } from 'types/api/alerts/alertTypes';
@ -19,13 +20,25 @@ import SelectAlertType from './SelectAlertType';
function CreateRules(): JSX.Element { function CreateRules(): JSX.Element {
const [initValues, setInitValues] = useState<AlertDef | null>(null); const [initValues, setInitValues] = useState<AlertDef | null>(null);
const [alertType, setAlertType] = useState<AlertTypes>();
const location = useLocation(); const location = useLocation();
const queryParams = new URLSearchParams(location.search); const queryParams = new URLSearchParams(location.search);
const version = queryParams.get('version'); const version = queryParams.get('version');
const alertTypeFromParams = queryParams.get(QueryParams.alertType);
const compositeQuery = useGetCompositeQueryParam(); const compositeQuery = useGetCompositeQueryParam();
function getAlertTypeFromDataSource(): AlertTypes | null {
if (!compositeQuery) {
return null;
}
const dataSource = compositeQuery?.builder?.queryData[0]?.dataSource;
return ALERT_TYPE_VS_SOURCE_MAPPING[dataSource];
}
const [alertType, setAlertType] = useState<AlertTypes>(
(alertTypeFromParams as AlertTypes) || getAlertTypeFromDataSource(),
);
const [formInstance] = Form.useForm(); const [formInstance] = Form.useForm();
@ -47,21 +60,17 @@ function CreateRules(): JSX.Element {
version: version || ENTITY_VERSION_V4, version: version || ENTITY_VERSION_V4,
}); });
} }
queryParams.set(QueryParams.alertType, typ);
const generatedUrl = `${location.pathname}?${queryParams.toString()}`;
history.replace(generatedUrl);
}; };
useEffect(() => { useEffect(() => {
if (!compositeQuery) { if (alertType) {
return; onSelectType(alertType);
}
const dataSource = compositeQuery?.builder?.queryData[0]?.dataSource;
const alertTypeFromQuery = ALERT_TYPE_VS_SOURCE_MAPPING[dataSource];
if (alertTypeFromQuery && !isEqual(alertType, alertTypeFromQuery)) {
onSelectType(alertTypeFromQuery);
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [compositeQuery]); }, [alertType]);
if (!initValues) { if (!initValues) {
return ( return (

View File

@ -523,6 +523,7 @@ function FormAlertRules({
runQuery={handleRunQuery} runQuery={handleRunQuery}
alertDef={alertDef} alertDef={alertDef}
panelType={panelType || PANEL_TYPES.TIME_SERIES} panelType={panelType || PANEL_TYPES.TIME_SERIES}
key={currentQuery.queryType}
/> />
<RuleOptions <RuleOptions