fix: logs time is fixed (#1772)

* fix: logs parsing is fixed

* fix: start and end time is updated
This commit is contained in:
Palash Gupta 2022-11-29 14:41:36 +05:30 committed by GitHub
parent 7e590f4bfb
commit 5ae9557293
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 16 deletions

View File

@ -1,3 +1,7 @@
import GetMinMax, { GetMinMaxPayload } from 'lib/getMinMax';
import { Time } from '../DateTimeSelection/config';
export const options: IOptions[] = [ export const options: IOptions[] = [
{ {
label: 'off', label: 'off',
@ -61,3 +65,12 @@ export interface IOptions {
key: string; key: string;
value: number; value: number;
} }
export const getMinMax = (
selectedTime: Time,
minTime: number,
maxTime: number,
): GetMinMaxPayload =>
selectedTime !== 'custom'
? GetMinMax(selectedTime)
: GetMinMax(selectedTime, [minTime, maxTime]);

View File

@ -12,7 +12,6 @@ import { CheckboxChangeEvent } from 'antd/lib/checkbox';
import get from 'api/browser/localstorage/get'; import get from 'api/browser/localstorage/get';
import set from 'api/browser/localstorage/set'; import set from 'api/browser/localstorage/set';
import { DASHBOARD_TIME_IN_DURATION } from 'constants/app'; import { DASHBOARD_TIME_IN_DURATION } from 'constants/app';
import dayjs from 'dayjs';
import useUrlQuery from 'hooks/useUrlQuery'; import useUrlQuery from 'hooks/useUrlQuery';
import _omit from 'lodash-es/omit'; import _omit from 'lodash-es/omit';
import React, { useCallback, useEffect, useMemo, useState } from 'react'; import React, { useCallback, useEffect, useMemo, useState } from 'react';
@ -28,21 +27,19 @@ import {
} from 'types/actions/globalTime'; } from 'types/actions/globalTime';
import { GlobalReducer } from 'types/reducer/globalTime'; import { GlobalReducer } from 'types/reducer/globalTime';
import { options } from './config'; import { getMinMax, options } from './config';
import { ButtonContainer, Container } from './styles'; import { ButtonContainer, Container } from './styles';
function AutoRefresh({ disabled = false }: AutoRefreshProps): JSX.Element { function AutoRefresh({ disabled = false }: AutoRefreshProps): JSX.Element {
const { const globalTime = useSelector<AppState, GlobalReducer>(
minTime: initialMinTime, (state) => state.globalTime,
selectedTime, );
isAutoRefreshDisabled,
} = useSelector<AppState, GlobalReducer>((state) => state.globalTime);
const { pathname } = useLocation(); const { pathname } = useLocation();
const isDisabled = useMemo(() => disabled || isAutoRefreshDisabled, [ const isDisabled = useMemo(
isAutoRefreshDisabled, () => disabled || globalTime.isAutoRefreshDisabled,
disabled, [globalTime.isAutoRefreshDisabled, disabled],
]); );
const localStorageData = JSON.parse(get(DASHBOARD_TIME_IN_DURATION) || '{}'); const localStorageData = JSON.parse(get(DASHBOARD_TIME_IN_DURATION) || '{}');
@ -89,14 +86,18 @@ function AutoRefresh({ disabled = false }: AutoRefreshProps): JSX.Element {
} }
if (selectedOption !== 'off' && selectedValue) { if (selectedOption !== 'off' && selectedValue) {
const min = initialMinTime / 1000000; const { maxTime, minTime } = getMinMax(
globalTime.selectedTime,
globalTime.minTime,
globalTime.maxTime,
);
dispatch({ dispatch({
type: UPDATE_TIME_INTERVAL, type: UPDATE_TIME_INTERVAL,
payload: { payload: {
maxTime: dayjs().valueOf() * 1000000, maxTime,
minTime: dayjs(min).subtract(selectedValue, 'second').valueOf() * 1000000, minTime,
selectedTime, selectedTime: globalTime.selectedTime,
}, },
}); });
} }

View File

@ -53,7 +53,7 @@ const GetMinMax = (
}; };
}; };
interface GetMinMaxPayload { export interface GetMinMaxPayload {
minTime: GlobalReducer['minTime']; minTime: GlobalReducer['minTime'];
maxTime: GlobalReducer['maxTime']; maxTime: GlobalReducer['maxTime'];
} }