Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

AuditApp.tsx 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2022 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 { getValues } from '../../../api/settings';
  22. import { AdminPageExtension } from '../../../types/extension';
  23. import { SettingsKey } from '../../../types/settings';
  24. import { Extension } from '../../../types/types';
  25. import '../style.css';
  26. import { HousekeepingPolicy, RangeOption } from '../utils';
  27. import AuditAppRenderer from './AuditAppRenderer';
  28. interface Props {
  29. adminPages: Extension[];
  30. }
  31. interface State {
  32. dateRange?: { from?: Date; to?: Date };
  33. downloadStarted: boolean;
  34. housekeepingPolicy: HousekeepingPolicy;
  35. selection: RangeOption;
  36. }
  37. export default class AuditApp extends React.PureComponent<Props, State> {
  38. constructor(props: Props) {
  39. super(props);
  40. this.state = {
  41. downloadStarted: false,
  42. housekeepingPolicy: HousekeepingPolicy.Monthly,
  43. selection: RangeOption.Today
  44. };
  45. }
  46. componentDidMount() {
  47. if (this.hasGovernanceExtension()) {
  48. this.fetchHouseKeepingPolicy();
  49. }
  50. }
  51. componentDidUpdate(prevProps: Props) {
  52. if (prevProps.adminPages !== this.props.adminPages && this.hasGovernanceExtension()) {
  53. this.fetchHouseKeepingPolicy();
  54. }
  55. }
  56. fetchHouseKeepingPolicy = async () => {
  57. const results = await getValues({ keys: SettingsKey.AuditHouseKeeping });
  58. this.setState({
  59. housekeepingPolicy:
  60. (results[0]?.value as HousekeepingPolicy | undefined) ?? HousekeepingPolicy.Monthly
  61. });
  62. };
  63. hasGovernanceExtension = () => {
  64. return Boolean(
  65. this.props.adminPages?.find(e => e.key === AdminPageExtension.GovernanceConsole)
  66. );
  67. };
  68. handleDateSelection = (dateRange: { from?: Date; to?: Date }) =>
  69. this.setState({ dateRange, downloadStarted: false, selection: RangeOption.Custom });
  70. handleOptionSelection = (selection: RangeOption) =>
  71. this.setState({ dateRange: undefined, downloadStarted: false, selection });
  72. handleStartDownload = () => {
  73. setTimeout(() => {
  74. this.setState({ downloadStarted: true });
  75. }, 0);
  76. };
  77. render() {
  78. if (!this.hasGovernanceExtension()) {
  79. return null;
  80. }
  81. return (
  82. <AuditAppRenderer
  83. handleDateSelection={this.handleDateSelection}
  84. handleOptionSelection={this.handleOptionSelection}
  85. handleStartDownload={this.handleStartDownload}
  86. {...this.state}
  87. />
  88. );
  89. }
  90. }