Browse Source

SONAR-22017 Active version is also based on current EOL

tags/10.5.0.89998
Ismail Cherri 2 months ago
parent
commit
0072c50e15

+ 17
- 4
server/sonar-web/src/main/js/app/components/__tests__/GlobalFooter-test.tsx View File

@@ -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', () => {

+ 1
- 0
server/sonar-web/src/main/js/app/components/app-state/AppStateContext.tsx View File

@@ -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,

+ 23
- 17
server/sonar-web/src/main/js/components/shared/AppVersionStatus.tsx View File

@@ -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>
),
}
);
}

+ 6
- 0
server/sonar-web/src/main/js/helpers/system.ts View File

@@ -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());
}

+ 3
- 1
server/sonar-web/src/main/js/helpers/testMocks.ts View File

@@ -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,
};
}

+ 1
- 0
server/sonar-web/src/main/js/types/appstate.ts View File

@@ -28,6 +28,7 @@ export interface AppState {
edition?: EditionKey;
globalPages?: Extension[];
instanceUsesDefaultAdminCredentials?: boolean;
installedVersionEOL: string;
needIssueSync?: boolean;
productionDatabase: boolean;
qualifiers: string[];

Loading…
Cancel
Save