mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 10:25:54 +08:00
fix: added card to show message for deleted alert id (#5565)
* fix: added card to show message for deleted alert id * refactor: added new constants for handling error message when alert is deleted * refactor: added error response to error message field * refactor: removed console statement * refactor: renamed the variables
This commit is contained in:
parent
abe65975c9
commit
a6848f6abd
@ -9,9 +9,9 @@ export function ErrorResponseHandler(error: AxiosError): ErrorResponse {
|
|||||||
// making the error status code as standard Error Status Code
|
// making the error status code as standard Error Status Code
|
||||||
const statusCode = response.status as ErrorStatusCode;
|
const statusCode = response.status as ErrorStatusCode;
|
||||||
|
|
||||||
if (statusCode >= 400 && statusCode < 500) {
|
const { data } = response as AxiosResponse;
|
||||||
const { data } = response as AxiosResponse;
|
|
||||||
|
|
||||||
|
if (statusCode >= 400 && statusCode < 500) {
|
||||||
if (statusCode === 404) {
|
if (statusCode === 404) {
|
||||||
return {
|
return {
|
||||||
statusCode,
|
statusCode,
|
||||||
@ -34,12 +34,11 @@ export function ErrorResponseHandler(error: AxiosError): ErrorResponse {
|
|||||||
body: JSON.stringify((response.data as any).data),
|
body: JSON.stringify((response.data as any).data),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
statusCode,
|
statusCode,
|
||||||
payload: null,
|
payload: null,
|
||||||
error: 'Something went wrong',
|
error: 'Something went wrong',
|
||||||
message: null,
|
message: data?.error,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (request) {
|
if (request) {
|
||||||
|
32
frontend/src/pages/EditRules/EditRules.styles.scss
Normal file
32
frontend/src/pages/EditRules/EditRules.styles.scss
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
.edit-rules-container {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
margin-top: 5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.edit-rules-card {
|
||||||
|
width: 20rem;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 300;
|
||||||
|
font-size: 18px;
|
||||||
|
line-height: 20px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
text-align: center;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-container {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
margin-top: 2rem;
|
||||||
|
}
|
||||||
|
|
6
frontend/src/pages/EditRules/constants.ts
Normal file
6
frontend/src/pages/EditRules/constants.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export const returnToAlertsPage = 'Return to Alerts Page';
|
||||||
|
|
||||||
|
export const errorMessageReceivedFromBackend = 'sql: no rows in result set';
|
||||||
|
|
||||||
|
export const improvedErrorMessage =
|
||||||
|
'The Alert that you are trying to access does not exist.';
|
@ -1,19 +1,27 @@
|
|||||||
|
import './EditRules.styles.scss';
|
||||||
|
|
||||||
|
import { Button, Card } from 'antd';
|
||||||
import get from 'api/alerts/get';
|
import get from 'api/alerts/get';
|
||||||
import Spinner from 'components/Spinner';
|
import Spinner from 'components/Spinner';
|
||||||
|
import { QueryParams } from 'constants/query';
|
||||||
import ROUTES from 'constants/routes';
|
import ROUTES from 'constants/routes';
|
||||||
import EditRulesContainer from 'container/EditRules';
|
import EditRulesContainer from 'container/EditRules';
|
||||||
import { useNotifications } from 'hooks/useNotifications';
|
import { useNotifications } from 'hooks/useNotifications';
|
||||||
|
import useUrlQuery from 'hooks/useUrlQuery';
|
||||||
import history from 'lib/history';
|
import history from 'lib/history';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useQuery } from 'react-query';
|
import { useQuery } from 'react-query';
|
||||||
import { useLocation } from 'react-router-dom';
|
|
||||||
|
import {
|
||||||
|
errorMessageReceivedFromBackend,
|
||||||
|
improvedErrorMessage,
|
||||||
|
returnToAlertsPage,
|
||||||
|
} from './constants';
|
||||||
|
|
||||||
function EditRules(): JSX.Element {
|
function EditRules(): JSX.Element {
|
||||||
const { search } = useLocation();
|
const params = useUrlQuery();
|
||||||
const params = new URLSearchParams(search);
|
|
||||||
const ruleId = params.get('ruleId');
|
const ruleId = params.get('ruleId');
|
||||||
|
|
||||||
const { t } = useTranslation('common');
|
const { t } = useTranslation('common');
|
||||||
|
|
||||||
const isValidRuleId = ruleId !== null && String(ruleId).length !== 0;
|
const isValidRuleId = ruleId !== null && String(ruleId).length !== 0;
|
||||||
@ -31,6 +39,14 @@ function EditRules(): JSX.Element {
|
|||||||
|
|
||||||
const { notifications } = useNotifications();
|
const { notifications } = useNotifications();
|
||||||
|
|
||||||
|
const clickHandler = (): void => {
|
||||||
|
params.delete(QueryParams.compositeQuery);
|
||||||
|
params.delete(QueryParams.panelTypes);
|
||||||
|
params.delete(QueryParams.ruleId);
|
||||||
|
params.delete(QueryParams.relativeTime);
|
||||||
|
history.push(`${ROUTES.LIST_ALL_ALERT}?${params.toString()}`);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isValidRuleId) {
|
if (!isValidRuleId) {
|
||||||
notifications.error({
|
notifications.error({
|
||||||
@ -45,7 +61,22 @@ function EditRules(): JSX.Element {
|
|||||||
ruleId == null ||
|
ruleId == null ||
|
||||||
(data?.payload?.data === undefined && !isLoading)
|
(data?.payload?.data === undefined && !isLoading)
|
||||||
) {
|
) {
|
||||||
return <div>{data?.error || t('something_went_wrong')}</div>;
|
return (
|
||||||
|
<div className="edit-rules-container">
|
||||||
|
<Card size="small" className="edit-rules-card">
|
||||||
|
<p className="content">
|
||||||
|
{data?.message === errorMessageReceivedFromBackend
|
||||||
|
? improvedErrorMessage
|
||||||
|
: data?.error || t('something_went_wrong')}
|
||||||
|
</p>
|
||||||
|
<div className="btn-container">
|
||||||
|
<Button type="default" size="large" onClick={clickHandler}>
|
||||||
|
{returnToAlertsPage}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLoading || isRefetching || !data?.payload) {
|
if (isLoading || isRefetching || !data?.payload) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user