Skip to content

Commit

Permalink
[Synthetics] Fix next / prev test navigation (#155624)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 authored Apr 25, 2023
1 parent 1ae38df commit 4e4f408
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
38 changes: 22 additions & 16 deletions x-pack/plugins/synthetics/server/queries/get_journey_details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ export const getJourneyDetails: UMElasticsearchQueryFn<
body: {
query: {
bool: {
must_not: [
{
term: {
'monitor.check_group': {
value: journeySource.monitor.check_group,
},
},
},
],
filter: [
{
term: {
Expand Down Expand Up @@ -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,
{
Expand All @@ -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,
{
Expand Down Expand Up @@ -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 },
Expand All @@ -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;
};

0 comments on commit 4e4f408

Please sign in to comment.