From 9b66bdef10f17cf8d684ba814bcedfa08b51fdd6 Mon Sep 17 00:00:00 2001 From: Zipeng WU Date: Sun, 4 Jul 2021 23:26:31 +0200 Subject: SONAR-10762 remove Custom Metric UI --- server/sonar-web/src/main/js/api/metrics.ts | 35 +--- .../js/app/components/nav/settings/SettingsNav.tsx | 5 - .../__snapshots__/SettingsNav-test.tsx.snap | 16 -- .../src/main/js/app/utils/startReactApp.tsx | 2 - .../main/js/apps/custom-metrics/components/App.tsx | 174 ------------------ .../custom-metrics/components/CreateButton.tsx | 76 -------- .../apps/custom-metrics/components/DeleteForm.tsx | 60 ------- .../js/apps/custom-metrics/components/Form.tsx | 198 --------------------- .../js/apps/custom-metrics/components/Header.tsx | 50 ------ .../js/apps/custom-metrics/components/Item.tsx | 146 --------------- .../js/apps/custom-metrics/components/List.tsx | 57 ------ .../components/__tests__/App-test.tsx | 77 -------- .../components/__tests__/CreateButton-test.tsx | 37 ---- .../components/__tests__/DeleteForm-test.tsx | 29 --- .../components/__tests__/Form-test.tsx | 90 ---------- .../components/__tests__/Header-test.tsx | 38 ---- .../components/__tests__/Item-test.tsx | 66 ------- .../components/__tests__/List-test.tsx | 36 ---- .../__tests__/__snapshots__/App-test.tsx.snap | 136 -------------- .../__snapshots__/CreateButton-test.tsx.snap | 41 ----- .../__snapshots__/DeleteForm-test.tsx.snap | 45 ----- .../__tests__/__snapshots__/Form-test.tsx.snap | 156 ---------------- .../__tests__/__snapshots__/Header-test.tsx.snap | 49 ----- .../__tests__/__snapshots__/Item-test.tsx.snap | 61 ------- .../__tests__/__snapshots__/List-test.tsx.snap | 53 ------ .../src/main/js/apps/custom-metrics/routes.ts | 28 --- 26 files changed, 1 insertion(+), 1760 deletions(-) delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/App.tsx delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/CreateButton.tsx delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/DeleteForm.tsx delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/Form.tsx delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/Header.tsx delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/Item.tsx delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/List.tsx delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/App-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/CreateButton-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/DeleteForm-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/Form-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/Header-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/Item-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/List-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/__snapshots__/App-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/__snapshots__/CreateButton-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/__snapshots__/DeleteForm-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/__snapshots__/Form-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/__snapshots__/Header-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/__snapshots__/Item-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/__snapshots__/List-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/custom-metrics/routes.ts (limited to 'server/sonar-web/src/main') diff --git a/server/sonar-web/src/main/js/api/metrics.ts b/server/sonar-web/src/main/js/api/metrics.ts index 306b2dbfbfd..ab95885760d 100644 --- a/server/sonar-web/src/main/js/api/metrics.ts +++ b/server/sonar-web/src/main/js/api/metrics.ts @@ -17,7 +17,7 @@ * 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, post, postJSON } from 'sonar-ui-common/helpers/request'; +import { getJSON } from 'sonar-ui-common/helpers/request'; import throwGlobalError from '../app/utils/throwGlobalError'; export interface MetricsResponse { @@ -55,36 +55,3 @@ export function getAllMetrics(data?: { }); } } - -export function getMetricDomains(): Promise { - return getJSON('/api/metrics/domains').then(r => r.domains, throwGlobalError); -} - -export function getMetricTypes(): Promise { - return getJSON('/api/metrics/types').then(r => r.types, throwGlobalError); -} - -export function createMetric(data: { - description?: string; - domain?: string; - key: string; - name: string; - type: string; -}): Promise { - return postJSON('/api/metrics/create', data).catch(throwGlobalError); -} - -export function updateMetric(data: { - description?: string; - domain?: string; - id: string; - key?: string; - name?: string; - type?: string; -}) { - return post('/api/metrics/update', data).catch(throwGlobalError); -} - -export function deleteMetric(data: { keys: string }) { - return post('/api/metrics/delete', data).catch(throwGlobalError); -} diff --git a/server/sonar-web/src/main/js/app/components/nav/settings/SettingsNav.tsx b/server/sonar-web/src/main/js/app/components/nav/settings/SettingsNav.tsx index f3030b36a17..5e63bd06600 100644 --- a/server/sonar-web/src/main/js/app/components/nav/settings/SettingsNav.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/settings/SettingsNav.tsx @@ -103,11 +103,6 @@ export default class SettingsNav extends React.PureComponent { {translate('property.category.security.encryption')} -
  • - - {translate('custom_metrics.page')} - -
  • {translate('webhooks.page')} diff --git a/server/sonar-web/src/main/js/app/components/nav/settings/__tests__/__snapshots__/SettingsNav-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/settings/__tests__/__snapshots__/SettingsNav-test.tsx.snap index f300a114dce..54b7d0ac624 100644 --- a/server/sonar-web/src/main/js/app/components/nav/settings/__tests__/__snapshots__/SettingsNav-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/nav/settings/__tests__/__snapshots__/SettingsNav-test.tsx.snap @@ -58,14 +58,6 @@ exports[`should work with extensions 1`] = ` property.category.security.encryption
  • -
  • - - custom_metrics.page - -
  • -
  • - - custom_metrics.page - -
  • - diff --git a/server/sonar-web/src/main/js/apps/custom-metrics/components/App.tsx b/server/sonar-web/src/main/js/apps/custom-metrics/components/App.tsx deleted file mode 100644 index c1c37f8db24..00000000000 --- a/server/sonar-web/src/main/js/apps/custom-metrics/components/App.tsx +++ /dev/null @@ -1,174 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2021 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 { Helmet } from 'react-helmet-async'; -import ListFooter from 'sonar-ui-common/components/controls/ListFooter'; -import { translate } from 'sonar-ui-common/helpers/l10n'; -import { - createMetric, - deleteMetric, - getMetricDomains, - getMetrics, - getMetricTypes, - MetricsResponse, - updateMetric -} from '../../../api/metrics'; -import Suggestions from '../../../app/components/embed-docs-modal/Suggestions'; -import { MetricProps } from './Form'; -import Header from './Header'; -import List from './List'; - -interface Props {} - -interface State { - domains?: string[]; - loading: boolean; - metrics?: T.Metric[]; - paging?: T.Paging; - types?: string[]; -} - -const PAGE_SIZE = 50; - -export default class App extends React.PureComponent { - mounted = false; - state: State = { loading: true }; - - componentDidMount() { - this.mounted = true; - this.fetchData(); - } - - componentWillUnmount() { - this.mounted = false; - } - - fetchData = () => { - Promise.all([ - getMetricDomains(), - getMetricTypes(), - getMetrics({ isCustom: true, ps: PAGE_SIZE }) - ]).then(([domains, types, metricsResponse]) => { - if (this.mounted) { - this.setState({ - domains, - loading: false, - metrics: metricsResponse.metrics, - paging: this.getPaging(metricsResponse), - types - }); - } - }, this.stopLoading); - }; - - fetchMore = () => { - const { paging } = this.state; - if (paging) { - this.setState({ loading: true }); - getMetrics({ isCustom: true, p: paging.pageIndex + 1, ps: PAGE_SIZE }).then( - metricsResponse => { - if (this.mounted) { - this.setState(({ metrics = [] }: State) => ({ - loading: false, - metrics: [...metrics, ...metricsResponse.metrics], - paging: this.getPaging(metricsResponse) - })); - } - }, - this.stopLoading - ); - } - }; - - stopLoading = () => { - if (this.mounted) { - this.setState({ loading: false }); - } - }; - - getPaging = (response: MetricsResponse): T.Paging => ({ - pageIndex: response.p, - pageSize: response.ps, - total: response.total - }); - - handleCreate = (data: MetricProps) => { - return createMetric(data).then(metric => { - if (this.mounted) { - this.setState(({ metrics = [], paging }: State) => ({ - metrics: [...metrics, metric], - paging: paging && { ...paging, total: paging.total + 1 } - })); - } - }); - }; - - handleEdit = (data: { id: string } & MetricProps) => { - return updateMetric(data).then(() => { - if (this.mounted) { - this.setState(({ metrics = [] }: State) => ({ - metrics: metrics.map(metric => (metric.id === data.id ? { ...metric, ...data } : metric)) - })); - } - }); - }; - - handleDelete = (metricKey: string) => { - return deleteMetric({ keys: metricKey }).then(() => { - if (this.mounted) { - this.setState(({ metrics = [], paging }: State) => ({ - metrics: metrics.filter(metric => metric.key !== metricKey), - paging: paging && { ...paging, total: paging.total - 1 } - })); - } - }); - }; - - render() { - const { domains, loading, metrics, paging, types } = this.state; - - return ( - <> - - -
    -
    - {metrics && ( - - )} - {metrics && paging && ( - - )} -
    - - ); - } -} diff --git a/server/sonar-web/src/main/js/apps/custom-metrics/components/CreateButton.tsx b/server/sonar-web/src/main/js/apps/custom-metrics/components/CreateButton.tsx deleted file mode 100644 index 9f7b69b7251..00000000000 --- a/server/sonar-web/src/main/js/apps/custom-metrics/components/CreateButton.tsx +++ /dev/null @@ -1,76 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2021 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 { Button } from 'sonar-ui-common/components/controls/buttons'; -import { translate } from 'sonar-ui-common/helpers/l10n'; -import Form, { MetricProps } from './Form'; - -interface Props { - domains: string[]; - onCreate: (data: MetricProps) => Promise; - types: string[]; -} - -interface State { - modal: boolean; -} - -export default class CreateButton extends React.PureComponent { - mounted = false; - state: State = { modal: false }; - - componentDidMount() { - this.mounted = true; - } - - componentWillUnmount() { - this.mounted = false; - } - - handleClick = () => { - this.setState({ modal: true }); - }; - - handleClose = () => { - if (this.mounted) { - this.setState({ modal: false }); - } - }; - - render() { - return ( - <> - - {this.state.modal && ( -
    - )} - - ); - } -} diff --git a/server/sonar-web/src/main/js/apps/custom-metrics/components/DeleteForm.tsx b/server/sonar-web/src/main/js/apps/custom-metrics/components/DeleteForm.tsx deleted file mode 100644 index 36a7869d4ee..00000000000 --- a/server/sonar-web/src/main/js/apps/custom-metrics/components/DeleteForm.tsx +++ /dev/null @@ -1,60 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2021 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 SimpleModal from 'sonar-ui-common/components/controls/SimpleModal'; -import DeferredSpinner from 'sonar-ui-common/components/ui/DeferredSpinner'; -import { translate, translateWithParameters } from 'sonar-ui-common/helpers/l10n'; - -interface Props { - metric: T.Metric; - onClose: () => void; - onSubmit: () => Promise; -} - -export default function DeleteForm({ metric, onClose, onSubmit }: Props) { - const header = translate('custom_metrics.delete_metric'); - - return ( - - {({ onCloseClick, onFormSubmit, submitting }) => ( - -
    -

    {header}

    -
    - -
    - {translateWithParameters('custom_metrics.delete_metric.confirmation', metric.name)} -
    - -
    - - - {translate('delete')} - - - {translate('cancel')} - -
    - - )} -
    - ); -} diff --git a/server/sonar-web/src/main/js/apps/custom-metrics/components/Form.tsx b/server/sonar-web/src/main/js/apps/custom-metrics/components/Form.tsx deleted file mode 100644 index 7d564cd2533..00000000000 --- a/server/sonar-web/src/main/js/apps/custom-metrics/components/Form.tsx +++ /dev/null @@ -1,198 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2021 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 Select, { Creatable } from 'sonar-ui-common/components/controls/Select'; -import SimpleModal from 'sonar-ui-common/components/controls/SimpleModal'; -import DeferredSpinner from 'sonar-ui-common/components/ui/DeferredSpinner'; -import MandatoryFieldMarker from 'sonar-ui-common/components/ui/MandatoryFieldMarker'; -import MandatoryFieldsExplanation from 'sonar-ui-common/components/ui/MandatoryFieldsExplanation'; -import { translate } from 'sonar-ui-common/helpers/l10n'; - -export interface MetricProps { - description: string; - domain?: string; - key: string; - name: string; - type: string; -} - -interface Props { - confirmButtonText: string; - domains: string[]; - metric?: T.Metric; - header: string; - onClose: () => void; - onSubmit: (data: MetricProps) => Promise; - types: string[]; -} - -interface State extends MetricProps {} - -export default class Form extends React.PureComponent { - constructor(props: Props) { - super(props); - this.state = { - description: (props.metric && props.metric.description) || '', - domain: props.metric && props.metric.domain, - key: (props.metric && props.metric.key) || '', - name: (props.metric && props.metric.name) || '', - type: (props.metric && props.metric.type) || 'INT' - }; - } - - handleSubmit = () => { - return this.props - .onSubmit({ - description: this.state.description, - domain: this.state.domain, - key: this.state.key, - name: this.state.name, - type: this.state.type - }) - .then(this.props.onClose); - }; - - handleKeyChange = (event: React.ChangeEvent) => { - this.setState({ key: event.currentTarget.value }); - }; - - handleDescriptionChange = (event: React.ChangeEvent) => { - this.setState({ description: event.currentTarget.value }); - }; - - handleNameChange = (event: React.ChangeEvent) => { - this.setState({ name: event.currentTarget.value }); - }; - - handleDomainChange = (option: { value: string } | null) => { - this.setState({ domain: option ? option.value : undefined }); - }; - - handleTypeChange = ({ value }: { value: string }) => { - this.setState({ type: value }); - }; - - render() { - const domains = [...this.props.domains]; - if (this.state.domain) { - domains.push(this.state.domain); - } - - return ( - - {({ onCloseClick, onFormSubmit, submitting }) => ( -
    -
    -

    {this.props.header}

    -
    - -
    - - -
    - - -
    -
    - - -
    -
    - -