]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13220 Use project's key instead of project's id with Quality Gate WS
authorPhilippe Perrin <philippe.perrin@sonarsource.com>
Wed, 25 Mar 2020 13:35:12 +0000 (14:35 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 14 Apr 2020 20:04:05 +0000 (20:04 +0000)
server/sonar-web/src/main/js/api/quality-gates.ts
server/sonar-web/src/main/js/apps/quality-gates/components/Projects.tsx
server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/Projects-test.tsx

index 2af81857bfa4cf2d1aed22fb15392f4bcde24a4f..9e9255e02ec1bd81c368aa325bec953be9ec00c6 100644 (file)
@@ -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<void | Response> {
   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<void | Response> {
   return post('/api/qualitygates/deselect', data).catch(throwGlobalError);
 }
index 7cd7ee42da0d144032368415b4f5cbb11c0b04b4..a7eadc3eaa402bded97007391f117fc91e1f2220 100644 (file)
@@ -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<Props, State> {
           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<Props, State> {
       }
     });
 
-  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 (
       <div className="select-list-list-item">
         {project === undefined ? (
-          id
+          key
         ) : (
           <>
             {project.name}
@@ -145,7 +145,7 @@ export default class Projects extends React.PureComponent<Props, State> {
   render() {
     return (
       <SelectList
-        elements={this.state.projects.map(project => 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')}
index 39135e168fe1565bc057535caebe011b3ff91c71..15e36a03b11b7921bc9b5eeb0e39dac3e574fffe 100644 (file)
@@ -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);