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.

AuditApp.tsx 3.1KB

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