Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
praveen5959 committed Dec 3, 2024
1 parent 7e1e2da commit a54091c
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/components/Header/RefreshInterval.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import _ from 'lodash';
import { appStoreReducers, useAppStore } from '@/layouts/MainLayout/providers/AppProvider';

const { setRefreshInterval, getCleanStoreForRefetch } = logsStoreReducers;
const { setCleanAppStore } = appStoreReducers;
const { syncTimeRange } = appStoreReducers;
const RefreshInterval: FC = () => {
const [, setAppStore] = useAppStore((_store) => null);
const [refreshInterval, setLogsStore] = useLogsStore((store) => store.refreshInterval);
Expand All @@ -37,7 +37,7 @@ const RefreshInterval: FC = () => {
clearIntervalInstance();
if (refreshInterval !== null) {
const intervalId = setInterval(() => {
setAppStore(setCleanAppStore);
setAppStore(syncTimeRange);
setLogsStore(getCleanStoreForRefetch);
}, refreshInterval);
timerRef.current = intervalId;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Header/RefreshNow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import IconButton from '../Button/IconButton';
import { appStoreReducers, useAppStore } from '@/layouts/MainLayout/providers/AppProvider';

const { getCleanStoreForRefetch } = logsStoreReducers;
const { setCleanAppStore } = appStoreReducers;
const { syncTimeRange } = appStoreReducers;

const renderRefreshIcon = () => <IconReload size={px('1rem')} stroke={1.5} />;

Expand All @@ -15,7 +15,7 @@ const RefreshNow: FC = () => {
const [, setAppStore] = useAppStore((_store) => null);

const onRefresh = useCallback(() => {
setAppStore((store) => setCleanAppStore(store));
setAppStore((store) => syncTimeRange(store));
setLogsStore((store) => getCleanStoreForRefetch(store));
}, []);
return <IconButton size={38} renderIcon={renderRefreshIcon} onClick={onRefresh} tooltipLabel="Refresh now" />;
Expand Down
6 changes: 3 additions & 3 deletions src/layouts/MainLayout/providers/AppProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type AppStoreReducers = {
changeStream: (store: AppStore, stream: string) => ReducerOutput;
setUserRoles: (store: AppStore, roles: UserRoles | null) => ReducerOutput;
setshiftInterval: (store: AppStore, interval: number) => ReducerOutput;
setCleanAppStore: (store: AppStore) => ReducerOutput;
syncTimeRange: (store: AppStore) => ReducerOutput;
setUserSpecificStreams: (store: AppStore, userSpecficStreams: LogStreamData | null) => ReducerOutput;
setUserAccessMap: (store: AppStore, accessRoles: string[] | null) => ReducerOutput;
setStreamSpecificUserAccess: (store: AppStore, streamSpecificUserAccess: string[] | null) => ReducerOutput;
Expand Down Expand Up @@ -132,7 +132,7 @@ function getHTTPContext() {
return window.isSecureContext;
}
// reducers
const setCleanAppStore = (store: AppStore) => {
const syncTimeRange = (store: AppStore) => {
const { timeRange } = store;
const { interval, type } = timeRange;
const duration = _.find(FIXED_DURATIONS, (duration) => duration.milliseconds === timeRange.interval);
Expand Down Expand Up @@ -251,7 +251,7 @@ const appStoreReducers: AppStoreReducers = {
setSavedFilters,
setTimeRange,
setshiftInterval,
setCleanAppStore,
syncTimeRange,
applyQueryWithResetTime,
};

Expand Down
4 changes: 2 additions & 2 deletions src/pages/Stream/Views/Explore/LoadingViews.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import classes from '../../styles/Logs.module.css';
import { appStoreReducers, useAppStore } from '@/layouts/MainLayout/providers/AppProvider';

const { getCleanStoreForRefetch } = logsStoreReducers;
const { setCleanAppStore } = appStoreReducers;
const { syncTimeRange } = appStoreReducers;

export const ErrorView = (props: { message: string }) => {
const [, setLogsStore] = useLogsStore((_store) => null);
const [, setAppStore] = useAppStore((_store) => null);

const { message } = props;
const onRetry = useCallback(() => {
setAppStore((store) => setCleanAppStore(store));
setAppStore((store) => syncTimeRange(store));
setLogsStore((store) => getCleanStoreForRefetch(store));
}, []);
return (
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Stream/Views/Explore/useLogsFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useFetchCount } from '@/hooks/useQueryResult';
import { useStreamStore } from '../../providers/StreamProvider';

const { setCleanStoreForStreamChange } = logsStoreReducers;
const { setCleanAppStore } = appStoreReducers;
const { syncTimeRange } = appStoreReducers;

const useLogsFetcher = (props: { schemaLoading: boolean; infoLoading: boolean }) => {
const { schemaLoading, infoLoading } = props;
Expand All @@ -24,7 +24,7 @@ const useLogsFetcher = (props: { schemaLoading: boolean; infoLoading: boolean })
const showTable = hasContentLoaded && !hasNoData && !errorMessage;

useEffect(() => {
setAppStore(setCleanAppStore);
setAppStore(syncTimeRange);
setLogsStore(setCleanStoreForStreamChange);
}, [currentStream]);

Expand Down
4 changes: 2 additions & 2 deletions src/pages/Stream/components/Querier/SavedFiltersModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { useLocation } from 'react-router-dom';
const { toggleSavedFiltersModal, resetFilters, parseQuery, applySavedFilters, setAppliedFilterQuery } =
filterStoreReducers;
const { applyCustomQuery, updateSavedFilterId, getCleanStoreForRefetch } = logsStoreReducers;
const { setCleanAppStore, setTimeRange, applyQueryWithResetTime } = appStoreReducers;
const { syncTimeRange, setTimeRange, applyQueryWithResetTime } = appStoreReducers;

const renderDeleteIcon = () => <IconTrash size={px('1rem')} stroke={1.5} />;
const renderCloseIcon = () => <IconX size={px('1rem')} stroke={1.5} />;
Expand Down Expand Up @@ -229,7 +229,7 @@ const SavedFiltersModal = () => {
);

const hardRefresh = useCallback(() => {
setAppStore((store) => setCleanAppStore(store));
setAppStore((store) => syncTimeRange(store));
setLogsStore((store) => getCleanStoreForRefetch(store));
closeModal();
}, []);
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Stream/components/Querier/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const { setFields, parseQuery, storeAppliedQuery, resetFilters, toggleSubmitBtn,
const { toggleQueryBuilder, toggleCustQuerySearchViewMode, applyCustomQuery, resetCustQuerySearchState } =
logsStoreReducers;

const { applyQueryWithResetTime, setCleanAppStore } = appStoreReducers;
const { applyQueryWithResetTime, syncTimeRange } = appStoreReducers;

const getLabel = (mode: string | null) => {
return mode === 'filters' ? 'Filters' : mode === 'sql' ? 'SQL' : '';
Expand Down Expand Up @@ -183,7 +183,7 @@ const Querier = () => {

const onClear = useCallback(() => {
setFilterStore((store) => resetFilters(store));
setAppStore((store) => setCleanAppStore(store));
setAppStore((store) => syncTimeRange(store));
setLogsStore((store) => resetCustQuerySearchState(store));
}, []);

Expand Down
12 changes: 4 additions & 8 deletions src/pages/Stream/hooks/useParamsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { generateQueryBuilderASTFromSQL } from '../utils';
import { appStoreReducers, TimeRange, useAppStore } from '@/layouts/MainLayout/providers/AppProvider';

const { getRelativeStartAndEndDate, formatDateWithTimezone, getLocalTimezone } = timeRangeUtils;
const { onToggleView, setPerPage, setCustQuerySearchState, getCleanStoreForRefetch } = logsStoreReducers;
const { setTimeRange, setCleanAppStore } = appStoreReducers;
const { onToggleView, setPerPage, setCustQuerySearchState } = logsStoreReducers;
const { setTimeRange, syncTimeRange } = appStoreReducers;
const { applySavedFilters } = filterStoreReducers;
const timeRangeFormat = 'DD-MMM-YYYY_HH-mmz';
const keys = ['view', 'rows', 'interval', 'from', 'to', 'query', 'filterType'];
Expand Down Expand Up @@ -117,7 +117,7 @@ const useParamsController = () => {
}

if (storeAsParams.query !== presentParams.query) {
setAppStore((store) => setCleanAppStore(store));
setAppStore((store) => syncTimeRange(store));
setLogsStore((store) => setCustQuerySearchState(store, presentParams.query, presentParams.filterType));
if (presentParams.filterType === 'filters')
setFilterStore((store) =>
Expand Down Expand Up @@ -174,7 +174,7 @@ const useParamsController = () => {
setFilterStore((store) =>
applySavedFilters(store, generateQueryBuilderASTFromSQL(presentParams.query) as QueryType),
);
setAppStore((store) => setCleanAppStore(store));
setAppStore((store) => syncTimeRange(store));
setLogsStore((store) => setCustQuerySearchState(store, presentParams.query, presentParams.filterType));
}
syncTimeRangeToStore(storeAsParams, presentParams);
Expand All @@ -188,17 +188,13 @@ const useParamsController = () => {
if (!duration) return;

const { startTime, endTime } = getRelativeStartAndEndDate(duration);
setAppStore((store) => setCleanAppStore(store));
setLogsStore((store) => getCleanStoreForRefetch(store));
return setAppStore((store) => setTimeRange(store, { startTime, endTime, type: 'fixed' }));
}
} else if (_.has(presentParams, 'from') && _.has(presentParams, 'to')) {
if (storeAsParams.from !== presentParams.from && storeAsParams.to !== presentParams.to) {
const startTime = dateParamStrToDateObj(presentParams.from);
const endTime = dateParamStrToDateObj(presentParams.to);
if (_.isDate(startTime) && _.isDate(endTime)) {
setAppStore((store) => setCleanAppStore(store));
setLogsStore((store) => getCleanStoreForRefetch(store));
return setAppStore((store) =>
setTimeRange(store, { startTime: dayjs(startTime), endTime: dayjs(endTime), type: 'custom' }),
);
Expand Down

0 comments on commit a54091c

Please sign in to comment.