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.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 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 { connect } from 'react-redux';
  22. import { getAppState, getGlobalSettingValue, Store } from '../../../store/rootReducer';
  23. import { AdminPageExtension } from '../../../types/extension';
  24. import { fetchValues } from '../../settings/store/actions';
  25. import '../style.css';
  26. import { HousekeepingPolicy, RangeOption } from '../utils';
  27. import AuditAppRenderer from './AuditAppRenderer';
  28. interface Props {
  29. auditHousekeepingPolicy: HousekeepingPolicy;
  30. fetchValues: typeof fetchValues;
  31. hasGovernanceExtension?: boolean;
  32. }
  33. interface State {
  34. dateRange?: { from?: Date; to?: Date };
  35. downloadStarted: boolean;
  36. selection: RangeOption;
  37. }
  38. export class AuditApp extends React.PureComponent<Props, State> {
  39. state: State = {
  40. downloadStarted: false,
  41. selection: RangeOption.Today
  42. };
  43. componentDidMount() {
  44. const { hasGovernanceExtension } = this.props;
  45. if (hasGovernanceExtension) {
  46. this.props.fetchValues(['sonar.dbcleaner.auditHousekeeping']);
  47. }
  48. }
  49. handleDateSelection = (dateRange: { from?: Date; to?: Date }) =>
  50. this.setState({ dateRange, downloadStarted: false, selection: RangeOption.Custom });
  51. handleOptionSelection = (selection: RangeOption) =>
  52. this.setState({ dateRange: undefined, downloadStarted: false, selection });
  53. handleStartDownload = () => {
  54. setTimeout(() => {
  55. this.setState({ downloadStarted: true });
  56. }, 0);
  57. };
  58. render() {
  59. const { hasGovernanceExtension, auditHousekeepingPolicy } = this.props;
  60. return hasGovernanceExtension ? (
  61. <AuditAppRenderer
  62. handleDateSelection={this.handleDateSelection}
  63. handleOptionSelection={this.handleOptionSelection}
  64. handleStartDownload={this.handleStartDownload}
  65. housekeepingPolicy={auditHousekeepingPolicy || HousekeepingPolicy.Monthly}
  66. {...this.state}
  67. />
  68. ) : null;
  69. }
  70. }
  71. const mapDispatchToProps = { fetchValues };
  72. const mapStateToProps = (state: Store) => {
  73. const settingValue = getGlobalSettingValue(state, 'sonar.dbcleaner.auditHousekeeping');
  74. const { adminPages } = getAppState(state);
  75. const hasGovernanceExtension = Boolean(
  76. adminPages?.find(e => e.key === AdminPageExtension.GovernanceConsole)
  77. );
  78. return {
  79. auditHousekeepingPolicy: settingValue?.value as HousekeepingPolicy,
  80. hasGovernanceExtension
  81. };
  82. };
  83. export default connect(mapStateToProps, mapDispatchToProps)(AuditApp);