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.

AuditAppRenderer.tsx 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 { subDays } from 'date-fns';
  21. import * as React from 'react';
  22. import { Helmet } from 'react-helmet-async';
  23. import { FormattedMessage } from 'react-intl';
  24. import Link from '../../../components/common/Link';
  25. import DateRangeInput from '../../../components/controls/DateRangeInput';
  26. import Radio from '../../../components/controls/Radio';
  27. import Suggestions from '../../../components/embed-docs-modal/Suggestions';
  28. import { now } from '../../../helpers/dates';
  29. import { translate } from '../../../helpers/l10n';
  30. import { queryToSearch } from '../../../helpers/urls';
  31. import '../style.css';
  32. import { HousekeepingPolicy, RangeOption } from '../utils';
  33. import DownloadButton from './DownloadButton';
  34. export interface AuditAppRendererProps {
  35. dateRange?: { from?: Date; to?: Date };
  36. downloadStarted: boolean;
  37. handleOptionSelection: (option: RangeOption) => void;
  38. handleDateSelection: (dateRange: { from?: Date; to?: Date }) => void;
  39. handleStartDownload: () => void;
  40. housekeepingPolicy: HousekeepingPolicy;
  41. selection: RangeOption;
  42. }
  43. const HOUSEKEEPING_MONTH_THRESHOLD = 30;
  44. const HOUSEKEEPING_TRIMESTER_THRESHOLD = 90;
  45. const HOUSEKEEPING_POLICY_VALUES = {
  46. [HousekeepingPolicy.Weekly]: 7,
  47. [HousekeepingPolicy.Monthly]: 30,
  48. [HousekeepingPolicy.Trimestrial]: 90,
  49. [HousekeepingPolicy.Yearly]: 365
  50. };
  51. const getRangeOptions = (housekeepingPolicy: HousekeepingPolicy) => {
  52. const rangeOptions = [RangeOption.Today, RangeOption.Week];
  53. if (HOUSEKEEPING_POLICY_VALUES[housekeepingPolicy] >= HOUSEKEEPING_MONTH_THRESHOLD) {
  54. rangeOptions.push(RangeOption.Month);
  55. }
  56. if (HOUSEKEEPING_POLICY_VALUES[housekeepingPolicy] >= HOUSEKEEPING_TRIMESTER_THRESHOLD) {
  57. rangeOptions.push(RangeOption.Trimester);
  58. }
  59. rangeOptions.push(RangeOption.Custom);
  60. return rangeOptions;
  61. };
  62. export default function AuditAppRenderer(props: AuditAppRendererProps) {
  63. const { dateRange, downloadStarted, housekeepingPolicy, selection } = props;
  64. return (
  65. <div className="page page-limited" id="marketplace-page">
  66. <Suggestions suggestions="audit-logs" />
  67. <Helmet title={translate('audit_logs.page')} />
  68. <header className="page-header">
  69. <h1 className="page-title">{translate('audit_logs.page')}</h1>
  70. </header>
  71. <p className="big-spacer-bottom">
  72. {translate('audit_logs.page.description.1')}
  73. <br />
  74. <FormattedMessage
  75. id="audit_logs.page.description.2"
  76. defaultMessage={translate('audit_logs.page.description.2')}
  77. values={{
  78. housekeeping: translate('audit_logs.housekeeping_policy', housekeepingPolicy),
  79. link: (
  80. <Link
  81. to={{
  82. pathname: '/admin/settings',
  83. search: queryToSearch({ category: 'housekeeping' }),
  84. hash: '#auditLogs'
  85. }}>
  86. {translate('audit_logs.page.description.link')}
  87. </Link>
  88. )
  89. }}
  90. />
  91. </p>
  92. <div className="huge-spacer-bottom">
  93. <h2 className="big-spacer-bottom">{translate('audit_logs.download')}</h2>
  94. <ul>
  95. {getRangeOptions(housekeepingPolicy).map(option => (
  96. <li key={option} className="spacer-bottom">
  97. <Radio
  98. checked={selection === option}
  99. onCheck={props.handleOptionSelection}
  100. value={option}>
  101. {translate('audit_logs.range_option', option)}
  102. </Radio>
  103. </li>
  104. ))}
  105. </ul>
  106. <DateRangeInput
  107. className="big-spacer-left"
  108. onChange={props.handleDateSelection}
  109. minDate={subDays(now(), HOUSEKEEPING_POLICY_VALUES[housekeepingPolicy])}
  110. maxDate={now()}
  111. value={dateRange}
  112. />
  113. </div>
  114. <DownloadButton
  115. dateRange={dateRange}
  116. downloadStarted={downloadStarted}
  117. onStartDownload={props.handleStartDownload}
  118. selection={selection}
  119. />
  120. </div>
  121. );
  122. }