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.

LifetimeInformation.tsx 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 withAppStateContext from '../../../app/components/app-state/withAppStateContext';
  23. import { AppState } from '../../../types/appstate';
  24. import { SettingsKey } from '../../../types/settings';
  25. import LifetimeInformationRenderer from './LifetimeInformationRenderer';
  26. interface Props {
  27. appState: AppState;
  28. }
  29. interface State {
  30. branchAndPullRequestLifeTimeInDays?: string;
  31. loading: boolean;
  32. }
  33. export class LifetimeInformation extends React.PureComponent<Props, State> {
  34. mounted = false;
  35. state: State = { loading: true };
  36. componentDidMount() {
  37. this.mounted = true;
  38. this.fetchBranchAndPullRequestLifetimeSetting();
  39. }
  40. componentWillUnmount() {
  41. this.mounted = false;
  42. }
  43. fetchBranchAndPullRequestLifetimeSetting() {
  44. getValues({ keys: SettingsKey.DaysBeforeDeletingInactiveBranchesAndPRs }).then(
  45. settings => {
  46. if (this.mounted) {
  47. this.setState({
  48. loading: false,
  49. branchAndPullRequestLifeTimeInDays: settings.length > 0 ? settings[0].value : undefined
  50. });
  51. }
  52. },
  53. () => {
  54. if (this.mounted) {
  55. this.setState({ loading: false });
  56. }
  57. }
  58. );
  59. }
  60. render() {
  61. const {
  62. appState: { canAdmin }
  63. } = this.props;
  64. const { branchAndPullRequestLifeTimeInDays, loading } = this.state;
  65. return (
  66. <LifetimeInformationRenderer
  67. branchAndPullRequestLifeTimeInDays={branchAndPullRequestLifeTimeInDays}
  68. canAdmin={canAdmin}
  69. loading={loading}
  70. />
  71. );
  72. }
  73. }
  74. export default withAppStateContext(LifetimeInformation);