From 51488b107ed2589f5c1c216b821c2ea993d68ad2 Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Mon, 12 Oct 2020 09:04:02 +0200 Subject: [PATCH] SONAR-13950 Move Application UI logic to DE --- .../sonar-web/src/main/js/api/application.ts | 78 +++- .../extensions/CreateApplicationForm.tsx | 185 ++++++++ .../__tests__/CreateApplicationForm-test.tsx | 80 ++++ .../CreateApplicationForm-test.tsx.snap | 150 ++++++ .../js/app/components/nav/component/Menu.tsx | 23 +- .../__snapshots__/Menu-test.tsx.snap | 41 +- .../branch-like/CurrentBranchLike.tsx | 4 +- .../CurrentBranchLike-test.tsx.snap | 3 +- .../components/nav/global/GlobalNavPlus.tsx | 36 +- .../global/__tests__/GlobalNavPlus-test.tsx | 29 +- .../__snapshots__/GlobalNavPlus-test.tsx.snap | 2 +- .../src/main/js/app/utils/startReactApp.tsx | 2 + .../ApplicationBranches.tsx | 120 +++++ .../ApplicationDetails.tsx | 180 ++++++++ .../ApplicationDetailsProjects.tsx | 221 +++++++++ .../ApplicationProjectBranch.tsx | 58 +++ .../application-console/ApplicationView.tsx | 169 +++++++ .../application-console/BranchRowActions.tsx | 111 +++++ .../application-console/BranchSelectItem.tsx | 76 +++ .../ConsoleApplicationApp.tsx | 51 ++ .../application-console/CreateBranchForm.tsx | 294 ++++++++++++ .../js/apps/application-console/EditForm.tsx | 123 +++++ .../application-console/ProjectBranchRow.tsx | 140 ++++++ .../__tests__/ApplicationBranches-test.tsx | 60 +++ .../__tests__/ApplicationDetails-test.tsx | 91 ++++ .../ApplicationDetailsProjects-test.tsx | 98 ++++ .../ApplicationProjectBranch-test.tsx | 43 ++ .../__tests__/ApplicationView-test.tsx | 110 +++++ .../__tests__/BranchRowActions-test.tsx | 39 ++ .../__tests__/BranchSelectItem-test.tsx | 37 ++ .../__tests__/ConsoleApplicationApp-test.tsx | 38 ++ .../__tests__/CreateBranchForm-test.tsx | 132 ++++++ .../__tests__/EditForm-test.tsx | 66 +++ .../__tests__/ProjectBranchRow-test.tsx | 41 ++ .../ApplicationBranches-test.tsx.snap | 176 +++++++ .../ApplicationDetails-test.tsx.snap | 284 ++++++++++++ .../ApplicationDetailsProjects-test.tsx.snap | 72 +++ .../ApplicationProjectBranch-test.tsx.snap | 69 +++ .../ApplicationView-test.tsx.snap | 7 + .../BranchRowActions-test.tsx.snap | 15 + .../BranchSelectItem-test.tsx.snap | 22 + .../ConsoleApplicationApp-test.tsx.snap | 32 ++ .../CreateBranchForm-test.tsx.snap | 12 + .../__snapshots__/EditForm-test.tsx.snap | 77 ++++ .../ProjectBranchRow-test.tsx.snap | 59 +++ .../js/apps/application-console/routes.ts | 28 ++ .../main/js/apps/application-console/utils.ts | 29 ++ .../global/components/AllHoldersList.tsx | 13 +- .../__tests__/AllHoldersList-test.tsx | 94 ++++ .../AllHoldersList-test.tsx.snap | 436 ++++++++++++++++++ .../project/components/PageHeader.tsx | 10 +- .../src/main/js/apps/permissions/utils.ts | 29 +- .../src/main/js/apps/projectDeletion/Form.tsx | 14 +- .../projectDeletion/__tests__/Form-test.tsx | 18 + .../src/main/js/helpers/mocks/application.ts | 27 +- .../src/main/js/helpers/mocks/permissions.ts | 38 ++ server/sonar-web/src/main/js/helpers/urls.ts | 26 +- .../sonar-web/src/main/js/types/component.ts | 10 +- .../resources/org/sonar/l10n/core.properties | 24 +- 59 files changed, 4481 insertions(+), 71 deletions(-) create mode 100644 server/sonar-web/src/main/js/app/components/extensions/CreateApplicationForm.tsx create mode 100644 server/sonar-web/src/main/js/app/components/extensions/__tests__/CreateApplicationForm-test.tsx create mode 100644 server/sonar-web/src/main/js/app/components/extensions/__tests__/__snapshots__/CreateApplicationForm-test.tsx.snap create mode 100644 server/sonar-web/src/main/js/apps/application-console/ApplicationBranches.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/ApplicationDetails.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/ApplicationDetailsProjects.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/ApplicationProjectBranch.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/ApplicationView.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/BranchRowActions.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/BranchSelectItem.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/ConsoleApplicationApp.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/CreateBranchForm.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/EditForm.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/ProjectBranchRow.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/ApplicationBranches-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/ApplicationDetails-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/ApplicationDetailsProjects-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/ApplicationProjectBranch-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/ApplicationView-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/BranchRowActions-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/BranchSelectItem-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/ConsoleApplicationApp-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/CreateBranchForm-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/EditForm-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/ProjectBranchRow-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/__snapshots__/ApplicationBranches-test.tsx.snap create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/__snapshots__/ApplicationDetails-test.tsx.snap create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/__snapshots__/ApplicationDetailsProjects-test.tsx.snap create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/__snapshots__/ApplicationProjectBranch-test.tsx.snap create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/__snapshots__/ApplicationView-test.tsx.snap create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/__snapshots__/BranchRowActions-test.tsx.snap create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/__snapshots__/BranchSelectItem-test.tsx.snap create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/__snapshots__/ConsoleApplicationApp-test.tsx.snap create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/__snapshots__/CreateBranchForm-test.tsx.snap create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/__snapshots__/EditForm-test.tsx.snap create mode 100644 server/sonar-web/src/main/js/apps/application-console/__tests__/__snapshots__/ProjectBranchRow-test.tsx.snap create mode 100644 server/sonar-web/src/main/js/apps/application-console/routes.ts create mode 100644 server/sonar-web/src/main/js/apps/application-console/utils.ts create mode 100644 server/sonar-web/src/main/js/apps/permissions/global/components/__tests__/AllHoldersList-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/permissions/global/components/__tests__/__snapshots__/AllHoldersList-test.tsx.snap create mode 100644 server/sonar-web/src/main/js/helpers/mocks/permissions.ts diff --git a/server/sonar-web/src/main/js/api/application.ts b/server/sonar-web/src/main/js/api/application.ts index d3636ce817a..e26af6755df 100644 --- a/server/sonar-web/src/main/js/api/application.ts +++ b/server/sonar-web/src/main/js/api/application.ts @@ -17,9 +17,10 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import { getJSON } from 'sonar-ui-common/helpers/request'; +import { getJSON, post, postJSON } from 'sonar-ui-common/helpers/request'; import throwGlobalError from '../app/utils/throwGlobalError'; -import { Application, ApplicationPeriod } from '../types/application'; +import { Application, ApplicationPeriod, ApplicationProject } from '../types/application'; +import { Visibility } from '../types/component'; export function getApplicationLeak( application: string, @@ -37,3 +38,76 @@ export function getApplicationDetails(application: string, branch?: string): Pro throwGlobalError ); } + +export function addApplicationBranch(data: { + application: string; + branch: string; + project: string[]; + projectBranch: string[]; +}) { + return post('/api/applications/create_branch', data).catch(throwGlobalError); +} + +export function updateApplicationBranch(data: { + application: string; + branch: string; + name: string; + project: string[]; + projectBranch: string[]; +}) { + return post('/api/applications/update_branch', data).catch(throwGlobalError); +} + +export function deleteApplicationBranch(application: string, branch: string) { + return post('/api/applications/delete_branch', { application, branch }).catch(throwGlobalError); +} + +export function getApplicationProjects(data: { + application: string; + p?: number; + ps?: number; + q?: string; + selected: string; +}): Promise<{ paging: T.Paging; projects: ApplicationProject[] }> { + return getJSON('/api/applications/search_projects', data).catch(throwGlobalError); +} + +export function addProjectToApplication(application: string, project: string) { + return post('/api/applications/add_project', { application, project }).catch(throwGlobalError); +} + +export function removeProjectFromApplication(application: string, project: string) { + return post('/api/applications/remove_project', { application, project }).catch(throwGlobalError); +} + +export function refreshApplication(key: string) { + return post('/api/applications/refresh', { key }).catch(throwGlobalError); +} + +export function createApplication( + name: string, + description: string, + key: string | undefined, + visibility: string +): Promise<{ + application: { + description?: string; + key: string; + name: string; + visibility: Visibility; + }; +}> { + return postJSON('/api/applications/create', { description, key, name, visibility }).catch( + throwGlobalError + ); +} + +export function deleteApplication(application: string) { + return post('/api/applications/delete', { application }).catch(throwGlobalError); +} + +export function editApplication(application: string, name: string, description: string) { + return post('/api/applications/update', { name, description, application }).catch( + throwGlobalError + ); +} diff --git a/server/sonar-web/src/main/js/app/components/extensions/CreateApplicationForm.tsx b/server/sonar-web/src/main/js/app/components/extensions/CreateApplicationForm.tsx new file mode 100644 index 00000000000..9a64dd8c304 --- /dev/null +++ b/server/sonar-web/src/main/js/app/components/extensions/CreateApplicationForm.tsx @@ -0,0 +1,185 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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 * as React from 'react'; +import { ResetButtonLink, SubmitButton } from 'sonar-ui-common/components/controls/buttons'; +import Radio from 'sonar-ui-common/components/controls/Radio'; +import SimpleModal from 'sonar-ui-common/components/controls/SimpleModal'; +import DeferredSpinner from 'sonar-ui-common/components/ui/DeferredSpinner'; +import { translate } from 'sonar-ui-common/helpers/l10n'; +import { createApplication } from '../../../api/application'; +import { ComponentQualifier, Visibility } from '../../../types/component'; + +interface Props { + onClose: () => void; + onCreate: (application: { key: string; qualifier: ComponentQualifier }) => Promise; +} + +interface State { + description: string; + key: string; + name: string; + visibility: Visibility; +} + +export default class CreateApplicationForm extends React.PureComponent { + mounted = false; + + constructor(props: Props) { + super(props); + this.state = { + description: '', + key: '', + name: '', + visibility: Visibility.Public + }; + } + + componentDidMount() { + this.mounted = true; + } + + componentWillUnmount() { + this.mounted = false; + } + + handleDescriptionChange = (event: React.ChangeEvent) => { + this.setState({ description: event.currentTarget.value }); + }; + + handleKeyChange = (event: React.ChangeEvent) => { + this.setState({ key: event.currentTarget.value }); + }; + + handleNameChange = (event: React.ChangeEvent) => { + this.setState({ name: event.currentTarget.value }); + }; + + handleVisibilityChange = (visibility: Visibility) => { + this.setState({ visibility }); + }; + + handleFormSubmit = () => { + const { name, description, key, visibility } = this.state; + return createApplication(name, description, key.length > 0 ? key : undefined, visibility).then( + ({ application }) => { + if (this.mounted) { + this.props.onCreate({ + key: application.key, + qualifier: ComponentQualifier.Application + }); + } + } + ); + }; + + render() { + const { name, description, key, visibility } = this.state; + const header = translate('qualifiers.create.APP'); + const submitDisabled = !this.state.name.length; + + return ( + + {({ onCloseClick, onFormSubmit, submitting }) => ( +
+
+

{header}

+
+ +
+
+ + +
+
+ +