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.

SystemUpgradeForm.tsx 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 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 { FlagMessage, Link, Modal } from 'design-system';
  21. import { filter, flatMap, isEmpty, negate } from 'lodash';
  22. import * as React from 'react';
  23. import { useAppState } from '../../app/components/app-state/withAppStateContext';
  24. import { BANNER_VARIANT } from '../../app/components/update-notification/helpers';
  25. import { translate } from '../../helpers/l10n';
  26. import { SystemUpgrade } from '../../types/system';
  27. import SystemUpgradeItem from './SystemUpgradeItem';
  28. import { SYSTEM_VERSION_REGEXP, UpdateUseCase } from './utils';
  29. interface Props {
  30. onClose: () => void;
  31. systemUpgrades: SystemUpgrade[][];
  32. latestLTA: string;
  33. updateUseCase: UpdateUseCase;
  34. }
  35. export default function SystemUpgradeForm(props: Readonly<Props>) {
  36. const appState = useAppState();
  37. const { latestLTA, onClose, updateUseCase, systemUpgrades } = props;
  38. let systemUpgradesWithPatch: SystemUpgrade[][] = [];
  39. const alertVariant =
  40. updateUseCase !== UpdateUseCase.NewVersion ? BANNER_VARIANT[updateUseCase] : undefined;
  41. const header = translate('system.system_upgrade');
  42. const parsedVersion = SYSTEM_VERSION_REGEXP.exec(appState.version);
  43. let patches: SystemUpgrade[] = [];
  44. if (updateUseCase === UpdateUseCase.NewPatch && parsedVersion !== null) {
  45. const [, major, minor] = parsedVersion;
  46. const majoMinorVersion = `${major}.${minor}`;
  47. patches = flatMap(systemUpgrades, (upgrades) =>
  48. filter(upgrades, (upgrade) => upgrade.version.startsWith(majoMinorVersion)),
  49. );
  50. systemUpgradesWithPatch = systemUpgrades
  51. .map((upgrades) =>
  52. upgrades.filter((upgrade) => !upgrade.version.startsWith(majoMinorVersion)),
  53. )
  54. .filter(negate(isEmpty));
  55. systemUpgradesWithPatch.push(patches);
  56. } else {
  57. let untilLTA = false;
  58. for (const upgrades of systemUpgrades) {
  59. if (untilLTA === false) {
  60. systemUpgradesWithPatch.push(upgrades);
  61. untilLTA = upgrades.some((upgrade) => upgrade.version.startsWith(latestLTA));
  62. }
  63. }
  64. }
  65. return (
  66. <Modal
  67. headerTitle={header}
  68. onClose={onClose}
  69. body={
  70. <>
  71. {alertVariant && (
  72. <FlagMessage variant={alertVariant} className={`it__upgrade-alert-${updateUseCase}`}>
  73. {translate('admin_notification.update', updateUseCase)}
  74. </FlagMessage>
  75. )}
  76. {systemUpgradesWithPatch.map((upgrades) => (
  77. <SystemUpgradeItem
  78. edition={appState.edition}
  79. key={upgrades[upgrades.length - 1].version}
  80. systemUpgrades={upgrades}
  81. isPatch={upgrades === patches}
  82. isLTAVersion={upgrades.some((upgrade) => upgrade.version.startsWith(latestLTA))}
  83. />
  84. ))}
  85. </>
  86. }
  87. primaryButton={
  88. <Link to="https://www.sonarsource.com/products/sonarqube/downloads/?referrer=sonarqube">
  89. {translate('system.see_sonarqube_downloads')}
  90. </Link>
  91. }
  92. secondaryButtonLabel={translate('cancel')}
  93. />
  94. );
  95. }