Skip to content

Commit c454479

Browse files
author
Alejandro Fernández Gómez
committed
Refactor processCursor
1 parent 5829456 commit c454479

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

x-pack/legacy/plugins/infra/server/lib/adapters/log_entries/kibana_log_entries_adapter.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -497,23 +497,24 @@ function processCursor(
497497
sortDirection: 'asc' | 'desc';
498498
searchAfterClause: { search_after?: readonly [number, number] };
499499
} {
500-
let sortDirection: 'asc' | 'desc' = 'asc';
501-
let searchAfterClause = {};
502-
503-
if (!cursor) {
504-
return { sortDirection, searchAfterClause };
505-
}
506-
507-
if ('before' in cursor) {
508-
sortDirection = 'desc';
509-
if (cursor.before !== 'last') {
510-
searchAfterClause = { search_after: [cursor.before.time, cursor.before.tiebreaker] as const };
500+
if (cursor) {
501+
if ('before' in cursor) {
502+
return {
503+
sortDirection: 'desc',
504+
searchAfterClause:
505+
cursor.before !== 'last'
506+
? { search_after: [cursor.before.time, cursor.before.tiebreaker] as const }
507+
: {},
508+
};
509+
} else if (cursor.after !== 'first') {
510+
return {
511+
sortDirection: 'asc',
512+
searchAfterClause: { search_after: [cursor.after.time, cursor.after.tiebreaker] as const },
513+
};
511514
}
512-
} else if ('after' in cursor && cursor.after !== 'first') {
513-
searchAfterClause = { search_after: [cursor.after.time, cursor.after.tiebreaker] as const };
514515
}
515516

516-
return { sortDirection, searchAfterClause };
517+
return { sortDirection: 'asc', searchAfterClause: {} };
517518
}
518519

519520
const LogSummaryDateRangeBucketRuntimeType = runtimeTypes.intersection([

0 commit comments

Comments
 (0)