Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const AlertViewSubHeader: FunctionComponent<AlertViewSubHeaderProps> = ({
const getAlertInsightQuery = useFetchQuery({
queryKey: ["alertInsight", alert.id],
queryFn: () => {
return getAlertInsight({ alertId: alert.id });
return getAlertInsight({ alert });
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ import {
useNotificationProviderV1,
} from "../../platform/components";
import { ActionStatus } from "../../rest/actions.interfaces";
import {
useGetAlertInsight,
useResetAlert,
} from "../../rest/alerts/alerts.actions";
import { useResetAlert } from "../../rest/alerts/alerts.actions";
import {
getAlert,
getAlertStats,
Expand Down Expand Up @@ -97,7 +94,6 @@ export const AlertsViewPage: FunctionComponent = () => {
useState<NotificationV1 | null>(null);
const [resetStatusNotification, setResetStatusNotification] =
useState<NotificationV1 | null>(null);
const { alertInsight, getAlertInsight } = useGetAlertInsight();
const [taskStatusLoading, setTaskStatusLoading] = useState(false);

const [searchParams, setSearchParams] = useSearchParams();
Expand Down Expand Up @@ -153,7 +149,6 @@ export const AlertsViewPage: FunctionComponent = () => {
getAlertQuery.refetch();
getEnumerationItemsQuery.refetch();
getAnomaliesQuery.refetch();
getAlertInsight({ alertId: Number(alertId) });
fetchStats();
setNextAttemptTime(0);
}
Expand All @@ -172,7 +167,6 @@ export const AlertsViewPage: FunctionComponent = () => {
getAlertQuery.refetch();
getEnumerationItemsQuery.refetch();
getAnomaliesQuery.refetch();
getAlertInsight({ alertId: Number(alertId) });
fetchStats();
setNextAttemptTime(0);
}
Expand Down Expand Up @@ -239,26 +233,6 @@ export const AlertsViewPage: FunctionComponent = () => {
[searchParams]
);

useEffect(() => {
getAlertInsight({ alertId: Number(alertId) });
}, []);

useEffect(() => {
if (
!alertInsight?.analysisRunInfo?.success &&
alertInsight?.analysisRunInfo?.message
) {
notifyIfErrors(
ActionStatus.Error,
[{ message: alertInsight.analysisRunInfo.message }],
notify,
t("message.error-while-fetching", {
entity: t("label.alert-insight"),
})
);
}
}, [alertInsight?.analysisRunInfo]);

const fetchStats = (): void => {
getAlertStats({
alertId: Number(alertId),
Expand Down
4 changes: 4 additions & 0 deletions thirdeye-ui/src/app/routers/alerts/alerts.router.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { MemoryRouter, Route, Routes } from "react-router-dom";
import { AppLoadingIndicatorV1 } from "../../platform/components/app-loading-indicator-v1/app-loading-indicator-v1.component";
import { AppRoute, AppRouteRelative } from "../../utils/routes/routes.util";
import { AlertsRouter } from "./alerts.router";
import axios from "axios";

jest.mock("react-i18next", () => ({
useTranslation: jest.fn().mockReturnValue({
Expand Down Expand Up @@ -133,6 +134,9 @@ describe("Alerts Router", () => {
});

it("should render alerts view page at exact alerts view path", async () => {
jest.spyOn(axios, "get").mockResolvedValueOnce({
data: {},
});
render(
<MemoryRouter initialEntries={[`/alerts/1234`]}>
<Routes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import {
TimeRangeQueryStringKey,
} from "../../../components/time-range/time-range-provider/time-range-provider.interfaces";
import { AppLoadingIndicatorV1 } from "../../../platform/components";
import { useGetAlertInsight } from "../../../rest/alerts/alerts.actions";
import {
useGetAlert,
useGetAlertInsight,
} from "../../../rest/alerts/alerts.actions";
import { useLastUsedSearchParams } from "../../../stores/last-used-params/last-used-search-params.store";
import { AlertFetchRedirectParamsProps } from "./alert-fetch-redirect-params.interfaces";

Expand All @@ -34,21 +37,24 @@ export const AlertFetchRedirectParams: FunctionComponent<AlertFetchRedirectParam
const [isLoading, setIsLoading] = useState(true);
const { id: alertId } = useParams();
const { alertInsight, getAlertInsight } = useGetAlertInsight();
const { alert, getAlert } = useGetAlert();
const location = useLocation();
const navigate = useNavigate();
const [searchParams] = useSearchParams();
const { getLastUsedForPath } = useLastUsedSearchParams();
let searchString: string | undefined;

useEffect(() => {
if (alertId) {
getAlertInsight({ alertId: Number(alertId) }).finally(() =>
getAlert(Number(alertId));
}, [alertId]);

useEffect(() => {
if (alert) {
getAlertInsight({ alert: alert }).finally(() =>
setIsLoading(false)
);
} else {
setIsLoading(false);
}
}, []);
}, [alert]);

useEffect(() => {
if (isLoading) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ jest.mock(

describe("Alert Fetch Redirect Params", () => {
it("should have called navigate with the time range values in query string returned from API request", async () => {
jest.spyOn(axios, "get").mockResolvedValueOnce({
data: {},
});
jest.spyOn(axios, "post").mockResolvedValueOnce({
data: {
defaultStartTime: 10,
Expand All @@ -72,6 +75,9 @@ describe("Alert Fetch Redirect Params", () => {
});

it("should have called navigate with the time range values from fallbackDurationGenerator in query string is API request fails", async () => {
jest.spyOn(axios, "get").mockResolvedValueOnce({
data: {},
});
jest.spyOn(axios, "post").mockRejectedValueOnce({
data: {},
});
Expand All @@ -93,7 +99,10 @@ describe("Alert Fetch Redirect Params", () => {
});

it("should have called navigate with the time range values in query string if there are no last used paths for key", async () => {
jest.spyOn(axios, "get").mockRejectedValueOnce({
jest.spyOn(axios, "get").mockResolvedValueOnce({
data: {},
});
jest.spyOn(axios, "post").mockRejectedValue({
data: {},
});
mockGetLastUsedForPath.mockReturnValue(undefined);
Expand Down
Loading