aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIsmail Cherri <ismail.cherri@sonarsource.com>2024-04-09 09:04:23 +0200
committersonartech <sonartech@sonarsource.com>2024-04-10 20:02:56 +0000
commit0072c50e15384396032de42e12f95d7449c35c22 (patch)
tree7823d72b58078f019cd8b8d4bdcc2889bb5b09eb
parent17d2777a0039403fb75789fefc2f5999430b92da (diff)
downloadsonarqube-0072c50e15384396032de42e12f95d7449c35c22.tar.gz
sonarqube-0072c50e15384396032de42e12f95d7449c35c22.zip
SONAR-22017 Active version is also based on current EOL
-rw-r--r--server/sonar-web/src/main/js/app/components/__tests__/GlobalFooter-test.tsx21
-rw-r--r--server/sonar-web/src/main/js/app/components/app-state/AppStateContext.tsx1
-rw-r--r--server/sonar-web/src/main/js/components/shared/AppVersionStatus.tsx40
-rw-r--r--server/sonar-web/src/main/js/helpers/system.ts6
-rw-r--r--server/sonar-web/src/main/js/helpers/testMocks.ts4
-rw-r--r--server/sonar-web/src/main/js/types/appstate.ts1
6 files changed, 51 insertions, 22 deletions
diff --git a/server/sonar-web/src/main/js/app/components/__tests__/GlobalFooter-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/GlobalFooter-test.tsx
index 4c0503d5c2d..cc174d6ee81 100644
--- a/server/sonar-web/src/main/js/app/components/__tests__/GlobalFooter-test.tsx
+++ b/server/sonar-web/src/main/js/app/components/__tests__/GlobalFooter-test.tsx
@@ -17,6 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+import { addDays, subDays } from 'date-fns';
import * as React from 'react';
import SystemServiceMock from '../../../api/mocks/SystemServiceMock';
import { mockAppState } from '../../../helpers/testMocks';
@@ -54,12 +55,24 @@ it('should render the inactive version and cleanup build number', async () => {
expect(await ui.ltaDocumentationLinkInactive.find()).toBeInTheDocument();
});
-it('should active status if undefined', () => {
+it('should show active status if offline and did not reach EOL', async () => {
systemMock.setSystemUpgrades({ installedVersionActive: undefined });
- renderGlobalFooter({}, { version: '4.2 (build 12345)' });
+ renderGlobalFooter(
+ {},
+ { version: '4.2 (build 12345)', installedVersionEOL: addDays(new Date(), 10).toISOString() },
+ );
+
+ expect(await ui.ltaDocumentationLinkActive.find()).toBeInTheDocument();
+});
- expect(ui.ltaDocumentationLinkInactive.query()).not.toBeInTheDocument();
- expect(ui.ltaDocumentationLinkActive.query()).not.toBeInTheDocument();
+it('should show inactive status if offline and reached EOL', async () => {
+ systemMock.setSystemUpgrades({ installedVersionActive: undefined });
+ renderGlobalFooter(
+ {},
+ { version: '4.2 (build 12345)', installedVersionEOL: subDays(new Date(), 10).toISOString() },
+ );
+
+ expect(await ui.ltaDocumentationLinkInactive.find()).toBeInTheDocument();
});
it('should not render missing logged-in information', () => {
diff --git a/server/sonar-web/src/main/js/app/components/app-state/AppStateContext.tsx b/server/sonar-web/src/main/js/app/components/app-state/AppStateContext.tsx
index a679b8d05ac..bfd1538af22 100644
--- a/server/sonar-web/src/main/js/app/components/app-state/AppStateContext.tsx
+++ b/server/sonar-web/src/main/js/app/components/app-state/AppStateContext.tsx
@@ -21,6 +21,7 @@ import * as React from 'react';
import { AppState } from '../../../types/appstate';
export const DEFAULT_APP_STATE = {
+ installedVersionEOL: '',
authenticationError: false,
authorizationError: false,
edition: undefined,
diff --git a/server/sonar-web/src/main/js/components/shared/AppVersionStatus.tsx b/server/sonar-web/src/main/js/components/shared/AppVersionStatus.tsx
index 99a26e972e0..7fe3277d0e0 100644
--- a/server/sonar-web/src/main/js/components/shared/AppVersionStatus.tsx
+++ b/server/sonar-web/src/main/js/components/shared/AppVersionStatus.tsx
@@ -19,16 +19,25 @@
*/
import { LinkHighlight, LinkStandalone } from '@sonarsource/echoes-react';
-import React from 'react';
+import React, { useMemo } from 'react';
import { FormattedMessage, useIntl } from 'react-intl';
import { useAppState } from '../../app/components/app-state/withAppStateContext';
import { useDocUrl } from '../../helpers/docs';
import { getInstanceVersionNumber } from '../../helpers/strings';
+import { isCurrentVersionEOLActive } from '../../helpers/system';
import { useSystemUpgrades } from '../../queries/system';
export default function AppVersionStatus() {
const { data } = useSystemUpgrades();
- const { version } = useAppState();
+ const { version, installedVersionEOL } = useAppState();
+
+ const isActiveVersion = useMemo(() => {
+ if (data?.installedVersionActive !== undefined) {
+ return data.installedVersionActive;
+ }
+
+ return isCurrentVersionEOLActive(installedVersionEOL);
+ }, [data?.installedVersionActive, installedVersionEOL]);
const docUrl = useDocUrl();
const intl = useIntl();
@@ -37,20 +46,17 @@ export default function AppVersionStatus() {
{ id: `footer.version` },
{
version: getInstanceVersionNumber(version),
- status:
- data?.installedVersionActive !== undefined ? (
- <LinkStandalone
- className="sw-ml-1"
- highlight={LinkHighlight.CurrentColor}
- to={docUrl('/setup-and-upgrade/upgrade-the-server/active-versions/')}
- >
- <FormattedMessage
- id={`footer.version.status.${data.installedVersionActive ? 'active' : 'inactive'}`}
- />
- </LinkStandalone>
- ) : (
- ''
- ),
- },
+ status: (
+ <LinkStandalone
+ className="sw-ml-1"
+ highlight={LinkHighlight.CurrentColor}
+ to={docUrl('/setup-and-upgrade/upgrade-the-server/active-versions/')}
+ >
+ <FormattedMessage
+ id={`footer.version.status.${isActiveVersion ? 'active' : 'inactive'}`}
+ />
+ </LinkStandalone>
+ ),
+ }
);
}
diff --git a/server/sonar-web/src/main/js/helpers/system.ts b/server/sonar-web/src/main/js/helpers/system.ts
index 730beed41cb..1503850fe67 100644
--- a/server/sonar-web/src/main/js/helpers/system.ts
+++ b/server/sonar-web/src/main/js/helpers/system.ts
@@ -17,8 +17,10 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+import { isAfter } from 'date-fns';
import { AppVariablesElement } from '../types/browser';
import { getEnhancedWindow } from './browser';
+import { parseDate } from './dates';
export function getBaseUrl() {
return getEnhancedWindow().baseUrl;
@@ -53,3 +55,7 @@ export function initAppVariables() {
getEnhancedWindow().instance = appVariablesDiv.dataset.instance;
getEnhancedWindow().official = Boolean(appVariablesDiv.dataset.official);
}
+
+export function isCurrentVersionEOLActive(installedVersionEOL: string) {
+ return isAfter(parseDate(installedVersionEOL), new Date());
+}
diff --git a/server/sonar-web/src/main/js/helpers/testMocks.ts b/server/sonar-web/src/main/js/helpers/testMocks.ts
index 0ef2c641c7c..1ea0bc60e69 100644
--- a/server/sonar-web/src/main/js/helpers/testMocks.ts
+++ b/server/sonar-web/src/main/js/helpers/testMocks.ts
@@ -33,6 +33,7 @@ import {
SoftwareQuality,
} from '../types/clean-code-taxonomy';
import { RuleRepository } from '../types/coding-rules';
+import { ComponentQualifier } from '../types/component';
import { EditionKey } from '../types/editions';
import {
IssueDeprecatedStatus,
@@ -90,10 +91,11 @@ export function mockAppState(overrides: Partial<AppState> = {}): AppState {
return {
edition: EditionKey.community,
productionDatabase: true,
- qualifiers: ['TRK'],
+ qualifiers: [ComponentQualifier.Project],
settings: {},
version: '1.0',
documentationUrl: 'https://docs.sonarsource.com/sonarqube/10.0',
+ installedVersionEOL: '2024-01-01T00:00:00Z',
...overrides,
};
}
diff --git a/server/sonar-web/src/main/js/types/appstate.ts b/server/sonar-web/src/main/js/types/appstate.ts
index 00e5c67e082..f9bac3f35fd 100644
--- a/server/sonar-web/src/main/js/types/appstate.ts
+++ b/server/sonar-web/src/main/js/types/appstate.ts
@@ -28,6 +28,7 @@ export interface AppState {
edition?: EditionKey;
globalPages?: Extension[];
instanceUsesDefaultAdminCredentials?: boolean;
+ installedVersionEOL: string;
needIssueSync?: boolean;
productionDatabase: boolean;
qualifiers: string[];