From 3f21c1f431a01adb12c86b36b042f8bd87de4fd8 Mon Sep 17 00:00:00 2001 From: Alan Quach Date: Tue, 4 Jun 2019 12:18:09 -0700 Subject: [PATCH] feat(executions): Adding redirect for execution without application (#7076) --- .../pipeline/executions/ExecutionNotFound.tsx | 18 ++++++++++ .../core/src/pipeline/pipeline.states.ts | 36 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 app/scripts/modules/core/src/pipeline/executions/ExecutionNotFound.tsx diff --git a/app/scripts/modules/core/src/pipeline/executions/ExecutionNotFound.tsx b/app/scripts/modules/core/src/pipeline/executions/ExecutionNotFound.tsx new file mode 100644 index 00000000000..5a7e7f95df9 --- /dev/null +++ b/app/scripts/modules/core/src/pipeline/executions/ExecutionNotFound.tsx @@ -0,0 +1,18 @@ +import * as React from 'react'; +import { ReactInjector } from 'core/reactShims'; + +export class ExecutionNotFound extends React.Component { + public render() { + const { params } = ReactInjector.$state; + return ( +
+
+

Execution Not Found

+

+ Please check your URL - we can't find any data for {params.executionId}. +

+
+
+ ); + } +} diff --git a/app/scripts/modules/core/src/pipeline/pipeline.states.ts b/app/scripts/modules/core/src/pipeline/pipeline.states.ts index 56d7371094b..de974d63dcc 100644 --- a/app/scripts/modules/core/src/pipeline/pipeline.states.ts +++ b/app/scripts/modules/core/src/pipeline/pipeline.states.ts @@ -5,7 +5,9 @@ import { INestedState, StateConfigProvider } from 'core/navigation/state.provide import { filterModelConfig } from './filter/ExecutionFilterModel'; import { Executions } from 'core/pipeline/executions/Executions'; +import { ExecutionNotFound } from 'core/pipeline/executions/ExecutionNotFound'; import { SingleExecutionDetails } from 'core/pipeline/details/SingleExecutionDetails'; +import { ExecutionService } from './service/execution.service'; export const PIPELINE_STATES = 'spinnaker.core.pipeline.states'; module(PIPELINE_STATES, [APPLICATION_STATE_PROVIDER]).config([ @@ -92,5 +94,39 @@ module(PIPELINE_STATES, [APPLICATION_STATE_PROVIDER]).config([ }; applicationStateProvider.addChildState(pipelines); + + const executionsLookup: INestedState = { + name: 'executionLookup', + url: '/executions/:executionId', + params: { + executionId: { dynamic: true }, + }, + redirectTo: transition => { + const { executionId } = transition.params(); + const executionService: ExecutionService = transition.injector().get('executionService'); + + if (!executionId) { + return undefined; + } + + return Promise.resolve() + .then(() => executionService.getExecution(executionId)) + .then(execution => + transition.router.stateService.target( + 'home.applications.application.pipelines.executionDetails.execution', + { + application: execution.application, + executionId: execution.id, + }, + ), + ) + .catch(() => {}); + }, + views: { + 'main@': { component: ExecutionNotFound, $type: 'react' }, + }, + }; + + stateConfigProvider.addToRootState(executionsLookup); }, ]);