123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- /*
- * 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 { setQualityGateAsDefault } from '../../../api/quality-gates';
- import { Button } from '../../../components/controls/buttons';
- import ModalButton from '../../../components/controls/ModalButton';
- import Tooltip from '../../../components/controls/Tooltip';
- import AlertWarnIcon from '../../../components/icons/AlertWarnIcon';
- import { translate } from '../../../helpers/l10n';
- import { CaycStatus, QualityGate } from '../../../types/types';
- import BuiltInQualityGateBadge from './BuiltInQualityGateBadge';
- import CaycBadgeTooltip from './CaycBadgeTooltip';
- import CopyQualityGateForm from './CopyQualityGateForm';
- import DeleteQualityGateForm from './DeleteQualityGateForm';
- import RenameQualityGateForm from './RenameQualityGateForm';
-
- interface Props {
- onSetDefault: () => void;
- qualityGate: QualityGate;
- refreshItem: () => Promise<void>;
- refreshList: () => Promise<void>;
- }
-
- const TOOLTIP_MOUSE_LEAVE_DELAY = 0.3;
-
- export default class DetailsHeader extends React.PureComponent<Props> {
- handleActionRefresh = () => {
- const { refreshItem, refreshList } = this.props;
- return Promise.all([refreshItem(), refreshList()]).then(
- () => {},
- () => {}
- );
- };
-
- handleSetAsDefaultClick = () => {
- const { qualityGate } = this.props;
- if (!qualityGate.isDefault) {
- // Optimistic update
- this.props.onSetDefault();
- setQualityGateAsDefault({ name: qualityGate.name }).then(
- this.handleActionRefresh,
- this.handleActionRefresh
- );
- }
- };
-
- render() {
- const { qualityGate } = this.props;
- const actions = qualityGate.actions || ({} as any);
-
- return (
- <div className="layout-page-header-panel layout-page-main-header issues-main-header">
- <div className="layout-page-header-panel-inner layout-page-main-header-inner">
- <div className="layout-page-main-inner">
- <div className="pull-left display-flex-center">
- <h2>{qualityGate.name}</h2>
- {qualityGate.isBuiltIn && <BuiltInQualityGateBadge className="spacer-left" />}
- {qualityGate.caycStatus === CaycStatus.NonCompliant && (
- <Tooltip overlay={<CaycBadgeTooltip />} mouseLeaveDelay={TOOLTIP_MOUSE_LEAVE_DELAY}>
- <AlertWarnIcon className="spacer-left" />
- </Tooltip>
- )}
- </div>
-
- <div className="pull-right">
- {actions.rename && (
- <ModalButton
- modal={({ onClose }) => (
- <RenameQualityGateForm
- onClose={onClose}
- onRename={this.props.refreshList}
- qualityGate={qualityGate}
- />
- )}
- >
- {({ onClick }) => (
- <Button id="quality-gate-rename" onClick={onClick}>
- {translate('rename')}
- </Button>
- )}
- </ModalButton>
- )}
- {actions.copy && (
- <ModalButton
- modal={({ onClose }) => (
- <CopyQualityGateForm
- onClose={onClose}
- onCopy={this.handleActionRefresh}
- qualityGate={qualityGate}
- />
- )}
- >
- {({ onClick }) => (
- <Tooltip
- overlay={
- qualityGate.caycStatus === CaycStatus.NonCompliant
- ? translate('quality_gates.cannot_copy_no_cayc')
- : null
- }
- accessible={false}
- >
- <Button
- className="little-spacer-left"
- id="quality-gate-copy"
- onClick={onClick}
- disabled={qualityGate.caycStatus === CaycStatus.NonCompliant}
- >
- {translate('copy')}
- </Button>
- </Tooltip>
- )}
- </ModalButton>
- )}
- {actions.setAsDefault && (
- <Tooltip
- overlay={
- qualityGate.caycStatus === CaycStatus.NonCompliant
- ? translate('quality_gates.cannot_set_default_no_cayc')
- : null
- }
- accessible={false}
- >
- <Button
- className="little-spacer-left"
- disabled={qualityGate.caycStatus === CaycStatus.NonCompliant}
- id="quality-gate-toggle-default"
- onClick={this.handleSetAsDefaultClick}
- >
- {translate('set_as_default')}
- </Button>
- </Tooltip>
- )}
- {actions.delete && (
- <DeleteQualityGateForm
- onDelete={this.props.refreshList}
- qualityGate={qualityGate}
- />
- )}
- </div>
- </div>
- </div>
- </div>
- );
- }
- }
|