You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WebhookItemLatestDelivery.tsx 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2023 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import * as React from 'react';
  21. import { ButtonIcon } from '../../../components/controls/buttons';
  22. import AlertErrorIcon from '../../../components/icons/AlertErrorIcon';
  23. import AlertSuccessIcon from '../../../components/icons/AlertSuccessIcon';
  24. import BulletListIcon from '../../../components/icons/BulletListIcon';
  25. import DateTimeFormatter from '../../../components/intl/DateTimeFormatter';
  26. import { translate } from '../../../helpers/l10n';
  27. import { WebhookResponse } from '../../../types/webhook';
  28. import LatestDeliveryForm from './LatestDeliveryForm';
  29. interface Props {
  30. webhook: WebhookResponse;
  31. }
  32. interface State {
  33. modal: boolean;
  34. }
  35. export default class WebhookItemLatestDelivery extends React.PureComponent<Props, State> {
  36. mounted = false;
  37. state: State = { modal: false };
  38. componentDidMount() {
  39. this.mounted = true;
  40. }
  41. componentWillUnmount() {
  42. this.mounted = false;
  43. }
  44. handleClick = () => {
  45. this.setState({ modal: true });
  46. };
  47. handleModalClose = () => {
  48. if (this.mounted) {
  49. this.setState({ modal: false });
  50. }
  51. };
  52. render() {
  53. const { webhook } = this.props;
  54. if (!webhook.latestDelivery) {
  55. return <span>{translate('webhooks.last_execution.none')}</span>;
  56. }
  57. const { modal } = this.state;
  58. return (
  59. <>
  60. {webhook.latestDelivery.success ? (
  61. <AlertSuccessIcon className="text-text-top" />
  62. ) : (
  63. <AlertErrorIcon className="text-text-top" />
  64. )}
  65. <span className="spacer-left display-inline-flex-center">
  66. <DateTimeFormatter date={webhook.latestDelivery.at} />
  67. <ButtonIcon className="button-small little-spacer-left" onClick={this.handleClick}>
  68. <BulletListIcon />
  69. </ButtonIcon>
  70. </span>
  71. {modal && (
  72. <LatestDeliveryForm
  73. delivery={webhook.latestDelivery}
  74. onClose={this.handleModalClose}
  75. webhook={webhook}
  76. />
  77. )}
  78. </>
  79. );
  80. }
  81. }