From effef8dfdb3a0aa0c6dc36f891f62b354647221e Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Tue, 14 Mar 2017 09:43:28 +0100 Subject: [PATCH] SONAR-8800 remove usages of deprecated api --- .../sonar-web/src/main/js/api/components.js | 22 +++++++++++-------- .../sonar-web/src/main/js/apps/code/utils.js | 2 +- .../projects-admin/__tests__/projects-test.js | 2 +- .../js/apps/projects-admin/create-view.js | 2 +- .../src/main/js/apps/projects-admin/main.js | 10 ++++----- .../main/js/apps/projects-admin/projects.js | 4 ++-- 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/server/sonar-web/src/main/js/api/components.js b/server/sonar-web/src/main/js/api/components.js index c09192522e3..456cb90e0e5 100644 --- a/server/sonar-web/src/main/js/api/components.js +++ b/server/sonar-web/src/main/js/api/components.js @@ -35,18 +35,23 @@ export function getGhosts (data?: Object) { return getJSON(url, data); } -export function deleteComponents (data?: Object) { +export function deleteComponents (data: { projects: string, organization?: string }) { const url = '/api/projects/bulk_delete'; return post(url, data); } -export function deleteProject (key: string) { +export function deleteProject (project: string) { const url = '/api/projects/delete'; - const data = { key }; + const data = { project }; return post(url, data); } -export function createProject (data?: Object) { +export function createProject (data: { + branch?: string, + name: string, + project: string, + organization?: string +}) { const url = '/api/projects/create'; return postJSON(url, data); } @@ -80,9 +85,9 @@ export function getComponent (componentKey: string, metrics: Array = []) return getJSON(url, data).then(r => r.component); } -export function getTree (baseComponentKey: string, options?: Object = {}) { +export function getTree (component: string, options?: Object = {}) { const url = '/api/components/tree'; - const data = Object.assign({}, options, { baseComponentKey }); + const data = { ...options, component }; return getJSON(url, data); } @@ -92,10 +97,9 @@ export function getParents ({ id, key }: { id: string, key: string }) { return getJSON(url, data).then(r => r.ancestors); } -export function getBreadcrumbs ({ id, key }: { id: string, key: string }) { +export function getBreadcrumbs (component: string) { const url = '/api/components/show'; - const data = id ? { id } : { key }; - return getJSON(url, data).then(r => { + return getJSON(url, { component }).then(r => { const reversedAncestors = [...r.ancestors].reverse(); return [...reversedAncestors, r.component]; }); diff --git a/server/sonar-web/src/main/js/apps/code/utils.js b/server/sonar-web/src/main/js/apps/code/utils.js index 2a3505d7bc8..c6999204de8 100644 --- a/server/sonar-web/src/main/js/apps/code/utils.js +++ b/server/sonar-web/src/main/js/apps/code/utils.js @@ -166,7 +166,7 @@ function retrieveComponentBreadcrumbs (componentKey) { return Promise.resolve(existing); } - return getBreadcrumbs({ key: componentKey }) + return getBreadcrumbs(componentKey) .then(skipRootDir) .then(breadcrumbs => { addComponentBreadcrumbs(componentKey, breadcrumbs); diff --git a/server/sonar-web/src/main/js/apps/projects-admin/__tests__/projects-test.js b/server/sonar-web/src/main/js/apps/projects-admin/__tests__/projects-test.js index d69c7a54ee6..4684de66847 100644 --- a/server/sonar-web/src/main/js/apps/projects-admin/__tests__/projects-test.js +++ b/server/sonar-web/src/main/js/apps/projects-admin/__tests__/projects-test.js @@ -38,7 +38,7 @@ it('should render list of projects with one selected', () => { { id: '1', key: 'a', name: 'A', qualifier: 'TRK' }, { id: '2', key: 'b', name: 'B', qualifier: 'TRK' } ]; - const selection = ['1']; + const selection = ['a']; const result = shallow(); expect(result.find('tr').length).toBe(2); diff --git a/server/sonar-web/src/main/js/apps/projects-admin/create-view.js b/server/sonar-web/src/main/js/apps/projects-admin/create-view.js index 07210b6e5d4..fb44ac62486 100644 --- a/server/sonar-web/src/main/js/apps/projects-admin/create-view.js +++ b/server/sonar-web/src/main/js/apps/projects-admin/create-view.js @@ -43,7 +43,7 @@ export default ModalForm.extend({ const data = { name: this.$('#create-project-name').val(), branch: this.$('#create-project-branch').val(), - key: this.$('#create-project-key').val() + project: this.$('#create-project-key').val() }; if (this.options.organization) { data.organization = this.options.organization.key; diff --git a/server/sonar-web/src/main/js/apps/projects-admin/main.js b/server/sonar-web/src/main/js/apps/projects-admin/main.js index c683e7d0c28..d23dabeab8c 100644 --- a/server/sonar-web/src/main/js/apps/projects-admin/main.js +++ b/server/sonar-web/src/main/js/apps/projects-admin/main.js @@ -165,17 +165,17 @@ export default React.createClass({ }, onProjectSelected (project) { - const newSelection = uniq([].concat(this.state.selection, project.id)); + const newSelection = uniq([].concat(this.state.selection, project.key)); this.setState({ selection: newSelection }); }, onProjectDeselected (project) { - const newSelection = without(this.state.selection, project.id); + const newSelection = without(this.state.selection, project.key); this.setState({ selection: newSelection }); }, onAllSelected () { - const newSelection = this.state.projects.map(project => project.id); + const newSelection = this.state.projects.map(project => project.key); this.setState({ selection: newSelection }); }, @@ -185,8 +185,8 @@ export default React.createClass({ deleteProjects () { this.setState({ ready: false }); - const ids = this.state.selection.join(','); - const data = { ids }; + const projects = this.state.selection.join(','); + const data = { projects }; if (this.props.organization) { Object.assign(data, { organization: this.props.organization.key }); } diff --git a/server/sonar-web/src/main/js/apps/projects-admin/projects.js b/server/sonar-web/src/main/js/apps/projects-admin/projects.js index 6086c8ae2a9..7c2aaf752f8 100644 --- a/server/sonar-web/src/main/js/apps/projects-admin/projects.js +++ b/server/sonar-web/src/main/js/apps/projects-admin/projects.js @@ -55,14 +55,14 @@ export default class Projects extends React.Component { } isProjectSelected (project) { - return this.props.selection.indexOf(project.id) !== -1; + return this.props.selection.indexOf(project.key) !== -1; } renderProject (project) { const permissionsUrl = getComponentPermissionsUrl(project.key); return ( - +