Commit 137f3e7a authored by Florent Chehab's avatar Florent Chehab

Infer parseRawModelData instead of writting it.

And bug fixes
parent 6cd8ddc9
...@@ -85,12 +85,12 @@ export default class SmartActions { ...@@ -85,12 +85,12 @@ export default class SmartActions {
* @param {string} apiEndPoint * @param {string} apiEndPoint
* @param {function} isSavingSpecific * @param {function} isSavingSpecific
* @param {function} saveSpecificSucceeded * @param {function} saveSpecificSucceeded
* @param {function} failedSpecific * @param {function} saveSpecificFailed
* @param {function} [onSuccessCallback = (newData) => {}] CallBack called if the update was successful besides calling the saveSpecificSucceeded action * @param {function} [onSuccessCallback = (newData) => {}] CallBack called if the update was successful besides calling the saveSpecificSucceeded action
* @returns {function} Function that takes the `dispatch` function of redux as argument. * @returns {function} Function that takes the `dispatch` function of redux as argument.
* @memberof SmartActions * @memberof SmartActions
*/ */
_ElSaveData(data, apiEndPoint, isSavingSpecific, saveSpecificSucceeded, failedSpecific, onSuccessCallback = () => { }) { _ElSaveData(data, apiEndPoint, isSavingSpecific, saveSpecificSucceeded, saveSpecificFailed, onSuccessCallback = () => { }) {
return (dispatch) => { return (dispatch) => {
let method = "POST"; let method = "POST";
let pk = ""; let pk = "";
...@@ -138,8 +138,8 @@ export default class SmartActions { ...@@ -138,8 +138,8 @@ export default class SmartActions {
} }
}) })
.then((errorContent) => { .then((errorContent) => {
if (typeof errorContent != "undefined") { if (typeof errorContent !== "undefined") {
dispatch(failedSpecific(true, { message: errorStatusText, content: errorContent })); dispatch(saveSpecificFailed(true, { message: errorStatusText, content: errorContent }));
dispatch(isSavingSpecific(false)); dispatch(isSavingSpecific(false));
} }
}); });
......
...@@ -36,7 +36,7 @@ class CountryDriForm extends Form { ...@@ -36,7 +36,7 @@ class CountryDriForm extends Form {
class CountryDriEditor extends Editor { class CountryDriEditor extends Editor {
renderForm() { renderForm() {
return <CountryDriForm return <CountryDriForm
modelData={this.props.modelData} modelData={this.props.rawModelData}
outsideData={this.props.outsideData} outsideData={this.props.outsideData}
ref={this.formRef} ref={this.formRef}
/>; />;
...@@ -44,7 +44,7 @@ class CountryDriEditor extends Editor { ...@@ -44,7 +44,7 @@ class CountryDriEditor extends Editor {
} }
CountryDriEditor.propTypes = { CountryDriEditor.propTypes = {
modelData: PropTypes.object.isRequired, outsideData: PropTypes.object.isRequired,
}; };
......
...@@ -29,7 +29,7 @@ class CountryScholarshipEditor extends Editor { ...@@ -29,7 +29,7 @@ class CountryScholarshipEditor extends Editor {
renderForm() { renderForm() {
return ( return (
<CountryScholarshipForm <CountryScholarshipForm
modelData={this.props.modelData} modelData={this.props.rawModelData}
outsideData={this.props.outsideData} outsideData={this.props.outsideData}
ref={this.formRef} ref={this.formRef}
/> />
...@@ -37,10 +37,7 @@ class CountryScholarshipEditor extends Editor { ...@@ -37,10 +37,7 @@ class CountryScholarshipEditor extends Editor {
} }
} }
CountryScholarshipEditor.propTypes = { CountryScholarshipEditor.propTypes = {
modelData: PropTypes.object.isRequired,
outsideData: PropTypes.object.isRequired, outsideData: PropTypes.object.isRequired,
}; };
......
...@@ -34,7 +34,7 @@ class UniversityDriEditor extends Editor { ...@@ -34,7 +34,7 @@ class UniversityDriEditor extends Editor {
renderForm() { renderForm() {
return <UniversityDriForm return <UniversityDriForm
modelData={this.props.modelData} modelData={this.props.rawModelData}
outsideData={this.props.outsideData} outsideData={this.props.outsideData}
ref={this.formRef} ref={this.formRef}
/>; />;
...@@ -42,7 +42,6 @@ class UniversityDriEditor extends Editor { ...@@ -42,7 +42,6 @@ class UniversityDriEditor extends Editor {
} }
UniversityDriEditor.propTypes = { UniversityDriEditor.propTypes = {
modelData: PropTypes.object.isRequired,
outsideData: PropTypes.object.isRequired, outsideData: PropTypes.object.isRequired,
}; };
......
...@@ -51,7 +51,7 @@ class UniversityGeneralForm extends Form { ...@@ -51,7 +51,7 @@ class UniversityGeneralForm extends Form {
class UniversityGeneralEditor extends Editor { class UniversityGeneralEditor extends Editor {
renderForm() { renderForm() {
return <UniversityGeneralForm return <UniversityGeneralForm
modelData={this.props.modelData} modelData={this.props.rawModelData}
ref={this.formRef} ref={this.formRef}
/>; />;
} }
......
...@@ -25,10 +25,12 @@ class UniversityScholarshipForm extends ScholarshipForm { ...@@ -25,10 +25,12 @@ class UniversityScholarshipForm extends ScholarshipForm {
} }
class UniversityScholarshipEditor extends Editor { class UniversityScholarshipEditor extends Editor {
extraFieldMappings = ["university"];
renderForm() { renderForm() {
return ( return (
<UniversityScholarshipForm <UniversityScholarshipForm
modelData={this.props.modelData} modelData={this.props.rawModelData}
outsideData={this.props.outsideData} outsideData={this.props.outsideData}
ref={this.formRef} ref={this.formRef}
/> />
...@@ -37,7 +39,6 @@ class UniversityScholarshipEditor extends Editor { ...@@ -37,7 +39,6 @@ class UniversityScholarshipEditor extends Editor {
} }
UniversityScholarshipEditor.propTypes = { UniversityScholarshipEditor.propTypes = {
modelData: PropTypes.object.isRequired,
outsideData: PropTypes.object.isRequired, outsideData: PropTypes.object.isRequired,
}; };
......
...@@ -77,20 +77,18 @@ function onlyOneIsNull(a, b) { ...@@ -77,20 +77,18 @@ function onlyOneIsNull(a, b) {
} }
class UniversitySemestersDatesEditor extends Editor { class UniversitySemestersDatesEditor extends Editor {
extraFieldMappings = ["university"];
renderForm() { renderForm() {
return ( return (
<UniversitySemestersDatesForm <UniversitySemestersDatesForm
modelData={this.props.modelData} modelData={this.props.rawModelData}
ref={this.formRef} ref={this.formRef}
/> />
); );
} }
} }
UniversitySemestersDatesEditor.propTypes = {
modelData: PropTypes.object.isRequired,
};
export default compose( export default compose(
withSnackbar, withSnackbar,
......
...@@ -28,24 +28,6 @@ function renderCore(rawModelData, classes, outsideData) { ...@@ -28,24 +28,6 @@ function renderCore(rawModelData, classes, outsideData) {
); );
} }
function parseRawModelData(rawModelData) {
// reverse serialization
const modelData = __pick(rawModelData,
[
"id",
"title",
"importance_level",
"countries",
"comment",
"useful_links",
// "obj_moderation_level",
]);
return modelData;
}
class CountryDri extends Module { class CountryDri extends Module {
customRender() { customRender() {
const countryDriItems = this.getReadData("countryDri"); const countryDriItems = this.getReadData("countryDri");
...@@ -62,8 +44,7 @@ class CountryDri extends Module { ...@@ -62,8 +44,7 @@ class CountryDri extends Module {
editor={CountryDriEditor} editor={CountryDriEditor}
invalidateGroup={this.props.invalidateData} invalidateGroup={this.props.invalidateData}
propsForEditor={{ propsForEditor={{
modelData: { countries: [this.props.countryId], importance_level: "-" }, rawModelData: { countries: [this.props.countryId], importance_level: "-" },
parseRawModelData: parseRawModelData,
outsideData: outsideData, outsideData: outsideData,
__apiAttr: this.props.countryId, __apiAttr: this.props.countryId,
}} }}
...@@ -74,7 +55,6 @@ class CountryDri extends Module { ...@@ -74,7 +55,6 @@ class CountryDri extends Module {
key={idx} key={idx}
buildTitle={(modelData) => modelData.title} buildTitle={(modelData) => modelData.title}
rawModelData={rawModelData} rawModelData={rawModelData}
parseRawModelData={parseRawModelData}
editor={CountryDriEditor} editor={CountryDriEditor}
renderCore={renderCore} renderCore={renderCore}
coreClasses={classes} coreClasses={classes}
......
...@@ -41,29 +41,6 @@ function renderCore(rawModelData, classes, outsideData) { ...@@ -41,29 +41,6 @@ function renderCore(rawModelData, classes, outsideData) {
} }
function parseRawModelData(rawModelData) {
// reverse serialization
const modelData = __pick(rawModelData,
[
"id",
"title",
"type",
"currency",
"frequency",
"amount_min",
"amount_max",
// "importance_level",
"countries",
"comment",
"other_advantages",
"useful_links",
"obj_moderation_level",
]);
return modelData;
}
class CountryScholarships extends Module { class CountryScholarships extends Module {
customRender() { customRender() {
const countryScholarshipsItems = this.getReadData("countryScholarships"); const countryScholarshipsItems = this.getReadData("countryScholarships");
...@@ -81,8 +58,7 @@ class CountryScholarships extends Module { ...@@ -81,8 +58,7 @@ class CountryScholarships extends Module {
editor={CountryScholarshipEditor} editor={CountryScholarshipEditor}
invalidateGroup={this.props.invalidateData} invalidateGroup={this.props.invalidateData}
propsForEditor={{ propsForEditor={{
modelData: { countries: [this.props.countryId], importance_level: "-", currency: "EUR", obj_moderation_level: 0 }, rawModelData: { countries: [this.props.countryId], importance_level: "-", currency: "EUR", obj_moderation_level: 0 },
parseRawModelData: parseRawModelData,
outsideData: outsideData, outsideData: outsideData,
__apiAttr: this.props.countryId, __apiAttr: this.props.countryId,
}} }}
...@@ -93,7 +69,6 @@ class CountryScholarships extends Module { ...@@ -93,7 +69,6 @@ class CountryScholarships extends Module {
key={idx} key={idx}
buildTitle={(modelData) => modelData.title} buildTitle={(modelData) => modelData.title}
rawModelData={rawModelData} rawModelData={rawModelData}
parseRawModelData={parseRawModelData}
editor={CountryScholarshipEditor} editor={CountryScholarshipEditor}
renderCore={renderCore} renderCore={renderCore}
coreClasses={classes} coreClasses={classes}
......
...@@ -31,24 +31,6 @@ function renderCore(rawModelData, classes, outsideData) { ...@@ -31,24 +31,6 @@ function renderCore(rawModelData, classes, outsideData) {
} }
function parseRawModelData(rawModelData) {
// reverse serialization
const univInfos = rawModelData;
const modelData = __pick(univInfos,
[
"id",
"title",
"importance_level",
"universities",
"comment",
"useful_links",
// "obj_moderation_level",
]);
return modelData;
}
class UniversityDri extends Module { class UniversityDri extends Module {
customRender() { customRender() {
...@@ -64,8 +46,7 @@ class UniversityDri extends Module { ...@@ -64,8 +46,7 @@ class UniversityDri extends Module {
editor={UniversityDriEditor} editor={UniversityDriEditor}
invalidateGroup={this.props.invalidateData} invalidateGroup={this.props.invalidateData}
propsForEditor={{ propsForEditor={{
modelData: { universities: [this.props.univId], importance_level: "-" }, rawModelData: { universities: [this.props.univId], importance_level: "-" },
parseRawModelData: parseRawModelData,
outsideData: outsideData, outsideData: outsideData,
__apiAttr: this.props.univId, __apiAttr: this.props.univId,
}} }}
...@@ -76,7 +57,6 @@ class UniversityDri extends Module { ...@@ -76,7 +57,6 @@ class UniversityDri extends Module {
key={rawModelData.id} // use the id of the model to prevent useless unmount key={rawModelData.id} // use the id of the model to prevent useless unmount
buildTitle={(modelData) => modelData.title} buildTitle={(modelData) => modelData.title}
rawModelData={rawModelData} rawModelData={rawModelData}
parseRawModelData={parseRawModelData}
editor={UniversityDriEditor} editor={UniversityDriEditor}
renderCore={renderCore} renderCore={renderCore}
coreClasses={classes} coreClasses={classes}
......
...@@ -57,26 +57,6 @@ function renderCore(rawModelData, classes, outsideData) { ...@@ -57,26 +57,6 @@ function renderCore(rawModelData, classes, outsideData) {
} }
function parseRawModelData(rawModelData) {
// reverse serialization
const univInfos = rawModelData;
const modelData = __pick(univInfos,
[
"name",
"acronym",
"logo",
"website",
// "useful_links",
// "comment",
"university",
// "obj_moderation_level",
"id"
]);
return modelData;
}
class UniversityGeneral extends Module { class UniversityGeneral extends Module {
customRender() { customRender() {
const univInfos = this.getReadData("university"); const univInfos = this.getReadData("university");
...@@ -90,7 +70,6 @@ class UniversityGeneral extends Module { ...@@ -90,7 +70,6 @@ class UniversityGeneral extends Module {
<ModuleWrapper <ModuleWrapper
buildTitle={() => "Présentation"} buildTitle={() => "Présentation"}
rawModelData={univInfos} rawModelData={univInfos}
parseRawModelData={parseRawModelData}
editor={UniversityGeneralEditor} editor={UniversityGeneralEditor}
renderCore={renderCore} renderCore={renderCore}
coreClasses={classes} coreClasses={classes}
......
...@@ -19,8 +19,8 @@ const styles = theme => ({ ...@@ -19,8 +19,8 @@ const styles = theme => ({
}); });
function renderCore(rawModelData, classes, outsideData) { function renderCore(rawModelData, classes, outsideData) {
const { comment, frequency, currency, type } = rawModelData; const { comment, frequency, currency, type } = rawModelData,
const amountMin = rawModelData.amount_min, amountMin = rawModelData.amount_min,
amountMax = rawModelData.amount_max, amountMax = rawModelData.amount_max,
otherAdvantages = rawModelData.other_advantages; otherAdvantages = rawModelData.other_advantages;
...@@ -38,30 +38,6 @@ function renderCore(rawModelData, classes, outsideData) { ...@@ -38,30 +38,6 @@ function renderCore(rawModelData, classes, outsideData) {
); );
} }
function parseRawModelData(rawModelData) {
// reverse serialization
const modelData = __pick(rawModelData,
[
"id",
"title",
"type",
"currency",
"frequency",
"amount_min",
"amount_max",
// "importance_level",
"universities",
"comment",
"other_advantages",
"useful_links",
"obj_moderation_level",
]);
return modelData;
}
class UniversityScholarships extends Module { class UniversityScholarships extends Module {
customRender() { customRender() {
const univScholarshipsItems = this.getReadData("universityScholarships"); const univScholarshipsItems = this.getReadData("universityScholarships");
...@@ -79,8 +55,7 @@ class UniversityScholarships extends Module { ...@@ -79,8 +55,7 @@ class UniversityScholarships extends Module {
editor={UniversityScholarshipEditor} editor={UniversityScholarshipEditor}
invalidateGroup={this.props.invalidateData} invalidateGroup={this.props.invalidateData}
propsForEditor={{ propsForEditor={{
modelData: { universities: [this.props.univId], importance_level: "-", currency: "EUR", obj_moderation_level: 0 }, rawModelData: { universities: [this.props.univId], importance_level: "-", currency: "EUR", obj_moderation_level: 0 },
parseRawModelData: parseRawModelData,
outsideData: outsideData, outsideData: outsideData,
__apiAttr: this.props.univId, __apiAttr: this.props.univId,
}} }}
...@@ -91,7 +66,6 @@ class UniversityScholarships extends Module { ...@@ -91,7 +66,6 @@ class UniversityScholarships extends Module {
key={idx} key={idx}
buildTitle={(modelData) => modelData.title} buildTitle={(modelData) => modelData.title}
rawModelData={rawModelData} rawModelData={rawModelData}
parseRawModelData={parseRawModelData}
editor={UniversityScholarshipEditor} editor={UniversityScholarshipEditor}
renderCore={renderCore} renderCore={renderCore}
coreClasses={classes} coreClasses={classes}
......
...@@ -103,26 +103,6 @@ function renderCore(rawModelData, classes) { ...@@ -103,26 +103,6 @@ function renderCore(rawModelData, classes) {
} }
function parseRawModelData(rawModelData) {
// reverse serialization
const semestersDates = rawModelData;
const modelData = __pick(semestersDates,
[
"autumn_begin",
"autumn_end",
"spring_begin",
"spring_end",
"useful_links",
"comment",
"university",
"obj_moderation_level",
"id"
]);
return modelData;
}
class UniversitySemestersDates extends Module { class UniversitySemestersDates extends Module {
customRender() { customRender() {
...@@ -132,7 +112,6 @@ class UniversitySemestersDates extends Module { ...@@ -132,7 +112,6 @@ class UniversitySemestersDates extends Module {
<ModuleWrapper <ModuleWrapper
buildTitle={() => "Date des semestres"} buildTitle={() => "Date des semestres"}
rawModelData={semestersDates} rawModelData={semestersDates}
parseRawModelData={parseRawModelData}
editor={UniversitySemestersDatesEditor} editor={UniversitySemestersDatesEditor}
renderCore={renderCore} renderCore={renderCore}
coreClasses={classes} coreClasses={classes}
......
...@@ -35,7 +35,7 @@ class Alert extends React.Component { ...@@ -35,7 +35,7 @@ class Alert extends React.Component {
{this.props.infoText} {this.props.infoText}
</Button> </Button>
: :
<> <div>
<Button <Button
onClick={() => { this.props.handleClose(); this.props.handleResponse(false); }} onClick={() => { this.props.handleClose(); this.props.handleResponse(false); }}
color='secondary' color='secondary'
...@@ -52,7 +52,7 @@ class Alert extends React.Component { ...@@ -52,7 +52,7 @@ class Alert extends React.Component {
> >
{this.props.agreeText} {this.props.agreeText}
</Button> </Button>
</> </div>
} }
</DialogActions> </DialogActions>
</> </>
......
...@@ -20,7 +20,7 @@ import Form from "./Form"; ...@@ -20,7 +20,7 @@ import Form from "./Form";
* class BlablaEditor extends Editor { * class BlablaEditor extends Editor {
* renderForm() { * renderForm() {
* return <blablaForm * return <blablaForm
* modelData={this.props.modelData} * modelData={this.props.rawModelData}
* ref={this.formRef} * ref={this.formRef}
* />; * />;
* } * }
...@@ -45,6 +45,41 @@ class Editor extends Component { ...@@ -45,6 +45,41 @@ class Editor extends Component {
// reference to the form that the editor should contain // reference to the form that the editor should contain
formRef = React.createRef(); formRef = React.createRef();
/**
* Extra attributes that should be retrieved in rawModelData when parsing
* I.e. the fields that are not present in the form but still need to be there
*
* @memberof Editor
*/
extraFieldMappings = []
/**
* Function that extracts the modelData from the raw one.
*