Commit 5749fb2f authored by Florent Chehab's avatar Florent Chehab

Less ambigous naming of read data

parent 5cc3220b
Pipeline #35807 passed with stages
in 9 minutes and 37 seconds
......@@ -191,13 +191,14 @@ class CustomComponentForAPI extends Component {
}
/**
* Get the data that was read from the api given the `propName` and the time at which is was read
* Get the latest data that was read from the api given the `propName` and the time at which is was read
* read, create and update are taken into account
*
* @param {string} propName
* @returns {Any}
* @memberof CustomComponentForAPI
*/
getReadDataAndTime(propName) {
getLatestReadDataAndTime(propName) {
const prop = this.props[propName],
out = getLatestRead(prop);
......@@ -210,56 +211,71 @@ class CustomComponentForAPI extends Component {
/**
* Get the data that was read from the api given the `propName`
* Get the latest data that was read from the api given the `propName`
* read, create and update are taken into account
*
* @param {string} propName
* @param {boolean} [returnLatest=true] Should the lastest data from read, create or update response be returned?
* @returns {Any}
* @memberof CustomComponentForAPI
*/
getReadData(propName, returnLatest = true) {
if (!returnLatest) {
return this.props[propName].readSucceeded.data;
}
return this.getReadDataAndTime(propName).data;
getLatestReadData(propName) {
return this.getLatestReadDataAndTime(propName).data;
}
/**
* In some very rare case, we need to consider only the data that was read and not create ou updated.
* That what this function does.
*
* @param {string} propName
* @returns
* @memberof CustomComponentForAPI
*/
getOnlyReadData(propName) {
return this.props[propName].readSucceeded.data;
}
/**
* Get the time at which the latest data from the api corresponding to `propName` was read
* Get the latest time at which the latest data from the api corresponding to `propName` was read
*
* read, create and update are taken into account
*
* @param {string} propName
* @returns {Any}
* @memberof CustomComponentForAPI
*/
getReadTime(propName) {
return this.getReadDataAndTime(propName).readAt;
getLatestReadTime(propName) {
return this.getLatestReadDataAndTime(propName).readAt;
}
/**
* Access to all the data loaded from the api given the props
* Access to all the latest data loaded from the api given the props
*
* read, create and update are taken into account
*
* @returns {object}
* @memberof CustomComponentForAPI
*/
getAllReadData() {
getAllLatestReadData() {
let out = Object();
this.apiProps.forEach((propName) => {
out[propName] = this.getReadData(propName);
out[propName] = this.getLatestReadData(propName);
});
return out;
}
/**
* Access to the read data from the propNames array
* This should be used instead of getAllReadData to optimize things
* Access to the latest read data from the propNames array
* This should be used instead of getAllLatestReadData to optimize things
*
* read, create and update are taken into account
*
* @param {array} propNames Array of the prop names you want to read data from
* @returns {object}
* @memberof CustomComponentForAPI
*/
getReadDataFor(propNames) {
getLatestReadDataFor(propNames) {
let out = Object();
propNames.forEach(propName => out[propName] = this.getReadData(propName));
propNames.forEach(propName => out[propName] = this.getLatestReadData(propName));
return out;
}
......@@ -274,7 +290,7 @@ class CustomComponentForAPI extends Component {
* @memberof CustomComponentForAPI
*/
joinCampus(campus) {
const { universities, countries, cities } = this.getReadDataFor(["universities", "countries", "cities"]);
const { universities, countries, cities } = this.getLatestReadDataFor(["universities", "countries", "cities"]);
let res = Object.assign({}, campus); //copy for safety
res.university = universities.find(univ => univ.id = campus.university);
res.city = cities.find(city => city.id = campus.city);
......@@ -292,7 +308,7 @@ class CustomComponentForAPI extends Component {
*/
getUnivCityAndCountry(univId) {
const univMainCampus = this.findMainCampus(univId),
{ countries, cities } = this.getReadDataFor(["countries", "cities"]),
{ countries, cities } = this.getLatestReadDataFor(["countries", "cities"]),
city = cities.find(city => city.id == univMainCampus.city),
country = countries.find(country => country.id == city.country);
return { city, country };
......@@ -307,7 +323,7 @@ class CustomComponentForAPI extends Component {
* @memberof CustomComponentForAPI
*/
findMainCampus(univId) {
const mainCampuses = this.getReadData("mainCampuses");
const mainCampuses = this.getLatestReadData("mainCampuses");
return mainCampuses.find(campus => campus.university == univId);
}
}
......
......@@ -37,13 +37,13 @@ class ThemeProvider extends CustomComponentForAPI {
const currentTheme = this.state.theme,
themeSavedInTheApp = this.props.themeSavedInTheApp.theme,
themeSavedInTheAppAt = this.props.themeSavedInTheApp.savedAt,
userDataAndTime = this.getReadDataAndTime("userData"),
userDataAndTime = this.getLatestReadDataAndTime("userData"),
themeOnServer = userDataAndTime.data.config.theme,
themeOnServerRetrievedAt = userDataAndTime.readAt;
if (!themeOnServer) {
// config on server is raw, we need to add the default one.
const userData = this.getReadData("userData");
const userData = this.getLatestReadData("userData");
let newUserData = Object.assign({}, userData);
newUserData.config.theme = this.state.theme;
this.props.saveUserData(newUserData);
......
......@@ -59,7 +59,7 @@ class Filter extends CustomComponentForAPI {
* @memberof Filter
*/
getCountriesWhereThereAreUniversities() {
const mainCampuses = this.getReadData("mainCampuses");
const mainCampuses = this.getLatestReadData("mainCampuses");
// use of map to get only each country once
let res = new Map();
......@@ -76,7 +76,7 @@ class Filter extends CustomComponentForAPI {
updateSelectedUniversities(selection) {
const mainCampuses = this.getReadData("mainCampuses"),
const mainCampuses = this.getLatestReadData("mainCampuses"),
listOfCountries = __map(selection, (s) => s.id);
let selectedUniversities = [];
......
......@@ -26,7 +26,7 @@ class UnivMarkers extends CustomComponentForAPI {
const { universities,
mainCampuses,
countries,
cities } = this.getAllReadData();
cities } = this.getAllLatestReadData();
// some conversions for optimization (faster search of element in a map)
const universitiesMap = arrayOfInstancesToMap(universities),
......
......@@ -39,7 +39,7 @@ class PageUniversity extends CustomComponentForAPI {
if (this.props.universities.readSucceeded.readAt) {
// we have the university data
const universities = this.getReadData("universities"),
const universities = this.getLatestReadData("universities"),
{ match, universityBeingViewed } = this.props,
requestedUniversity = match.params.id;
......@@ -55,7 +55,7 @@ class PageUniversity extends CustomComponentForAPI {
customRender() {
const { match, universityBeingViewed } = this.props,
requestedUnivId = match.params.id,
universities = this.getReadData("universities");
universities = this.getLatestReadData("universities");
if (requestedUnivId == "undefined") {
if (universityBeingViewed != null) {
......
......@@ -33,7 +33,7 @@ class Search extends CustomComponentForAPI {
* @memberof Search
*/
getSuggestions(input) {
const universities = this.getReadData("universities"),
const universities = this.getLatestReadData("universities"),
filter = fuzzysort.go(input, universities, { keys: ["name", "acronym"] });
let suggestions = filter.map(item => item.obj);
......
......@@ -74,10 +74,10 @@ class ColorTool extends CustomComponentForAPI {
return;
}
const configOnServer = this.getReadData("userData").config,
const configOnServer = this.getLatestReadData("userData").config,
themeOnServer = configOnServer.theme,
colorPickerConfigOnServer = configOnServer.colorPicker,
serverDataRetrievedAt = this.getReadTime("userData");
serverDataRetrievedAt = this.getLatestReadTime("userData");
if ((!themeOnServer) || (!colorPickerConfigOnServer)) {
// There is nothing to restore
......@@ -175,7 +175,7 @@ class ColorTool extends CustomComponentForAPI {
}
handleSendToServer = () => {
const userData = this.getReadData("userData");
const userData = this.getLatestReadData("userData");
let newUserData = Object.assign({}, userData);
newUserData.config.theme = this.getThemeFromProps();
......
......@@ -21,7 +21,7 @@ class UnivInfoProvider extends CustomComponentForAPI {
customRender() {
const { univId } = this.props,
{ city, country } = this.getUnivCityAndCountry(univId),
{ universities, countries, currencies } = this.getReadDataFor(["universities", "countries", "currencies"]),
{ universities, countries, currencies } = this.getLatestReadDataFor(["universities", "countries", "currencies"]),
countryId = country.id,
cityId = city.id;
......
......@@ -29,7 +29,7 @@ function renderCore(rawModelData, classes, outsideData) {
class CountryDri extends Module {
customRender() {
const countryDriItems = this.getReadData("countryDri", false),
const countryDriItems = this.getOnlyReadData("countryDri"),
{ countries, classes } = this.props,
outsideData = { countries };
......
......@@ -44,7 +44,7 @@ function renderCore(rawModelData, classes, outsideData) {
class CountryScholarships extends Module {
customRender() {
const countryScholarshipsItems = this.getReadData("countryScholarships", false),
const countryScholarshipsItems = this.getOnlyReadData("countryScholarships"),
{ countries, currencies, classes } = this.props,
outsideData = {
countries,
......
......@@ -35,7 +35,7 @@ class UniversityDri extends Module {
customRender() {
const { universities, classes } = this.props,
outsideData = { universities },
univDriItems = this.getReadData("universityDri", false);
univDriItems = this.getLatestReadData("universityDri", false);
return (
<ModuleGroupWrapper
......
......@@ -58,7 +58,7 @@ function renderCore(rawModelData, classes, outsideData) {
class UniversityGeneral extends Module {
customRender() {
const univInfos = this.getReadData("university");
const univInfos = this.getLatestReadData("university");
const { classes } = this.props;
const outsideData = {
city: this.props.city.name,
......
......@@ -39,7 +39,7 @@ function renderCore(rawModelData, classes, outsideData) {
class UniversityScholarships extends Module {
customRender() {
const univScholarshipsItems = this.getReadData("universityScholarships", false),
const univScholarshipsItems = this.getOnlyReadData("universityScholarships"),
{ universities, currencies, classes } = this.props,
outsideData = {
universities,
......
......@@ -105,7 +105,7 @@ function renderCore(rawModelData, classes) {
class UniversitySemestersDates extends Module {
customRender() {
const semestersDates = this.getReadData("universitySemestersDates");
const semestersDates = this.getLatestReadData("universitySemestersDates");
const { classes } = this.props;
return (
<ModuleWrapper
......
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