From 4e4f408a34f418053d5433eec8d59250816b0ba8 Mon Sep 17 00:00:00 2001 From: Shahzad Date: Tue, 25 Apr 2023 08:11:19 +0200 Subject: [PATCH] [Synthetics] Fix next / prev test navigation (#155624) --- .../step_details_page/step_page_nav.tsx | 30 ++++++++------- .../server/queries/get_journey_details.ts | 38 +++++++++++-------- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/step_details_page/step_page_nav.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/step_details_page/step_page_nav.tsx index 528e3c9d6aa1b..9bd25a715dff1 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/step_details_page/step_page_nav.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/step_details_page/step_page_nav.tsx @@ -57,19 +57,23 @@ export const StepPageNavigation = ({ testRunPage }: { testRunPage?: boolean }) = checkGroupId: data?.details?.next?.checkGroup, }); - if (testRunPage && data?.details?.previous?.checkGroup && data?.details?.next?.checkGroup) { - prevHref = getTestRunDetailLink({ - basePath, - monitorId, - locationId: selectedLocation?.id, - checkGroup: data?.details?.previous?.checkGroup, - }); - nextHref = getTestRunDetailLink({ - basePath, - monitorId, - locationId: selectedLocation?.id, - checkGroup: data?.details?.next?.checkGroup, - }); + if (testRunPage) { + if (data?.details?.previous?.checkGroup) { + prevHref = getTestRunDetailLink({ + basePath, + monitorId, + locationId: selectedLocation?.id, + checkGroup: data?.details?.previous?.checkGroup, + }); + } + if (data?.details?.next?.checkGroup) { + nextHref = getTestRunDetailLink({ + basePath, + monitorId, + locationId: selectedLocation?.id, + checkGroup: data?.details?.next?.checkGroup, + }); + } } if (!startedAt) { diff --git a/x-pack/plugins/synthetics/server/queries/get_journey_details.ts b/x-pack/plugins/synthetics/server/queries/get_journey_details.ts index 025688af45242..551696614d749 100644 --- a/x-pack/plugins/synthetics/server/queries/get_journey_details.ts +++ b/x-pack/plugins/synthetics/server/queries/get_journey_details.ts @@ -64,6 +64,15 @@ export const getJourneyDetails: UMElasticsearchQueryFn< body: { query: { bool: { + must_not: [ + { + term: { + 'monitor.check_group': { + value: journeySource.monitor.check_group, + }, + }, + }, + ], filter: [ { term: { @@ -93,6 +102,7 @@ export const getJourneyDetails: UMElasticsearchQueryFn< ...baseSiblingParams.body, query: { bool: { + must_not: baseSiblingParams.body.query.bool.must_not, filter: [ ...baseSiblingParams.body.query.bool.filter, { @@ -114,6 +124,7 @@ export const getJourneyDetails: UMElasticsearchQueryFn< ...baseSiblingParams.body, query: { bool: { + must_not: baseSiblingParams.body.query.bool.must_not, filter: [ ...baseSiblingParams.body.query.bool.filter, { @@ -151,20 +162,6 @@ export const getJourneyDetails: UMElasticsearchQueryFn< ({ _source: summarySource }) => summarySource.synthetics?.type === 'heartbeat/summary' )?._source; - const previousInfo = previousJourney - ? { - checkGroup: previousJourney._source.monitor.check_group, - timestamp: previousJourney._source['@timestamp'], - } - : undefined; - - const nextInfo = nextJourney - ? { - checkGroup: nextJourney._source.monitor.check_group, - timestamp: nextJourney._source['@timestamp'], - } - : undefined; - return { timestamp: journeySource['@timestamp'], journey: { ...journeySource, _id: foundJourney._id }, @@ -175,10 +172,19 @@ export const getJourneyDetails: UMElasticsearchQueryFn< }, } : {}), - previous: previousInfo, - next: nextInfo, + previous: filterNextPrevJourney(journeySource.monitor.check_group, previousJourney?._source), + next: filterNextPrevJourney(journeySource.monitor.check_group, nextJourney?._source), }; } else { return null; } }; + +const filterNextPrevJourney = (checkGroup: string, pingSource: DocumentSource) => { + return pingSource && pingSource.monitor.check_group !== checkGroup + ? { + checkGroup: pingSource.monitor.check_group, + timestamp: pingSource['@timestamp'], + } + : undefined; +};