Skip to content

Commit

Permalink
Support skipped step for executed journeys.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkambic committed Sep 28, 2020
1 parent cd1d813 commit b098917
Showing 1 changed file with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,45 @@
*/

import { EuiFlexGroup, EuiSpacer, EuiText } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import React, { FC } from 'react';
import { Ping } from '../../../../common/runtime_types';
import { JourneyState } from '../../../state/reducers/journey';
import { ExecutedStep } from './executed_step';

interface StepStatusCount {
succeeded: number;
failed: number;
skipped: number;
succeeded: number;
}

function statusMessage(count: StepStatusCount) {
if (count.succeeded === 0) {
return `${count.failed} Steps - all failed.`;
} else if (count.failed === 0) {
return `${count.succeeded} Steps - all succeeded`;
const total = count.succeeded + count.failed + count.skipped;
if (count.failed + count.skipped === total) {
return i18n.translate('xpack.uptime.synthetics.journey.allFailedMessage', {
defaultMessage: '{total} Steps - all failed or skipped',
values: { total },
});
} else if (count.succeeded === total) {
return i18n.translate('xpack.uptime.synthetics.journey.allSucceededMessage', {
defaultMessage: '{total} Steps - all succeeded',
values: { total },
});
}
return `${count.succeeded + count.failed} Steps - ${count.succeeded} succeeded`;
return i18n.translate('xpack.uptime.synthetics.journey.partialSuccessMessage', {
defaultMessage: '{total} Steps - {succeeded} succeeded',
values: { succeeded: count.succeeded, total },
});
}

function reduceStepStatus(prev: StepStatusCount, cur: Ping): StepStatusCount {
if (cur.synthetics?.payload?.status === 'succeeded') {
prev.succeeded += 1;
return prev;
} else if (cur.synthetics?.payload?.status === 'skipped') {
prev.skipped += 1;
return prev;
}
prev.failed += 1;
return prev;
Expand All @@ -42,8 +58,17 @@ export const ExecutedJourney: FC<ExecutedJourneyProps> = ({ journey, fetchScreen
return (
<div>
<EuiText>
<h3>Summary information</h3>
<p>{statusMessage(journey.steps.reduce(reduceStepStatus, { succeeded: 0, failed: 0 }))}</p>
<h3>
<FormattedMessage
id="xpack.uptime.synthetics.executedJourney.heading"
defaultMessage="Summary information"
/>
</h3>
<p>
{statusMessage(
journey.steps.reduce(reduceStepStatus, { failed: 0, skipped: 0, succeeded: 0 })
)}
</p>
</EuiText>
<EuiSpacer />
<EuiFlexGroup direction="column">
Expand Down

0 comments on commit b098917

Please sign in to comment.