fix: retain the alerts table sorting when editing or discarding the opened alert (#5066)

This commit is contained in:
Vikrant Gupta 2024-05-23 22:46:17 +05:30 committed by GitHub
parent 3b599ea41a
commit 0d043bf380
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 14 deletions

View File

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

View File

@ -157,8 +157,12 @@ function FormAlertRules({
}, [alertDef, currentQuery?.queryType, queryOptions]);
const onCancelHandler = useCallback(() => {
history.replace(ROUTES.LIST_ALL_ALERT);
}, []);
urlQuery.delete(QueryParams.compositeQuery);
urlQuery.delete(QueryParams.panelTypes);
urlQuery.delete(QueryParams.ruleId);
urlQuery.delete(QueryParams.relativeTime);
history.replace(`${ROUTES.LIST_ALL_ALERT}?${urlQuery.toString()}`);
}, [urlQuery]);
// onQueryCategoryChange handles changes to query category
// in state as well as sets additional defaults
@ -343,8 +347,13 @@ function FormAlertRules({
// invalidate rule in cache
ruleCache.invalidateQueries(['ruleId', ruleId]);
// eslint-disable-next-line sonarjs/no-identical-functions
setTimeout(() => {
history.replace(ROUTES.LIST_ALL_ALERT);
urlQuery.delete(QueryParams.compositeQuery);
urlQuery.delete(QueryParams.panelTypes);
urlQuery.delete(QueryParams.ruleId);
urlQuery.delete(QueryParams.relativeTime);
history.replace(`${ROUTES.LIST_ALL_ALERT}?${urlQuery.toString()}`);
}, 2000);
} else {
notifications.error({
@ -360,12 +369,13 @@ function FormAlertRules({
}
setLoading(false);
}, [
t,
isFormValid,
ruleId,
ruleCache,
memoizedPreparePostData,
ruleId,
notifications,
t,
ruleCache,
urlQuery,
]);
const onSaveHandler = useCallback(async () => {

View File

@ -117,14 +117,19 @@ function ListAlert({ allAlertRules, refetch }: ListAlertProps): JSX.Element {
.refetch()
.then(() => {
const compositeQuery = mapQueryDataFromApi(record.condition.compositeQuery);
history.push(
`${ROUTES.EDIT_ALERTS}?ruleId=${record.id.toString()}&${
QueryParams.compositeQuery
}=${encodeURIComponent(JSON.stringify(compositeQuery))}&panelTypes=${
record.condition.compositeQuery.panelType
}`,
params.set(
QueryParams.compositeQuery,
encodeURIComponent(JSON.stringify(compositeQuery)),
);
params.set(
QueryParams.panelTypes,
record.condition.compositeQuery.panelType,
);
params.set(QueryParams.ruleId, record.id.toString());
history.push(`${ROUTES.EDIT_ALERTS}?${params.toString()}`);
})
.catch(handleError);
};
@ -151,7 +156,8 @@ function ListAlert({ allAlertRules, refetch }: ListAlertProps): JSX.Element {
setData(refetchData.payload || []);
setTimeout(() => {
const clonedAlert = refetchData.payload[refetchData.payload.length - 1];
history.push(`${ROUTES.EDIT_ALERTS}?ruleId=${clonedAlert.id}`);
params.set(QueryParams.ruleId, String(clonedAlert.id));
history.push(`${ROUTES.EDIT_ALERTS}?${params.toString()}`);
}, 2000);
}
if (status === 'error') {