Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

enh(libs): upgrade front libraries + improve dynamic import #7724

Merged
merged 29 commits into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e23f149
fix(libs): update libs + fix systemjs global import
kduret Jul 22, 2019
0e69b1b
remove comments
kduret Jul 22, 2019
c59e029
fix dynamic default import
kduret Jul 22, 2019
f7c9241
improve dynamic import (use-default)
kduret Jul 23, 2019
4fcdafc
downgrade query-string
kduret Jul 23, 2019
22f18a0
polyfill customevent
kduret Jul 23, 2019
12d2739
improve global dynamic import alorythm
kduret Jul 23, 2019
5e2f988
feat(ui): add breadcrumb on react pages (#7731)
kduret Jul 31, 2019
b96181d
fix(remote-server): check bam on remote server is http only (#7640)
lpinsivy Jul 22, 2019
bcd95aa
fix(tooltips): close tooltip when user clicks somewhere else (#7729)
miteto Jul 25, 2019
28d68f4
Update Host.rst FR (#7658)
psamecentreon Jul 25, 2019
ca37439
fix(doc): correst SSH exchange notice #7620 (#7639)
lpinsivy Jul 25, 2019
83341e0
fix(remote): fix enableremote parameters parsing and setting (#7711)
cgagnaire Jul 25, 2019
2539ccd
fix(#7711): hostname can have dash in name
lpinsivy Jul 25, 2019
77e7471
Update README.md
sc979 Jul 26, 2019
821f4d4
fix(pagination) fix filter save with pagination (#7732)
loiclau Jul 31, 2019
c408144
fix(generate) fix meta service generation with special char (#7705)
loiclau Jul 31, 2019
c8f5ee9
fix coding style
kduret Jul 31, 2019
38eb770
Merge branch '19.04.x' into MON-3218-update-react-libs
kduret Jul 31, 2019
34d88d7
update centreon-test-lib version
kduret Jul 31, 2019
1533d98
update topology_page of poller wizard
kduret Jul 31, 2019
4997a57
update composer.lock
kduret Jul 31, 2019
6b425d6
Merge branch '19.04.x' into MON-3218-update-react-libs
kduret Aug 6, 2019
dca82fe
fix breadcrumb generation
kduret Aug 6, 2019
150a6ea
Merge branch '19.04.x' into MON-3218-update-react-libs
loiclau Aug 7, 2019
10b2868
enh(lib) update composer
loiclau Aug 8, 2019
2cc9e1a
Revert "enh(lib) update composer"
loiclau Aug 8, 2019
3eaf901
enh(lib) update composer
loiclau Aug 8, 2019
9fef0cf
Revert "update centreon-test-lib version"
loiclau Aug 8, 2019
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
12,849 changes: 4,641 additions & 8,208 deletions package-lock.json

Large diffs are not rendered by default.

65 changes: 33 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,58 @@
"build:dev": "webpack --mode development"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/core": "^7.5.5",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-transform-arrow-functions": "^7.2.0",
"@babel/plugin-transform-regenerator": "^7.3.4",
"@babel/plugin-transform-regenerator": "^7.4.5",
"@babel/plugin-transform-shorthand-properties": "^7.2.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.3.4",
"@babel/polyfill": "^7.4.4",
"@babel/preset-env": "^7.5.5",
"@babel/preset-react": "^7.0.0",
"clean-webpack-plugin": "^2.0.1",
"css-loader": "^2.1.0",
"file-loader": "^3.0.1",
"clean-webpack-plugin": "^3.0.0",
"css-loader": "^3.1.0",
"file-loader": "^4.1.0",
"html-webpack-plugin": "^3.2.0",
"mini-css-extract-plugin": "^0.5.0",
"node-sass": "^4.9.3",
"mini-css-extract-plugin": "^0.8.0",
"node-sass": "^4.12.0",
"postcss-loader": "^3.0.0",
"postcss-safe-parser": "^4.0.1",
"resolve-url-loader": "^3.0.1",
"resolve-url-loader": "^3.1.0",
"sass-loader": "^7.1.0",
"terser-webpack-plugin": "^1.2.3",
"url-loader": "^1.1.2",
"webpack": "^4.30.0",
"webpack-cli": "^3.0.8"
"terser-webpack-plugin": "^1.3.0",
"url-loader": "^2.1.0",
"webpack": "^4.36.1",
"webpack-cli": "^3.3.6"
},
"dependencies": {
"@centreon/react-components": "19.4.0-alpha.126",
"axios": "^0.18.0",
"@centreon/react-components": "19.4.0-alpha.139",
"axios": "^0.19.0",
"classnames": "^2.2.6",
"dom-serializer": "^0.1.0",
"install": "^0.12.2",
"connected-react-router": "^6.5.2",
"dom-serializer": "^0.1.1",
"install": "^0.13.0",
"loaders.css": "^0.1.2",
"moment-timezone": "^0.5.25",
"moment-timezone": "^0.5.26",
"numeral": "^2.0.6",
"query-string": "^5.1.1",
"react": "^16.4.2",
"react-dom": "^16.4.2",
"react-full-screen": "^0.2.3",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-full-screen": "^0.2.4",
"react-fullscreen-crossbrowser": "^1.0.9",
"react-helmet": "^5.2.0",
"react-redux": "^5.0.7",
"react-helmet": "^5.2.1",
"react-redux": "^7.1.0",
"react-redux-i18n": "^1.9.3",
"react-router-dom": "^4.2.2",
"react-router-redux": "^5.0.0-alpha.8",
"react-scripts": "2.0.3",
"react-select": "^2.0.0",
"redux": "^4.0.0",
"react-router-dom": "^5.0.1",
"react-scripts": "3.0.1",
"react-select": "^3.0.4",
"redux": "^4.0.4",
"redux-batched-actions": "^0.4.1",
"redux-form": "^7.4.2",
"redux-form": "^8.2.4",
"redux-logger": "^3.0.6",
"redux-saga": "^0.16.2",
"redux-saga": "^1.0.5",
"redux-thunk": "^2.3.0",
"systemjs": "^3.1.6",
"reselect": "^4.0.0",
"systemjs": "^4.1.0",
"systemjs-plugin-css": "^0.1.37"
},
"jest": {
Expand Down
14 changes: 9 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
Expand All @@ -21,6 +21,9 @@ module.exports = {
library: '[name]',
umdNamedDefine: true,
},
resolve: {
extensions: ['.js', '.jsx'],
},
optimization: {
minimizer: [
new TerserPlugin({
Expand Down Expand Up @@ -79,7 +82,7 @@ module.exports = {
rules: [
{ parser: { system: false } },
{
test: /\.js$/,
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
Expand All @@ -95,9 +98,10 @@ module.exports = {
{
loader: "css-loader",
options: {
modules: true,
localIdentName: "[local]__[hash:base64:5]",
sourceMap: true
modules: {
localIdentName: "[local]__[hash:base64:5]",
},
sourceMap: true,
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion www/front_src/src/App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component } from "react";
import Header from "./components/header";
import { connect } from 'react-redux';
import { ConnectedRouter } from "react-router-redux";
import { ConnectedRouter } from 'connected-react-router';
import { history } from "./store";

import NavigationComponent from "./components/navigation";
Expand Down
92 changes: 92 additions & 0 deletions www/front_src/src/helpers/dynamicImport/global.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* SystemJS global script loading support
* Extra for the s.js build only
* (Included by default in system.js build)
*/
(function (global) {

const systemJSPrototype = System.constructor.prototype;

// safari unpredictably lists some new globals first or second in object order
let firstGlobalProp, secondGlobalProp, lastGlobalProp;
function getGlobalProp () {
let cnt = 0;
let lastProp;
for (let p in global) {
// in firefox, new page is loaded before the iframe is totally unmounted
// then, we need to avoid to compare global object with iframes
if (!global.hasOwnProperty(p) || (!isNaN(p) && p < global.frames.length)) {
continue;
}
if (cnt === 0 && p !== firstGlobalProp || cnt === 1 && p !== secondGlobalProp) {
return p;
}
cnt++;
lastProp = p;
}
if (lastProp !== lastGlobalProp) {
return lastProp;
}
}

function noteGlobalProps () {
// alternatively Object.keys(global).pop()
// but this may be faster (pending benchmarks)
firstGlobalProp = secondGlobalProp = undefined;
for (let p in global) {
// in firefox, new page is loaded before the iframe is totally unmounted
// then, we need to avoid to compare global object with iframes
if (!global.hasOwnProperty(p) || (!isNaN(p) && p < global.frames.length)) {
continue;
}
if (!firstGlobalProp) {
firstGlobalProp = p;
} else if (!secondGlobalProp) {
secondGlobalProp = p;
}
lastGlobalProp = p;
}
return lastGlobalProp;
}

const impt = systemJSPrototype.import;
systemJSPrototype.import = function (id, parentUrl) {
noteGlobalProps();
return impt.call(this, id, parentUrl);
};

const emptyInstantiation = [[], function () { return {} }];

const getRegister = systemJSPrototype.getRegister;
systemJSPrototype.getRegister = function () {
const lastRegister = getRegister.call(this);
if (lastRegister) {
return lastRegister;
}

// no registration -> attempt a global detection as difference from snapshot
// when multiple globals, we take the global value to be the last defined new global object property
// for performance, this will not support multi-version / global collisions as previous SystemJS versions did
// note in Edge, deleting and re-adding a global does not change its ordering
const globalProp = getGlobalProp();
if (!globalProp) {
return emptyInstantiation;
}

let globalExport;
try {
globalExport = global[globalProp];
} catch (e) {
return emptyInstantiation;
}

return [[], function (_export) {
return {
execute: function () {
_export({ default: globalExport, __useDefault: true });
}
};
}];
};

})(typeof self !== 'undefined' ? self : global);
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import '../../../../node_modules/systemjs/dist/system.js'; // IIFE format so it's imported on window
import '../../../../../node_modules/systemjs/dist/s.js'; // IIFE format so it's imported on window
import './global'; // override extra bundle of systemjs to manage firefox issue
import '../../../../../node_modules/systemjs/dist/extras/use-default.js'; // avoid to check module.default.default
import systemCss from 'systemjs-plugin-css'; // used to import css in <head>

// this function allows to import dynamically js and css using systemjs
Expand All @@ -24,11 +26,7 @@ export function dynamicImport(basename, parameters) {
return resolve(window[vector]);
} else {
const module = await(window.System.import(basename + parameters.js));
if (module.default && typeof(module.default) === 'object') { // named umd export
window[vector] = module.default;
} else { // unnamed umd export or systemjs export
window[vector] = module;
}
window[vector] = module;
return resolve(window[vector]);
}
} catch (error) {
Expand Down
4 changes: 3 additions & 1 deletion www/front_src/src/redux/reducers/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { combineReducers } from "redux";
import { connectRouter } from 'connected-react-router';
import { reducer as formReducer } from "redux-form";
import { i18nReducer } from 'react-redux-i18n';

Expand All @@ -9,7 +10,8 @@ import axiosReducer from "./axiosReducer";
import externalComponentsReducer from "./externalComponentsReducer";
import tooltipReducer from './tooltipReducer';

export default combineReducers({
export default (history) => combineReducers({
router: connectRouter(history),
form: formReducer,
pollerForm: pollerWizardReducer,
i18n: i18nReducer,
Expand Down
9 changes: 3 additions & 6 deletions www/front_src/src/redux/reducers/navigationReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,9 @@ const navigationReducer = (state = initialState, action) => {
};
// navigated to another URL
case "@@router/LOCATION_CHANGE":
let event = new CustomEvent('react.href.update', {
detail: {
href: window.location.href
}
});
window.dispatchEvent(event);
const event = document.createEvent('CustomEvent');
event.initCustomEvent('react.href.update', false, false, { href: window.location.href });
window.dispatchEvent(event);
return state;
default:
return state;
Expand Down
6 changes: 3 additions & 3 deletions www/front_src/src/store/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createStore, applyMiddleware, compose } from "redux";
import { routerMiddleware } from "react-router-redux";
import { routerMiddleware } from 'connected-react-router';
import { batchDispatchMiddleware } from 'redux-batched-actions';
import reducers from "../redux/reducers";
import createRootReducer from "../redux/reducers";
import thunk from "redux-thunk";
import createSagaMiddleware from "redux-saga";
import sagas from "../redux/sagas";
Expand All @@ -16,7 +16,7 @@ const createAppStore = (options, initialState = {}) => {
const middlewares = [routerMiddleware(history), thunk, sagaMiddleware, batchDispatchMiddleware];

const store = createStore(
reducers,
createRootReducer(history),
initialState,
compose(
applyMiddleware(...middlewares),
Expand Down