From 7a090f7a951b839d94f4d1af2b53ee9a1453e399 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Tue, 9 Jan 2018 10:09:03 +0100 Subject: [PATCH] SONAR-10178 Pending notification should not filter tasks --- server/sonar-web/src/main/js/api/ce.ts | 7 ++-- .../components/nav/component/ComponentNav.tsx | 3 +- .../nav/component/ComponentNavBgTaskNotif.tsx | 8 ++--- .../ComponentNavBgTaskNotif-test.tsx | 9 +++++ .../ComponentNavBgTaskNotif-test.tsx.snap | 33 +++++++++++++++++++ .../tutorials/onboarding/ProjectWatcher.js | 31 +++++++++-------- server/sonar-web/src/main/js/helpers/urls.ts | 4 +-- 7 files changed, 69 insertions(+), 26 deletions(-) diff --git a/server/sonar-web/src/main/js/api/ce.ts b/server/sonar-web/src/main/js/api/ce.ts index 31ae8e10046..c9c16350492 100644 --- a/server/sonar-web/src/main/js/api/ce.ts +++ b/server/sonar-web/src/main/js/api/ce.ts @@ -90,11 +90,8 @@ export function cancelAllTasks(): Promise { 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 { diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx index 7d4cd235925..39925c34c99 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx @@ -75,7 +75,8 @@ export default class ComponentNav extends React.PureComponent { isPending: r.queue.some(task => task.status === STATUSES.PENDING) }); } - } + }, + () => {} ); }; diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBgTaskNotif.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBgTaskNotif.tsx index 5b906826ecc..9680f0e1c9b 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBgTaskNotif.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBgTaskNotif.tsx @@ -41,11 +41,11 @@ export default class ComponentNavBgTaskNotif extends React.PureComponent 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 ( @@ -76,7 +76,7 @@ export default class ComponentNavBgTaskNotif extends React.PureComponent return ( - {this.renderMessage('component_navigation.status.pending')} + {this.renderMessage('component_navigation.status.pending', STATUSES.ALL)} ); } else if (currentTask && currentTask.status === STATUSES.FAILED) { diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx index e5441faa51f..c149ae037b8 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx @@ -47,6 +47,15 @@ it('renders background task pending info correctly', () => { 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(); }); diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBgTaskNotif-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBgTaskNotif-test.tsx.snap index 679067cb000..bb69e51c46d 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBgTaskNotif-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBgTaskNotif-test.tsx.snap @@ -54,3 +54,36 @@ exports[`renders background task pending info correctly 1`] = ` `; + +exports[`renders background task pending info correctly for admin 1`] = ` + + + + background_tasks.page + , + } + } + /> + +`; diff --git a/server/sonar-web/src/main/js/apps/tutorials/onboarding/ProjectWatcher.js b/server/sonar-web/src/main/js/apps/tutorials/onboarding/ProjectWatcher.js index 252fdbb7f6c..86813dca37d 100644 --- a/server/sonar-web/src/main/js/apps/tutorials/onboarding/ProjectWatcher.js +++ b/server/sonar-web/src/main/js/apps/tutorials/onboarding/ProjectWatcher.js @@ -67,23 +67,26 @@ export default class ProjectWatcher extends React.PureComponent { 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() { diff --git a/server/sonar-web/src/main/js/helpers/urls.ts b/server/sonar-web/src/main/js/helpers/urls.ts index d15cee6a3e7..323b519b7e5 100644 --- a/server/sonar-web/src/main/js/helpers/urls.ts +++ b/server/sonar-web/src/main/js/helpers/urls.ts @@ -64,8 +64,8 @@ export function getProjectUrl(key: string, branch?: string): Location { 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 { -- 2.39.5