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

[release-4.4] Bug 1808115: dynamically determine parent scroll container for EventStreamList #4540

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export const RecentEventsBodyContent: React.FC<RecentEventsBodyContentProps> = (
className="co-activity-card__recent-list"
events={sortedEvents}
EventComponent={eventItem}
scrollableElementId="activity-body"
/>
</Accordion>
);
Expand Down
59 changes: 29 additions & 30 deletions frontend/public/components/utils/event-stream.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { CSSTransition } from 'react-transition-group';
import classNames from 'classnames';

import { EventKind } from '../../module/k8s';
import { WithScrollContainer } from './dom-utils';

// Keep track of seen events so we only animate new ones.
const seen = new Set();
Expand Down Expand Up @@ -73,7 +74,6 @@ export const EventStreamList: React.FC<EventStreamListProps> = ({
events,
className,
EventComponent,
scrollableElementId = 'content-scrollable',
}) => {
const [list, setList] = React.useState();
const onResize = React.useCallback(() => measurementCache.clearAll(), []);
Expand Down Expand Up @@ -109,39 +109,38 @@ export const EventStreamList: React.FC<EventStreamListProps> = ({
[events, className, EventComponent],
);

return (
events.length > 0 && (
<WindowScroller scrollElement={document.getElementById(scrollableElementId)}>
{({ height, isScrolling, registerChild, onChildScroll, scrollTop }) => (
<AutoSizer disableHeight onResize={onResize}>
{({ width }) => (
<div ref={registerChild}>
<VirtualList
autoHeight
data={events}
deferredMeasurementCache={measurementCache}
height={height || 0}
isScrolling={isScrolling}
onScroll={onChildScroll}
ref={setList}
rowCount={events.length}
rowHeight={measurementCache.rowHeight}
rowRenderer={rowRenderer}
scrollTop={scrollTop}
tabIndex={null}
width={width}
/>
</div>
)}
</AutoSizer>
)}
</WindowScroller>
)
const renderVirtualizedTable = (scrollContainer) => (
<WindowScroller scrollElement={scrollContainer}>
{({ height, isScrolling, registerChild, onChildScroll, scrollTop }) => (
<AutoSizer disableHeight onResize={onResize}>
{({ width }) => (
<div ref={registerChild}>
<VirtualList
autoHeight
data={events}
deferredMeasurementCache={measurementCache}
height={height || 0}
isScrolling={isScrolling}
onScroll={onChildScroll}
ref={setList}
rowCount={events.length}
rowHeight={measurementCache.rowHeight}
rowRenderer={rowRenderer}
scrollTop={scrollTop}
tabIndex={null}
width={width}
/>
</div>
)}
</AutoSizer>
)}
</WindowScroller>
);

return events.length > 0 && <WithScrollContainer>{renderVirtualizedTable}</WithScrollContainer>;
};

type EventStreamListProps = {
scrollableElementId?: string;
events: EventKind[];
EventComponent: React.ComponentType<EventComponentProps>;
className?: string;
Expand Down