Verified Commit e7ca842c authored by Florent Chehab's avatar Florent Chehab
Browse files

refactor(frontend): use new NetWrapParam API

parent e9fe8f47
...@@ -49,5 +49,5 @@ ExternalDataUpdateInfo.propTypes = { ...@@ -49,5 +49,5 @@ ExternalDataUpdateInfo.propTypes = {
ExternalDataUpdateInfo.defaultProps = {}; ExternalDataUpdateInfo.defaultProps = {};
export default withNetworkWrapper([ export default withNetworkWrapper([
new NetWrapParam("externalDataUpdateInfo", "all", "updates") new NetWrapParam("externalDataUpdateInfo", "all", { propKey: "updates" })
])(ExternalDataUpdateInfo); ])(ExternalDataUpdateInfo);
...@@ -54,12 +54,10 @@ InformationList.defaultProps = { ...@@ -54,12 +54,10 @@ InformationList.defaultProps = {
export default compose( export default compose(
withNetworkWrapper([ withNetworkWrapper([
new NetWrapParam( new NetWrapParam("information", "all", {
"information", propKey: "informationList",
"all", params: RequestParams.Builder.withQueryParam("now", "true").build()
"informationList", })
RequestParams.Builder.withQueryParam("now", "true").build()
)
]), ]),
withErrorBoundary() withErrorBoundary()
)(InformationList); )(InformationList);
...@@ -26,12 +26,10 @@ NotifierImportantInformation.propTypes = { ...@@ -26,12 +26,10 @@ NotifierImportantInformation.propTypes = {
export default compose( export default compose(
withNetworkWrapper( withNetworkWrapper(
[ [
new NetWrapParam( new NetWrapParam("information", "all", {
"information", propKey: "informationList",
"all", params: RequestParams.Builder.withQueryParam("now", "true").build()
"informationList", })
RequestParams.Builder.withQueryParam("now", "true").build()
)
], ],
React.Fragment React.Fragment
), ),
......
...@@ -75,5 +75,7 @@ UnlinkedPartners.propTypes = { ...@@ -75,5 +75,7 @@ UnlinkedPartners.propTypes = {
}; };
export default withNetworkWrapper([ export default withNetworkWrapper([
new NetWrapParam("unlinkedUtcPartners", "all", "unlinkedPartners") new NetWrapParam("unlinkedUtcPartners", "all", {
propKey: "unlinkedPartners"
})
])(UnlinkedPartners); ])(UnlinkedPartners);
...@@ -31,10 +31,8 @@ ThemeProvider.propTypes = { ...@@ -31,10 +31,8 @@ ThemeProvider.propTypes = {
}; };
export default withNetworkWrapper([ export default withNetworkWrapper([
new NetWrapParam( new NetWrapParam("userData", "one", {
"userData", propKey: "userData",
"one", params: RequestParams.Builder.withId(CURRENT_USER_ID).build()
"userData", })
RequestParams.Builder.withId(CURRENT_USER_ID).build()
)
])(ThemeProvider); ])(ThemeProvider);
...@@ -15,10 +15,7 @@ import FullScreenDialogService from "../../services/FullScreenDialogService"; ...@@ -15,10 +15,7 @@ import FullScreenDialogService from "../../services/FullScreenDialogService";
import useStepper from "../../hooks/useStepper"; import useStepper from "../../hooks/useStepper";
import FullScreenDialogFrame from "../common/FullScreenDialogFrame"; import FullScreenDialogFrame from "../common/FullScreenDialogFrame";
import dateTimeStrToStr from "../../utils/dateTimeStrToStr"; import dateTimeStrToStr from "../../utils/dateTimeStrToStr";
import withNetworkWrapper, { import withNetworkWrapper, { NetWrapParam } from "../../hoc/withNetworkWrapper";
getApiPropTypes,
NetWrapParam
} from "../../hoc/withNetworkWrapper";
import { useApiInvalidateAll } from "../../hooks/wrappers/api"; import { useApiInvalidateAll } from "../../hooks/wrappers/api";
const useStyles = makeStyles(theme => ({ const useStyles = makeStyles(theme => ({
...@@ -74,8 +71,6 @@ const buildParams = modelInfo => { ...@@ -74,8 +71,6 @@ const buildParams = modelInfo => {
function History({ function History({
versions, versions,
modelInfo,
api,
renderTitle, renderTitle,
renderCore, renderCore,
editFromVersion, editFromVersion,
...@@ -87,11 +82,6 @@ function History({ ...@@ -87,11 +82,6 @@ function History({
return () => resetVersions(); // only on unmount return () => resetVersions(); // only on unmount
}, []); }, []);
// keep the component up to date
useEffect(() => {
api.versions.setParams(buildParams(modelInfo));
}, [modelInfo]);
const [currentVersion, goNextVersion, goPreviousVersion] = useStepper( const [currentVersion, goNextVersion, goPreviousVersion] = useStepper(
versions.length - 1 versions.length - 1
); );
...@@ -154,20 +144,22 @@ function History({ ...@@ -154,20 +144,22 @@ function History({
History.propTypes = { History.propTypes = {
editFromVersion: PropTypes.func.isRequired, editFromVersion: PropTypes.func.isRequired,
versions: PropTypes.array.isRequired, versions: PropTypes.array.isRequired,
modelInfo: PropTypes.shape({
contentTypeId: PropTypes.number.isRequired,
id: PropTypes.number.isRequired
}).isRequired,
renderCore: PropTypes.func.isRequired, renderCore: PropTypes.func.isRequired,
renderTitle: PropTypes.func.isRequired, renderTitle: PropTypes.func.isRequired,
rawModelDataEx: PropTypes.object.isRequired, rawModelDataEx: PropTypes.object.isRequired
api: getApiPropTypes("versions").isRequired
}; };
export default compose( export default compose(
withNetworkWrapper([ withNetworkWrapper([
new NetWrapParam("versions", "all", "versions", props => new NetWrapParam("versions", "all", {
buildParams(props.modelInfo) propKey: "versions",
) params: props => buildParams(props.modelInfo),
propTypes: {
modelInfo: PropTypes.shape({
contentTypeId: PropTypes.number.isRequired,
id: PropTypes.number.isRequired
}).isRequired
}
})
]) ])
)(History); )(History);
import React, { useCallback, useEffect, useMemo } from "react"; import React, { useCallback, useMemo } from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import compose from "recompose/compose"; import compose from "recompose/compose";
...@@ -9,10 +9,7 @@ import { makeStyles } from "@material-ui/styles"; ...@@ -9,10 +9,7 @@ import { makeStyles } from "@material-ui/styles";
import RequestParams from "../../utils/api/RequestParams"; import RequestParams from "../../utils/api/RequestParams";
import FullScreenDialogService from "../../services/FullScreenDialogService"; import FullScreenDialogService from "../../services/FullScreenDialogService";
import FullScreenDialogFrame from "../common/FullScreenDialogFrame"; import FullScreenDialogFrame from "../common/FullScreenDialogFrame";
import withNetworkWrapper, { import withNetworkWrapper, { NetWrapParam } from "../../hoc/withNetworkWrapper";
getApiPropTypes,
NetWrapParam
} from "../../hoc/withNetworkWrapper";
import { useApiInvalidateAll } from "../../hooks/wrappers/api"; import { useApiInvalidateAll } from "../../hooks/wrappers/api";
import useOnComponentUnMount from "../../hooks/useOnComponentUnMount"; import useOnComponentUnMount from "../../hooks/useOnComponentUnMount";
...@@ -69,8 +66,6 @@ const buildParams = modelInfo => { ...@@ -69,8 +66,6 @@ const buildParams = modelInfo => {
}; };
function PendingModeration({ function PendingModeration({
api,
modelInfo,
pendingModeration, pendingModeration,
editFromPendingModeration, editFromPendingModeration,
renderTitle, renderTitle,
...@@ -83,11 +78,6 @@ function PendingModeration({ ...@@ -83,11 +78,6 @@ function PendingModeration({
resetData(); resetData();
}); });
// keep the component up to date
useEffect(() => {
api.pendingModeration.setParams(buildParams(modelInfo));
}, [modelInfo]);
const pendingModelData = useMemo(() => { const pendingModelData = useMemo(() => {
const pending = pendingModeration[0]; const pending = pendingModeration[0];
return { return {
...@@ -131,17 +121,20 @@ PendingModeration.propTypes = { ...@@ -131,17 +121,20 @@ PendingModeration.propTypes = {
userCanModerate: PropTypes.bool.isRequired, userCanModerate: PropTypes.bool.isRequired,
pendingModeration: PropTypes.array.isRequired, pendingModeration: PropTypes.array.isRequired,
renderTitle: PropTypes.func.isRequired, renderTitle: PropTypes.func.isRequired,
renderCore: PropTypes.func.isRequired, renderCore: PropTypes.func.isRequired
api: getApiPropTypes("pendingModeration").isRequired
}; };
export default compose( export default compose(
withNetworkWrapper([ withNetworkWrapper([
new NetWrapParam( new NetWrapParam("pendingModerationObj", "all", {
"pendingModerationObj", propKey: "pendingModeration",
"all", params: props => buildParams(props.modelInfo),
"pendingModeration", propTypes: {
props => buildParams(props.modelInfo) modelInfo: PropTypes.shape({
) contentTypeId: PropTypes.number.isRequired,
id: PropTypes.number.isRequired
}).isRequired
}
})
]) ])
)(PendingModeration); )(PendingModeration);
import React, { useEffect } from "react"; import React from "react";
import { compose } from "recompose"; import { compose } from "recompose";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import Typography from "@material-ui/core/Typography"; import Typography from "@material-ui/core/Typography";
...@@ -11,10 +11,7 @@ import EditModuleCoursesFeedback from "../university/modules/previousExchangeFee ...@@ -11,10 +11,7 @@ import EditModuleCoursesFeedback from "../university/modules/previousExchangeFee
import CustomLink from "../common/CustomLink"; import CustomLink from "../common/CustomLink";
import APP_ROUTES from "../../config/appRoutes"; import APP_ROUTES from "../../config/appRoutes";
import UniversityService from "../../services/data/UniversityService"; import UniversityService from "../../services/data/UniversityService";
import withNetworkWrapper, { import withNetworkWrapper, { NetWrapParam } from "../../hoc/withNetworkWrapper";
getApiPropTypes,
NetWrapParam
} from "../../hoc/withNetworkWrapper";
function getExchangeId(match) { function getExchangeId(match) {
return parseInt(match.params.exchangeId, 10); return parseInt(match.params.exchangeId, 10);
...@@ -36,14 +33,10 @@ const buildParams = match => ...@@ -36,14 +33,10 @@ const buildParams = match =>
/** /**
* Page that handle the modification of exchange feedbacks. * Page that handle the modification of exchange feedbacks.
*/ */
function PageEditExchangeFeedbacks({ match, exchange, api }) { function PageEditExchangeFeedbacks({ match, exchange }) {
const classes = useStyles(); const classes = useStyles();
const id = getExchangeId(match); const id = getExchangeId(match);
useEffect(() => {
api.exchange.setParams(buildParams(match));
}, [id]);
const univId = exchange.university; const univId = exchange.university;
const univName = UniversityService.getUnivName(univId); const univName = UniversityService.getUnivName(univId);
...@@ -89,15 +82,22 @@ PageEditExchangeFeedbacks.propTypes = { ...@@ -89,15 +82,22 @@ PageEditExchangeFeedbacks.propTypes = {
exchangeId: PropTypes.string.isRequired exchangeId: PropTypes.string.isRequired
}) })
}).isRequired, }).isRequired,
exchange: PropTypes.object.isRequired, exchange: PropTypes.object.isRequired
api: getApiPropTypes("exchange").isRequired
}; };
export default compose( export default compose(
withNetworkWrapper([ withNetworkWrapper([
new NetWrapParam("exchanges", "one", "exchange", props => new NetWrapParam("exchanges", "one", {
buildParams(props.match) propKey: "exchange",
) params: props => buildParams(props.match),
propTypes: {
match: PropTypes.shape({
params: PropTypes.shape({
exchangeId: PropTypes.string.isRequired
})
}).isRequired
}
})
]), ]),
withPaddedPaper(), withPaddedPaper(),
withErrorBoundary() withErrorBoundary()
......
...@@ -61,11 +61,27 @@ PageFiles.propTypes = { ...@@ -61,11 +61,27 @@ PageFiles.propTypes = {
export default compose( export default compose(
withNetworkWrapper([ withNetworkWrapper([
new NetWrapParam("pictures", "all", "pictures", props => new NetWrapParam("pictures", "all", {
buildPictureParams(props.match) propKey: "pictures",
), params: props => buildPictureParams(props.match),
new NetWrapParam("files", "all", "files", props => propTypes: {
buildFilesParams(props.match) match: PropTypes.shape({
) params: PropTypes.shape({
userId: PropTypes.string.isRequired
})
}).isRequired
}
}),
new NetWrapParam("files", "all", {
propKey: "files",
params: props => buildFilesParams(props.match),
propTypes: {
match: PropTypes.shape({
params: PropTypes.shape({
userId: PropTypes.string.isRequired
})
}).isRequired
}
})
]) ])
)(PageFiles); )(PageFiles);
...@@ -136,12 +136,13 @@ PageMyExchanges.propTypes = { ...@@ -136,12 +136,13 @@ PageMyExchanges.propTypes = {
export default compose( export default compose(
withNetworkWrapper([ withNetworkWrapper([
new NetWrapParam( new NetWrapParam("exchanges", "all", {
"exchanges", prop: "exchanges",
"all", params: RequestParams.Builder.withQueryParam(
"exchanges", "student",
RequestParams.Builder.withQueryParam("student", CURRENT_USER_ID).build() CURRENT_USER_ID
) ).build()
})
]), ]),
withPaddedPaper(), withPaddedPaper(),
withErrorBoundary() withErrorBoundary()
......
...@@ -181,5 +181,7 @@ SelectListSubPage.propTypes = { ...@@ -181,5 +181,7 @@ SelectListSubPage.propTypes = {
}; };
export default compose( export default compose(
withNetworkWrapper([new NetWrapParam("recommendationLists", "all", "lists")]) withNetworkWrapper([
new NetWrapParam("recommendationLists", "all", { propKey: "lists" })
])
)(SelectListSubPage); )(SelectListSubPage);
import React, { useEffect } from "react"; import React from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { compose } from "recompose"; import { compose } from "recompose";
import Button from "@material-ui/core/Button"; import Button from "@material-ui/core/Button";
import ArrowBackIcon from "@material-ui/icons/ArrowBack"; import ArrowBackIcon from "@material-ui/icons/ArrowBack";
import RequestParams from "../../utils/api/RequestParams"; import RequestParams from "../../utils/api/RequestParams";
import List from "./view/View"; import List from "./view/View";
import withNetworkWrapper, { import withNetworkWrapper, { NetWrapParam } from "../../hoc/withNetworkWrapper";
getApiPropTypes,
NetWrapParam
} from "../../hoc/withNetworkWrapper";
import NavigationService from "../../services/NavigationService"; import NavigationService from "../../services/NavigationService";
const buildParams = listId => RequestParams.Builder.withId(listId).build(); const buildParams = listId => RequestParams.Builder.withId(listId).build();
...@@ -16,11 +13,7 @@ const buildParams = listId => RequestParams.Builder.withId(listId).build(); ...@@ -16,11 +13,7 @@ const buildParams = listId => RequestParams.Builder.withId(listId).build();
/** /**
* Component to display one recommendation list * Component to display one recommendation list
*/ */
function ViewListSubPage({ list, listId, api }) { function ViewListSubPage({ list }) {
useEffect(() => {
api.list.setParams(buildParams(listId));
}, [listId]);
return ( return (
<> <>
<Button onClick={NavigationService.goToLists}> <Button onClick={NavigationService.goToLists}>
...@@ -32,15 +25,17 @@ function ViewListSubPage({ list, listId, api }) { ...@@ -32,15 +25,17 @@ function ViewListSubPage({ list, listId, api }) {
} }
ViewListSubPage.propTypes = { ViewListSubPage.propTypes = {
listId: PropTypes.number.isRequired, list: PropTypes.object.isRequired
list: PropTypes.object.isRequired,
api: getApiPropTypes("list").isRequired
}; };
export default compose( export default compose(
withNetworkWrapper([ withNetworkWrapper([
new NetWrapParam("recommendationLists", "one", "list", props => new NetWrapParam("recommendationLists", "one", {
buildParams(props.listId) propKey: "list",
) params: props => buildParams(props.listId),
propTypes: {
listId: PropTypes.number.isRequired
}
})
]) ])
)(ViewListSubPage); )(ViewListSubPage);
...@@ -331,12 +331,10 @@ const styles = theme => ({ ...@@ -331,12 +331,10 @@ const styles = theme => ({
const ConnectedComp = compose( const ConnectedComp = compose(
withNetworkWrapper([ withNetworkWrapper([
new NetWrapParam( new NetWrapParam("userData", "one", {
"userData", propKey: "userData",
"one", params: RequestParams.Builder.withId(CURRENT_USER_ID).build()
"userData", })
RequestParams.Builder.withId(CURRENT_USER_ID).build()
)
]), ]),
withStyles(styles, { withTheme: true }) withStyles(styles, { withTheme: true })
)(ColorTool); )(ColorTool);
......
import React, { useEffect, useMemo } from "react"; import React, { useMemo } from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import compose from "recompose/compose"; import compose from "recompose/compose";
...@@ -11,7 +11,6 @@ import CountryDriForm from "../forms/CountryDriForm"; ...@@ -11,7 +11,6 @@ import CountryDriForm from "../forms/CountryDriForm";
import withUnivInfo from "../../../hoc/withUnivInfo"; import withUnivInfo from "../../../hoc/withUnivInfo";
import RequestParams from "../../../utils/api/RequestParams"; import RequestParams from "../../../utils/api/RequestParams";
import withNetworkWrapper, { import withNetworkWrapper, {
getApiPropTypes,
NetWrapParam NetWrapParam
} from "../../../hoc/withNetworkWrapper"; } from "../../../hoc/withNetworkWrapper";
...@@ -33,11 +32,7 @@ CoreComponent.defaultProps = { ...@@ -33,11 +32,7 @@ CoreComponent.defaultProps = {
const buildParams = countryId => const buildParams = countryId =>
RequestParams.Builder.withQueryParam("countries", countryId).build(); RequestParams.Builder.withQueryParam("countries", countryId).build();
function CountryDri({ countryId, countryDriItems, api }) { function CountryDri({ countryId, countryDriItems }) {
useEffect(() => {
api.countryDriItems.setParams(buildParams(countryId));
}, [countryId]);
const defaultModelData = useMemo( const defaultModelData = useMemo(
() => ({ () => ({
countries: [countryId], countries: [countryId],
...@@ -67,15 +62,18 @@ function CountryDri({ countryId, countryDriItems, api }) { ...@@ -67,15 +62,18 @@ function CountryDri({ countryId, countryDriItems, api }) {
CountryDri.propTypes = { CountryDri.propTypes = {
countryId: PropTypes.string.isRequired, countryId: PropTypes.string.isRequired,
countryDriItems: PropTypes.array.isRequired, countryDriItems: PropTypes.array.isRequired
api: getApiPropTypes("countryDriItems").isRequired
}; };
export default compose( export default compose(
withUnivInfo(["countryId"]), withUnivInfo(["countryId"]),
withNetworkWrapper([ withNetworkWrapper([
new NetWrapParam("countryDri", "all", "countryDriItems", props => new NetWrapParam("countryDri", "all", {
buildParams(props.countryId) propKey: "countryDriItems",
) params: props => buildParams(props.countryId),
propTypes: {
countryId: PropTypes.string.isRequired
}
})
]) ])
)(CountryDri); )(CountryDri);
import React, { useEffect, useMemo } from "react"; import React, { useMemo } from "react";