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.

DetailsHeader.tsx 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 { setQualityGateAsDefault } from '../../../api/quality-gates';
  22. import { Button } from '../../../components/controls/buttons';
  23. import ModalButton from '../../../components/controls/ModalButton';
  24. import Tooltip from '../../../components/controls/Tooltip';
  25. import AlertWarnIcon from '../../../components/icons/AlertWarnIcon';
  26. import { translate } from '../../../helpers/l10n';
  27. import { CaycStatus, QualityGate } from '../../../types/types';
  28. import BuiltInQualityGateBadge from './BuiltInQualityGateBadge';
  29. import CaycBadgeTooltip from './CaycBadgeTooltip';
  30. import CopyQualityGateForm from './CopyQualityGateForm';
  31. import DeleteQualityGateForm from './DeleteQualityGateForm';
  32. import RenameQualityGateForm from './RenameQualityGateForm';
  33. interface Props {
  34. onSetDefault: () => void;
  35. qualityGate: QualityGate;
  36. refreshItem: () => Promise<void>;
  37. refreshList: () => Promise<void>;
  38. }
  39. const TOOLTIP_MOUSE_LEAVE_DELAY = 0.3;
  40. export default class DetailsHeader extends React.PureComponent<Props> {
  41. handleActionRefresh = () => {
  42. const { refreshItem, refreshList } = this.props;
  43. return Promise.all([refreshItem(), refreshList()]).then(
  44. () => {},
  45. () => {}
  46. );
  47. };
  48. handleSetAsDefaultClick = () => {
  49. const { qualityGate } = this.props;
  50. if (!qualityGate.isDefault) {
  51. // Optimistic update
  52. this.props.onSetDefault();
  53. setQualityGateAsDefault({ name: qualityGate.name }).then(
  54. this.handleActionRefresh,
  55. this.handleActionRefresh
  56. );
  57. }
  58. };
  59. render() {
  60. const { qualityGate } = this.props;
  61. const actions = qualityGate.actions || ({} as any);
  62. return (
  63. <div className="layout-page-header-panel layout-page-main-header issues-main-header">
  64. <div className="layout-page-header-panel-inner layout-page-main-header-inner">
  65. <div className="layout-page-main-inner">
  66. <div className="pull-left display-flex-center">
  67. <h2>{qualityGate.name}</h2>
  68. {qualityGate.isBuiltIn && <BuiltInQualityGateBadge className="spacer-left" />}
  69. {qualityGate.caycStatus === CaycStatus.NonCompliant && (
  70. <Tooltip overlay={<CaycBadgeTooltip />} mouseLeaveDelay={TOOLTIP_MOUSE_LEAVE_DELAY}>
  71. <AlertWarnIcon className="spacer-left" />
  72. </Tooltip>
  73. )}
  74. </div>
  75. <div className="pull-right">
  76. {actions.rename && (
  77. <ModalButton
  78. modal={({ onClose }) => (
  79. <RenameQualityGateForm
  80. onClose={onClose}
  81. onRename={this.props.refreshList}
  82. qualityGate={qualityGate}
  83. />
  84. )}
  85. >
  86. {({ onClick }) => (
  87. <Button id="quality-gate-rename" onClick={onClick}>
  88. {translate('rename')}
  89. </Button>
  90. )}
  91. </ModalButton>
  92. )}
  93. {actions.copy && (
  94. <ModalButton
  95. modal={({ onClose }) => (
  96. <CopyQualityGateForm
  97. onClose={onClose}
  98. onCopy={this.handleActionRefresh}
  99. qualityGate={qualityGate}
  100. />
  101. )}
  102. >
  103. {({ onClick }) => (
  104. <Tooltip
  105. overlay={
  106. qualityGate.caycStatus === CaycStatus.NonCompliant
  107. ? translate('quality_gates.cannot_copy_no_cayc')
  108. : null
  109. }
  110. accessible={false}
  111. >
  112. <Button
  113. className="little-spacer-left"
  114. id="quality-gate-copy"
  115. onClick={onClick}
  116. disabled={qualityGate.caycStatus === CaycStatus.NonCompliant}
  117. >
  118. {translate('copy')}
  119. </Button>
  120. </Tooltip>
  121. )}
  122. </ModalButton>
  123. )}
  124. {actions.setAsDefault && (
  125. <Tooltip
  126. overlay={
  127. qualityGate.caycStatus === CaycStatus.NonCompliant
  128. ? translate('quality_gates.cannot_set_default_no_cayc')
  129. : null
  130. }
  131. accessible={false}
  132. >
  133. <Button
  134. className="little-spacer-left"
  135. disabled={qualityGate.caycStatus === CaycStatus.NonCompliant}
  136. id="quality-gate-toggle-default"
  137. onClick={this.handleSetAsDefaultClick}
  138. >
  139. {translate('set_as_default')}
  140. </Button>
  141. </Tooltip>
  142. )}
  143. {actions.delete && (
  144. <DeleteQualityGateForm
  145. onDelete={this.props.refreshList}
  146. qualityGate={qualityGate}
  147. />
  148. )}
  149. </div>
  150. </div>
  151. </div>
  152. </div>
  153. );
  154. }
  155. }