Skip to content

Commit

Permalink
Fix explore tables don't display data when a global filter is applied (
Browse files Browse the repository at this point in the history
  • Loading branch information
machadoum authored Apr 13, 2022
1 parent 35d575c commit 3877763
Showing 1 changed file with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { set } from '@elastic/safer-lodash-set/fp';
import { getOr } from 'lodash/fp';
import React, { memo, useEffect, useCallback, useMemo } from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { connect, ConnectedProps, useDispatch } from 'react-redux';
import { Dispatch } from 'redux';
import { Subscription } from 'rxjs';
import styled from 'styled-components';
Expand All @@ -35,10 +35,11 @@ import {
startSelector,
toStrSelector,
} from './selectors';
import { hostsActions } from '../../../hosts/store';
import { networkActions } from '../../../network/store';
import { timelineActions } from '../../../timelines/store/timeline';
import { useKibana } from '../../lib/kibana';
import { usersActions } from '../../../users/store';
import { hostsActions } from '../../../hosts/store';
import { networkActions } from '../../../network/store';

const APP_STATE_STORAGE_KEY = 'securitySolution.searchBar.appState';

Expand Down Expand Up @@ -91,16 +92,25 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
},
} = useKibana().services;

const dispatch = useDispatch();
const setTablesActivePageToZero = useCallback(() => {
dispatch(usersActions.setUsersTablesActivePageToZero());
dispatch(hostsActions.setHostTablesActivePageToZero());
dispatch(networkActions.setNetworkTablesActivePageToZero());
}, [dispatch]);

useEffect(() => {
if (fromStr != null && toStr != null) {
timefilter.setTime({ from: fromStr, to: toStr });
} else if (start != null && end != null) {
setTablesActivePageToZero();

timefilter.setTime({
from: new Date(start).toISOString(),
to: new Date(end).toISOString(),
});
}
}, [end, fromStr, start, timefilter, toStr]);
}, [end, fromStr, start, timefilter, toStr, setTablesActivePageToZero]);

const onQuerySubmit = useCallback(
(payload: { dateRange: TimeRange; query?: Query }) => {
Expand All @@ -119,6 +129,7 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
isQuickSelection,
updateTime: false,
filterManager,
setTablesActivePageToZero,
};
let isStateUpdated = false;

Expand Down Expand Up @@ -164,6 +175,7 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
filterQuery,
queries,
updateSearch,
setTablesActivePageToZero,
]
);

Expand All @@ -178,12 +190,13 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
isQuickSelection: true,
updateTime: true,
filterManager,
setTablesActivePageToZero,
});
} else {
queries.forEach((q) => q.refetch && (q.refetch as inputsModel.Refetch)());
}
},
[updateSearch, id, filterManager, queries]
[updateSearch, id, filterManager, queries, setTablesActivePageToZero]
);

const onSaved = useCallback(
Expand All @@ -209,6 +222,7 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
isQuickSelection,
updateTime: false,
filterManager,
setTablesActivePageToZero,
};

if (savedQueryUpdated.attributes.timefilter) {
Expand All @@ -226,7 +240,7 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(

updateSearch(updateSearchBar);
},
[id, toStr, end, fromStr, start, filterManager, updateSearch]
[id, toStr, end, fromStr, start, filterManager, updateSearch, setTablesActivePageToZero]
);

const onClearSavedQuery = useCallback(() => {
Expand All @@ -246,9 +260,20 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
resetSavedQuery: true,
savedQuery: undefined,
filterManager,
setTablesActivePageToZero,
});
}
}, [savedQuery, updateSearch, id, toStr, end, fromStr, start, filterManager]);
}, [
savedQuery,
updateSearch,
id,
toStr,
end,
fromStr,
start,
filterManager,
setTablesActivePageToZero,
]);

const saveAppStateToStorage = useCallback(
(filters: Filter[]) => storage.set(APP_STATE_STORAGE_KEY, filters),
Expand All @@ -273,6 +298,8 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
id,
filters: filterManager.getFilters(),
});

setTablesActivePageToZero();
}
},
})
Expand Down Expand Up @@ -369,6 +396,7 @@ interface UpdateReduxSearchBar extends OnTimeChangeProps {
resetSavedQuery?: boolean;
timelineId?: string;
updateTime: boolean;
setTablesActivePageToZero: () => void;
}

export const dispatchUpdateSearch =
Expand All @@ -385,6 +413,7 @@ export const dispatchUpdateSearch =
timelineId,
filterManager,
updateTime = false,
setTablesActivePageToZero,
}: UpdateReduxSearchBar): void => {
if (updateTime) {
const fromDate = formatDate(start);
Expand Down Expand Up @@ -446,8 +475,7 @@ export const dispatchUpdateSearch =
dispatch(inputsActions.setSavedQuery({ id, savedQuery }));
}

dispatch(hostsActions.setHostTablesActivePageToZero());
dispatch(networkActions.setNetworkTablesActivePageToZero());
setTablesActivePageToZero();
};

const mapDispatchToProps = (dispatch: Dispatch) => ({
Expand Down

0 comments on commit 3877763

Please sign in to comment.