Skip to content

Commit 3bd2e27

Browse files
XavierMcnasikas
authored andcommitted
make show timeline more generic so we can re-use if need it
1 parent 5c6407a commit 3bd2e27

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

x-pack/legacy/plugins/siem/public/pages/home/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { AutoSaveWarningMsg } from '../../components/timeline/auto_save_warning'
2121
import { UseUrlState } from '../../components/url_state';
2222
import { WithSource, indicesExistOrDataTemporarilyUnavailable } from '../../containers/source';
2323
import { SpyRoute } from '../../utils/route/spy_routes';
24+
import { useShowTimeline } from '../../utils/timeline/use_show_timeline';
2425
import { NotFoundPage } from '../404';
2526
import { DetectionEngineContainer } from '../detection_engine';
2627
import { HostsContainer } from '../hosts';
@@ -68,7 +69,7 @@ export const HomePage: React.FC = () => {
6869
windowHeight,
6970
});
7071

71-
const currentLocation = useLocation();
72+
const [showTimeline] = useShowTimeline();
7273

7374
return (
7475
<WrappedByAutoSizer data-test-subj="wrapped-by-auto-sizer" ref={measureRef}>
@@ -79,7 +80,7 @@ export const HomePage: React.FC = () => {
7980
{({ browserFields, indexPattern, indicesExist }) => (
8081
<DragDropContextWrapper browserFields={browserFields}>
8182
<UseUrlState indexPattern={indexPattern} navTabs={navTabs} />
82-
{indicesExistOrDataTemporarilyUnavailable(indicesExist) && (
83+
{indicesExistOrDataTemporarilyUnavailable(indicesExist) && showTimeline && (
8384
<>
8485
<AutoSaveWarningMsg />
8586
<Flyout
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { useLocation } from 'react-router-dom';
8+
9+
import { useState, useEffect } from 'react';
10+
import { SiemPageName } from '../../pages/home/types';
11+
12+
const hideTimelineForRoutes = [`/${SiemPageName.case}/configure`];
13+
14+
export const useShowTimeline = () => {
15+
const currentLocation = useLocation();
16+
const [showTimeline, setShowTimeline] = useState(
17+
!hideTimelineForRoutes.includes(currentLocation.pathname)
18+
);
19+
20+
useEffect(() => {
21+
if (hideTimelineForRoutes.includes(currentLocation.pathname)) {
22+
if (showTimeline) {
23+
setShowTimeline(false);
24+
}
25+
} else if (!showTimeline) {
26+
setShowTimeline(true);
27+
}
28+
}, [currentLocation.pathname]);
29+
30+
return [showTimeline];
31+
};

0 commit comments

Comments
 (0)