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.

ApplicationQualityGate.tsx 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 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 { keyBy } from 'lodash';
  22. import ApplicationQualityGateProject from './ApplicationQualityGateProject';
  23. import Level from '../../../components/ui/Level';
  24. import DocTooltip from '../../../components/docs/DocTooltip';
  25. import HelpTooltip from '../../../components/controls/HelpTooltip';
  26. import { getApplicationQualityGate, ApplicationProject } from '../../../api/quality-gates';
  27. import { translate } from '../../../helpers/l10n';
  28. interface Props {
  29. branch?: T.LongLivingBranch;
  30. component: T.LightComponent;
  31. }
  32. type State = {
  33. loading: boolean;
  34. metrics?: { [key: string]: T.Metric };
  35. projects?: ApplicationProject[];
  36. status?: string;
  37. };
  38. export default class ApplicationQualityGate extends React.PureComponent<Props, State> {
  39. mounted = false;
  40. state: State = { loading: true };
  41. componentDidMount() {
  42. this.mounted = true;
  43. this.fetchDetails();
  44. }
  45. componentDidUpdate(prevProps: Props) {
  46. if (prevProps.component.key !== this.props.component.key) {
  47. this.fetchDetails();
  48. }
  49. }
  50. componentWillUnmount() {
  51. this.mounted = false;
  52. }
  53. fetchDetails = () => {
  54. const { branch, component } = this.props;
  55. this.setState({ loading: true });
  56. getApplicationQualityGate({
  57. application: component.key,
  58. branch: branch ? branch.name : undefined,
  59. organization: component.organization
  60. }).then(
  61. ({ status, projects, metrics }) => {
  62. if (this.mounted) {
  63. this.setState({
  64. loading: false,
  65. metrics: keyBy(metrics, 'key'),
  66. status,
  67. projects
  68. });
  69. }
  70. },
  71. () => {
  72. if (this.mounted) {
  73. this.setState({ loading: false });
  74. }
  75. }
  76. );
  77. };
  78. render() {
  79. const { metrics, status, projects } = this.state;
  80. return (
  81. <div className="overview-quality-gate" id="overview-quality-gate">
  82. <h2 className="overview-title">
  83. {translate('overview.quality_gate')}
  84. {this.state.loading && <i className="spinner spacer-left" />}
  85. <DocTooltip
  86. className="spacer-left"
  87. doc={import(/* webpackMode: "eager" */ 'Docs/tooltips/quality-gates/project-homepage-quality-gate.md')}
  88. />
  89. {status != null && <Level className="big-spacer-left" level={status} />}
  90. {status === 'WARN' && (
  91. <HelpTooltip
  92. className="little-spacer-left"
  93. overlay={translate('quality_gates.conditions.warning.tootlip')}
  94. />
  95. )}
  96. </h2>
  97. {projects &&
  98. metrics && (
  99. <div
  100. className="overview-quality-gate-conditions-list clearfix"
  101. id="overview-quality-gate-conditions-list">
  102. {projects.filter(project => project.status !== 'OK').map(project => (
  103. <ApplicationQualityGateProject
  104. key={project.key}
  105. metrics={metrics}
  106. project={project}
  107. />
  108. ))}
  109. </div>
  110. )}
  111. </div>
  112. );
  113. }
  114. }