mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 23:05:53 +08:00
bug: list of rules is fixed when created and come back to all rules (#998)
This commit is contained in:
parent
6064840dd1
commit
bf52722689
@ -2,28 +2,35 @@
|
|||||||
import { PlusOutlined } from '@ant-design/icons';
|
import { PlusOutlined } from '@ant-design/icons';
|
||||||
import { notification, Tag, Typography } from 'antd';
|
import { notification, Tag, Typography } from 'antd';
|
||||||
import Table, { ColumnsType } from 'antd/lib/table';
|
import Table, { ColumnsType } from 'antd/lib/table';
|
||||||
import getAll from 'api/alerts/getAll';
|
|
||||||
import TextToolTip from 'components/TextToolTip';
|
import TextToolTip from 'components/TextToolTip';
|
||||||
import ROUTES from 'constants/routes';
|
import ROUTES from 'constants/routes';
|
||||||
import useInterval from 'hooks/useInterval';
|
import useInterval from 'hooks/useInterval';
|
||||||
import history from 'lib/history';
|
import history from 'lib/history';
|
||||||
import React, { useCallback, useState } from 'react';
|
import React, { useCallback, useState } from 'react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { UseQueryResult } from 'react-query';
|
||||||
import { generatePath } from 'react-router-dom';
|
import { generatePath } from 'react-router-dom';
|
||||||
|
import { ErrorResponse, SuccessResponse } from 'types/api';
|
||||||
import { Alerts } from 'types/api/alerts/getAll';
|
import { Alerts } from 'types/api/alerts/getAll';
|
||||||
|
|
||||||
import DeleteAlert from './DeleteAlert';
|
import DeleteAlert from './DeleteAlert';
|
||||||
import { Button, ButtonContainer } from './styles';
|
import { Button, ButtonContainer } from './styles';
|
||||||
import Status from './TableComponents/Status';
|
import Status from './TableComponents/Status';
|
||||||
|
|
||||||
function ListAlert({ allAlertRules }: ListAlertProps): JSX.Element {
|
function ListAlert({ allAlertRules, refetch }: ListAlertProps): JSX.Element {
|
||||||
const [data, setData] = useState<Alerts[]>(allAlertRules || []);
|
const [data, setData] = useState<Alerts[]>(allAlertRules || []);
|
||||||
|
const { t } = useTranslation('common');
|
||||||
|
|
||||||
useInterval(() => {
|
useInterval(() => {
|
||||||
(async (): Promise<void> => {
|
(async (): Promise<void> => {
|
||||||
const { payload, statusCode } = await getAll();
|
const { data: refetchData, status } = await refetch();
|
||||||
|
if (status === 'success') {
|
||||||
if (statusCode === 200 && payload !== null) {
|
setData(refetchData?.payload || []);
|
||||||
setData(payload);
|
}
|
||||||
|
if (status === 'error') {
|
||||||
|
notification.error({
|
||||||
|
message: t('something_went_wrong'),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}, 30000);
|
}, 30000);
|
||||||
@ -148,6 +155,7 @@ function ListAlert({ allAlertRules }: ListAlertProps): JSX.Element {
|
|||||||
|
|
||||||
interface ListAlertProps {
|
interface ListAlertProps {
|
||||||
allAlertRules: Alerts[];
|
allAlertRules: Alerts[];
|
||||||
|
refetch: UseQueryResult<ErrorResponse | SuccessResponse<Alerts[]>>['refetch'];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ListAlert;
|
export default ListAlert;
|
||||||
|
@ -8,8 +8,9 @@ import ListAlert from './ListAlert';
|
|||||||
|
|
||||||
function ListAlertRules(): JSX.Element {
|
function ListAlertRules(): JSX.Element {
|
||||||
const { t } = useTranslation('common');
|
const { t } = useTranslation('common');
|
||||||
const { data, isError, isLoading } = useQuery('allAlerts', {
|
const { data, isError, isLoading, refetch } = useQuery('allAlerts', {
|
||||||
queryFn: getAll,
|
queryFn: getAll,
|
||||||
|
cacheTime: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isError) {
|
if (isError) {
|
||||||
@ -24,6 +25,7 @@ function ListAlertRules(): JSX.Element {
|
|||||||
<ListAlert
|
<ListAlert
|
||||||
{...{
|
{...{
|
||||||
allAlertRules: data.payload,
|
allAlertRules: data.payload,
|
||||||
|
refetch,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user