Commit 50d6e34e authored by Florent Chehab's avatar Florent Chehab

Fixed todos and cleaning

parent 16553345
...@@ -12,7 +12,7 @@ import Badge from "@material-ui/core/Badge"; ...@@ -12,7 +12,7 @@ import Badge from "@material-ui/core/Badge";
export default function MyBadge(props) { export default function MyBadge(props) {
if (props.badgeContent) { if (props.badgeContent) {
return ( return (
<Badge {...props} > <Badge badgeContent={props.badgeContent} color={props.color} max={5} >
{props.children} {props.children}
</Badge> </Badge>
); );
......
...@@ -182,7 +182,6 @@ class Editor extends Component { ...@@ -182,7 +182,6 @@ class Editor extends Component {
this.props.openFullScreenDialog(this.renderEditor()); this.props.openFullScreenDialog(this.renderEditor());
} }
// TODO is this needed with redesign
// To handle moderation, we use the editor in "hacky" manner // To handle moderation, we use the editor in "hacky" manner
// with the `dataToSave` props, which triggers a save. // with the `dataToSave` props, which triggers a save.
const { dataToSave } = this.props; const { dataToSave } = this.props;
......
...@@ -81,16 +81,14 @@ class Form extends Component { ...@@ -81,16 +81,14 @@ class Form extends Component {
/** /**
* Function to build all the errors from the fields of the form. * Function to build all the errors from the fields of the form.
* *
* TODO change setup with new custom error
*
* @returns * @returns
* @memberof Form * @memberof Form
*/ */
fieldsHaveError() { fieldsHaveError() {
const messages = this.getFields() return CustomError.superCombine(
.map(({ field }) => field.getError().messages) this.getFields()
.filter(messages => messages.length > 0); .map(({ field }) => field.getError())
return new CustomError(messages); );
} }
/** /**
...@@ -116,7 +114,7 @@ class Form extends Component { ...@@ -116,7 +114,7 @@ class Form extends Component {
* @memberof Form * @memberof Form
*/ */
hasFormLevelErrors() { hasFormLevelErrors() {
return CustomError([]); // default: no errors return new CustomError([]); // default: no errors
} }
......
...@@ -30,7 +30,7 @@ import getActions from "../../../api/getActions"; ...@@ -30,7 +30,7 @@ import getActions from "../../../api/getActions";
/** /**
* Component to display the previous versions of module * Component to display the previous versions of module
* *
* TODO: use with CustomComponentForAPI * TODO: check if we can use CustomComponentForAPI
* *
* @class History * @class History
* @extends {Component} * @extends {Component}
...@@ -123,7 +123,7 @@ class History extends Component { ...@@ -123,7 +123,7 @@ class History extends Component {
* @memberof History * @memberof History
*/ */
closeHistory() { closeHistory() {
this.props.handleHistoryWasClosed(); this.props.closeHistoryPanel();
this.props.closeFullScreenDialog(); this.props.closeFullScreenDialog();
this.props.resetVersions(); this.props.resetVersions();
} }
...@@ -186,14 +186,14 @@ class History extends Component { ...@@ -186,14 +186,14 @@ class History extends Component {
// className={classes.mobileStepper} // className={classes.mobileStepper}
nextButton={ nextButton={
<Button color="secondary" size="small" onClick={() => this.handleGoBy(1)} disabled={activeStep >= maxSteps - 1}> <Button color="secondary" size="small" onClick={() => this.handleGoBy(1)} disabled={activeStep >= maxSteps - 1}>
Version suivante Version précédente
{theme.direction === "rtl" ? <KeyboardArrowLeft /> : <KeyboardArrowRight />} {theme.direction === "rtl" ? <KeyboardArrowLeft /> : <KeyboardArrowRight />}
</Button> </Button>
} }
backButton={ backButton={
<Button color="secondary" size="small" onClick={() => this.handleGoBy(-1)} disabled={activeStep === 0}> <Button color="secondary" size="small" onClick={() => this.handleGoBy(-1)} disabled={activeStep === 0}>
{theme.direction === "rtl" ? <KeyboardArrowRight /> : <KeyboardArrowLeft />} {theme.direction === "rtl" ? <KeyboardArrowRight /> : <KeyboardArrowLeft />}
Version précédente Version suivante
</Button> </Button>
} }
/> />
...@@ -216,7 +216,8 @@ class History extends Component { ...@@ -216,7 +216,8 @@ class History extends Component {
*/ */
renderVersionInfo(rawModelData) { renderVersionInfo(rawModelData) {
let dateInfo = <em>(Information non connue.)</em>; let dateInfo = <em>(Information non connue.)</em>;
const { updated_on } = rawModelData; const { updated_on } = rawModelData,
versions = this.getVersions();
if (updated_on) { if (updated_on) {
const data = dateTimeStrToStr(updated_on); const data = dateTimeStrToStr(updated_on);
dateInfo = `${data.date} à ${data.time}`; dateInfo = `${data.date} à ${data.time}`;
...@@ -224,12 +225,12 @@ class History extends Component { ...@@ -224,12 +225,12 @@ class History extends Component {
return ( return (
<div> <div>
<Typography variant='caption' align='center'>Les versions successives d'un même utilisateur ne sont pas enregistrés (dans de tels cas, seul la dernière est conservée).</Typography> <Typography variant='caption' align='center'>Les versions successives d'un même utilisateur ne sont pas enregistrés (dans de tels cas, seul la dernière est conservée).</Typography>
<Typography variant='h6' align='center'>Version n°{this.state.versionInView + 1} du {dateInfo}</Typography> <Typography variant='h6' align='center'>Version n°{versions.length - this.state.versionInView} du {dateInfo}</Typography>
<Button <Button
variant='outlined' variant='outlined'
color="primary" color="primary"
className={this.props.classes.editButton} className={this.props.classes.editButton}
onClick={() => this.props.handleRestoreVersion(rawModelData)} onClick={() => this.props.handleEditFromVersion(rawModelData)}
> >
Éditer à partir de cette version Éditer à partir de cette version
</Button> </Button>
...@@ -246,9 +247,9 @@ class History extends Component { ...@@ -246,9 +247,9 @@ class History extends Component {
History.propTypes = { History.propTypes = {
classes: PropTypes.object.isRequired, classes: PropTypes.object.isRequired,
handleRestoreVersion: PropTypes.func.isRequired, handleEditFromVersion: PropTypes.func.isRequired,
readVersions: PropTypes.func.isRequired, readVersions: PropTypes.func.isRequired,
handleHistoryWasClosed: PropTypes.func.isRequired, closeHistoryPanel: PropTypes.func.isRequired,
resetVersions: PropTypes.func.isRequired, resetVersions: PropTypes.func.isRequired,
open: PropTypes.bool.isRequired, open: PropTypes.bool.isRequired,
versions: PropTypes.object.isRequired, versions: PropTypes.object.isRequired,
...@@ -262,7 +263,7 @@ History.propTypes = { ...@@ -262,7 +263,7 @@ History.propTypes = {
History.defaultProps = { History.defaultProps = {
open: false, open: false,
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
handleHistoryWasClosed: () => console.error("Dev forgot something..."), closeHistoryPanel: () => console.error("Dev forgot something..."),
}; };
......
...@@ -40,7 +40,7 @@ class ModuleWrapper extends CustomComponentForAPI { ...@@ -40,7 +40,7 @@ class ModuleWrapper extends CustomComponentForAPI {
alert: { open: false } alert: { open: false }
}; };
handleOpenEditor = (force = false) => { openEditorPanel = (force = false) => {
if (force || this.props.rawModelData.pending_moderation.length == 0) { if (force || this.props.rawModelData.pending_moderation.length == 0) {
this.setState({ editorOpen: true }); this.setState({ editorOpen: true });
} else { } else {
...@@ -56,7 +56,7 @@ class ModuleWrapper extends CustomComponentForAPI { ...@@ -56,7 +56,7 @@ class ModuleWrapper extends CustomComponentForAPI {
if (agree) { if (agree) {
this.handleOpenPendingModeration(); this.handleOpenPendingModeration();
} else { } else {
this.handleOpenEditor(true); this.openEditorPanel(true);
} }
}, },
multilineButtons: true, multilineButtons: true,
...@@ -76,7 +76,7 @@ class ModuleWrapper extends CustomComponentForAPI { ...@@ -76,7 +76,7 @@ class ModuleWrapper extends CustomComponentForAPI {
this.setState({ alert: { open: false } }); this.setState({ alert: { open: false } });
} }
handleHistoryWasClosed = () => { closeHistoryPanel = () => {
this.setState({ historyOpen: false }); this.setState({ historyOpen: false });
}; };
...@@ -88,7 +88,7 @@ class ModuleWrapper extends CustomComponentForAPI { ...@@ -88,7 +88,7 @@ class ModuleWrapper extends CustomComponentForAPI {
this.setState({ pendingModerationOpen: true }); this.setState({ pendingModerationOpen: true });
} }
handleClosePendingModeration = () => { closePendingModerationPanel = () => {
this.setState({ pendingModerationOpen: false }); this.setState({ pendingModerationOpen: false });
} }
...@@ -99,8 +99,8 @@ class ModuleWrapper extends CustomComponentForAPI { ...@@ -99,8 +99,8 @@ class ModuleWrapper extends CustomComponentForAPI {
rawModelDataForEditor: rawModelData, rawModelDataForEditor: rawModelData,
forceSave: this.userCanModerate(), forceSave: this.userCanModerate(),
}); });
this.handleClosePendingModeration(); this.closePendingModerationPanel();
this.handleOpenEditor(true); this.openEditorPanel(true);
} }
handleEditCurrent = () => { handleEditCurrent = () => {
...@@ -108,16 +108,18 @@ class ModuleWrapper extends CustomComponentForAPI { ...@@ -108,16 +108,18 @@ class ModuleWrapper extends CustomComponentForAPI {
rawModelDataForEditor: this.props.rawModelData, rawModelDataForEditor: this.props.rawModelData,
forceSave: false, forceSave: false,
}); });
this.handleOpenEditor(); this.openEditorPanel();
} }
handleRestoreVersion = (rawModelData) => { handleEditFromVersion = (rawModelData) => {
this.setState({ this.setState({
rawModelDataForEditor: rawModelData, rawModelDataForEditor: rawModelData,
forceSave: true, forceSave: true,
}); });
this.handleHistoryWasClosed();
this.handleOpenEditor(); this.closeHistoryPanel();
this.openEditorPanel();
} }
handleApproveModeration = (modelDataInModeration) => { handleApproveModeration = (modelDataInModeration) => {
...@@ -168,7 +170,7 @@ class ModuleWrapper extends CustomComponentForAPI { ...@@ -168,7 +170,7 @@ class ModuleWrapper extends CustomComponentForAPI {
modelData={this.props.parseRawModelData(this.state.rawModelDataForEditor)} modelData={this.props.parseRawModelData(this.state.rawModelDataForEditor)}
outsideData={this.props.outsideData} outsideData={this.props.outsideData}
userData={this.props.userData} userData={this.props.userData}
forceSave={this.state.forceSave} forceSave={this.state.forceSave} // don't take into account that the form hasn't change, it's normal
dataToSave={this.state.dataToSave} dataToSave={this.state.dataToSave}
__apiAttr={this.props.__apiAttr} __apiAttr={this.props.__apiAttr}
/> />
...@@ -176,13 +178,13 @@ class ModuleWrapper extends CustomComponentForAPI { ...@@ -176,13 +178,13 @@ class ModuleWrapper extends CustomComponentForAPI {
renderer={this} renderer={this}
modelInfo={{ contentTypeId: rawModelData.content_type_id, id: rawModelData.id }} modelInfo={{ contentTypeId: rawModelData.content_type_id, id: rawModelData.id }}
open={this.state.historyOpen} open={this.state.historyOpen}
handleHistoryWasClosed={this.handleHistoryWasClosed} closeHistoryPanel={this.closeHistoryPanel}
handleRestoreVersion={this.handleRestoreVersion} handleEditFromVersion={this.handleEditFromVersion}
/> />
<PendingModeration <PendingModeration
renderer={this} renderer={this}
open={this.state.pendingModerationOpen} open={this.state.pendingModerationOpen}
handleClosePendingModeration={this.handleClosePendingModeration} closePendingModerationPanel={this.closePendingModerationPanel}
handleEditPendingModeration={this.handleEditPendingModeration} handleEditPendingModeration={this.handleEditPendingModeration}
handleApproveModeration={this.handleApproveModeration} handleApproveModeration={this.handleApproveModeration}
userCanModerate={userCanModerate} userCanModerate={userCanModerate}
......
...@@ -52,7 +52,6 @@ class ScholarshipForm extends Form { ...@@ -52,7 +52,6 @@ class ScholarshipForm extends Form {
label: "Fréquence de la bourse", label: "Fréquence de la bourse",
options: frequencyOptions, options: frequencyOptions,
fieldMapping: "frequency", fieldMapping: "frequency",
required: true, //TODO remove
})} })}
{this.renderMarkdownField({ {this.renderMarkdownField({
label: "Autres avantages", label: "Autres avantages",
......
...@@ -63,15 +63,8 @@ class UsefulLinksField extends Field { ...@@ -63,15 +63,8 @@ class UsefulLinksField extends Field {
} }
serializeFromField() { serializeFromField() {
// TODO CLEAN
const usefulLinks = this.state.value; const usefulLinks = this.state.value;
let emptyIndexes = Array(); return usefulLinks.filter(el => !(el.url === "" && el.description === ""));
usefulLinks.map((el, idx) => {
if (el.url == "" && el.description == "") {
emptyIndexes.push(idx);
}
});
return usefulLinks.filter((s, idx) => !(idx in emptyIndexes));
} }
updateUsefulLinks(newUsefulLinks) { updateUsefulLinks(newUsefulLinks) {
......
...@@ -17,20 +17,19 @@ import Tooltip from "@material-ui/core/Tooltip"; ...@@ -17,20 +17,19 @@ import Tooltip from "@material-ui/core/Tooltip";
export default function renderFirstRow(userCanModerate) { export default function renderFirstRow(userCanModerate) {
const { classes, theme } = this.props; const { classes, theme, rawModelData } = this.props,
const { rawModelData } = this.props; nbVersions = Math.max(0, rawModelData.nb_versions - 1),
{ pending_moderation } = rawModelData;
const nbVersions = Math.max(0, rawModelData.nb_versions - 1);
const { pending_moderation } = rawModelData;
let nbPendingModeration = 0; let nbPendingModeration = 0;
if (pending_moderation) { if (pending_moderation) {
nbPendingModeration = pending_moderation.length; nbPendingModeration = pending_moderation.length;
} }
const readOnly = rawModelData.model_config.read_only;
const { versionTooltip, versionClass } = getVersionTooltipAndClass(nbVersions); const readOnly = rawModelData.model_config.read_only,
const { moderTooltip, moderClass } = getModerationTooltipAndClass(nbPendingModeration, readOnly); { versionTooltip, versionClass } = getVersionTooltipAndClass(nbVersions),
const { editTooltip, editClass } = getEditTooltipAndClass(readOnly, userCanModerate); { moderTooltip, moderClass } = getModerationTooltipAndClass(nbPendingModeration, readOnly),
{ editTooltip, editClass } = getEditTooltipAndClass(readOnly, userCanModerate);
return ( return (
<Grid container spacing={8}> <Grid container spacing={8}>
...@@ -42,7 +41,7 @@ export default function renderFirstRow(userCanModerate) { ...@@ -42,7 +41,7 @@ export default function renderFirstRow(userCanModerate) {
<Tooltip title={moderTooltip} placement="top"> <Tooltip title={moderTooltip} placement="top">
<div style={{ display: "inline-block" }}> {/* Needed to fire events for the tooltip when below is disabled! when below is disabled!! */} <div style={{ display: "inline-block" }}> {/* Needed to fire events for the tooltip when below is disabled! when below is disabled!! */}
<MyBadge classes={{ badge: classes.badge }} badgeContent={nbPendingModeration} color="secondary"> <MyBadge className={classes.badge} badgeContent={nbPendingModeration} color="secondary">
<IconButton aria-label="Modération" disabled={moderClass == "disabled" || moderClass == "green"} onClick={this.handleOpenPendingModeration} className={classes.button}> <IconButton aria-label="Modération" disabled={moderClass == "disabled" || moderClass == "green"} onClick={this.handleOpenPendingModeration} className={classes.button}>
<VerifiedUserIcon className={classes[moderClass]} /> <VerifiedUserIcon className={classes[moderClass]} />
</IconButton> </IconButton>
...@@ -60,7 +59,7 @@ export default function renderFirstRow(userCanModerate) { ...@@ -60,7 +59,7 @@ export default function renderFirstRow(userCanModerate) {
<Tooltip title={versionTooltip} placement="top"> <Tooltip title={versionTooltip} placement="top">
<div style={{ display: "inline-block" }}> {/* Needed to fire events for the tooltip when below is disabled!! */} <div style={{ display: "inline-block" }}> {/* Needed to fire events for the tooltip when below is disabled!! */}
<MyBadge classes={{ badge: classes.badge }} badgeContent={nbVersions} color="secondary"> <MyBadge className={classes.badge} badgeContent={nbVersions} color="secondary">
<IconButton aria-label="Restorer" disabled={versionClass == "disabled"} className={classes.button} onClick={this.handleOpenHistory}> <IconButton aria-label="Restorer" disabled={versionClass == "disabled"} className={classes.button} onClick={this.handleOpenHistory}>
<SettingsBackRestoreIcon className={classes[versionClass]} /> <SettingsBackRestoreIcon className={classes[versionClass]} />
</IconButton> </IconButton>
......
...@@ -11,9 +11,6 @@ import NumberField from "./fields/NumberField"; ...@@ -11,9 +11,6 @@ import NumberField from "./fields/NumberField";
import store from "../../../store/index"; import store from "../../../store/index";
import { getLatestRead } from "../../../api/utils"; import { getLatestRead } from "../../../api/utils";
import __map from "lodash/map";
export default { export default {
/** /**
* For field mixins that handle custom props, we need to make use of getReferenceAndValue too * For field mixins that handle custom props, we need to make use of getReferenceAndValue too
...@@ -110,7 +107,7 @@ export default { ...@@ -110,7 +107,7 @@ export default {
renderUniversitiesField() { renderUniversitiesField() {
const { outsideData } = this.props, const { outsideData } = this.props,
universities = __map(outsideData.universities, // TODO __map required ? universities = outsideData.universities.map(
(univ) => { return { label: univ.name, value: univ.id, disabled: false }; } (univ) => { return { label: univ.name, value: univ.id, disabled: false }; }
); );
...@@ -125,7 +122,7 @@ export default { ...@@ -125,7 +122,7 @@ export default {
renderCountriesField() { renderCountriesField() {
const { outsideData } = this.props, const { outsideData } = this.props,
countries = __map(outsideData.countries, // TODO __map required ? countries = outsideData.countries.map(
(country) => { return { label: country.name, value: country.id, disabled: false }; } (country) => { return { label: country.name, value: country.id, disabled: false }; }
); );
...@@ -148,7 +145,7 @@ export default { ...@@ -148,7 +145,7 @@ export default {
renderCurrencyField(props) { renderCurrencyField(props) {
const { outsideData } = this.props; const { outsideData } = this.props;
const currencies = __map(outsideData.currencies, const currencies = outsideData.currencies.map(
(c) => { return { label: c.code, value: c.code, disabled: false }; } (c) => { return { label: c.code, value: c.code, disabled: false }; }
); );
......
...@@ -27,4 +27,19 @@ export default class CustomError { ...@@ -27,4 +27,19 @@ export default class CustomError {
combine(other) { combine(other) {
return new CustomError(Array.prototype.concat(this.messages, other.messages)); return new CustomError(Array.prototype.concat(this.messages, other.messages));
} }
/**
* Combines an array of CustomError
*
* @static
* @param {Array[CustomError]} arrOfCustomErrors
* @returns
* @memberof CustomError
*/
static superCombine(arrOfCustomErrors) {
return new CustomError(
Array.prototype.concat(
arrOfCustomErrors
.flatMap(el => el.messages)));
}
} }
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