Skip to content

Commit

Permalink
add indexToAdd for Resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierM committed Jul 14, 2020
1 parent 1c5b3d3 commit dc0d03e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
}
}, [defaultFilters, filterGroup]);
const { filterManager } = useKibana().services.data.query;
const { initializeTimeline, setTimelineRowActions } = useManageTimeline();
const { initializeTimeline, setTimelineRowActions, setIndexToAdd } = useManageTimeline();

useEffect(() => {
initializeTimeline({
Expand All @@ -375,13 +375,15 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
filterManager,
footerText: i18n.TOTAL_COUNT_OF_ALERTS,
id: timelineId,
indexToAdd: defaultIndices,
loadingText: i18n.LOADING_ALERTS,
selectAll: canUserCRUD ? selectAll : false,
timelineRowActions: () => [getInvestigateInResolverAction({ dispatch, timelineId })],
title: '',
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
setTimelineRowActions({
id: timelineId,
Expand All @@ -390,6 +392,11 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [additionalActions]);

useEffect(() => {
setIndexToAdd({ id: timelineId, indexToAdd: defaultIndices });
}, [timelineId, defaultIndices, setIndexToAdd]);

const headerFilterGroup = useMemo(
() => <AlertsTableFilterGroup onFilterGroupChanged={onFilterGroupChangedCallback} />,
[onFilterGroupChangedCallback]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const reducerManageTimeline = (
};

interface UseTimelineManager {
getIndexToAddById: (id: string) => string[] | null;
getManageTimelineById: (id: string) => ManageTimeline;
getTimelineFilterManager: (id: string) => FilterManager | undefined;
initializeTimeline: (newTimeline: ManageTimelineInit) => void;
Expand Down Expand Up @@ -216,9 +217,19 @@ const useTimelineManager = (manageTimelineForTesting?: ManageTimelineById): UseT
},
[initializeTimeline, state]
);
const getIndexToAddById = useCallback(
(id: string): string[] | null => {
if (state[id] != null) {
return state[id].indexToAdd;
}
return getTimelineDefaults(id).indexToAdd;
},
[state]
);
const isManagedTimeline = useCallback((id: string): boolean => state[id] != null, [state]);

return {
getIndexToAddById,
getManageTimelineById,
getTimelineFilterManager,
initializeTimeline,
Expand All @@ -231,6 +242,7 @@ const useTimelineManager = (manageTimelineForTesting?: ManageTimelineById): UseT

const init = {
getManageTimelineById: (id: string) => getTimelineDefaults(id),
getIndexToAddById: (id: string) => null,
getTimelineFilterManager: () => undefined,
setIndexToAdd: () => undefined,
isManagedTimeline: () => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const Body = React.memo<BodyProps>(
updateNote,
}) => {
const containerElementRef = useRef<HTMLDivElement>(null);
const { getManageTimelineById } = useManageTimeline();
const { getManageTimelineById, getIndexToAddById } = useManageTimeline();
const timelineActions = useMemo(
() =>
data.reduce((acc: TimelineRowAction[], rowData) => {
Expand Down Expand Up @@ -152,6 +152,7 @@ export const Body = React.memo<BodyProps>(
<GraphOverlay
bodyHeight={height}
graphEventId={graphEventId}
indexToAdd={getIndexToAddById(id) ?? []}
timelineId={id}
timelineType={timelineType}
/>
Expand Down

0 comments on commit dc0d03e

Please sign in to comment.