Skip to content

Commit

Permalink
Merge pull request #49 from EmmanuelDemey/master
Browse files Browse the repository at this point in the history
Zenika
  • Loading branch information
Evargalo authored Jun 7, 2019
2 parents e164e49 + d21280c commit 0cecc17
Show file tree
Hide file tree
Showing 18 changed files with 4,541 additions and 4,091 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ yarn-debug.log*
yarn-error.log*

/swagger
.cache
.cache
cypress/videos
cypress/screenshots
8,111 changes: 4,029 additions & 4,082 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
"e2e": "start-server-and-test start http://localhost:3000 cypress:run",
"eject": "react-scripts eject",
"lint": "eslint src",
"start": "cross-env NODE_PATH=src/ REACT_APP_VERSION=$npm_package_version REACT_APP_NAME=$npm_package_name react-scripts start",
"start-https": "cross-env NODE_PATH=src/ HTTPS=true REACT_APP_VERSION=$npm_package_version REACT_APP_NAME=$npm_package_name react-scripts start",
"start": "cross-env REACT_APP_VERSION=$npm_package_version REACT_APP_NAME=$npm_package_name react-scripts start",
"start-https": "cross-env HTTPS=true REACT_APP_VERSION=$npm_package_version REACT_APP_NAME=$npm_package_name react-scripts start",
"start-storybook": "cross-env NODE_PATH=src/ start-storybook -p 9999",
"test": "cross-env NODE_PATH=src/ react-scripts test",
"test:coverage": "cross-env CI=true NODE_PATH=src/ react-scripts test --coverage --collectCoverageFrom=src/**/*.js --collectCoverageFrom=!src/**/*.spec.js --collectCoverageFrom=!src/**/*.stories.js"
"test": "react-scripts test",
"test:coverage": "cross-env CI=true react-scripts test --coverage --collectCoverageFrom=src/**/*.js --collectCoverageFrom=!src/**/*.spec.js --collectCoverageFrom=!src/**/*.stories.js"
},
"husky": {
"hooks": {
Expand Down Expand Up @@ -103,7 +103,7 @@
"npm-run-all": "4.1.5",
"prettier": "1.16.4",
"react-test-renderer": "16.8.6",
"start-server-and-test": "1.7.11",
"start-server-and-test": "1.9.1",
"term-size": "^1.2.0"
},
"browserslist": [
Expand Down
6 changes: 6 additions & 0 deletions src/js/actions/constants/operations/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ export const LOAD_OPERATIONS_DOCUMENT_SUCCESS =
'LOAD_OPERATIONS_DOCUMENT_SUCCESS';
export const LOAD_OPERATIONS_DOCUMENT_FAILURE =
'LOAD_OPERATIONS_DOCUMENT_FAILURE';

export const SAVE_OPERATIONS_DOCUMENT = 'SAVE_OPERATIONS_DOCUMENT';
export const SAVE_OPERATIONS_DOCUMENT_SUCCESS =
'SAVE_OPERATIONS_DOCUMENT_SUCCESS';
export const SAVE_OPERATIONS_DOCUMENT_FAILURE =
'SAVE_OPERATIONS_DOCUMENT_FAILURE';
32 changes: 32 additions & 0 deletions src/js/actions/operations/documents/item.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
import api from 'js/remote-api/api';
import * as A from 'js/actions/constants';

export const saveDocument = (document, callback) => dispatch => {
dispatch({
type: A.SAVE_OPERATIONS_DOCUMENT,
payload: document,
});
const method = document.id ? 'putDocument' : 'postLink';
let body = document;
if (!document.id) {
const formData = new FormData();
formData.append('body', JSON.stringify(document));
body = formData;
}
return api[method](body).then(
results => {
dispatch({
type: A.SAVE_OPERATIONS_DOCUMENT_SUCCESS,
payload: {
...document,
id: document.id ? document.id : results,
},
});
callback(results);
},
err => {
dispatch({
type: A.SAVE_OPERATIONS_DOCUMENT_FAILURE,
payload: { err },
});
callback();
}
);
};
export default id => dispatch => {
dispatch({
type: A.LOAD_OPERATIONS_DOCUMENT,
Expand Down
226 changes: 226 additions & 0 deletions src/js/components/operations/document/edition/edition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
import React, { Component } from 'react';
import PageSubtitle from 'js/components/shared/page-subtitle';
import PageTitle from 'js/components/shared/page-title';
import D from 'js/i18n';
import { goBack } from 'js/utils/redirection';
import NoteFlag from 'js/components/shared/note-flag/note-flag';
import PropTypes from 'prop-types';
import EditorMarkdown from 'js/components/shared/editor-html/editor-markdown';
import Button from 'js/components/shared/button';
import { validate } from 'js/components/operations/document/edition/validation';
const defaultDocument = {
labelLg1: '',
labelLg2: '',
descriptionLg1: '',
descriptionLg2: '',
url: '',
lang: '',
};
class OperationsDocumentationEdition extends Component {
static propTypes = {
document: PropTypes.object.isRequired,
langs: PropTypes.object.isRequired,
saveDocument: PropTypes.func.isRequired,
};

constructor(props) {
super(props);
this.state = {
document: {
...defaultDocument,
...props.document,
},
};
}

componentWillReceiveProps(nextProps) {
this.setState({
document: {
...defaultDocument,
...nextProps.document,
},
});
}

onChange = e => {
this.setState({
document: {
...this.state.document,
[e.target.id]: e.target.value,
},
});
};
onSubmit = () => {
this.props.saveDocument(
this.state.document,
(id = this.state.document.id) => {
this.props.history.push(`/operations/document/${id}`);
}
);
};

render() {
const {
langs: { lg1, lg2 },
} = this.props;
const { document } = this.state;
const isEditing = !!document.id;

const errors = validate(document);

return (
<div className="container editor-container">
{isEditing && (
<React.Fragment>
<PageTitle
title={this.props.document.labelLg1}
context="operations"
/>
{this.props.document.labelLg2 && (
<PageSubtitle
subTitle={this.props.document.labelLg2}
context="operations"
/>
)}
</React.Fragment>
)}

<div className="row btn-line">
<Button
action={goBack(this.props, '/operations/documents')}
label={
<React.Fragment>
<span
className="glyphicon glyphicon-floppy-remove"
aria-hidden="true"
/>
<span> {D.btnCancel}</span>
</React.Fragment>
}
context="operations"
/>

<div className="col-md-8 centered">
<div
style={{ visibility: errors.errorMessage ? 'visible' : 'hidden' }}
className="alert alert-danger bold"
role="alert"
>
{/* HACK: if no content, the line height is set to 0 and the rest
of the page moves a little */}
{errors.errorMessage || (
<span style={{ whiteSpace: 'pre-wrap' }}> </span>
)}
</div>
</div>
<Button
action={this.onSubmit}
label={
<React.Fragment>
<span
className="glyphicon glyphicon-floppy-disk"
aria-hidden="true"
/>
<span> {D.btnSave}</span>
</React.Fragment>
}
context="operations"
disabled={errors.errorMessage}
/>
</div>
<form>
<div className="row">
<div className="col-md-6 form-group">
<label htmlFor="prefLabelLg1">
<NoteFlag text={D.title} lang={lg1} />
<span className="boldRed">*</span>
</label>
<input
type="text"
className="form-control"
id="labelLg1"
value={document.labelLg1}
onChange={this.onChange}
aria-invalid={errors.fields.labelLg1}
/>
</div>
<div className="col-md-6 form-group">
<label htmlFor="prefLabelLg2">
<NoteFlag text={D.title} lang={lg2} />
<span className="boldRed">*</span>
</label>
<input
type="text"
className="form-control"
id="labelLg2"
value={document.labelLg2}
onChange={this.onChange}
aria-invalid={errors.fields.labelLg2}
/>
</div>
</div>
<div className="row">
<div className="col-md-6 form-group">
<label htmlFor="abstractLg1">
<NoteFlag text={D.descriptionTitle} lang={lg1} />
</label>
<EditorMarkdown
text={document.descriptionLg1}
handleChange={value =>
this.onChange({ target: { value, id: 'descriptionLg1' } })
}
/>
</div>
<div className="col-md-6 form-group">
<label htmlFor="abstractLg2">
<NoteFlag text={D.descriptionTitle} lang={lg2} />
</label>
<EditorMarkdown
text={document.descriptionLg2}
handleChange={value =>
this.onChange({ target: { value, id: 'descriptionLg2' } })
}
/>
</div>
</div>
<div className="row">
<div className="col-md-12 form-group">
<label htmlFor="url">
<NoteFlag text={D.titleLink} lang={lg1} />
<span className="boldRed">*</span>
</label>
<input
type="text"
className="form-control"
id="url"
value={document.url}
onChange={this.onChange}
aria-invalid={errors.fields.url}
/>
</div>
</div>
<div className="row">
<div className="col-md-12 form-group">
<label htmlFor="lang">
<NoteFlag text={D.langTitle} lang={lg1} />
<span className="boldRed">*</span>
</label>
<input
type="text"
className="form-control"
id="lang"
value={document.lang}
onChange={this.onChange}
aria-invalid={errors.fields.lang}
/>
</div>
</div>
</form>
</div>
);
// TODO n'afficher que l'URL pour les liens
// TODO ajouter un select pour savoir si c'est un lien ou un document qu'on souhaite creer
}
}

export default OperationsDocumentationEdition;
52 changes: 52 additions & 0 deletions src/js/components/operations/document/edition/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';
import loadDocument, {
saveDocument,
} from 'js/actions/operations/documents/item';
import * as select from 'js/reducers';
import { connect } from 'react-redux';
import buildExtract from 'js/utils/build-extract';
import Loading from 'js/components/shared/loading';
import DocumentationEdition from 'js/components/operations/document/edition/edition';
import { getCurrentDocument } from 'js/reducers/operations/selector';

const extractId = buildExtract('id');

class OperationsDocumentationEditionContainer extends Component {
componentDidMount() {
if (!this.props.document.id && this.props.id) {
this.props.loadDocument(this.props.id);
}
}
render() {
if (!this.props.document)
return <Loading textType="loading" context="operations" />;
if (this.props.operationsAsyncTask)
return <Loading textType="saving" context="operations" />;
return <DocumentationEdition {...this.props} />;
}
}

const mapDispatchToProps = {
loadDocument,
saveDocument,
};

export const mapStateToProps = (state, ownProps) => {
const id = extractId(ownProps);
const document = id ? getCurrentDocument(state) : {};
const langs = select.getLangs(state);
return {
id,
document,
langs,
operationsAsyncTask: state.operationsAsyncTask,
};
};

export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(OperationsDocumentationEditionContainer)
);
18 changes: 18 additions & 0 deletions src/js/components/operations/document/edition/validation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import D from 'js/i18n';

export function validate(document) {
let errorMessage = '';
if (!document.labelLg1 || !document.labelLg2)
errorMessage = D.requiredPrefLabel;
if (!document.url) errorMessage = D.requiredUrl; //TODO only for the likn
if (!document.lang) errorMessage = D.requiredLang;
return {
fields: {
prefLabelLg1: !document.labelLg1,
prefLabelLg2: !document.labelLg2,
url: !document.url, //TODO seulement pour les liens
lang: !document.lang,
},
errorMessage,
};
}
2 changes: 1 addition & 1 deletion src/js/components/operations/msd/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function getParentUri(sims) {
if (sims.idOperation) {
return `/operations/operation/${sims.idOperation}`;
} else if (sims.idSeries) {
return `/operations/serie/${sims.idSeries}`;
return `/operations/series/${sims.idSeries}`;
} else if (sims.idIndicator) {
return `/operations/indicator/${sims.idIndicator}`;
}
Expand Down
Loading

0 comments on commit 0cecc17

Please sign in to comment.