这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions console/src/components/Main/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ADMIN_SECRET_ERROR,
UPDATE_DATA_HEADERS,
} from '../Services/Data/DataActions';
import semverCheck, { componentsSemver } from '../../helpers/semver';
import { getFeaturesCompatibility } from '../../helpers/versionUtils';
import { changeRequestHeader } from '../Services/ApiExplorer/Actions';

const SET_MIGRATION_STATUS_SUCCESS = 'Main/SET_MIGRATION_STATUS_SUCCESS';
Expand All @@ -31,23 +31,22 @@ const UPDATE_ADMIN_SECRET_INPUT = 'Main/UPDATE_ADMIN_SECRET_INPUT';
const LOGIN_IN_PROGRESS = 'Main/LOGIN_IN_PROGRESS';
const LOGIN_ERROR = 'Main/LOGIN_ERROR';

const SET_SEMVER = 'Main/SET_SEMVER';
const setSemverBulk = data => ({
type: SET_SEMVER,
const SET_FEATURES_COMPATIBILITY = 'Main/SET_FEATURES_COMPATIBILITY';
const setFeaturesCompatibility = data => ({
type: SET_FEATURES_COMPATIBILITY,
data,
});

const semverInit = () => {
const featureCompatibilityInit = () => {
return (dispatch, getState) => {
const { serverVersion } = getState().main;
if (!serverVersion) {
return;
}
const semverObj = {};
Object.keys(componentsSemver).forEach(feature => {
semverObj[feature] = semverCheck(feature, serverVersion);
});
return dispatch(setSemverBulk(semverObj));

const featuresCompatibility = getFeaturesCompatibility(serverVersion);

return dispatch(setFeaturesCompatibility(featuresCompatibility));
};
};

Expand Down Expand Up @@ -95,7 +94,7 @@ const loadServerVersion = () => dispatch => {
);
};

const checkServerUpdates = () => (dispatch, getState) => {
const loadLatestServerVersion = () => (dispatch, getState) => {
const url =
Endpoints.updateCheck +
'?agent=console&version=' +
Expand Down Expand Up @@ -305,10 +304,10 @@ const mainReducer = (state = defaultState, action) => {
return { ...state, loginInProgress: action.data };
case LOGIN_ERROR:
return { ...state, loginError: action.data };
case SET_SEMVER:
case SET_FEATURES_COMPATIBILITY:
return {
...state,
semver: { ...action.data },
featuresCompatibility: { ...action.data },
};
default:
return state;
Expand All @@ -328,6 +327,6 @@ export {
LOGIN_ERROR,
validateLogin,
loadServerVersion,
checkServerUpdates,
semverInit,
loadLatestServerVersion,
featureCompatibilityInit,
};
57 changes: 31 additions & 26 deletions console/src/components/Main/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,34 @@ import globals from '../../Globals';
import * as tooltip from './Tooltips';
import 'react-toggle/style.css';
import Spinner from '../Common/Spinner/Spinner';
import { loadServerVersion, checkServerUpdates, semverInit } from './Actions';
import {
loadServerVersion,
loadLatestServerVersion,
featureCompatibilityInit,
} from './Actions';
import { loadConsoleOpts } from '../../telemetry/Actions.js';
import './NotificationOverrides.css';
import {
loadInconsistentObjects,
redirectToMetadataStatus,
} from '../Services/Metadata/Actions';

const semver = require('semver');

import {
getLoveConsentState,
setLoveConsentState,
} from './loveConsentLocalStorage';

import { versionGT } from '../../helpers/versionUtils';

class Main extends React.Component {
constructor(props) {
super(props);

this.state = {
showBannerNotification: false,
showUpdateNotification: false,
loveConsentState: getLoveConsentState(),
};

this.state.loveConsentState = getLoveConsentState();
this.handleBodyClick = this.handleBodyClick.bind(this);
}

Expand All @@ -40,31 +45,31 @@ class Main extends React.Component {
.addEventListener('click', this.handleBodyClick);

dispatch(loadServerVersion()).then(() => {
dispatch(semverInit());
dispatch(featureCompatibilityInit());

dispatch(loadInconsistentObjects()).then(() => {
this.handleMetadataRedirect();
});

dispatch(loadConsoleOpts());

dispatch(checkServerUpdates()).then(() => {
let isUpdateAvailable = false;
dispatch(loadLatestServerVersion()).then(() => {
try {
isUpdateAvailable = semver.gt(
this.props.latestServerVersion,
this.props.serverVersion
);
const isClosedBefore = window.localStorage.getItem(
this.props.latestServerVersion + '_BANNER_NOTIFICATION_CLOSED'
);
if (isClosedBefore === 'true') {
isUpdateAvailable = false;
this.setState({ showBannerNotification: false });
} else {
this.setState({
showBannerNotification: isUpdateAvailable,
});

if (isClosedBefore !== 'true') {
const isUpdateAvailable = versionGT(
this.props.latestServerVersion,
this.props.serverVersion
);

if (isUpdateAvailable) {
this.setState({
showUpdateNotification: true,
});
}
}
} catch (e) {
console.error(e);
Expand Down Expand Up @@ -111,7 +116,7 @@ class Main extends React.Component {
latestServerVersion + '_BANNER_NOTIFICATION_CLOSED',
'true'
);
this.setState({ showBannerNotification: false });
this.setState({ showUpdateNotification: false });
}

render() {
Expand Down Expand Up @@ -207,11 +212,11 @@ class Main extends React.Component {
return adminSecretHtml;
};

const getBannerNotification = () => {
let bannerNotificationHtml = null;
const getUpdateNotification = () => {
let updateNotificationHtml = null;

if (this.state.showBannerNotification) {
bannerNotificationHtml = (
if (this.state.showUpdateNotification) {
updateNotificationHtml = (
<div>
<div className={styles.phantom} />{' '}
{/* phantom div to prevent overlapping of banner with content. */}
Expand Down Expand Up @@ -254,7 +259,7 @@ class Main extends React.Component {
</div>
);
}
return bannerNotificationHtml;
return updateNotificationHtml;
};

const getLoveSection = () => {
Expand Down Expand Up @@ -587,7 +592,7 @@ class Main extends React.Component {
{getMainContent()}
</div>

{getBannerNotification()}
{getUpdateNotification()}
</div>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions console/src/components/Main/State.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const defaultState = {
serverVersion: null,
latestServerVersion: null,
telemetryEnabled: true,
featuresCompatibility: {},
};

export default defaultState;
84 changes: 0 additions & 84 deletions console/src/helpers/semver.js

This file was deleted.

32 changes: 32 additions & 0 deletions console/src/helpers/versionUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const semver = require('semver');

// list of feature launch versions
const featureLaunchVersions = {
// feature: 'v1.0.0'
};

export const getFeaturesCompatibility = serverVersion => {
const featuresCompatibility = {};

const isPullRequest = serverVersion.startsWith('pull');

try {
Object.keys(featureLaunchVersions).forEach(feature => {
featuresCompatibility[feature] =
isPullRequest ||
semver.satisfies(featureLaunchVersions[feature], '>=' + serverVersion);
});
} catch (e) {
console.error(e);
}

return featuresCompatibility;
};

export const versionGT = (version1, version2) => {
try {
return semver.gt(version1, version2);
} catch (e) {
console.error(e);
}
};