/* * SonarQube * Copyright (C) 2009-2019 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 { translate } from 'sonar-ui-common/helpers/l10n'; import { SubmitButton, ResetButtonLink } from 'sonar-ui-common/components/controls/buttons'; import DeferredSpinner from 'sonar-ui-common/components/ui/DeferredSpinner'; import SimpleModal from 'sonar-ui-common/components/controls/SimpleModal'; import Select, { Creatable } from 'sonar-ui-common/components/controls/Select'; 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}