/* * SonarQube * Copyright (C) 2009-2023 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 ActionsDropdown, { ActionsDropdownDivider, ActionsDropdownItem, } from '../../../components/controls/ActionsDropdown'; import { translate, translateWithParameters } from '../../../helpers/l10n'; import { WebhookResponse, WebhookUpdatePayload } from '../../../types/webhook'; import CreateWebhookForm from './CreateWebhookForm'; import DeleteWebhookForm from './DeleteWebhookForm'; import DeliveriesForm from './DeliveriesForm'; interface Props { onDelete: (webhook: string) => Promise; onUpdate: (data: WebhookUpdatePayload) => Promise; webhook: WebhookResponse; } interface State { deleting: boolean; deliveries: boolean; updating: boolean; } export default class WebhookActions extends React.PureComponent { mounted = false; state: State = { deleting: false, deliveries: false, updating: false }; componentDidMount() { this.mounted = true; } componentWillUnmount() { this.mounted = false; } handleDelete = () => { return this.props.onDelete(this.props.webhook.key); }; handleDeleteClick = () => { this.setState({ deleting: true }); }; handleDeletingStop = () => { if (this.mounted) { this.setState({ deleting: false }); } }; handleDeliveriesClick = () => { this.setState({ deliveries: true }); }; handleDeliveriesStop = () => { this.setState({ deliveries: false }); }; handleUpdate = (data: { name: string; secret?: string; url: string }) => { return this.props.onUpdate({ ...data, webhook: this.props.webhook.key }); }; handleUpdateClick = () => { this.setState({ updating: true }); }; handleUpdatingStop = () => { this.setState({ updating: false }); }; render() { const { webhook } = this.props; return ( <> {translate('update_verb')} {webhook.latestDelivery && ( {translate('webhooks.deliveries.show')} )} {translate('delete')} {this.state.deliveries && ( )} {this.state.updating && ( )} {this.state.deleting && ( )} ); } }