Skip to content

Commit

Permalink
fix(core): Navigate to the first stage if passed in stage does not ex…
Browse files Browse the repository at this point in the history
…ist (#4309)
  • Loading branch information
Justin Reynolds authored Oct 23, 2017
1 parent e5af2b3 commit 3f3258f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ export class ExecutionDetails extends React.Component<IExecutionDetailsProps, IE
return { refId: null };
}

private validateStageExists(summaries: IExecutionStageSummary[], stage: number, subStage: number): { stage: number, subStage: number } {
if (isNaN(subStage)) { subStage = undefined; }
const foundStage = summaries[stage];
let foundSubStage;

if (foundStage) {
if (foundStage.groupStages) {
foundSubStage = foundStage.groupStages[subStage];
subStage = foundSubStage ? subStage : 0;
} else {
subStage = undefined;
}
} else {
stage = 0;
}
return { stage, subStage };
}

private getCurrentStage(summaries: IExecutionStageSummary[]): { stage: number, subStage: number } {
const { $state, $stateParams } = ReactInjector;
if ($stateParams.stageId) {
Expand All @@ -116,7 +134,14 @@ export class ExecutionDetails extends React.Component<IExecutionDetailsProps, IE
}
}

return { stage: parseInt($stateParams.stage, 10), subStage: parseInt($stateParams.subStage, 10) };
const stateStage = parseInt($stateParams.stage, 10);
const stateSubStage = parseInt($stateParams.subStage, 10);
const { stage, subStage } = this.validateStageExists(summaries, stateStage, stateSubStage);
if (stage !== stateStage || subStage !== stateSubStage) {
$state.go('.', { stage, subStage }, { location: 'replace' });
}

return { stage, subStage };
}

private getCurrentStep() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { get } from 'lodash';
import { BindAll } from 'lodash-decorators';

import { Application } from 'core/application';
Expand All @@ -20,7 +21,7 @@ export interface IStageSummaryState {
export class StageSummary extends React.Component<IStageSummaryProps, IStageSummaryState> {

private getSourceUrl(): string {
return this.props.config.executionSummaryUrl || require('../../pipeline/config/stages/core/executionSummary.html');
return get(this.props, 'config.executionSummaryUrl', require('../../pipeline/config/stages/core/executionSummary.html'));
}

public render(): React.ReactElement<StageSummary> {
Expand Down

0 comments on commit 3f3258f

Please sign in to comment.