-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from EmmanuelDemey/master
fix: test if documents is available
- Loading branch information
Showing
12 changed files
with
269 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import api from 'js/remote-api/api'; | ||
import * as A from 'js/actions/constants'; | ||
|
||
export default id => dispatch => { | ||
dispatch({ | ||
type: A.LOAD_OPERATIONS_DOCUMENT, | ||
payload: { | ||
id, | ||
}, | ||
}); | ||
/** | ||
* @param {{ uri: { substr: (arg0: any) => void; lastIndexOf: (arg0: string) => number; }; }} results | ||
*/ | ||
/** | ||
* @param {any} err | ||
*/ | ||
return api.getDocument(id).then( | ||
results => | ||
dispatch({ | ||
type: A.LOAD_OPERATIONS_DOCUMENT_SUCCESS, | ||
payload: { | ||
...results, | ||
id: results.uri.substr(results.uri.lastIndexOf('/') + 1), | ||
}, | ||
}), | ||
err => | ||
dispatch({ | ||
type: A.LOAD_OPERATIONS_DOCUMENT_FAILURE, | ||
payload: { err }, | ||
}) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/js/components/operations/document/visualization/home.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Note } from 'js/components/shared/note/note'; | ||
import D from 'js/i18n'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
/** | ||
* @typedef OperationsDocumentationVisualizationProps | ||
* @property {any} attr | ||
* @property {boolean} secondLang | ||
* @property {{ lg1: string, lg2: string }} langs | ||
* | ||
* @param {OperationsDocumentationVisualizationProps} props | ||
*/ | ||
function OperationsDocumentationVisualization({ | ||
attr, | ||
secondLang, | ||
langs: { lg1, lg2 }, | ||
}) { | ||
return ( | ||
<React.Fragment> | ||
<div className="row"> | ||
<Note | ||
text={attr.descriptionLg1} | ||
title={D.descriptionTitle} | ||
lang={lg1} | ||
alone={!secondLang} | ||
allowEmpty={true} | ||
context="operations" | ||
/> | ||
{secondLang && ( | ||
<Note | ||
text={attr.descriptionLg2} | ||
title={D.descriptionTitle} | ||
lang={lg2} | ||
alone={false} | ||
allowEmpty={true} | ||
context="operations" | ||
/> | ||
)} | ||
</div> | ||
<div className="row"> | ||
<Note | ||
text={ | ||
<a href={attr.url} rel="noopener noreferrer" target="_blank"> | ||
{attr.url} | ||
</a> | ||
} | ||
title={D.titleLink} | ||
lang={lg1} | ||
alone={true} | ||
allowEmpty={true} | ||
context="operations" | ||
/> | ||
</div> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
OperationsDocumentationVisualization.propTypes = { | ||
attr: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default OperationsDocumentationVisualization; |
105 changes: 105 additions & 0 deletions
105
src/js/components/operations/document/visualization/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { saveSecondLang } from 'js/actions/app'; | ||
import loadDocument from 'js/actions/operations/documents/item'; | ||
import Button from 'js/components/shared/button'; | ||
import Loading from 'js/components/shared/loading'; | ||
import PageSubtitle from 'js/components/shared/page-subtitle'; | ||
import PageTitle from 'js/components/shared/page-title'; | ||
import CheckSecondLang from 'js/components/shared/second-lang-checkbox'; | ||
import D from 'js/i18n'; | ||
import * as select from 'js/reducers'; | ||
import { getSecondLang } from 'js/reducers/app'; | ||
import { getCurrentDocument } from 'js/reducers/operations/selector'; | ||
import buildExtract from 'js/utils/build-extract'; | ||
import { goBack } from 'js/utils/redirection'; | ||
import PropTypes from 'prop-types'; | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { withRouter } from 'react-router-dom'; | ||
import OperationsDocumentVisualization from './home'; | ||
import { compose } from 'recompose'; | ||
|
||
const extractId = buildExtract('id'); | ||
|
||
class DocumentationVisualizationContainer extends Component { | ||
static propTypes = { | ||
document: PropTypes.object.isRequired, | ||
id: PropTypes.string.isRequired, | ||
langs: PropTypes.object, | ||
secondLang: PropTypes.bool, | ||
saveSecondLang: PropTypes.func, | ||
}; | ||
|
||
componentWillMount() { | ||
if (!this.props.document.id) { | ||
this.props.loadDocument(this.props.id); | ||
} | ||
} | ||
|
||
render() { | ||
const { id, document, langs, secondLang, saveSecondLang } = this.props; | ||
|
||
if (!document.id) | ||
return <Loading textType="loading" context="operations" />; | ||
|
||
return ( | ||
<div className="container"> | ||
<CheckSecondLang secondLang={secondLang} onChange={saveSecondLang} /> | ||
|
||
<PageTitle | ||
title={document.labelLg1 || document.labelLg2} | ||
context="operations" | ||
/> | ||
{secondLang && document.labelLg2 && ( | ||
<PageSubtitle subTitle={document.labelLg2} context="operations" /> | ||
)} | ||
|
||
<div className="row btn-line"> | ||
<Button | ||
action={goBack(this.props, '/operations/documents')} | ||
label={D.btnReturn} | ||
context="operations" | ||
/> | ||
|
||
<div className="col-md-8 centered" /> | ||
|
||
<Button | ||
action={`/operations/document/${document.id}/modify`} | ||
label={D.btnUpdate} | ||
context="operations" | ||
/> | ||
</div> | ||
<OperationsDocumentVisualization | ||
id={id} | ||
attr={document} | ||
langs={langs} | ||
secondLang={secondLang} | ||
saveSecondLang={saveSecondLang} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export const mapStateToProps = (state, ownProps) => { | ||
const id = extractId(ownProps); | ||
const document = getCurrentDocument(state); | ||
return { | ||
id, | ||
document: id === document.id ? document : {}, | ||
langs: select.getLangs(state), | ||
secondLang: getSecondLang(state), | ||
}; | ||
}; | ||
|
||
const mapDispatchToProps = { | ||
saveSecondLang, | ||
loadDocument, | ||
}; | ||
|
||
export default compose( | ||
connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
), | ||
withRouter | ||
)(DocumentationVisualizationContainer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters