From c454479ddd0d26d8f032764fafa6a6090143089c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Fern=C3=A1ndez=20G=C3=B3mez?= Date: Thu, 2 Jan 2020 14:16:02 +0100 Subject: [PATCH] Refactor `processCursor` --- .../log_entries/kibana_log_entries_adapter.ts | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/log_entries/kibana_log_entries_adapter.ts b/x-pack/legacy/plugins/infra/server/lib/adapters/log_entries/kibana_log_entries_adapter.ts index 6bae46c60969f..b936d79a8edcd 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/log_entries/kibana_log_entries_adapter.ts +++ b/x-pack/legacy/plugins/infra/server/lib/adapters/log_entries/kibana_log_entries_adapter.ts @@ -497,23 +497,24 @@ function processCursor( sortDirection: 'asc' | 'desc'; searchAfterClause: { search_after?: readonly [number, number] }; } { - let sortDirection: 'asc' | 'desc' = 'asc'; - let searchAfterClause = {}; - - if (!cursor) { - return { sortDirection, searchAfterClause }; - } - - if ('before' in cursor) { - sortDirection = 'desc'; - if (cursor.before !== 'last') { - searchAfterClause = { search_after: [cursor.before.time, cursor.before.tiebreaker] as const }; + if (cursor) { + if ('before' in cursor) { + return { + sortDirection: 'desc', + searchAfterClause: + cursor.before !== 'last' + ? { search_after: [cursor.before.time, cursor.before.tiebreaker] as const } + : {}, + }; + } else if (cursor.after !== 'first') { + return { + sortDirection: 'asc', + searchAfterClause: { search_after: [cursor.after.time, cursor.after.tiebreaker] as const }, + }; } - } else if ('after' in cursor && cursor.after !== 'first') { - searchAfterClause = { search_after: [cursor.after.time, cursor.after.tiebreaker] as const }; } - return { sortDirection, searchAfterClause }; + return { sortDirection: 'asc', searchAfterClause: {} }; } const LogSummaryDateRangeBucketRuntimeType = runtimeTypes.intersection([