export function getTasksForComponent(
componentKey: string
-): Promise<{
- queue: PendingTask[];
- current: Task;
-}> {
- return getJSON('/api/ce/component', { componentKey });
+): Promise<{ queue: PendingTask[]; current: Task }> {
+ return getJSON('/api/ce/component', { componentKey }).catch(throwGlobalError);
}
export function getTypes(): Promise<any> {
isPending: r.queue.some(task => task.status === STATUSES.PENDING)
});
}
- }
+ },
+ () => {}
);
};
canAdmin: PropTypes.bool.isRequired
};
- renderMessage(messageKey: string) {
+ renderMessage(messageKey: string, status?: string) {
const { component } = this.props;
const canSeeBackgroundTasks =
- component.configuration !== undefined && component.configuration.showBackgroundTasks;
- const bgTaskUrl = getComponentBackgroundTaskUrl(component.key);
+ component.configuration && component.configuration.showBackgroundTasks;
+ const bgTaskUrl = getComponentBackgroundTaskUrl(component.key, status);
if (canSeeBackgroundTasks) {
return (
return (
<NavBarNotif className="alert alert-info">
<PendingIcon className="spacer-right" />
- {this.renderMessage('component_navigation.status.pending')}
+ {this.renderMessage('component_navigation.status.pending', STATUSES.ALL)}
</NavBarNotif>
);
} else if (currentTask && currentTask.status === STATUSES.FAILED) {
expect(getWrapper({ isPending: true })).toMatchSnapshot();
});
+it('renders background task pending info correctly for admin', () => {
+ expect(
+ getWrapper({
+ component: { ...component, configuration: { showBackgroundTasks: true } },
+ isPending: true
+ })
+ ).toMatchSnapshot();
+});
+
it('renders background task in progress info correctly', () => {
expect(getWrapper({ isInProgress: true, isPending: true })).toMatchSnapshot();
});
</span>
</NavBarNotif>
`;
+
+exports[`renders background task pending info correctly for admin 1`] = `
+<NavBarNotif
+ className="alert alert-info"
+>
+ <PendingIcon
+ className="spacer-right"
+ />
+ <FormattedMessage
+ defaultMessage="component_navigation.status.pending.admin"
+ id="component_navigation.status.pending.admin"
+ values={
+ Object {
+ "url": <Link
+ onlyActiveOnIndex={false}
+ style={Object {}}
+ to={
+ Object {
+ "pathname": "/project/background_tasks",
+ "query": Object {
+ "id": "foo",
+ "status": "__ALL__",
+ },
+ }
+ }
+ >
+ background_tasks.page
+ </Link>,
+ }
+ }
+ />
+</NavBarNotif>
+`;
checkProject = () => {
const { projectKey } = this.props;
- getTasksForComponent(projectKey).then(response => {
- if (response.queue.length > 0) {
- this.setState({ inQueue: true });
- }
+ getTasksForComponent(projectKey).then(
+ response => {
+ if (response.queue.length > 0) {
+ this.setState({ inQueue: true });
+ }
- if (response.current != null) {
- const { status } = response.current;
- this.setState({ status });
- if (status === STATUSES.SUCCESS) {
- this.props.onFinish();
- } else if (status === STATUSES.PENDING || status === STATUSES.IN_PROGRESS) {
+ if (response.current != null) {
+ const { status } = response.current;
+ this.setState({ status });
+ if (status === STATUSES.SUCCESS) {
+ this.props.onFinish();
+ } else if (status === STATUSES.PENDING || status === STATUSES.IN_PROGRESS) {
+ this.watch();
+ }
+ } else {
this.watch();
}
- } else {
- this.watch();
- }
- });
+ },
+ () => {}
+ );
};
render() {
return { pathname: '/dashboard', query: { id: key, branch } };
}
-export function getComponentBackgroundTaskUrl(componentKey: string): Location {
- return { pathname: '/project/background_tasks', query: { id: componentKey } };
+export function getComponentBackgroundTaskUrl(componentKey: string, status?: string): Location {
+ return { pathname: '/project/background_tasks', query: { id: componentKey, status } };
}
export function getProjectBranchUrl(key: string, branch: Branch): Location {