Skip to content

Commit

Permalink
feat(tasks): Adding redirect for task by id without application (#7307)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanmquach authored Aug 14, 2019
1 parent 1ab9ce5 commit a67226c
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 18 deletions.
1 change: 1 addition & 0 deletions app/scripts/modules/core/src/domain/ITask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IOrchestratedItem } from './IOrchestratedItem';
import { ITaskStep } from './ITaskStep';

export interface ITask extends IOrchestratedItem {
application: string;
id: string;
name?: string;
steps?: ITaskStep[];
Expand Down
19 changes: 19 additions & 0 deletions app/scripts/modules/core/src/notfound/NotFound.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as React from 'react';

interface INotFoundProps {
type: string;
entityId: string;
}

export function NotFound(props: INotFoundProps) {
return (
<div className="application">
<div>
<h2 className="text-center">{props.type} Not Found</h2>
<p className="text-center" style={{ marginBottom: '20px' }}>
Please check your URL - we can't find any data for <em>{props.entityId}</em>.
</p>
</div>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import * as React from 'react';
import { ReactInjector } from 'core/reactShims';
import { NotFound } from 'core/notfound/NotFound';

export class ExecutionNotFound extends React.Component {
public render() {
const { params } = ReactInjector.$state;
return (
<div className="application">
<div>
<h2 className="text-center">Execution Not Found</h2>
<p className="text-center" style={{ marginBottom: '20px' }}>
Please check your URL - we can't find any data for <em>{params.executionId}</em>.
</p>
</div>
</div>
);
}
export function ExecutionNotFound() {
const { params } = ReactInjector.$state;
return <NotFound type="Execution" entityId={params.executionId} />;
}
3 changes: 1 addition & 2 deletions app/scripts/modules/core/src/pipeline/pipeline.states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ module(PIPELINE_STATES, [APPLICATION_STATE_PROVIDER]).config([
return undefined;
}

return Promise.resolve()
.then(() => executionService.getExecution(executionId))
return Promise.resolve(executionService.getExecution(executionId))
.then(execution =>
transition.router.stateService.target(
'home.applications.application.pipelines.executionDetails.execution',
Expand Down
8 changes: 8 additions & 0 deletions app/scripts/modules/core/src/task/TaskNotFound.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as React from 'react';
import { ReactInjector } from 'core/reactShims';
import { NotFound } from 'core/notfound/NotFound';

export function TaskNotFound() {
const { params } = ReactInjector.$state;
return <NotFound type="Task" entityId={params.taskId} />;
}
36 changes: 34 additions & 2 deletions app/scripts/modules/core/src/task/task.states.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { module } from 'angular';

import { INestedState } from 'core/navigation/state.provider';
import { INestedState, StateConfigProvider } from 'core/navigation/state.provider';
import { APPLICATION_STATE_PROVIDER, ApplicationStateProvider } from 'core/application/application.state.provider';
import { TaskReader } from './task.read.service';
import { TaskNotFound } from './TaskNotFound';

export const TASK_STATES = 'spinnaker.core.task.states';
module(TASK_STATES, [APPLICATION_STATE_PROVIDER]).config([
'applicationStateProvider',
(applicationStateProvider: ApplicationStateProvider) => {
'stateConfigProvider',
(applicationStateProvider: ApplicationStateProvider, stateConfigProvider: StateConfigProvider) => {
const taskDetails: INestedState = {
name: 'taskDetails',
url: '/:taskId',
Expand Down Expand Up @@ -40,6 +43,35 @@ module(TASK_STATES, [APPLICATION_STATE_PROVIDER]).config([
children: [taskDetails],
};

const taskLookup: INestedState = {
name: 'taskLookup',
url: '/tasks/:taskId',
params: {
taskId: { dynamic: true },
},
redirectTo: transition => {
const { taskId } = transition.params();

if (!taskId) {
return undefined;
}

return Promise.resolve(TaskReader.getTask(taskId))
.then(task =>
transition.router.stateService.target('home.applications.application.tasks.taskDetails', {
application: task.application,
taskId,
}),
)
.catch(() => {});
},
views: {
'main@': { component: TaskNotFound, $type: 'react' },
},
};

applicationStateProvider.addChildState(tasks);

stateConfigProvider.addToRootState(taskLookup);
},
]);

0 comments on commit a67226c

Please sign in to comment.