Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rex Dri
Rex Dri
Commits
0223fb20
Commit
0223fb20
authored
Sep 18, 2019
by
Florent Chehab
Committed by
Florent Chehab
Jan 12, 2020
Browse files
dropped(redux)
parent
1451f9ca
Changes
79
Hide whitespace changes
Inline
Side-by-side
frontend/src/redux/api/getActions.js
deleted
100644 → 0
View file @
1451f9ca
import
{
apiActions
}
from
"
./buildApiActionsAndReducers
"
;
// To ease auto completion, not really used here!
// eslint-disable-next-line no-unused-vars
import
CrudActions
from
"
./CrudActions
"
;
/**
* Function to get the the actions corresponding to an API end point.
*
* @export
* @param {string} name
* @returns {CrudActions}
*/
export
default
function
getActions
(
name
)
{
if
(
!
(
name
in
apiActions
))
{
console
.
error
(
"
available actions
"
,
apiActions
);
// eslint-disable-line no-console
throw
Error
(
`Requested api action is not defined, check the name:
${
name
}
`
);
}
return
apiActions
[
name
];
}
frontend/src/redux/reducers/filter.js
deleted
100644 → 0
View file @
1451f9ca
/*
* This file contains the redux reducers related to the filter component
*/
import
{
SAVE_SELECTED_UNIVERSITIES
}
from
"
../actions/action-types
"
;
/**
* Reducer: Save the selected universities
*
* @export
* @param {array} [state=[]]
* @param {object} action
* @returns
*/
// eslint-disable-next-line import/prefer-default-export
export
function
saveSelectedUniversities
(
state
=
null
,
action
)
{
// state === null => no selection applied
// state = [...] => selection
if
(
action
.
type
===
SAVE_SELECTED_UNIVERSITIES
)
{
return
action
.
newSelection
;
}
return
state
;
}
frontend/src/redux/reducers/index.js
deleted
100644 → 0
View file @
1451f9ca
import
{
combineReducers
}
from
"
redux
"
;
import
{
saveSelectedUniversities
}
from
"
./filter
"
;
import
{
apiReducers
}
from
"
../api/buildApiActionsAndReducers
"
;
// Combine the reducers related to the app
const
app
=
combineReducers
({
selectedUniversities
:
saveSelectedUniversities
});
// Get the redux reducer for all api related stuff
const
api
=
combineReducers
(
apiReducers
);
// Create the final reduce reducer
const
rootReducer
=
combineReducers
({
api
,
app
});
export
default
rootReducer
;
frontend/src/redux/store.js
deleted
100644 → 0
View file @
1451f9ca
/* eslint-disable no-unused-vars */
import
{
applyMiddleware
,
createStore
}
from
"
redux
"
;
import
thunkMiddleware
from
"
redux-thunk
"
;
import
{
createLogger
}
from
"
redux-logger
"
;
import
rootReducer
from
"
./reducers/index
"
;
const
loggerMiddleware
=
createLogger
({
collapsed
:
(
getState
,
action
,
logEntry
)
=>
// const {type} = action;
// if () {
// return false;
// }
true
});
const
middlewares
=
[
thunkMiddleware
// lets us dispatch() functions
];
// A bit of optimization for production builds
// eslint-disable-next-line no-undef
if
(
process
.
env
.
NODE_ENV
!==
"
production
"
)
{
middlewares
.
push
(
loggerMiddleware
);
// neat middleware that logs actions
}
const
store
=
createStore
(
rootReducer
,
applyMiddleware
(...
middlewares
));
export
default
store
;
frontend/src/services/data/CityService.js
View file @
0223fb20
import
{
getLatestReadDataFromStore
}
from
"
../../redux/api/utils
"
;
import
arrayOfInstancesToMap
from
"
../../utils/arrayOfInstancesToMap
"
;
import
{
getLatestApiReadData
}
from
"
../../hooks/usePersistentState
"
;
class
CityService
{
/**
...
...
@@ -28,7 +28,7 @@ class CityService {
}
getCities
()
{
return
getLatestReadData
FromStore
(
"
cities
A
ll
"
);
return
getLatest
Api
ReadData
(
"
cities
-a
ll
"
);
}
}
...
...
frontend/src/services/data/CountryService.js
View file @
0223fb20
import
{
getLatestReadDataFromStore
}
from
"
../../redux/api/utils
"
;
import
arrayOfInstancesToMap
from
"
../../utils/arrayOfInstancesToMap
"
;
import
{
getLatestApiReadData
}
from
"
../../hooks/usePersistentState
"
;
class
CountryService
{
/**
...
...
@@ -43,7 +43,7 @@ class CountryService {
* @returns {Array.<Object>}
*/
getCountries
()
{
return
getLatestReadData
FromStore
(
"
countries
A
ll
"
);
return
getLatest
Api
ReadData
(
"
countries
-a
ll
"
);
}
getCountryOptions
()
{
...
...
frontend/src/services/data/CurrencyService.js
View file @
0223fb20
import
{
getLatestReadDataFromStore
}
from
"
../../redux/api/utils
"
;
import
arrayOfInstancesToMap
from
"
../../utils/arrayOfInstancesToMap
"
;
import
{
getLatestApiReadData
}
from
"
../../hooks/usePersistentState
"
;
class
CurrencyService
{
/**
* Stores the currencies by currency id for quick join
* @type {Map<
number
, object>}
* @type {Map<
string
, object>}
* @private
*/
_currenciesByCurrencyId
=
new
Map
();
...
...
@@ -20,6 +20,16 @@ class CurrencyService {
*/
initialize
()
{
const
currencies
=
this
.
getCurrencies
();
if
(
currencies
.
length
===
0
)
{
// To use this function, you need to have currencies loaded in the store.
// **Make sure the currencies are loaded in the backend.**
// Also, make sure not use this function before we have the currencies loaded :)
throw
new
Error
(
"
Currencies in the store are empty see code for more info.
"
);
}
this
.
_currenciesByCurrencyId
=
arrayOfInstancesToMap
(
currencies
);
this
.
_options
=
currencies
.
map
(
c
=>
({
...
...
@@ -30,7 +40,7 @@ class CurrencyService {
}
getCurrencies
()
{
return
getLatestReadData
FromStore
(
"
currencies
A
ll
"
);
return
getLatest
Api
ReadData
(
"
currencies
-a
ll
"
);
}
getCurrenciesOptions
()
{
...
...
@@ -45,6 +55,37 @@ class CurrencyService {
getCurrencyForCurrencyId
(
currencyId
)
{
return
this
.
_currenciesByCurrencyId
.
get
(
currencyId
);
}
getCurrencySymbol
(
currencyCode
)
{
if
(
currencyCode
===
"
EUR
"
)
{
return
"
€
"
;
}
if
(
this
.
_currenciesByCurrencyId
.
has
(
currencyCode
))
{
return
this
.
_currenciesByCurrencyId
.
get
(
currencyCode
).
symbol
;
}
return
`
${
currencyCode
}
`
;
}
/**
* Function for converting money amounts to euros.
*
* @param {number} amount
* @param {string} currencyCode
* @returns {string|null} if no matching currency could be found
*/
convertAmountToEur
(
amount
,
currencyCode
)
{
if
(
currencyCode
===
"
EUR
"
)
{
return
amount
.
toFixed
(
2
);
}
if
(
this
.
_currenciesByCurrencyId
.
has
(
currencyCode
))
{
return
(
amount
/
this
.
_currenciesByCurrencyId
.
get
(
currencyCode
).
one_EUR_in_this_currency
).
toFixed
(
2
);
}
return
null
;
}
}
export
default
new
CurrencyService
();
frontend/src/services/data/LanguageService.js
View file @
0223fb20
import
{
getLatestReadDataFromStore
}
from
"
../../redux/api/utils
"
;
import
arrayOfInstancesToMap
from
"
../../utils/arrayOfInstancesToMap
"
;
import
{
getLatestApiReadData
}
from
"
../../hooks/usePersistentState
"
;
class
LanguageService
{
/**
...
...
@@ -46,7 +46,7 @@ class LanguageService {
* @returns {Array.<Object>}
*/
getLanguages
()
{
return
getLatestReadData
FromStore
(
"
languages
A
ll
"
);
return
getLatest
Api
ReadData
(
"
languages
-a
ll
"
);
}
/**
...
...
frontend/src/services/data/UniversityService.js
View file @
0223fb20
import
{
getLatestReadDataFromStore
}
from
"
../../redux/api/utils
"
;
import
CityService
from
"
./CityService
"
;
import
CountryService
from
"
./CountryService
"
;
import
arrayOfInstancesToMap
from
"
../../utils/arrayOfInstancesToMap
"
;
import
{
getLatestApiReadData
}
from
"
../../hooks/usePersistentState
"
;
class
UniversityService
{
/**
...
...
@@ -28,7 +28,7 @@ class UniversityService {
* Must be called once before accessing other methods.
*/
initialize
()
{
const
universities
=
getLatestReadDataFromStore
(
"
u
niversities
All
"
);
const
universities
=
this
.
getU
niversities
(
);
this
.
_universitiesById
=
arrayOfInstancesToMap
(
universities
);
const
mainCampuses
=
this
.
getMainCampuses
();
...
...
@@ -49,7 +49,7 @@ class UniversityService {
* @returns {Array<Object>}
*/
getUniversities
()
{
return
getLatestReadData
FromStore
(
"
universities
A
ll
"
);
return
getLatest
Api
ReadData
(
"
universities
-a
ll
"
);
}
getUniversitiesOptions
()
{
...
...
@@ -61,7 +61,7 @@ class UniversityService {
* @returns {array<Object>}
*/
getMainCampuses
()
{
return
getLatestReadData
FromStore
(
"
mainCampuses
A
ll
"
);
return
getLatest
Api
ReadData
(
"
mainCampuses
-a
ll
"
);
}
/**
...
...
frontend/src/
redux
/api/CrudActions.js
→
frontend/src/
utils
/api/CrudActions.js
View file @
0223fb20
File moved
frontend/src/
redux
/api/CrudReducers.js
→
frontend/src/
utils
/api/CrudReducers.js
View file @
0223fb20
...
...
@@ -57,6 +57,15 @@ export default class CrudReducers {
this
.
types
=
getCrudActionTypes
(
route
);
}
static
get
defaultAllState
()
{
return
{
isReading
:
false
,
readSucceeded
:
getDefaultSucceeded
([]),
readFailed
:
getDefaultFailed
(),
isInvalidated
:
false
};
}
/**
* Get the reducer for actions related to all (read all)
*
...
...
@@ -65,15 +74,8 @@ export default class CrudReducers {
*/
getForAll
()
{
const
self
=
this
;
// default state of the reducer
const
defaultAllState
=
{
isReading
:
false
,
readSucceeded
:
getDefaultSucceeded
([]),
readFailed
:
getDefaultFailed
(),
isInvalidated
:
false
};
return
(
state
=
defaultAllState
,
action
)
=>
{
return
(
state
=
CrudReducers
.
defaultAllState
,
action
)
=>
{
// Performance optimization: we don't go through the big switch
if
(
!
action
.
rootType
||
action
.
rootType
!==
self
.
types
.
rootType
)
{
return
state
;
...
...
@@ -111,16 +113,8 @@ export default class CrudReducers {
};
}
/**
* Get the reducer for all actions releted to one element
*
* @returns {function}
* @memberof CrudReducers
*/
getForOne
()
{
const
self
=
this
;
// default state of the reducer
const
defaultOneState
=
{
static
get
defaultOneState
()
{
return
{
isReading
:
false
,
readSucceeded
:
getDefaultSucceeded
(
Object
()),
readFailed
:
getDefaultFailed
(),
...
...
@@ -139,8 +133,18 @@ export default class CrudReducers {
//
isInvalidated
:
false
};
}
/**
* Get the reducer for all actions releted to one element
*
* @returns {function}
* @memberof CrudReducers
*/
getForOne
()
{
const
self
=
this
;
return
(
state
=
defaultOneState
,
action
)
=>
{
return
(
state
=
CrudReducers
.
defaultOneState
,
action
)
=>
{
// Performance optimization: we don't go through the big switch
if
(
!
action
.
rootType
||
action
.
rootType
!==
self
.
types
.
rootType
)
{
return
state
;
...
...
frontend/src/
redux
/api/RequestParams.js
→
frontend/src/
utils
/api/RequestParams.js
View file @
0223fb20
File moved
frontend/src/
redux
/api/getCrudActionTypes.js
→
frontend/src/
utils
/api/getCrudActionTypes.js
View file @
0223fb20
/**
* Function to generate CRUD action types for
redux
actions and reducers
* Function to generate CRUD action types for actions and reducers
*
* @export
* @param {string} name
...
...
frontend/src/
redux
/api/utils.js
→
frontend/src/
utils
/api/utils.js
View file @
0223fb20
/**
* This file contains utilities linked to the use of the API.
*/
import
store
from
"
../store
"
;
// Stores the name of the reducers/actions that result in read data
export
const
successActionsWithReads
=
[
...
...
@@ -37,25 +36,3 @@ export function apiDataIsUsable(stateExtract) {
.
every
(
action
=>
stateExtract
[
action
]
===
false
)
);
}
/**
* Function that returns the latest read data directly from the store.
* To be used with parsimony.
*
* It assumes that the data has already been fetched at some point.
*
* @export
* @param {string} entry eg: userDataOne
* @returns
*/
export
function
getLatestReadDataFromStore
(
entry
)
{
return
getLatestRead
(
store
.
getState
().
api
[
entry
]).
data
;
}
/**
* Direct access to the store state
* @returns {S & {}}
*/
export
function
getStoreState
()
{
return
store
.
getState
();
}
frontend/src/utils/convertAmountToEur.js
deleted
100644 → 0
View file @
1451f9ca
import
{
getLatestReadDataFromStore
}
from
"
../redux/api/utils
"
;
// For optimization
let
allCurrencies
;
/**
* Function for converting money amounts to euros.
*
* @export
* @param {number} amount
* @param {string} currencyStr
* @returns {string} or null if no matching currency could be found
*/
export
default
function
convertAmountToEur
(
amount
,
currencyStr
)
{
if
(
currencyStr
===
"
EUR
"
)
{
return
amount
.
toFixed
(
2
);
}
// a bit of optimization, will be useful if this function is used a lot
if
(
typeof
allCurrencies
===
"
undefined
"
)
{
allCurrencies
=
new
Map
();
const
currencies
=
getLatestReadDataFromStore
(
"
currenciesAll
"
);
if
(
currencies
.
length
===
0
)
{
// To use this function, you need to have currencies loaded in the store. Make sure the currencies are loaded in the backend.
// Also, make sure not use this function before we have the currencies loaded :)
throw
new
Error
(
"
Currencies in the store are empty see code for more info.
"
);
}
currencies
.
forEach
(
c
=>
allCurrencies
.
set
(
c
.
id
,
c
.
one_EUR_in_this_currency
)
);
}
if
(
allCurrencies
.
has
(
currencyStr
))
{
return
(
amount
/
allCurrencies
.
get
(
currencyStr
)).
toFixed
(
2
);
}
return
null
;
}
frontend/src/utils/editionRelated/getMapStateToPropsForEditor.js
deleted
100644 → 0
View file @
1451f9ca
import
{
getLatestRead
}
from
"
../../redux/api/utils
"
;
/**
* Function to create the mapStateToProps function for editor in a "generic way"
*
* @export
* @param {string} elKey
* @returns
*/
function
getMapStateToPropsForEditor
(
elKey
)
{
const
propName
=
`
${
elKey
}
One`
;
return
state
=>
{
let
lastUpdateTimeInModel
=
null
;
let
hasPendingModeration
=
null
;
// We make sure to get the latest data
const
latestRead
=
getLatestRead
(
state
.
api
[
propName
]);
if
(
latestRead
.
readAt
!==
0
)
{
lastUpdateTimeInModel
=
latestRead
.
data
.
updated_on
;
hasPendingModeration
=
latestRead
.
data
.
has_pending_moderation
;
}
// simple way to retreive the save error
const
{
updateFailed
}
=
state
.
api
[
propName
];
const
{
createFailed
}
=
state
.
api
[
propName
];
let
savingHasError
=
updateFailed
;
if
(
createFailed
.
failed
)
{
savingHasError
=
createFailed
;
}
return
{
savingHasError
,
lastUpdateTimeInModel
,
hasPendingModeration
};
};
}
export
default
getMapStateToPropsForEditor
;
frontend/src/utils/getCurrencySymbol.js
deleted
100644 → 0
View file @
1451f9ca
import
{
getLatestReadDataFromStore
}
from
"
../redux/api/utils
"
;
// For optimization
let
currenciesSymbols
;
/**
* Function to get the symbol associated with a currency.
* If no symbol is found, currencyStr is returned itsself.
*
* @export
* @param {string} currencyStr
* @returns
*/
export
default
function
getCurrencySymbol
(
currencyStr
)
{
if
(
currencyStr
===
"
EUR
"
)
{
return
"
€
"
;
}
// a bit of optimization, will be useful if this function is used a lot
if
(
typeof
currenciesSymbols
===
"
undefined
"
)
{
currenciesSymbols
=
new
Map
();
const
currencies
=
getLatestReadDataFromStore
(
"
currenciesAll
"
);
if
(
currencies
.
length
===
0
)
{
// To use this function, you need to have currencies loaded in the store. Make sure the currencies are loaded in the backend.
// Also, make sure not use this function before we have the currencies loaded :)
throw
new
Error
(
"
Currencies in the store are empty see code for more info.
"
);
}
currenciesSymbols
=
new
Map
();
currencies
.
filter
(
c
=>
c
.
symbol
!==
""
)
// We keep only the currencies with a symbol
.
forEach
(
c
=>
currenciesSymbols
.
set
(
c
.
id
,
c
.
symbol
));
}
if
(
currenciesSymbols
.
has
(
currencyStr
))
{
return
currenciesSymbols
.
get
(
currencyStr
);
}
return
`
${
currencyStr
}
`
;
}
frontend/yarn.lock
View file @
0223fb20
...
...
@@ -3887,11 +3887,6 @@ dedent@^0.7.0:
resolved "https://registry.yarnpkg.com/dedent/-/dedent-0.7.0.tgz#2495ddbaf6eb874abb0e1be9df22d2e5a544326c"
integrity sha1-JJXduvbrh0q7Dhvp3yLS5aVEMmw=
deep-diff@^0.3.5:
version "0.3.8"
resolved "https://registry.yarnpkg.com/deep-diff/-/deep-diff-0.3.8.tgz#c01de63efb0eec9798801d40c7e0dae25b582c84"
integrity sha1-wB3mPvsO7JeYgB1Ax+Da4ltYLIQ=
deep-equal@1.0.1, deep-equal@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-1.0.1.tgz#f5d260292b660e084eff4cdbc9f08ad3247448b5"
...
...
@@ -9038,7 +9033,7 @@ react-hot-loader@^4.12.12:
shallowequal "^1.1.0"
source-map "^0.7.3"
react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.4, react-is@^16.8.6
, react-is@^16.9.0
:
react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.4, react-is@^16.8.6:
version "16.9.0"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.9.0.tgz#21ca9561399aad0ff1a7701c01683e8ca981edcb"
integrity sha512-tJBzzzIgnnRfEm046qRcURvwQnZVXmuCbscxUO5RWrGTXpon2d4c8mI0D8WE6ydVIm29JiLB6+RslkIvym9Rjw==
...
...
@@ -9081,18 +9076,6 @@ react-markdown@^4.1.0:
unist-util-visit "^1.3.0"
xtend "^4.0.1"
react-redux@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-7.1.1.tgz#ce6eee1b734a7a76e0788b3309bf78ff6b34fa0a"
integrity sha512-QsW0vcmVVdNQzEkrgzh2W3Ksvr8cqpAv5FhEk7tNEft+5pp7rXxAudTz3VOPawRkLIepItpkEIyLcN/VVXzjTg==
dependencies:
"@babel/runtime" "^7.5.5"
hoist-non-react-statics "^3.3.0"
invariant "^2.2.4"
loose-envify "^1.4.0"
prop-types "^15.7.2"
react-is "^16.9.0"
react-router-dom@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-5.0.1.tgz#ee66f4a5d18b6089c361958e443489d6bab714be"
...
...
@@ -9333,26 +9316,6 @@ redeyed@~0.4.0:
dependencies:
esprima "~1.0.4"
redux-logger@^3.0.6:
version "3.0.6"
resolved "https://registry.yarnpkg.com/redux-logger/-/redux-logger-3.0.6.tgz#f7555966f3098f3c88604c449cf0baf5778274bf"
integrity sha1-91VZZvMJjzyIYExEnPC69XeCdL8=
dependencies:
deep-diff "^0.3.5"
redux-thunk@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.3.0.tgz#51c2c19a185ed5187aaa9a2d08b666d0d6467622"
integrity sha512-km6dclyFnmcvxhAcrQV2AkZmPQjzPDjgVlQtR0EQjxZPyJ0BnMf3in1ryuR8A2qU0HldVRfxYXbFSKlI3N7Slw==
redux@^4.0.4:
version "4.0.4"
resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.4.tgz#4ee1aeb164b63d6a1bcc57ae4aa0b6e6fa7a3796"
integrity sha512-vKv4WdiJxOWKxK0yRoaK3Y4pxxB0ilzVx6dszU2W8wLxlb2yikRph4iV/ymtdJ6ZxpBLFbyrxklnT5yBbQSl3Q==
dependencies:
loose-envify "^1.4.0"
symbol-observable "^1.2.0"
regenerate-unicode-properties@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-8.1.0.tgz#ef51e0f0ea4ad424b77bf7cb41f3e015c70a3f0e"
...
...
@@ -10440,7 +10403,7 @@ supports-color@^5.3.0:
dependencies:
has-flag "^3.0.0"
symbol-observable@^1.0.4
, symbol-observable@^1.2.0
:
symbol-observable@^1.0.4:
version "1.2.0"
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804"
integrity sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ==
...
...
server/docker-compose.prod.yml
View file @
0223fb20
...
...
@@ -39,7 +39,7 @@ services:
volumes
:
[
"
postgres_data_prod:/var/lib/postgresql/data/"
]
frontend
:
# Will be killed as soon as the front is generated
image
:
registry.gitlab.utc.fr/rex-dri/rex-dri/frontend:v1.
1.1
image
:
registry.gitlab.utc.fr/rex-dri/rex-dri/frontend:v1.
2.0
command
:
/bin/sh -c "cd frontend && cp -R /usr/src/deps/node_modules . && yarn build"
networks
:
[]
volumes
:
...
...
Prev
1
2
3
4
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment