Commit 5c580b14 authored by Florent Chehab's avatar Florent Chehab

Removed custom... from frontend, use of super instead

parent 75bbbf1b
Pipeline #35534 passed with stages
in 6 minutes and 45 seconds
...@@ -4505,12 +4505,14 @@ ...@@ -4505,12 +4505,14 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
...@@ -4531,12 +4533,14 @@ ...@@ -4531,12 +4533,14 @@
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
...@@ -4653,7 +4657,8 @@ ...@@ -4653,7 +4657,8 @@
"inherits": { "inherits": {
"version": "2.0.3", "version": "2.0.3",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
...@@ -4680,6 +4685,7 @@ ...@@ -4680,6 +4685,7 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
...@@ -4693,6 +4699,7 @@ ...@@ -4693,6 +4699,7 @@
"version": "2.2.4", "version": "2.2.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.1", "safe-buffer": "^5.1.1",
"yallist": "^3.0.0" "yallist": "^3.0.0"
...@@ -4804,6 +4811,7 @@ ...@@ -4804,6 +4811,7 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
...@@ -4925,6 +4933,7 @@ ...@@ -4925,6 +4933,7 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",
...@@ -5675,7 +5684,6 @@ ...@@ -5675,7 +5684,6 @@
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
...@@ -5690,8 +5698,7 @@ ...@@ -5690,8 +5698,7 @@
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
...@@ -5702,8 +5709,7 @@ ...@@ -5702,8 +5709,7 @@
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
...@@ -5820,8 +5826,7 @@ ...@@ -5820,8 +5826,7 @@
"inherits": { "inherits": {
"version": "2.0.3", "version": "2.0.3",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
...@@ -5833,7 +5838,6 @@ ...@@ -5833,7 +5838,6 @@
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
...@@ -5848,7 +5852,6 @@ ...@@ -5848,7 +5852,6 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
...@@ -5856,14 +5859,12 @@ ...@@ -5856,14 +5859,12 @@
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.3.5", "version": "2.3.5",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.2", "safe-buffer": "^5.1.2",
"yallist": "^3.0.0" "yallist": "^3.0.0"
...@@ -5882,7 +5883,6 @@ ...@@ -5882,7 +5883,6 @@
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
...@@ -5963,8 +5963,7 @@ ...@@ -5963,8 +5963,7 @@
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
...@@ -5976,7 +5975,6 @@ ...@@ -5976,7 +5975,6 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
...@@ -6098,7 +6096,6 @@ ...@@ -6098,7 +6096,6 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",
......
...@@ -34,40 +34,17 @@ class CustomComponentForAPI extends Component { ...@@ -34,40 +34,17 @@ class CustomComponentForAPI extends Component {
///// /////
componentDidMount() { componentDidMount() {
this.readPropsIfNeeded(); this.readPropsIfNeeded();
this.customComponentDidMount();
this.forceUpdate(); // bug otherwise
} }
customComponentDidMount() { }
shouldComponentUpdate(nextProps, nextState) {
// Below is buggy with redux connect
// if (this.nextProps && typeof this.nextProps.visible != 'undefined' && !this.nextProps.visible) {
// // don't rerender components that won't be visible.
// return false;
// }
// if (this.props.visible === false && !this.nextProps) {
// // don't rerender components if it is still not visible
// return false;
// }
// // if (this.nextProps && typeof this.nextProps.visible != 'undefined' && this.nextProps.visible) {
// // // render if nextprops should be visible
// // return true;
// // }
return this.customShouldComponentUpdate(nextProps, nextState);
}
// eslint-disable-next-line no-unused-vars
customShouldComponentUpdate(nextProps, nextState) { return true; }
// eslint-disable-next-line no-unused-vars
componentDidUpdate(prevProps, prevState, snapshot) { componentDidUpdate(prevProps, prevState, snapshot) {
// TODO add expire date // extends the default behavior of react to load props (api related) if needed on update.
this.readPropsIfNeeded(); this.readPropsIfNeeded();
this.customComponentDidUpdate(prevProps, prevState, snapshot);
} }
customComponentDidUpdate() { }
// Override of the default render behaviour to wait for data to arrive.
render() { render() {
// Override of the default react render behavior to wait for data to arrive.
// You should use `customRender` instead of `render` in your components.
if (this.checkPropsFailed()) { if (this.checkPropsFailed()) {
return <p>Une erreur est survenue lors du téléchargement des données. Merci de recharger la page et si l'erreur persiste, merci de contacter les administrateurs du site.</p>; return <p>Une erreur est survenue lors du téléchargement des données. Merci de recharger la page et si l'erreur persiste, merci de contacter les administrateurs du site.</p>;
} }
...@@ -79,6 +56,15 @@ class CustomComponentForAPI extends Component { ...@@ -79,6 +56,15 @@ class CustomComponentForAPI extends Component {
return this.customRender(); return this.customRender();
} }
/**
* Function to use instead of `render`.
*
* @memberof CustomComponentForAPI
*/
customRender() {
// eslint-disable-next-line no-console
console.error("Dev: you forget to define the `customRender` function that is used when rendering within a subClass of CustomComponentForAPI");
}
// End of react functions override // End of react functions override
...@@ -270,7 +256,7 @@ class CustomComponentForAPI extends Component { ...@@ -270,7 +256,7 @@ class CustomComponentForAPI extends Component {
/** /**
* Funciton to get the city and the country of a university given a university id * Function to get the city and the country of a university given a university id
* *
* @param {number} univId * @param {number} univId
* @returns {object} Object with city and country instance of the university (main campus) * @returns {object} Object with city and country instance of the university (main campus)
...@@ -299,7 +285,7 @@ class CustomComponentForAPI extends Component { ...@@ -299,7 +285,7 @@ class CustomComponentForAPI extends Component {
} }
CustomComponentForAPI.propTypes = { CustomComponentForAPI.propTypes = {
api: PropTypes.object api: PropTypes.object.isRequired
}; };
export default CustomComponentForAPI; export default CustomComponentForAPI;
...@@ -23,7 +23,9 @@ import { saveAppTheme } from "../actions/theme"; ...@@ -23,7 +23,9 @@ import { saveAppTheme } from "../actions/theme";
class ThemeProvider extends CustomComponentForAPI { class ThemeProvider extends CustomComponentForAPI {
state = { theme: this.props.themeSavedInTheApp.theme }; state = { theme: this.props.themeSavedInTheApp.theme };
customComponentDidUpdate() { componentDidUpdate(prevProps, prevState, snapshot) {
super.componentDidUpdate(prevProps, prevState, snapshot);
if (!this.allApiDataIsReady()) { if (!this.allApiDataIsReady()) {
return; return;
} }
......
...@@ -42,9 +42,10 @@ class UnivMap extends CustomComponentForAPI { ...@@ -42,9 +42,10 @@ class UnivMap extends CustomComponentForAPI {
this.updateDimensions(); this.updateDimensions();
} }
customComponentDidMount() { componentDidMount() {
// add an event listener to resize the map when needed // add an event listener to resize the map when needed
window.addEventListener("resize", this.updateDimensions.bind(this)); window.addEventListener("resize", this.updateDimensions.bind(this));
super.componentDidMount();
} }
componentWillUnmount() { componentWillUnmount() {
......
...@@ -33,7 +33,9 @@ import { ...@@ -33,7 +33,9 @@ import {
*/ */
class PageUniversity extends CustomComponentForAPI { class PageUniversity extends CustomComponentForAPI {
customComponentDidUpdate() { componentDidUpdate(prevProps, prevState, snapshot) {
super.componentDidUpdate(prevProps, prevState, snapshot);
if (this.props.universities.readSucceeded.readAt) { if (this.props.universities.readSucceeded.readAt) {
// we have the university data // we have the university data
const universities = this.getReadData("universities"), const universities = this.getReadData("universities"),
......
...@@ -66,7 +66,9 @@ class ColorTool extends CustomComponentForAPI { ...@@ -66,7 +66,9 @@ class ColorTool extends CustomComponentForAPI {
} }
customComponentDidUpdate() { componentDidUpdate(prevProps, prevState, snapshot) {
super.componentDidUpdate(prevProps, prevState, snapshot);
if (!this.allApiDataIsReady()) { if (!this.allApiDataIsReady()) {
return; return;
} }
......
...@@ -136,7 +136,9 @@ class Editor extends CustomComponentForAPI { ...@@ -136,7 +136,9 @@ class Editor extends CustomComponentForAPI {
} }
} }
customComponentDidUpdate() { componentDidUpdate(prevProps, prevState, snapshot) {
super.componentDidUpdate(prevProps, prevState, snapshot);
// usefull for handling moderation // usefull for handling moderation
const { dataToSave } = this.props; const { dataToSave } = this.props;
if (dataToSave) { if (dataToSave) {
......
...@@ -8,7 +8,9 @@ class Module extends CustomComponentForAPI { ...@@ -8,7 +8,9 @@ class Module extends CustomComponentForAPI {
this.props.invalidateData(true); this.props.invalidateData(true);
} }
customComponentDidUpdate() { componentDidUpdate(prevProps, prevState, snapshot) {
super.componentDidUpdate(prevProps, prevState, snapshot);
this.getListPropsNeedRead() this.getListPropsNeedRead()
.forEach(propName => this.performReadFromApi(propName)); .forEach(propName => this.performReadFromApi(propName));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment