Skip to content

Commit

Permalink
fix: fix the issue of alert history breaking on navigating back from …
Browse files Browse the repository at this point in the history
…selected time range
  • Loading branch information
ahmadshaheer committed Sep 27, 2024
1 parent 57822a0 commit 584bad3
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions frontend/src/pages/AlertDetails/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import AlertHistory from 'container/AlertHistory';
import { TIMELINE_TABLE_PAGE_SIZE } from 'container/AlertHistory/constants';
import { AlertDetailsTab, TimelineFilter } from 'container/AlertHistory/types';
import { urlKey } from 'container/AllError/utils';
import { RelativeTimeMap } from 'container/TopNav/DateTimeSelection/config';
import useAxiosError from 'hooks/useAxiosError';
import { useNotifications } from 'hooks/useNotifications';
import useUrlQuery from 'hooks/useUrlQuery';
Expand All @@ -31,9 +32,7 @@ import PaginationInfoText from 'periscope/components/PaginationInfoText/Paginati
import { useAlertRule } from 'providers/Alert';
import { useCallback, useMemo } from 'react';
import { useMutation, useQuery, useQueryClient } from 'react-query';
import { useSelector } from 'react-redux';
import { generatePath, useLocation } from 'react-router-dom';
import { AppState } from 'store/reducers';
import { ErrorResponse, SuccessResponse } from 'types/api';
import {
AlertDef,
Expand All @@ -44,7 +43,6 @@ import {
AlertRuleTopContributorsPayload,
} from 'types/api/alerts/def';
import { PayloadProps } from 'types/api/alerts/get';
import { GlobalReducer } from 'types/reducer/globalTime';
import { nanoToMilli } from 'utils/timeUtils';

export const useAlertHistoryQueryParams = (): {
Expand All @@ -56,11 +54,10 @@ export const useAlertHistoryQueryParams = (): {
} => {
const params = useUrlQuery();

const globalTime = useSelector<AppState, GlobalReducer>(
(state) => state.globalTime,
);
const startTime = params.get(QueryParams.startTime);
const endTime = params.get(QueryParams.endTime);
const relativeTime =
params.get(QueryParams.relativeTime) ?? RelativeTimeMap['6hr'];

const intStartTime = parseInt(startTime || '0', 10);
const intEndTime = parseInt(endTime || '0', 10);
Expand All @@ -69,8 +66,8 @@ export const useAlertHistoryQueryParams = (): {
const { maxTime, minTime } = useMemo(() => {
if (hasStartAndEndParams)
return GetMinMax('custom', [intStartTime, intEndTime]);
return GetMinMax(globalTime.selectedTime);
}, [hasStartAndEndParams, intStartTime, intEndTime, globalTime.selectedTime]);
return GetMinMax(relativeTime);
}, [hasStartAndEndParams, intStartTime, intEndTime, relativeTime]);

const ruleId = params.get(QueryParams.ruleId);

Expand Down

0 comments on commit 584bad3

Please sign in to comment.