Skip to content

Commit 6d10ca8

Browse files
[SIEM] Fix Timeline footer styling (#59587) (#60362)
1 parent 8665978 commit 6d10ca8

File tree

99 files changed

+2306
-3190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+2306
-3190
lines changed

x-pack/legacy/plugins/siem/cypress/integration/timeline_data_providers.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('timeline data providers', () => {
4949
.first()
5050
.invoke('text')
5151
.should(hostname => {
52-
expect(dataProviderText).to.eq(`host.name: "${hostname}"`);
52+
expect(dataProviderText).to.eq(hostname);
5353
});
5454
});
5555
});

x-pack/legacy/plugins/siem/cypress/integration/timeline_flyout_button.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { TIMELINE_FLYOUT_BODY, TIMELINE_NOT_READY_TO_DROP_BUTTON } from '../screens/timeline';
7+
import { TIMELINE_FLYOUT_HEADER, TIMELINE_NOT_READY_TO_DROP_BUTTON } from '../screens/timeline';
88

99
import { dragFirstHostToTimeline, waitForAllHostsToBeLoaded } from '../tasks/hosts/all_hosts';
1010
import { loginAndWaitForPage } from '../tasks/login';
@@ -26,7 +26,7 @@ describe('timeline flyout button', () => {
2626

2727
it('toggles open the timeline', () => {
2828
openTimeline();
29-
cy.get(TIMELINE_FLYOUT_BODY).should('have.css', 'visibility', 'visible');
29+
cy.get(TIMELINE_FLYOUT_HEADER).should('have.css', 'visibility', 'visible');
3030
});
3131

3232
// FLAKY: https://github.com/elastic/kibana/issues/60369

x-pack/legacy/plugins/siem/cypress/screens/timeline.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export const TIMELINE_DROPPED_DATA_PROVIDERS = '[data-test-subj="providerContain
3131
export const TIMELINE_FIELDS_BUTTON =
3232
'[data-test-subj="timeline"] [data-test-subj="show-field-browser"]';
3333

34+
export const TIMELINE_FLYOUT_HEADER = '[data-test-subj="eui-flyout-header"]';
35+
3436
export const TIMELINE_FLYOUT_BODY = '[data-test-subj="eui-flyout-body"]';
3537

3638
export const TIMELINE_INSPECT_BUTTON = '[data-test-subj="inspect-empty-button"]';

x-pack/legacy/plugins/siem/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"devDependencies": {
1515
"@types/lodash": "^4.14.110",
1616
"@types/js-yaml": "^3.12.1",
17-
"@types/react-beautiful-dnd": "^11.0.4"
17+
"@types/react-beautiful-dnd": "^12.1.1"
1818
},
1919
"dependencies": {
2020
"lodash": "^4.17.15",

x-pack/legacy/plugins/siem/public/components/charts/areachart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import {
1616
RecursivePartial,
1717
} from '@elastic/charts';
1818
import { getOr, get, isNull, isNumber } from 'lodash/fp';
19-
import useResizeObserver from 'use-resize-observer/polyfilled';
2019

20+
import { useThrottledResizeObserver } from '../utils';
2121
import { ChartPlaceHolder } from './chart_place_holder';
2222
import { useTimeZone } from '../../lib/kibana';
2323
import {
@@ -131,7 +131,7 @@ interface AreaChartComponentProps {
131131
}
132132

133133
export const AreaChartComponent: React.FC<AreaChartComponentProps> = ({ areaChart, configs }) => {
134-
const { ref: measureRef, width, height } = useResizeObserver<HTMLDivElement>({});
134+
const { ref: measureRef, width, height } = useThrottledResizeObserver();
135135
const customHeight = get('customHeight', configs);
136136
const customWidth = get('customWidth', configs);
137137
const chartHeight = getChartHeight(customHeight, height);

x-pack/legacy/plugins/siem/public/components/charts/barchart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import React from 'react';
88
import { Chart, BarSeries, Axis, Position, ScaleType, Settings } from '@elastic/charts';
99
import { getOr, get, isNumber } from 'lodash/fp';
1010
import deepmerge from 'deepmerge';
11-
import useResizeObserver from 'use-resize-observer/polyfilled';
1211

12+
import { useThrottledResizeObserver } from '../utils';
1313
import { useTimeZone } from '../../lib/kibana';
1414
import { ChartPlaceHolder } from './chart_place_holder';
1515
import {
@@ -105,7 +105,7 @@ interface BarChartComponentProps {
105105
}
106106

107107
export const BarChartComponent: React.FC<BarChartComponentProps> = ({ barChart, configs }) => {
108-
const { ref: measureRef, width, height } = useResizeObserver<HTMLDivElement>({});
108+
const { ref: measureRef, width, height } = useThrottledResizeObserver();
109109
const customHeight = get('customHeight', configs);
110110
const customWidth = get('customWidth', configs);
111111
const chartHeight = getChartHeight(customHeight, height);

x-pack/legacy/plugins/siem/public/components/drag_and_drop/drag_drop_context_wrapper.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { defaultTo, noop } from 'lodash/fp';
7+
import { noop } from 'lodash/fp';
88
import React, { useCallback } from 'react';
99
import { DropResult, DragDropContext } from 'react-beautiful-dnd';
1010
import { connect, ConnectedProps } from 'react-redux';
@@ -103,10 +103,7 @@ DragDropContextWrapperComponent.displayName = 'DragDropContextWrapperComponent';
103103
const emptyDataProviders: dragAndDropModel.IdToDataProvider = {}; // stable reference
104104

105105
const mapStateToProps = (state: State) => {
106-
const dataProviders = defaultTo(
107-
emptyDataProviders,
108-
dragAndDropSelectors.dataProvidersSelector(state)
109-
);
106+
const dataProviders = dragAndDropSelectors.dataProvidersSelector(state) ?? emptyDataProviders;
110107

111108
return { dataProviders };
112109
};

x-pack/legacy/plugins/siem/public/components/drag_and_drop/draggable_wrapper.test.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,9 @@ describe('DraggableWrapper', () => {
8888
describe('ConditionalPortal', () => {
8989
const mount = useMountAppended();
9090
const props = {
91-
usePortal: false,
9291
registerProvider: jest.fn(),
93-
isDragging: true,
9492
};
9593

96-
it(`doesn't call registerProvider is NOT isDragging`, () => {
97-
mount(
98-
<ConditionalPortal {...props} isDragging={false}>
99-
<div />
100-
</ConditionalPortal>
101-
);
102-
103-
expect(props.registerProvider.mock.calls.length).toEqual(0);
104-
});
105-
10694
it('calls registerProvider when isDragging', () => {
10795
mount(
10896
<ConditionalPortal {...props}>

x-pack/legacy/plugins/siem/public/components/drag_and_drop/draggable_wrapper.tsx

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import React, { createContext, useCallback, useContext, useEffect, useState } from 'react';
7+
import React, { useCallback, useEffect, useState } from 'react';
88
import {
99
Draggable,
1010
DraggableProvided,
@@ -15,7 +15,6 @@ import { useDispatch } from 'react-redux';
1515
import styled from 'styled-components';
1616
import deepEqual from 'fast-deep-equal';
1717

18-
import { EuiPortal } from '@elastic/eui';
1918
import { dragAndDropActions } from '../../store/drag_and_drop';
2019
import { DataProvider } from '../timeline/data_providers/data_provider';
2120
import { TruncatableText } from '../truncatable_text';
@@ -27,9 +26,6 @@ export const DragEffects = styled.div``;
2726

2827
DragEffects.displayName = 'DragEffects';
2928

30-
export const DraggablePortalContext = createContext<boolean>(false);
31-
export const useDraggablePortalContext = () => useContext(DraggablePortalContext);
32-
3329
/**
3430
* Wraps the `react-beautiful-dnd` error boundary. See also:
3531
* https://github.com/atlassian/react-beautiful-dnd/blob/v12.0.0/docs/guides/setup-problem-detection-and-error-recovery.md
@@ -89,7 +85,6 @@ export const DraggableWrapper = React.memo<Props>(
8985
({ dataProvider, render, truncate }) => {
9086
const [providerRegistered, setProviderRegistered] = useState(false);
9187
const dispatch = useDispatch();
92-
const usePortal = useDraggablePortalContext();
9388

9489
const registerProvider = useCallback(() => {
9590
if (!providerRegistered) {
@@ -113,7 +108,26 @@ export const DraggableWrapper = React.memo<Props>(
113108
return (
114109
<Wrapper data-test-subj="draggableWrapperDiv">
115110
<DragDropErrorBoundary>
116-
<Droppable isDropDisabled={true} droppableId={getDroppableId(dataProvider.id)}>
111+
<Droppable
112+
isDropDisabled={true}
113+
droppableId={getDroppableId(dataProvider.id)}
114+
renderClone={(provided, snapshot) => (
115+
<ConditionalPortal registerProvider={registerProvider}>
116+
<div
117+
{...provided.draggableProps}
118+
{...provided.dragHandleProps}
119+
ref={provided.innerRef}
120+
data-test-subj="providerContainer"
121+
>
122+
<ProviderContentWrapper
123+
data-test-subj={`draggable-content-${dataProvider.queryMatch.field}`}
124+
>
125+
{render(dataProvider, provided, snapshot)}
126+
</ProviderContentWrapper>
127+
</div>
128+
</ConditionalPortal>
129+
)}
130+
>
117131
{droppableProvided => (
118132
<div ref={droppableProvided.innerRef} {...droppableProvided.droppableProps}>
119133
<Draggable
@@ -122,35 +136,26 @@ export const DraggableWrapper = React.memo<Props>(
122136
key={getDraggableId(dataProvider.id)}
123137
>
124138
{(provided, snapshot) => (
125-
<ConditionalPortal
139+
<ProviderContainer
140+
{...provided.draggableProps}
141+
{...provided.dragHandleProps}
142+
ref={provided.innerRef}
143+
data-test-subj="providerContainer"
126144
isDragging={snapshot.isDragging}
127145
registerProvider={registerProvider}
128-
usePortal={snapshot.isDragging && usePortal}
129146
>
130-
<ProviderContainer
131-
{...provided.draggableProps}
132-
{...provided.dragHandleProps}
133-
ref={provided.innerRef}
134-
data-test-subj="providerContainer"
135-
isDragging={snapshot.isDragging}
136-
registerProvider={registerProvider}
137-
style={{
138-
...provided.draggableProps.style,
139-
}}
140-
>
141-
{truncate && !snapshot.isDragging ? (
142-
<TruncatableText data-test-subj="draggable-truncatable-content">
143-
{render(dataProvider, provided, snapshot)}
144-
</TruncatableText>
145-
) : (
146-
<ProviderContentWrapper
147-
data-test-subj={`draggable-content-${dataProvider.queryMatch.field}`}
148-
>
149-
{render(dataProvider, provided, snapshot)}
150-
</ProviderContentWrapper>
151-
)}
152-
</ProviderContainer>
153-
</ConditionalPortal>
147+
{truncate && !snapshot.isDragging ? (
148+
<TruncatableText data-test-subj="draggable-truncatable-content">
149+
{render(dataProvider, provided, snapshot)}
150+
</TruncatableText>
151+
) : (
152+
<ProviderContentWrapper
153+
data-test-subj={`draggable-content-${dataProvider.queryMatch.field}`}
154+
>
155+
{render(dataProvider, provided, snapshot)}
156+
</ProviderContentWrapper>
157+
)}
158+
</ProviderContainer>
154159
)}
155160
</Draggable>
156161
{droppableProvided.placeholder}
@@ -178,20 +183,16 @@ DraggableWrapper.displayName = 'DraggableWrapper';
178183

179184
interface ConditionalPortalProps {
180185
children: React.ReactNode;
181-
usePortal: boolean;
182-
isDragging: boolean;
183186
registerProvider: () => void;
184187
}
185188

186189
export const ConditionalPortal = React.memo<ConditionalPortalProps>(
187-
({ children, usePortal, registerProvider, isDragging }) => {
190+
({ children, registerProvider }) => {
188191
useEffect(() => {
189-
if (isDragging) {
190-
registerProvider();
191-
}
192-
}, [isDragging, registerProvider]);
192+
registerProvider();
193+
}, [registerProvider]);
193194

194-
return usePortal ? <EuiPortal>{children}</EuiPortal> : <>{children}</>;
195+
return <>{children}</>;
195196
}
196197
);
197198

x-pack/legacy/plugins/siem/public/components/drag_and_drop/droppable_wrapper.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { rgba } from 'polished';
88
import React from 'react';
9-
import { Droppable } from 'react-beautiful-dnd';
9+
import { Droppable, DraggableChildrenFn } from 'react-beautiful-dnd';
1010
import styled from 'styled-components';
1111

1212
interface Props {
@@ -16,6 +16,7 @@ interface Props {
1616
isDropDisabled?: boolean;
1717
type?: string;
1818
render?: ({ isDraggingOver }: { isDraggingOver: boolean }) => React.ReactNode;
19+
renderClone?: DraggableChildrenFn;
1920
}
2021

2122
const ReactDndDropTarget = styled.div<{ isDraggingOver: boolean; height: string }>`
@@ -94,12 +95,14 @@ export const DroppableWrapper = React.memo<Props>(
9495
isDropDisabled = false,
9596
type,
9697
render = null,
98+
renderClone,
9799
}) => (
98100
<Droppable
99101
isDropDisabled={isDropDisabled}
100102
droppableId={droppableId}
101103
direction={'horizontal'}
102104
type={type}
105+
renderClone={renderClone}
103106
>
104107
{(provided, snapshot) => (
105108
<ReactDndDropTarget

0 commit comments

Comments
 (0)