From b69e97d7b0780e00956320ceb3aa22e0d8bdd6f8 Mon Sep 17 00:00:00 2001 From: SagarRajput-7 <162284829+SagarRajput-7@users.noreply.github.com> Date: Wed, 19 Jun 2024 12:10:43 +0530 Subject: [PATCH] fix: fixed flakiness in alert list actions - delete, edit, clone & toggle (#5237) * fix: fixed flakiness in alert list actions - delete, edit, clone & toggle * fix: added onhover dropdown open and close --- frontend/src/components/DropDown/DropDown.tsx | 17 ++++- .../container/ListAlertRules/ListAlert.tsx | 74 ++++++++++++------- .../src/container/ListAlertRules/styles.ts | 3 + 3 files changed, 67 insertions(+), 27 deletions(-) diff --git a/frontend/src/components/DropDown/DropDown.tsx b/frontend/src/components/DropDown/DropDown.tsx index c29fbdd15b..df845b7084 100644 --- a/frontend/src/components/DropDown/DropDown.tsx +++ b/frontend/src/components/DropDown/DropDown.tsx @@ -3,6 +3,7 @@ import './DropDown.styles.scss'; import { EllipsisOutlined } from '@ant-design/icons'; import { Button, Dropdown, MenuProps } from 'antd'; import { useIsDarkMode } from 'hooks/useDarkMode'; +import { useState } from 'react'; function DropDown({ element }: { element: JSX.Element[] }): JSX.Element { const isDarkMode = useIsDarkMode(); @@ -14,12 +15,24 @@ function DropDown({ element }: { element: JSX.Element[] }): JSX.Element { }), ); + const [isDdOpen, setDdOpen] = useState(false); + return ( - + setDdOpen(true), + onMouseLeave: (): void => setDdOpen(false), + }} + open={isDdOpen} + > diff --git a/frontend/src/container/ListAlertRules/ListAlert.tsx b/frontend/src/container/ListAlertRules/ListAlert.tsx index 37a56ba921..91e0786e05 100644 --- a/frontend/src/container/ListAlertRules/ListAlert.tsx +++ b/frontend/src/container/ListAlertRules/ListAlert.tsx @@ -55,6 +55,9 @@ function ListAlert({ allAlertRules, refetch }: ListAlertProps): JSX.Element { role, ); + const [editLoader, setEditLoader] = useState(false); + const [cloneLoader, setCloneLoader] = useState(false); + const params = useUrlQuery(); const orderColumnParam = params.get('columnKey'); const orderQueryParam = params.get('order'); @@ -113,6 +116,7 @@ function ListAlert({ allAlertRules, refetch }: ListAlertProps): JSX.Element { }, [featureResponse, handleError]); const onEditHandler = (record: GettableAlert) => (): void => { + setEditLoader(true); featureResponse .refetch() .then(() => { @@ -129,9 +133,11 @@ function ListAlert({ allAlertRules, refetch }: ListAlertProps): JSX.Element { params.set(QueryParams.ruleId, record.id.toString()); + setEditLoader(false); history.push(`${ROUTES.EDIT_ALERTS}?${params.toString()}`); }) - .catch(handleError); + .catch(handleError) + .finally(() => setEditLoader(false)); }; const onCloneHandler = ( @@ -143,33 +149,41 @@ function ListAlert({ allAlertRules, refetch }: ListAlertProps): JSX.Element { }; const apiReq = { data: copyAlert }; - const response = await saveAlertApi(apiReq); + try { + setCloneLoader(true); + const response = await saveAlertApi(apiReq); - if (response.statusCode === 200) { - notificationsApi.success({ - message: 'Success', - description: 'Alert cloned successfully', - }); + if (response.statusCode === 200) { + notificationsApi.success({ + message: 'Success', + description: 'Alert cloned successfully', + }); - const { data: refetchData, status } = await refetch(); - if (status === 'success' && refetchData.payload) { - setData(refetchData.payload || []); - setTimeout(() => { - const clonedAlert = refetchData.payload[refetchData.payload.length - 1]; - params.set(QueryParams.ruleId, String(clonedAlert.id)); - history.push(`${ROUTES.EDIT_ALERTS}?${params.toString()}`); - }, 2000); - } - if (status === 'error') { + const { data: refetchData, status } = await refetch(); + if (status === 'success' && refetchData.payload) { + setData(refetchData.payload || []); + setTimeout(() => { + const clonedAlert = refetchData.payload[refetchData.payload.length - 1]; + params.set(QueryParams.ruleId, String(clonedAlert.id)); + history.push(`${ROUTES.EDIT_ALERTS}?${params.toString()}`); + }, 2000); + } + if (status === 'error') { + notificationsApi.error({ + message: t('something_went_wrong'), + }); + } + } else { notificationsApi.error({ - message: t('something_went_wrong'), + message: 'Error', + description: response.error || t('something_went_wrong'), }); } - } else { - notificationsApi.error({ - message: 'Error', - description: response.error || t('something_went_wrong'), - }); + } catch (error) { + handleError(); + console.error(error); + } finally { + setCloneLoader(false); } }; @@ -314,10 +328,20 @@ function ListAlert({ allAlertRules, refetch }: ListAlertProps): JSX.Element { setData={setData} id={id} />, - + Edit , - + Clone ,