From: Philippe Perrin Date: Wed, 25 Mar 2020 13:35:12 +0000 (+0100) Subject: SONAR-13220 Use project's key instead of project's id with Quality Gate WS X-Git-Tag: 8.3.0.34182~49 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=df3c515c32549db6be2ded722a6c217d25fa1122;p=sonarqube.git SONAR-13220 Use project's key instead of project's id with Quality Gate WS --- diff --git a/server/sonar-web/src/main/js/api/quality-gates.ts b/server/sonar-web/src/main/js/api/quality-gates.ts index 2af81857bfa..9e9255e02ec 100644 --- a/server/sonar-web/src/main/js/api/quality-gates.ts +++ b/server/sonar-web/src/main/js/api/quality-gates.ts @@ -117,7 +117,7 @@ export function searchProjects(data: { selected?: string; }): Promise<{ paging: T.Paging; - results: Array<{ id: string; key: string; name: string; selected: boolean }>; + results: Array<{ key: string; name: string; selected: boolean }>; }> { return getJSON('/api/qualitygates/search', data).catch(throwGlobalError); } @@ -125,8 +125,7 @@ export function searchProjects(data: { export function associateGateWithProject(data: { gateId: number; organization?: string; - projectKey?: string; - projectId?: string; + projectKey: string; }): Promise { return post('/api/qualitygates/select', data).catch(throwGlobalError); } @@ -134,8 +133,7 @@ export function associateGateWithProject(data: { export function dissociateGateWithProject(data: { gateId: number; organization?: string; - projectKey?: string; - projectId?: string; + projectKey: string; }): Promise { return post('/api/qualitygates/deselect', data).catch(throwGlobalError); } diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/Projects.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/Projects.tsx index 7cd7ee42da0..a7eadc3eaa4 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/Projects.tsx +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/Projects.tsx @@ -39,7 +39,7 @@ interface Props { interface State { needToReload: boolean; lastSearchParams?: SelectListSearchParams; - projects: Array<{ id: string; key: string; name: string; selected: boolean }>; + projects: Array<{ key: string; name: string; selected: boolean }>; projectsTotalCount?: number; selectedProjects: string[]; } @@ -81,7 +81,7 @@ export default class Projects extends React.PureComponent { const projects = more ? [...prevState.projects, ...data.results] : data.results; const newSelectedProjects = data.results .filter(project => project.selected) - .map(project => project.id); + .map(project => project.key); const selectedProjects = more ? [...prevState.selectedProjects, ...newSelectedProjects] : newSelectedProjects; @@ -97,40 +97,40 @@ export default class Projects extends React.PureComponent { } }); - handleSelect = (id: string) => + handleSelect = (key: string) => associateGateWithProject({ gateId: this.props.qualityGate.id, organization: this.props.organization, - projectId: id + projectKey: key }).then(() => { if (this.mounted) { this.setState(prevState => ({ needToReload: true, - selectedProjects: [...prevState.selectedProjects, id] + selectedProjects: [...prevState.selectedProjects, key] })); } }); - handleUnselect = (id: string) => + handleUnselect = (key: string) => dissociateGateWithProject({ gateId: this.props.qualityGate.id, organization: this.props.organization, - projectId: id + projectKey: key }).then(() => { if (this.mounted) { this.setState(prevState => ({ needToReload: true, - selectedProjects: without(prevState.selectedProjects, id) + selectedProjects: without(prevState.selectedProjects, key) })); } }); - renderElement = (id: string): React.ReactNode => { - const project = find(this.state.projects, { id }); + renderElement = (key: string): React.ReactNode => { + const project = find(this.state.projects, { key }); return (
{project === undefined ? ( - id + key ) : ( <> {project.name} @@ -145,7 +145,7 @@ export default class Projects extends React.PureComponent { render() { return ( project.id)} + elements={this.state.projects.map(project => project.key)} elementsTotalCount={this.state.projectsTotalCount} labelAll={translate('quality_gates.projects.all')} labelSelected={translate('quality_gates.projects.with')} diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/Projects-test.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/Projects-test.tsx index 39135e168fe..15e36a03b11 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/Projects-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/Projects-test.tsx @@ -90,7 +90,7 @@ it('should handle selection properly', async () => { expect(associateGateWithProject).toHaveBeenCalledWith( expect.objectContaining({ - projectId: 'toto' + projectKey: 'toto' }) ); expect(wrapper.state().needToReload).toBe(true); @@ -103,7 +103,7 @@ it('should handle deselection properly', async () => { expect(dissociateGateWithProject).toHaveBeenCalledWith( expect.objectContaining({ - projectId: 'tata' + projectKey: 'tata' }) ); expect(wrapper.state().needToReload).toBe(true);