[Terminal output] fix to a regression in the last pr (#140838)

* fix to a regression in the last pr

* fix to a regression in the last pr

Co-authored-by: Karl Godard <karlgodard@elastic.co>
This commit is contained in:
Karl Godard 2022-09-15 12:18:45 -07:00 committed by GitHub
parent d0a0a8f889
commit 2464aa69b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -64,10 +64,12 @@ export const useFetchSessionViewProcessEvents = (
getNextPageParam: (lastPage, pages) => {
const isRefetch = pages.length === 1 && jumpToCursor;
if (isRefetch || lastPage.events.length >= PROCESS_EVENTS_PER_PAGE) {
const cursor = lastPage.events.filter((event) => {
const filtered = lastPage.events.filter((event) => {
const action = event.event?.action;
return action && [EventAction.fork, EventAction.exec, EventAction.end].includes(action);
})?.[lastPage.events.length - 1]?.['@timestamp'];
});
const cursor = filtered?.[filtered.length - 1]?.['@timestamp'];
if (cursor) {
return {
@ -78,12 +80,17 @@ export const useFetchSessionViewProcessEvents = (
}
},
getPreviousPageParam: (firstPage, pages) => {
const atBeginning = pages.length > 1 && firstPage.events.length < PROCESS_EVENTS_PER_PAGE;
const filtered = firstPage.events.filter((event) => {
const action = event.event?.action;
return action && [EventAction.fork, EventAction.exec, EventAction.end].includes(action);
});
const atBeginning = pages.length > 1 && filtered.length < PROCESS_EVENTS_PER_PAGE;
if (jumpToCursor && !atBeginning) {
// it's possible the first page returned no events
// fallback to using jumpToCursor if there are no "forward" events.
const cursor = firstPage.events?.[0]?.['@timestamp'] || jumpToCursor;
const cursor = filtered[0]?.['@timestamp'] || jumpToCursor;
return {
cursor,