Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIEM] Attach VisibilitySensor to the TimelineBody instead of window #55620

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface Props {
browserFields: BrowserFields;
columnHeaders: ColumnHeader[];
columnRenderers: ColumnRenderer[];
containerElementRef: HTMLDivElement;
data: TimelineItem[];
eventIdToNoteIds: Readonly<Record<string, string[]>>;
getNotesByIds: (noteIds: string[]) => Note[];
Expand All @@ -53,61 +54,62 @@ interface Props {
// Passing the styles directly to the component because the width is
// being calculated and is recommended by Styled Components for performance
// https://github.com/styled-components/styled-components/issues/134#issuecomment-312415291
export const Events = React.memo<Props>(
({
actionsColumnWidth,
addNoteToEvent,
browserFields,
columnHeaders,
columnRenderers,
data,
eventIdToNoteIds,
getNotesByIds,
id,
isEventViewer = false,
loadingEventIds,
onColumnResized,
onPinEvent,
onRowSelected,
onUpdateColumns,
onUnPinEvent,
pinnedEventIds,
rowRenderers,
selectedEventIds,
showCheckboxes,
toggleColumn,
updateNote,
}) => (
<EventsTbody data-test-subj="events">
{data.map((event, i) => (
<StatefulEvent
actionsColumnWidth={actionsColumnWidth}
addNoteToEvent={addNoteToEvent}
browserFields={browserFields}
columnHeaders={columnHeaders}
columnRenderers={columnRenderers}
event={event}
eventIdToNoteIds={eventIdToNoteIds}
getNotesByIds={getNotesByIds}
isEventPinned={eventIsPinned({ eventId: event._id, pinnedEventIds })}
isEventViewer={isEventViewer}
key={event._id}
loadingEventIds={loadingEventIds}
maxDelay={maxDelay(i)}
onColumnResized={onColumnResized}
onPinEvent={onPinEvent}
onRowSelected={onRowSelected}
onUnPinEvent={onUnPinEvent}
onUpdateColumns={onUpdateColumns}
rowRenderers={rowRenderers}
selectedEventIds={selectedEventIds}
showCheckboxes={showCheckboxes}
timelineId={id}
toggleColumn={toggleColumn}
updateNote={updateNote}
/>
))}
</EventsTbody>
)
const EventsComponent: React.FC<Props> = ({
actionsColumnWidth,
addNoteToEvent,
browserFields,
columnHeaders,
columnRenderers,
containerElementRef,
data,
eventIdToNoteIds,
getNotesByIds,
id,
isEventViewer = false,
loadingEventIds,
onColumnResized,
onPinEvent,
onRowSelected,
onUpdateColumns,
onUnPinEvent,
pinnedEventIds,
rowRenderers,
selectedEventIds,
showCheckboxes,
toggleColumn,
updateNote,
}) => (
<EventsTbody data-test-subj="events">
{data.map((event, i) => (
<StatefulEvent
containerElementRef={containerElementRef}
actionsColumnWidth={actionsColumnWidth}
addNoteToEvent={addNoteToEvent}
browserFields={browserFields}
columnHeaders={columnHeaders}
columnRenderers={columnRenderers}
event={event}
eventIdToNoteIds={eventIdToNoteIds}
getNotesByIds={getNotesByIds}
isEventPinned={eventIsPinned({ eventId: event._id, pinnedEventIds })}
isEventViewer={isEventViewer}
key={event._id}
loadingEventIds={loadingEventIds}
maxDelay={maxDelay(i)}
onColumnResized={onColumnResized}
onPinEvent={onPinEvent}
onRowSelected={onRowSelected}
onUnPinEvent={onUnPinEvent}
onUpdateColumns={onUpdateColumns}
rowRenderers={rowRenderers}
selectedEventIds={selectedEventIds}
showCheckboxes={showCheckboxes}
timelineId={id}
toggleColumn={toggleColumn}
updateNote={updateNote}
/>
))}
</EventsTbody>
);
Events.displayName = 'Events';

export const Events = React.memo(EventsComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { StatefulEventChild } from './stateful_event_child';

interface Props {
actionsColumnWidth: number;
containerElementRef: HTMLDivElement;
addNoteToEvent: AddNoteToEvent;
browserFields: BrowserFields;
columnHeaders: ColumnHeader[];
Expand Down Expand Up @@ -115,6 +116,7 @@ const StatefulEventComponent: React.FC<Props> = ({
actionsColumnWidth,
addNoteToEvent,
browserFields,
containerElementRef,
columnHeaders,
columnRenderers,
event,
Expand Down Expand Up @@ -201,6 +203,7 @@ const StatefulEventComponent: React.FC<Props> = ({
<VisibilitySensor
partialVisibility={true}
scrollCheck={true}
containment={containerElementRef}
offset={{ top: TOP_OFFSET, bottom: BOTTOM_OFFSET }}
>
{({ isVisible }) => {
Expand Down Expand Up @@ -279,7 +282,7 @@ const StatefulEventComponent: React.FC<Props> = ({
} else {
// Height place holder for visibility detection as well as re-rendering sections.
const height =
divElement.current != null
divElement.current != null && divElement.current.clientHeight
? `${divElement.current.clientHeight}px`
: DEFAULT_ROW_HEIGHT;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useMemo } from 'react';
import React, { useMemo, useRef } from 'react';

import { BrowserFields } from '../../../containers/source';
import { TimelineItem, TimelineNonEcsData } from '../../../graphql/types';
Expand Down Expand Up @@ -95,6 +95,7 @@ export const Body = React.memo<BodyProps>(
toggleColumn,
updateNote,
}) => {
const containerElementRef = useRef<HTMLDivElement>(null);
const timelineTypeContext = useTimelineTypeContext();
const additionalActionWidth =
timelineTypeContext.timelineActions?.reduce((acc, v) => acc + v.width, 0) ?? 0;
Expand All @@ -112,7 +113,7 @@ export const Body = React.memo<BodyProps>(

return (
<>
<TimelineBody data-test-subj="timeline-body" bodyHeight={height}>
<TimelineBody data-test-subj="timeline-body" bodyHeight={height} ref={containerElementRef}>
<EventsTable
data-test-subj="events-table"
// Passing the styles directly to the component because the width is being calculated and is recommended by Styled Components for performance: https://github.com/styled-components/styled-components/issues/134#issuecomment-312415291
Expand All @@ -138,6 +139,7 @@ export const Body = React.memo<BodyProps>(
/>

<Events
containerElementRef={containerElementRef.current!}
actionsColumnWidth={actionsColumnWidth}
addNoteToEvent={addNoteToEvent}
browserFields={browserFields}
Expand Down