123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- /*
- * 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 } 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<void>;
- onUpdate: (data: WebhookUpdatePayload) => Promise<void>;
- webhook: WebhookResponse;
- }
-
- interface State {
- deleting: boolean;
- deliveries: boolean;
- updating: boolean;
- }
-
- export default class WebhookActions extends React.PureComponent<Props, State> {
- 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 (
- <>
- <ActionsDropdown className="big-spacer-left">
- <ActionsDropdownItem className="js-webhook-update" onClick={this.handleUpdateClick}>
- {translate('update_verb')}
- </ActionsDropdownItem>
- {webhook.latestDelivery && (
- <ActionsDropdownItem
- className="js-webhook-deliveries"
- onClick={this.handleDeliveriesClick}
- >
- {translate('webhooks.deliveries.show')}
- </ActionsDropdownItem>
- )}
- <ActionsDropdownDivider />
- <ActionsDropdownItem
- className="js-webhook-delete"
- destructive={true}
- onClick={this.handleDeleteClick}
- >
- {translate('delete')}
- </ActionsDropdownItem>
- </ActionsDropdown>
-
- {this.state.deliveries && (
- <DeliveriesForm onClose={this.handleDeliveriesStop} webhook={webhook} />
- )}
-
- {this.state.updating && (
- <CreateWebhookForm
- onClose={this.handleUpdatingStop}
- onDone={this.handleUpdate}
- webhook={webhook}
- />
- )}
-
- {this.state.deleting && (
- <DeleteWebhookForm
- onClose={this.handleDeletingStop}
- onSubmit={this.handleDelete}
- webhook={webhook}
- />
- )}
- </>
- );
- }
- }
|