From 46e6c34e5158c4afdc217282fb1c4de4a676adae Mon Sep 17 00:00:00 2001 From: Shaheer Kochai Date: Tue, 16 Jul 2024 13:13:25 +0430 Subject: [PATCH] fix: block alert creation if query_range API fails (#5441) --- .../container/FormAlertRules/ChartPreview/index.tsx | 7 +++++-- frontend/src/container/FormAlertRules/index.tsx | 12 ++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/frontend/src/container/FormAlertRules/ChartPreview/index.tsx b/frontend/src/container/FormAlertRules/ChartPreview/index.tsx index 331a5a0fc7..03db8a362e 100644 --- a/frontend/src/container/FormAlertRules/ChartPreview/index.tsx +++ b/frontend/src/container/FormAlertRules/ChartPreview/index.tsx @@ -48,6 +48,7 @@ export interface ChartPreviewProps { userQueryKey?: string; allowSelectedIntervalForStepGen?: boolean; yAxisUnit: string; + setQueryStatus?: (status: string) => void; } // eslint-disable-next-line sonarjs/cognitive-complexity @@ -62,6 +63,7 @@ function ChartPreview({ allowSelectedIntervalForStepGen = false, alertDef, yAxisUnit, + setQueryStatus, }: ChartPreviewProps): JSX.Element | null { const { t } = useTranslation('alerts'); const dispatch = useDispatch(); @@ -149,10 +151,10 @@ function ChartPreview({ useEffect((): void => { const { startTime, endTime } = getTimeRange(queryResponse); - + if (setQueryStatus) setQueryStatus(queryResponse.status); setMinTimeScale(startTime); setMaxTimeScale(endTime); - }, [maxTime, minTime, globalSelectedInterval, queryResponse]); + }, [maxTime, minTime, globalSelectedInterval, queryResponse, setQueryStatus]); if (queryResponse.data && graphType === PANEL_TYPES.BAR) { const sortedSeriesData = getSortedSeriesData( @@ -284,6 +286,7 @@ ChartPreview.defaultProps = { userQueryKey: '', allowSelectedIntervalForStepGen: false, alertDef: undefined, + setQueryStatus: (): void => {}, }; export default ChartPreview; diff --git a/frontend/src/container/FormAlertRules/index.tsx b/frontend/src/container/FormAlertRules/index.tsx index 40abbb3583..4b383eb272 100644 --- a/frontend/src/container/FormAlertRules/index.tsx +++ b/frontend/src/container/FormAlertRules/index.tsx @@ -101,6 +101,7 @@ function FormAlertRules({ const isNewRule = ruleId === 0; const [loading, setLoading] = useState(false); + const [queryStatus, setQueryStatus] = useState(''); // alertDef holds the form values to be posted const [alertDef, setAlertDef] = useState(initialValue); @@ -523,6 +524,7 @@ function FormAlertRules({ alertDef={alertDef} yAxisUnit={yAxisUnit || ''} graphType={panelType || PANEL_TYPES.TIME_SERIES} + setQueryStatus={setQueryStatus} /> ); @@ -540,6 +542,7 @@ function FormAlertRules({ selectedInterval={globalSelectedInterval} yAxisUnit={yAxisUnit || ''} graphType={panelType || PANEL_TYPES.TIME_SERIES} + setQueryStatus={setQueryStatus} /> ); @@ -665,7 +668,8 @@ function FormAlertRules({ disabled={ isAlertNameMissing || isAlertAvailableToSave || - !isChannelConfigurationValid + !isChannelConfigurationValid || + queryStatus === 'error' } > {isNewRule ? t('button_createrule') : t('button_savechanges')} @@ -674,7 +678,11 @@ function FormAlertRules({