diff options
author | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2019-04-25 14:59:31 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-05-07 20:21:27 +0200 |
commit | bba4533a8756e66a65656861507720b4c535194b (patch) | |
tree | 707bef0ccb885844e2841430de795c0ee5497e8c /server/sonar-web/src | |
parent | 98598c2f9120c5f554801142b54771f7283a2ad5 (diff) | |
download | sonarqube-bba4533a8756e66a65656861507720b4c535194b.tar.gz sonarqube-bba4533a8756e66a65656861507720b4c535194b.zip |
SONAR-11935 No WS error message when display issues in removed file
Diffstat (limited to 'server/sonar-web/src')
-rw-r--r-- | server/sonar-web/src/main/js/api/components.ts | 19 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/app/components/ComponentContainer.tsx | 38 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx | 10 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/app/utils/__tests__/handleRequiredAuthentication-test.ts (renamed from server/sonar-web/src/main/js/app/utils/__test__/handleRequiredAuthentication-test.ts) | 0 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/app/utils/__tests__/throwGlobalError-test.ts | 39 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/app/utils/throwGlobalError.ts | 10 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/code/utils.ts | 2 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/components/SourceViewer/SourceViewerBase.tsx | 6 |
8 files changed, 83 insertions, 41 deletions
diff --git a/server/sonar-web/src/main/js/api/components.ts b/server/sonar-web/src/main/js/api/components.ts index 6141c5d879b..2b98f70503f 100644 --- a/server/sonar-web/src/main/js/api/components.ts +++ b/server/sonar-web/src/main/js/api/components.ts @@ -122,8 +122,8 @@ export function getComponentLeaves( export function getComponent( data: { component: string; metricKeys: string } & T.BranchParameters -): Promise<any> { - return getJSON('/api/measures/component', data).then(r => r.component, throwGlobalError); +): Promise<{ component: T.ComponentMeasure }> { + return getJSON('/api/measures/component', data); } export interface TreeComponent extends T.LightComponent { @@ -151,17 +151,18 @@ export function getTree(data: { return getJSON('/api/components/tree', data).catch(throwGlobalError); } +export function getComponentData(data: { component: string } & T.BranchParameters): Promise<any> { + return getJSON('/api/components/show', data); +} + export function doesComponentExists( data: { component: string } & T.BranchParameters ): Promise<boolean> { - return getJSON('/api/components/show', data).then( - ({ component }) => component !== undefined, - () => false - ); + return getComponentData(data).then(({ component }) => component !== undefined, () => false); } export function getComponentShow(data: { component: string } & T.BranchParameters): Promise<any> { - return getJSON('/api/components/show', data).catch(throwGlobalError); + return getComponentData(data).catch(throwGlobalError); } export function getParents(component: string): Promise<any> { @@ -175,10 +176,6 @@ export function getBreadcrumbs(data: { component: string } & T.BranchParameters) }); } -export function getComponentData(data: { component: string } & T.BranchParameters): Promise<any> { - return getComponentShow(data).then(r => r.component); -} - export function getMyProjects(data: { p?: number; ps?: number; diff --git a/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx b/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx index b5294b59414..9ef3f832d68 100644 --- a/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx +++ b/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx @@ -114,28 +114,30 @@ export class ComponentContainer extends React.PureComponent<Props, State> { getComponentNavigation({ component: key, branch, pullRequest }), getComponentData({ component: key, branch, pullRequest }) ]) - .then(([nav, data]) => { - const component = this.addQualifier({ ...nav, ...data }); + .then(([nav, { component }]) => { + const componentWithQualifier = this.addQualifier({ ...nav, ...component }); if (isSonarCloud()) { - this.props.fetchOrganization(component.organization); + this.props.fetchOrganization(componentWithQualifier.organization); } - return component; - }) + return componentWithQualifier; + }, onError) .then(this.fetchBranches) - .then(({ branchLike, branchLikes, component }) => { - if (this.mounted) { - this.setState({ - branchLike, - branchLikes, - component, - loading: false - }); - this.fetchStatus(component); - this.fetchWarnings(component, branchLike); - } - }) - .catch(onError); + .then( + ({ branchLike, branchLikes, component }) => { + if (this.mounted) { + this.setState({ + branchLike, + branchLikes, + component, + loading: false + }); + this.fetchStatus(component); + this.fetchWarnings(component, branchLike); + } + }, + () => {} + ); } fetchBranches = ( diff --git a/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx index f534409f7cf..905e3bfe371 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx @@ -58,7 +58,7 @@ jest.mock('../../../api/ce', () => ({ })); jest.mock('../../../api/components', () => ({ - getComponentData: jest.fn().mockResolvedValue({ analysisDate: '2018-07-30' }) + getComponentData: jest.fn().mockResolvedValue({ component: { analysisDate: '2018-07-30' } }) })); jest.mock('../../../api/nav', () => ({ @@ -130,7 +130,9 @@ it('updates branches on change', async () => { it('loads organization', async () => { (isSonarCloud as jest.Mock).mockReturnValue(true); - (getComponentData as jest.Mock<any>).mockResolvedValueOnce({ organization: 'org' }); + (getComponentData as jest.Mock<any>).mockResolvedValueOnce({ + component: { organization: 'org' } + }); const fetchOrganization = jest.fn(); shallowRender({ fetchOrganization }); @@ -139,7 +141,9 @@ it('loads organization', async () => { }); it('fetches status', async () => { - (getComponentData as jest.Mock<any>).mockResolvedValueOnce({ organization: 'org' }); + (getComponentData as jest.Mock<any>).mockResolvedValueOnce({ + component: { organization: 'org' } + }); shallowRender(); await new Promise(setImmediate); diff --git a/server/sonar-web/src/main/js/app/utils/__test__/handleRequiredAuthentication-test.ts b/server/sonar-web/src/main/js/app/utils/__tests__/handleRequiredAuthentication-test.ts index 2d1b7ff4fd5..2d1b7ff4fd5 100644 --- a/server/sonar-web/src/main/js/app/utils/__test__/handleRequiredAuthentication-test.ts +++ b/server/sonar-web/src/main/js/app/utils/__tests__/handleRequiredAuthentication-test.ts diff --git a/server/sonar-web/src/main/js/app/utils/__tests__/throwGlobalError-test.ts b/server/sonar-web/src/main/js/app/utils/__tests__/throwGlobalError-test.ts new file mode 100644 index 00000000000..5f00a890a05 --- /dev/null +++ b/server/sonar-web/src/main/js/app/utils/__tests__/throwGlobalError-test.ts @@ -0,0 +1,39 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import throwGlobalError from '../throwGlobalError'; +import getStore from '../getStore'; + +it('should put the error message in the store', async () => { + const response: any = { json: jest.fn().mockResolvedValue({ errors: [{ msg: 'error 1' }] }) }; + await throwGlobalError({ response }).catch(() => {}); + expect(getStore().getState().globalMessages[0]).toMatchObject({ + level: 'ERROR', + message: 'error 1' + }); +}); + +it('should put a default error messsage in the store', async () => { + const response: any = { json: jest.fn().mockResolvedValue({}) }; + await throwGlobalError({ response }).catch(() => {}); + expect(getStore().getState().globalMessages[0]).toMatchObject({ + level: 'ERROR', + message: 'default_error_message' + }); +}); diff --git a/server/sonar-web/src/main/js/app/utils/throwGlobalError.ts b/server/sonar-web/src/main/js/app/utils/throwGlobalError.ts index fa582130c2d..fcd2506af13 100644 --- a/server/sonar-web/src/main/js/app/utils/throwGlobalError.ts +++ b/server/sonar-web/src/main/js/app/utils/throwGlobalError.ts @@ -25,11 +25,11 @@ export default function throwGlobalError(error: { response: Response }): Promise const store = getStore(); // eslint-disable-next-line promise/no-promise-in-callback - parseError(error) - .then(message => { + parseError(error).then( + message => { store.dispatch(addGlobalErrorMessage(message)); - }) - .catch(() => {}); - + }, + () => {} + ); return Promise.reject(error.response); } diff --git a/server/sonar-web/src/main/js/apps/code/utils.ts b/server/sonar-web/src/main/js/apps/code/utils.ts index ceae7a7f157..863bb094892 100644 --- a/server/sonar-web/src/main/js/apps/code/utils.ts +++ b/server/sonar-web/src/main/js/apps/code/utils.ts @@ -123,7 +123,7 @@ function retrieveComponentBase(componentKey: string, qualifier: string, branchLi component: componentKey, metricKeys: metrics.join(), ...getBranchLikeQuery(branchLike) - }).then(component => { + }).then(({ component }) => { addComponent(component); return component; }); diff --git a/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerBase.tsx b/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerBase.tsx index 3abf5f6e0d6..f1d3e452184 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerBase.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerBase.tsx @@ -719,9 +719,9 @@ function defaultLoadComponent(component: string, branchLike: T.BranchLike | unde return Promise.all([ getComponentForSourceViewer({ component, ...getBranchLikeQuery(branchLike) }), getComponentData({ component, ...getBranchLikeQuery(branchLike) }) - ]).then(([component, data]) => ({ - ...component, - leakPeriodDate: data.leakPeriodDate + ]).then(([sourceViewerComponent, { component }]) => ({ + ...sourceViewerComponent, + leakPeriodDate: component.leakPeriodDate })); } |