From aa1ee011af921cf00c47c7f839b3b8f286a30d10 Mon Sep 17 00:00:00 2001 From: djhi Date: Mon, 13 Feb 2017 18:23:17 +0100 Subject: [PATCH 1/5] [WIP] Formats --- src/app/js/admin/fields/FieldForm.js | 7 ++ src/app/js/dataset/Dataset.js | 12 ++-- src/app/js/formats/DefaultFormat.js | 7 ++ src/app/js/formats/Format.js | 30 ++++++++ src/app/js/formats/FormatEdition.js | 80 ++++++++++++++++++++++ src/app/js/formats/SelectFormat.js | 19 +++++ src/app/js/formats/formats.js | 1 + src/app/js/formats/uri/component.js | 34 +++++++++ src/app/js/formats/uri/editionComponent.js | 70 +++++++++++++++++++ src/app/js/formats/uri/index.js | 8 +++ 10 files changed, 263 insertions(+), 5 deletions(-) create mode 100644 src/app/js/formats/DefaultFormat.js create mode 100644 src/app/js/formats/Format.js create mode 100644 src/app/js/formats/FormatEdition.js create mode 100644 src/app/js/formats/SelectFormat.js create mode 100644 src/app/js/formats/formats.js create mode 100644 src/app/js/formats/uri/component.js create mode 100644 src/app/js/formats/uri/editionComponent.js create mode 100644 src/app/js/formats/uri/index.js diff --git a/src/app/js/admin/fields/FieldForm.js b/src/app/js/admin/fields/FieldForm.js index 098320cbd..397219296 100644 --- a/src/app/js/admin/fields/FieldForm.js +++ b/src/app/js/admin/fields/FieldForm.js @@ -15,6 +15,7 @@ import { saveField, } from './'; +import Format from '../../formats/FormatEdition'; import Alert from '../../lib/Alert'; import TransformerList from './TransformerList'; @@ -69,6 +70,12 @@ export const FieldFormComponent = ({ { isContribution ? null : } + { isContribution ? null : } ); }; diff --git a/src/app/js/dataset/Dataset.js b/src/app/js/dataset/Dataset.js index 971db28f0..6da39aa5b 100644 --- a/src/app/js/dataset/Dataset.js +++ b/src/app/js/dataset/Dataset.js @@ -18,6 +18,8 @@ import { import Pagination from '../lib/Pagination'; import Card from '../lib/Card'; import Loading from '../lib/Loading'; +import Format from '../formats/Format'; + import { polyglot as polyglotPropTypes } from '../lib/propTypes'; import { loadDatasetPage as loadDatasetPageAction } from './'; import { getCollectionFields } from '../publication'; @@ -56,12 +58,12 @@ export class DatasetComponent extends Component { {dataset.map(data => ( - {columns.map(({ name }) => ( - - {name === 'uri' ? - {data[name]} + {columns.map(column => ( + + {column.name === 'uri' ? + {data[column.name]} : - data[name] + } ))} diff --git a/src/app/js/formats/DefaultFormat.js b/src/app/js/formats/DefaultFormat.js new file mode 100644 index 000000000..788964ff9 --- /dev/null +++ b/src/app/js/formats/DefaultFormat.js @@ -0,0 +1,7 @@ +import React, { PropTypes } from 'react'; + +const DefaultFormat = ({ resource, field }) => ( + {resource[field.name]} +); + +export default DefaultFormat; diff --git a/src/app/js/formats/Format.js b/src/app/js/formats/Format.js new file mode 100644 index 000000000..c1a6b3bcd --- /dev/null +++ b/src/app/js/formats/Format.js @@ -0,0 +1,30 @@ +import React, { PropTypes } from 'react'; +import DefaultFormat from './DefaultFormat'; + +import uri from './uri'; + +const Format = ({ resource, field, fields }) => { + let Component = DefaultFormat; + + if (field.format && field.format.name) { + switch (field.format.name) { + case 'uri': + Component = uri.component; + break; + + default: + Component = DefaultFormat; + break; + } + } + + return ( + + ); +}; + +export default Format; diff --git a/src/app/js/formats/FormatEdition.js b/src/app/js/formats/FormatEdition.js new file mode 100644 index 000000000..1f51dfd9b --- /dev/null +++ b/src/app/js/formats/FormatEdition.js @@ -0,0 +1,80 @@ +import React, { Component, PropTypes } from 'react'; +import SelectFormat from './SelectFormat'; +import FORMATS from './formats'; + +import uri from './uri'; + + +const Empty = () => ; + +const styles = { + container: { + display: 'inline-flex', + }, +}; + +class FormatEdition extends Component { + constructor(props) { + super(props); + + this.state = { + name: props.input.value.name, + args: props.input.value.args, + }; + } + + componentWillReceiveProps(nextProps) { + if (nextProps.input.value.name !== this.state.name) { + this.setState({ name: nextProps.input.value.name }); + } + + if (nextProps.input.value.args !== this.state.args) { + this.setState({ args: nextProps.input.value.args }); + } + } + + setArguments = (args) => { + this.setState({ args }); + this.props.input.onChange({ + args, + name: this.state.name, + }); + } + + setFormat = (name) => { + this.setState({ name }); + this.props.input.onChange({ + args: this.state.args, + name, + }); + } + + render() { + const { name } = this.state; + + let EditionComponent = null; + + switch (name) { + case 'uri': + EditionComponent = uri.editionComponent; + break; + + default: + EditionComponent = Empty; + break; + } + + return ( +
+ + +
+ ); + } +} + +export default FormatEdition; diff --git a/src/app/js/formats/SelectFormat.js b/src/app/js/formats/SelectFormat.js new file mode 100644 index 000000000..3df392145 --- /dev/null +++ b/src/app/js/formats/SelectFormat.js @@ -0,0 +1,19 @@ +import React, { PropTypes } from 'react'; +import MenuItem from 'material-ui/MenuItem'; +import SelectField from 'material-ui/SelectField'; + +const SelectFormat = ({ formats, value, onChange }) => ( + onChange(newValue)} + value={value} + > + + + {formats.map(f => + , + )} + +); + +export default SelectFormat; diff --git a/src/app/js/formats/formats.js b/src/app/js/formats/formats.js new file mode 100644 index 000000000..c5c256024 --- /dev/null +++ b/src/app/js/formats/formats.js @@ -0,0 +1 @@ +export default ['uri']; diff --git a/src/app/js/formats/uri/component.js b/src/app/js/formats/uri/component.js new file mode 100644 index 000000000..6fbeef2f0 --- /dev/null +++ b/src/app/js/formats/uri/component.js @@ -0,0 +1,34 @@ +import React, { PropTypes } from 'react'; +import { Link } from 'react-router'; + +const UriComponent = ({ resource, field }) => { + let label = resource[field.name]; + + if (field.format.args.type) { + switch (field.format.args.type) { + case 'test': + label = field.format.args.value; + break; + + case 'column': { + label = resource[field.format.args.value]; + break; + } + + default: + label = resource[field.name]; + break; + } + } + + return {label}; +}; + +UriComponent.propTypes = { + args: PropTypes.array.isRequired, // eslint-disable-line + resource: PropTypes.object.isRequired, // eslint-disable-line + field: PropTypes.object.isRequired, // eslint-disable-line + fields: PropTypes.array.isRequired, // eslint-disable-line +}; + +export default UriComponent; diff --git a/src/app/js/formats/uri/editionComponent.js b/src/app/js/formats/uri/editionComponent.js new file mode 100644 index 000000000..b05d5c6e6 --- /dev/null +++ b/src/app/js/formats/uri/editionComponent.js @@ -0,0 +1,70 @@ +import React, { Component, PropTypes } from 'react'; +import MenuItem from 'material-ui/MenuItem'; +import SelectField from 'material-ui/SelectField'; +import TextField from 'material-ui/TextField'; + +const styles = { + container: { + display: 'inline-flex', + }, + input: { + marginLeft: '1rem', + }, +}; + +class UriEdition extends Component { + constructor(props) { + super(props); + + this.state = { + type: this.props.type || 'value', + value: this.props.value, + }; + } + + setType = (type) => { + this.setState({ type }); + this.props.onChange({ + type, + value: this.state.value, + }); + } + + setValue = (value) => { + this.setState({ value }); + this.props.onChange({ + value, + type: this.state.type, + }); + } + + render() { + const { type, value } = this.state; + + return ( +
+ this.setType(newValue)} + style={styles.input} + value={type} + > + + + + + + {type !== 'value' && + this.setValue(newValue)} + style={styles.input} + value={value} + /> + } +
+ ); + } +} + +export default UriEdition; diff --git a/src/app/js/formats/uri/index.js b/src/app/js/formats/uri/index.js new file mode 100644 index 000000000..191d03f80 --- /dev/null +++ b/src/app/js/formats/uri/index.js @@ -0,0 +1,8 @@ +import component from './component'; +import editionComponent from './editionComponent'; + +export default { + format: 'uri', + component, + editionComponent, +}; From 78f6c96cc0ac49fdf0020c4d2822e47669d7dad7 Mon Sep 17 00:00:00 2001 From: djhi Date: Thu, 16 Feb 2017 12:15:09 +0100 Subject: [PATCH 2/5] Finalize --- makefile | 16 ++++ src/app/js/admin/Admin.js | 2 +- src/app/js/admin/fields/FieldForm.js | 2 +- .../js/admin/fields/TransformerArgListItem.js | 2 +- src/app/js/admin/fields/TransformerList.js | 2 +- .../js/admin/fields/TransformerListItem.js | 2 +- .../admin/parsing/ParsingExcerptAddColumn.js | 2 +- src/app/js/admin/parsing/ParsingResult.js | 2 +- src/app/js/admin/parsing/ParsingSummary.js | 2 +- .../publicationPreview/PublicationExcerpt.js | 2 +- .../publicationPreview/PublicationPreview.js | 2 +- src/app/js/admin/publish/Publish.js | 2 +- .../removedResources/RemovedResourceList.js | 2 +- src/app/js/admin/validation/Validation.js | 2 +- .../js/admin/validation/ValidationField.js | 2 +- .../DatasetCharacteristicsEdition.js | 2 +- .../DatasetCharacteristicsView.js | 2 +- src/app/js/dataset/Dataset.js | 18 ++--- src/app/js/dataset/Dataset.spec.js | 44 ++++++++--- src/app/js/dataset/DatasetColumn.js | 10 +++ src/app/js/dataset/DefaultColumn.js | 62 ++++++++++++++++ src/app/js/dataset/DefaultColumn.spec.js | 73 +++++++++++++++++++ src/app/js/dataset/UriColumn.js | 17 +++++ src/app/js/dataset/UriColumn.spec.js | 34 +++++++++ src/app/js/formats/DefaultFormat.js | 6 ++ src/app/js/formats/Format.js | 26 ++++++- src/app/js/formats/FormatEdition.js | 7 +- src/app/js/formats/SelectFormat.js | 6 ++ src/app/js/formats/uri/component.js | 17 +++-- src/app/js/formats/uri/editionComponent.js | 7 ++ src/app/js/home/Home.js | 2 +- src/app/js/lib/Appbar/MenuAnonymous.js | 2 +- src/app/js/lib/Appbar/MenuSignedIn.js | 2 +- src/app/js/lib/Property.js | 2 +- src/app/js/lib/PropertyEdition.js | 2 +- src/app/js/lib/fetchByUri.js | 17 +++++ src/app/js/{lib => }/propTypes.js | 6 ++ src/app/js/publication/NoDataset.js | 2 +- src/app/js/publication/Published.js | 2 +- src/app/js/resource/Detail.js | 2 +- src/app/js/resource/EditDetail.js | 2 +- src/app/js/resource/HideDetail.js | 4 +- src/app/js/resource/RemovedDetail.js | 2 +- src/app/js/resource/Resource.js | 2 +- src/app/js/resource/index.js | 3 +- src/app/js/user/Login.js | 2 +- src/app/js/user/LoginDialog.js | 2 +- src/app/js/user/LoginForm.js | 2 +- 48 files changed, 365 insertions(+), 68 deletions(-) create mode 100644 src/app/js/dataset/DatasetColumn.js create mode 100644 src/app/js/dataset/DefaultColumn.js create mode 100644 src/app/js/dataset/DefaultColumn.spec.js create mode 100644 src/app/js/dataset/UriColumn.js create mode 100644 src/app/js/dataset/UriColumn.spec.js create mode 100644 src/app/js/lib/fetchByUri.js rename src/app/js/{lib => }/propTypes.js (86%) diff --git a/makefile b/makefile index 5c4ec4766..e3cdc4997 100644 --- a/makefile +++ b/makefile @@ -85,3 +85,19 @@ test-frontend-functional: ## Run the frontend application functional tests ./src/app/e2e test: test-frontend-unit test-api-unit test-frontend-functional + +clear-database: + docker-compose exec mongo mongo lodex --eval " \ + db.publishedDataset.remove({}); \ + db.publishedCharacteristic.remove({}); \ + db.field.remove({}); \ + db.uriDataset.remove({}); \ + db.dataset.remove({}); \ + " + +clear-publication: + docker-compose exec mongo mongo lodex --eval " \ + db.publishedDataset.remove({}); \ + db.publishedCharacteristic.remove({}); \ + db.uriDataset.remove({}); \ + " diff --git a/src/app/js/admin/Admin.js b/src/app/js/admin/Admin.js index 3057786bd..770cde10c 100644 --- a/src/app/js/admin/Admin.js +++ b/src/app/js/admin/Admin.js @@ -3,7 +3,7 @@ import compose from 'recompose/compose'; import { connect } from 'react-redux'; import translate from 'redux-polyglot/translate'; -import { polyglot as polyglotPropTypes } from '../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../propTypes'; import { loadParsingResult as loadParsingResultAction, diff --git a/src/app/js/admin/fields/FieldForm.js b/src/app/js/admin/fields/FieldForm.js index 397219296..83b39dbd4 100644 --- a/src/app/js/admin/fields/FieldForm.js +++ b/src/app/js/admin/fields/FieldForm.js @@ -5,7 +5,7 @@ import translate from 'redux-polyglot/translate'; import { Field, FieldArray, reduxForm, propTypes as reduxFormPropTypes } from 'redux-form'; import MenuItem from 'material-ui/MenuItem'; -import { polyglot as polyglotPropTypes } from '../../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../../propTypes'; import FormTextField from '../../lib/FormTextField'; import FormSelectField from '../../lib/FormSelectField'; import SchemeAutoComplete from '../../lib/SchemeAutoComplete'; diff --git a/src/app/js/admin/fields/TransformerArgListItem.js b/src/app/js/admin/fields/TransformerArgListItem.js index 1c77f044c..b0b70adf8 100644 --- a/src/app/js/admin/fields/TransformerArgListItem.js +++ b/src/app/js/admin/fields/TransformerArgListItem.js @@ -2,7 +2,7 @@ import React from 'react'; import pure from 'recompose/pure'; import { Field, propTypes as reduxFormPropTypes } from 'redux-form'; -import { polyglot as polyglotPropTypes } from '../../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../../propTypes'; import FormTextField from '../../lib/FormTextField'; const TransformerArgListItem = ({ fieldName, transformerArg }) => ( diff --git a/src/app/js/admin/fields/TransformerList.js b/src/app/js/admin/fields/TransformerList.js index 37f9367c1..d51dba704 100644 --- a/src/app/js/admin/fields/TransformerList.js +++ b/src/app/js/admin/fields/TransformerList.js @@ -8,7 +8,7 @@ import pure from 'recompose/pure'; import FlatButton from 'material-ui/FlatButton'; import { propTypes as reduxFormPropTypes } from 'redux-form'; -import { polyglot as polyglotPropTypes } from '../../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../../propTypes'; import TransformerListItem from './TransformerListItem'; const TransformerList = ({ fields, meta: { touched, error }, p: polyglot }) => ( diff --git a/src/app/js/admin/fields/TransformerListItem.js b/src/app/js/admin/fields/TransformerListItem.js index 54e2a407a..bd9d6652e 100644 --- a/src/app/js/admin/fields/TransformerListItem.js +++ b/src/app/js/admin/fields/TransformerListItem.js @@ -7,7 +7,7 @@ import MenuItem from 'material-ui/MenuItem'; import ActionDeleteIcon from 'material-ui/svg-icons/action/delete'; import { Field, FieldArray, propTypes as reduxFormPropTypes } from 'redux-form'; -import { polyglot as polyglotPropTypes } from '../../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../../propTypes'; import { getTransformers, getTransformerArgs } from './'; import FormSelectField from '../../lib/FormSelectField'; import TransformerArgList from './TransformerArgList'; diff --git a/src/app/js/admin/parsing/ParsingExcerptAddColumn.js b/src/app/js/admin/parsing/ParsingExcerptAddColumn.js index c9277c79a..f458c6245 100644 --- a/src/app/js/admin/parsing/ParsingExcerptAddColumn.js +++ b/src/app/js/admin/parsing/ParsingExcerptAddColumn.js @@ -8,7 +8,7 @@ import { TableRowColumn } from 'material-ui/Table'; import FlatButton from 'material-ui/FlatButton'; import { addField } from '../fields'; -import { polyglot as polyglotPropTypes } from '../../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../../propTypes'; export const ParsingExcerptAddColumnComponent = ({ addColumn, name, p: polyglot }) => ( diff --git a/src/app/js/admin/parsing/ParsingResult.js b/src/app/js/admin/parsing/ParsingResult.js index 13a096048..c76bb4561 100644 --- a/src/app/js/admin/parsing/ParsingResult.js +++ b/src/app/js/admin/parsing/ParsingResult.js @@ -8,7 +8,7 @@ import FlatButton from 'material-ui/FlatButton'; import { grey400 } from 'material-ui/styles/colors'; import Card from '../../lib/Card'; -import { polyglot as polyglotPropTypes } from '../../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../../propTypes'; import { getParsedExcerptColumns, clearParsing } from './'; import ParsingExcerpt from './ParsingExcerpt'; import ParsingSummary from './ParsingSummary'; diff --git a/src/app/js/admin/parsing/ParsingSummary.js b/src/app/js/admin/parsing/ParsingSummary.js index 20b725f41..e01ec9754 100644 --- a/src/app/js/admin/parsing/ParsingSummary.js +++ b/src/app/js/admin/parsing/ParsingSummary.js @@ -5,7 +5,7 @@ import pure from 'recompose/pure'; import { List, ListItem } from 'material-ui/List'; -import { polyglot as polyglotPropTypes } from '../../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../../propTypes'; import ParsingSummaryItem from './ParsingSummaryItem'; const styles = { diff --git a/src/app/js/admin/publicationPreview/PublicationExcerpt.js b/src/app/js/admin/publicationPreview/PublicationExcerpt.js index 84bd1558b..f532b47fb 100644 --- a/src/app/js/admin/publicationPreview/PublicationExcerpt.js +++ b/src/app/js/admin/publicationPreview/PublicationExcerpt.js @@ -4,7 +4,7 @@ import pure from 'recompose/pure'; import withHandlers from 'recompose/withHandlers'; import translate from 'redux-polyglot/translate'; import { Table, TableBody, TableHeader, TableHeaderColumn, TableRow, TableRowColumn } from 'material-ui/Table'; -import { polyglot as polyglotPropTypes } from '../../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../../propTypes'; const styles = { header: { diff --git a/src/app/js/admin/publicationPreview/PublicationPreview.js b/src/app/js/admin/publicationPreview/PublicationPreview.js index 615db4615..bed598d49 100644 --- a/src/app/js/admin/publicationPreview/PublicationPreview.js +++ b/src/app/js/admin/publicationPreview/PublicationPreview.js @@ -6,7 +6,7 @@ import { CardHeader, CardText } from 'material-ui/Card'; import PublicationExcerpt from './PublicationExcerpt'; import { getPublicationFields, editField } from '../fields'; -import { polyglot as polyglotPropTypes } from '../../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../../propTypes'; import Card from '../../lib/Card'; export const PublicationPreviewComponent = ({ columns, lines, editColumn, p: polyglot }) => ( diff --git a/src/app/js/admin/publish/Publish.js b/src/app/js/admin/publish/Publish.js index 37d6111cc..ffbf75312 100644 --- a/src/app/js/admin/publish/Publish.js +++ b/src/app/js/admin/publish/Publish.js @@ -5,7 +5,7 @@ import translate from 'redux-polyglot/translate'; import { CardActions, CardHeader, CardText } from 'material-ui/Card'; import FlatButton from 'material-ui/FlatButton'; -import { polyglot as polyglotPropTypes } from '../../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../../propTypes'; import { publish as publishAction, diff --git a/src/app/js/admin/removedResources/RemovedResourceList.js b/src/app/js/admin/removedResources/RemovedResourceList.js index ca623e453..400381b59 100644 --- a/src/app/js/admin/removedResources/RemovedResourceList.js +++ b/src/app/js/admin/removedResources/RemovedResourceList.js @@ -20,7 +20,7 @@ import ButtonWithStatus from '../../lib/ButtonWithStatus'; import Card from '../../lib/Card'; import Loading from '../../lib/Loading'; import Pagination from '../../lib/Pagination'; -import { polyglot as polyglotPropTypes } from '../../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../../propTypes'; import { loadRemovedResourcePage as loadRemovedResourcePageAction, restoreRessource as restoreRessourceAction, diff --git a/src/app/js/admin/validation/Validation.js b/src/app/js/admin/validation/Validation.js index 2fde2893e..9c97a28fb 100644 --- a/src/app/js/admin/validation/Validation.js +++ b/src/app/js/admin/validation/Validation.js @@ -3,7 +3,7 @@ import { connect } from 'react-redux'; import { getInvalidFields } from '../validation'; import ValidationField from './ValidationField'; import { editField as editFieldAction } from '../fields'; -import { validationField as validationFieldPropType } from '../../lib/propTypes'; +import { validationField as validationFieldPropType } from '../../propTypes'; const styles = { list: { diff --git a/src/app/js/admin/validation/ValidationField.js b/src/app/js/admin/validation/ValidationField.js index bf6403089..b2f391dac 100644 --- a/src/app/js/admin/validation/ValidationField.js +++ b/src/app/js/admin/validation/ValidationField.js @@ -2,7 +2,7 @@ import React, { PropTypes } from 'react'; import compose from 'recompose/compose'; import withHandlers from 'recompose/withHandlers'; import translate from 'redux-polyglot/translate'; -import { polyglot as polyglotPropTypes, validationField as validationFieldPropType } from '../../lib/propTypes'; +import { polyglot as polyglotPropTypes, validationField as validationFieldPropType } from '../../propTypes'; const styles = { label: { diff --git a/src/app/js/characteristic/DatasetCharacteristicsEdition.js b/src/app/js/characteristic/DatasetCharacteristicsEdition.js index 3ea9da500..06954f72b 100644 --- a/src/app/js/characteristic/DatasetCharacteristicsEdition.js +++ b/src/app/js/characteristic/DatasetCharacteristicsEdition.js @@ -9,7 +9,7 @@ import Card from '../lib/Card'; import { property as propertyPropTypes, polyglot as polyglotPropTypes, -} from '../lib/propTypes'; +} from '../propTypes'; import { getNewCharacteristics, diff --git a/src/app/js/characteristic/DatasetCharacteristicsView.js b/src/app/js/characteristic/DatasetCharacteristicsView.js index 0f5762938..29f06b31a 100644 --- a/src/app/js/characteristic/DatasetCharacteristicsView.js +++ b/src/app/js/characteristic/DatasetCharacteristicsView.js @@ -10,7 +10,7 @@ import Card from '../lib/Card'; import { property as propertyPropTypes, polyglot as polyglotPropTypes, -} from '../lib/propTypes'; +} from '../propTypes'; import { isLoggedIn } from '../user'; import { diff --git a/src/app/js/dataset/Dataset.js b/src/app/js/dataset/Dataset.js index 6da39aa5b..7a6395442 100644 --- a/src/app/js/dataset/Dataset.js +++ b/src/app/js/dataset/Dataset.js @@ -2,7 +2,6 @@ import React, { Component, PropTypes } from 'react'; import { connect } from 'react-redux'; import compose from 'recompose/compose'; import translate from 'redux-polyglot/translate'; -import { Link } from 'react-router'; import { CardText } from 'material-ui/Card'; @@ -13,14 +12,13 @@ import { TableHeader, TableHeaderColumn, TableRow, - TableRowColumn, } from 'material-ui/Table'; +import DatasetColumn from './DatasetColumn'; import Pagination from '../lib/Pagination'; import Card from '../lib/Card'; import Loading from '../lib/Loading'; -import Format from '../formats/Format'; -import { polyglot as polyglotPropTypes } from '../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../propTypes'; import { loadDatasetPage as loadDatasetPageAction } from './'; import { getCollectionFields } from '../publication'; @@ -59,13 +57,11 @@ export class DatasetComponent extends Component { {dataset.map(data => ( {columns.map(column => ( - - {column.name === 'uri' ? - {data[column.name]} - : - - } - + ))} ))} diff --git a/src/app/js/dataset/Dataset.spec.js b/src/app/js/dataset/Dataset.spec.js index 94439ccaf..6172e34e2 100644 --- a/src/app/js/dataset/Dataset.spec.js +++ b/src/app/js/dataset/Dataset.spec.js @@ -1,13 +1,11 @@ import React from 'react'; import expect, { createSpy } from 'expect'; import { shallow } from 'enzyme'; -import { - TableHeaderColumn, - TableRowColumn, -} from 'material-ui/Table'; +import { TableHeaderColumn } from 'material-ui/Table'; import { DatasetComponent as Dataset } from './Dataset'; import Pagination from '../lib/Pagination'; +import DatasetColumn from './DatasetColumn'; describe('', () => { const columns = [ @@ -65,13 +63,37 @@ describe('', () => { total={3} />); - const cells = wrapper.find(TableRowColumn); - expect(cells.at(0).children().text()).toEqual('value11'); - expect(cells.at(1).children().text()).toEqual('value12'); - expect(cells.at(2).children().text()).toEqual('value21'); - expect(cells.at(3).children().text()).toEqual('value22'); - expect(cells.at(4).children().text()).toEqual('value31'); - expect(cells.at(5).children().text()).toEqual('value32'); + const cells = wrapper.find(DatasetColumn); + expect(cells.at(0).props()).toEqual({ + column: columns.find(c => c.name === 'col1'), + columns, + resource: dataset[0], + }); + expect(cells.at(1).props()).toEqual({ + column: columns.find(c => c.name === 'col2'), + columns, + resource: dataset[0], + }); + expect(cells.at(2).props()).toEqual({ + column: columns.find(c => c.name === 'col1'), + columns, + resource: dataset[1], + }); + expect(cells.at(3).props()).toEqual({ + column: columns.find(c => c.name === 'col2'), + columns, + resource: dataset[1], + }); + expect(cells.at(4).props()).toEqual({ + column: columns.find(c => c.name === 'col1'), + columns, + resource: dataset[2], + }); + expect(cells.at(5).props()).toEqual({ + column: columns.find(c => c.name === 'col2'), + columns, + resource: dataset[2], + }); }); it('should render the Pagination', () => { diff --git a/src/app/js/dataset/DatasetColumn.js b/src/app/js/dataset/DatasetColumn.js new file mode 100644 index 000000000..384c01e4b --- /dev/null +++ b/src/app/js/dataset/DatasetColumn.js @@ -0,0 +1,10 @@ +import branch from 'recompose/branch'; +import renderComponent from 'recompose/renderComponent'; + +import UriColumn from './UriColumn'; +import DefaultColumn from './DefaultColumn'; + +export default branch( + props => props.column.name === 'uri', + renderComponent(UriColumn), +)(DefaultColumn); diff --git a/src/app/js/dataset/DefaultColumn.js b/src/app/js/dataset/DefaultColumn.js new file mode 100644 index 000000000..fa1fe1802 --- /dev/null +++ b/src/app/js/dataset/DefaultColumn.js @@ -0,0 +1,62 @@ +import React, { Component, PropTypes } from 'react'; +import { connect } from 'react-redux'; +import compose from 'recompose/compose'; +import withHandlers from 'recompose/withHandlers'; +import withState from 'recompose/withState'; + +import { TableRowColumn } from 'material-ui/Table'; +import Format from '../formats/Format'; +import fetchByUri from '../lib/fetchByUri'; +import { getToken } from '../user'; +import { field as fieldPropTypes } from '../propTypes'; + +export class DatasetColumnComponent extends Component { + componentWillMount() { + const { column, resource } = this.props; + const linkTransformer = column.transformers && column.transformers.find(t => t.operation === 'LINK'); + if (linkTransformer) { + const uri = resource[linkTransformer.args.find(a => a.name === 'reference').value]; + this.props.fetchLinkedResource(uri); + } + } + + render() { + const { column, columns, linkedResource, resource } = this.props; + + return ( + + + + ); + } +} + +DatasetColumnComponent.propTypes = { + column: fieldPropTypes.isRequired, + columns: PropTypes.arrayOf(fieldPropTypes).isRequired, + fetchLinkedResource: PropTypes.func.isRequired, + linkedResource: PropTypes.object, // eslint-disable-line + resource: PropTypes.object.isRequired, // eslint-disable-line +}; + +const mapStateToProps = state => ({ + token: getToken(state), +}); + +export default compose( + connect(mapStateToProps), + withState('linkedResource', 'setLinkedResource', null), + withHandlers({ + fetchLinkedResource: ({ setLinkedResource, token }) => uri => + fetchByUri(uri, token) + .then((linkedResource) => { + setLinkedResource(linkedResource); + }), + }), +)(DatasetColumnComponent); + diff --git a/src/app/js/dataset/DefaultColumn.spec.js b/src/app/js/dataset/DefaultColumn.spec.js new file mode 100644 index 000000000..8a5761ba9 --- /dev/null +++ b/src/app/js/dataset/DefaultColumn.spec.js @@ -0,0 +1,73 @@ +import React from 'react'; +import expect, { createSpy } from 'expect'; +import { shallow } from 'enzyme'; +import { TableRowColumn } from 'material-ui/Table'; + +import { DatasetColumnComponent as DefaultColumn } from './DefaultColumn'; +import Format from '../formats/Format'; + +describe('', () => { + const column = { name: 'a_name', label: 'Foo' }; + const columns = [ + column, + { name: 'another_name', label: 'Foo2' }, + ]; + + const resource = { + a_name: 'a_value', + reference_value: 'referenced_resource', + }; + + const fetchLinkedResource = createSpy(); + + + it('calls fetchLinkedResource on mount if column has a LINK transformer', () => { + const linkedColumn = { + name: 'linked', + label: 'Linked', + transformers: [ + { + operation: 'LINK', + args: [ + { name: 'reference', value: 'reference_value' }, + { name: 'identifier', value: 'identifier_value' }, + ], + }, + ], + }; + shallow(); + + expect(fetchLinkedResource).toHaveBeenCalledWith('referenced_resource'); + }); + + const linkedResource = { linked: true }; + const wrapper = shallow(); + + it('renders a TableRowColumn with correct class', () => { + const element = wrapper.find(TableRowColumn); + + expect(element.prop('className')).toEqual('dataset-a_name'); + }); + + it('renders a Format with correct props when no linkedResource is supplied', () => { + const element = wrapper.find(Format); + + expect(element.props()).toEqual({ + field: column, + fields: columns, + resource, + linkedResource, + }); + }); +}); diff --git a/src/app/js/dataset/UriColumn.js b/src/app/js/dataset/UriColumn.js new file mode 100644 index 000000000..ac7d0c9b8 --- /dev/null +++ b/src/app/js/dataset/UriColumn.js @@ -0,0 +1,17 @@ +import React, { PropTypes } from 'react'; +import { Link } from 'react-router'; +import { TableRowColumn } from 'material-ui/Table'; +import { field as fieldPropTypes } from '../propTypes'; + +const UriColumn = ({ column, resource }) => ( + + {resource[column.name]} + +); + +UriColumn.propTypes = { + column: fieldPropTypes.isRequired, + resource: PropTypes.object.isRequired, // eslint-disable-line +}; + +export default UriColumn; diff --git a/src/app/js/dataset/UriColumn.spec.js b/src/app/js/dataset/UriColumn.spec.js new file mode 100644 index 000000000..afe89f4db --- /dev/null +++ b/src/app/js/dataset/UriColumn.spec.js @@ -0,0 +1,34 @@ +import React from 'react'; +import expect from 'expect'; +import { shallow } from 'enzyme'; +import { TableRowColumn } from 'material-ui/Table'; +import { Link } from 'react-router'; + +import UriColumn from './UriColumn'; + +describe('', () => { + const column = { name: 'a_name' }; + const resource = { + a_name: 'a_value', + }; + + const wrapper = shallow(); + + it('renders a TableRowColumn with correct class', () => { + const element = wrapper.find(TableRowColumn); + + expect(element.prop('className')).toEqual('dataset-a_name'); + }); + + const link = wrapper.find(Link); + it('renders a Link with correct href', () => { + expect(link.prop('to')).toEqual('/resource?uri=a_value'); + }); + + it('renders a Link with correct text', () => { + expect(link.children().text()).toEqual('a_value'); + }); +}); diff --git a/src/app/js/formats/DefaultFormat.js b/src/app/js/formats/DefaultFormat.js index 788964ff9..936016198 100644 --- a/src/app/js/formats/DefaultFormat.js +++ b/src/app/js/formats/DefaultFormat.js @@ -1,7 +1,13 @@ import React, { PropTypes } from 'react'; +import { field as fieldPropTypes } from '../propTypes'; const DefaultFormat = ({ resource, field }) => ( {resource[field.name]} ); +DefaultFormat.propTypes = { + field: fieldPropTypes.isRequired, + resource: PropTypes.object.isRequired, // eslint-disable-line +}; + export default DefaultFormat; diff --git a/src/app/js/formats/Format.js b/src/app/js/formats/Format.js index c1a6b3bcd..ca3bec47d 100644 --- a/src/app/js/formats/Format.js +++ b/src/app/js/formats/Format.js @@ -1,9 +1,14 @@ import React, { PropTypes } from 'react'; +import { connect } from 'react-redux'; + import DefaultFormat from './DefaultFormat'; +import { getResourceLastVersion } from '../resource'; + +import { field as fieldPropTypes } from '../propTypes'; import uri from './uri'; -const Format = ({ resource, field, fields }) => { +const Format = ({ field, fields, linkedResource, rawLinkedResource, resource }) => { let Component = DefaultFormat; if (field.format && field.format.name) { @@ -20,11 +25,26 @@ const Format = ({ resource, field, fields }) => { return ( ); }; -export default Format; +Format.propTypes = { + field: fieldPropTypes.isRequired, + fields: PropTypes.arrayOf(fieldPropTypes).isRequired, + linkedResource: PropTypes.object, // eslint-disable-line + rawLinkedResource: PropTypes.object, // eslint-disable-line + resource: PropTypes.object, // eslint-disable-line +}; + +const mapStateToProps = (state, { linkedResource }) => ({ + linkedResource: linkedResource ? getResourceLastVersion(state, linkedResource) : null, + rawLinkedResource: linkedResource, +}); + +export default connect(mapStateToProps)(Format); diff --git a/src/app/js/formats/FormatEdition.js b/src/app/js/formats/FormatEdition.js index 1f51dfd9b..a5c398f04 100644 --- a/src/app/js/formats/FormatEdition.js +++ b/src/app/js/formats/FormatEdition.js @@ -1,10 +1,11 @@ -import React, { Component, PropTypes } from 'react'; +import React, { Component } from 'react'; +import { propTypes as reduxFormPropTypes } from 'redux-form'; + import SelectFormat from './SelectFormat'; import FORMATS from './formats'; import uri from './uri'; - const Empty = () => ; const styles = { @@ -77,4 +78,6 @@ class FormatEdition extends Component { } } +FormatEdition.propTypes = reduxFormPropTypes; + export default FormatEdition; diff --git a/src/app/js/formats/SelectFormat.js b/src/app/js/formats/SelectFormat.js index 3df392145..4db6e51ba 100644 --- a/src/app/js/formats/SelectFormat.js +++ b/src/app/js/formats/SelectFormat.js @@ -16,4 +16,10 @@ const SelectFormat = ({ formats, value, onChange }) => ( ); +SelectFormat.propTypes = { + formats: PropTypes.arrayOf(PropTypes.string).isRequired, + value: PropTypes.string.isRequired, + onChange: PropTypes.func.isRequired, +}; + export default SelectFormat; diff --git a/src/app/js/formats/uri/component.js b/src/app/js/formats/uri/component.js index 6fbeef2f0..71ba558b8 100644 --- a/src/app/js/formats/uri/component.js +++ b/src/app/js/formats/uri/component.js @@ -1,17 +1,21 @@ import React, { PropTypes } from 'react'; import { Link } from 'react-router'; +import { field as fieldPropTypes } from '../../propTypes'; -const UriComponent = ({ resource, field }) => { +const UriComponent = ({ linkedResource, resource, field }) => { + const uri = resource[field.name]; let label = resource[field.name]; if (field.format.args.type) { switch (field.format.args.type) { - case 'test': + case 'text': label = field.format.args.value; break; case 'column': { - label = resource[field.format.args.value]; + if (linkedResource) { + label = linkedResource[field.format.args.value]; + } break; } @@ -21,14 +25,13 @@ const UriComponent = ({ resource, field }) => { } } - return {label}; + return {label}; }; UriComponent.propTypes = { - args: PropTypes.array.isRequired, // eslint-disable-line + field: fieldPropTypes.isRequired, + linkedResource: PropTypes.object.isRequired, // eslint-disable-line resource: PropTypes.object.isRequired, // eslint-disable-line - field: PropTypes.object.isRequired, // eslint-disable-line - fields: PropTypes.array.isRequired, // eslint-disable-line }; export default UriComponent; diff --git a/src/app/js/formats/uri/editionComponent.js b/src/app/js/formats/uri/editionComponent.js index b05d5c6e6..299e782f3 100644 --- a/src/app/js/formats/uri/editionComponent.js +++ b/src/app/js/formats/uri/editionComponent.js @@ -67,4 +67,11 @@ class UriEdition extends Component { } } +UriEdition.propTypes = { + type: PropTypes.string.isRequired, + value: PropTypes.string.isRequired, + onChange: PropTypes.func.isRequired, +}; + + export default UriEdition; diff --git a/src/app/js/home/Home.js b/src/app/js/home/Home.js index 824474662..ac575e5dc 100644 --- a/src/app/js/home/Home.js +++ b/src/app/js/home/Home.js @@ -3,7 +3,7 @@ import compose from 'recompose/compose'; import { connect } from 'react-redux'; import translate from 'redux-polyglot/translate'; -import { polyglot as polyglotPropTypes } from '../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../propTypes'; import { loadPublication as loadPublicationAction, hasPublishedDataset as selectHasPublishedDataset, diff --git a/src/app/js/lib/Appbar/MenuAnonymous.js b/src/app/js/lib/Appbar/MenuAnonymous.js index cd60ae436..026ebe804 100644 --- a/src/app/js/lib/Appbar/MenuAnonymous.js +++ b/src/app/js/lib/Appbar/MenuAnonymous.js @@ -9,7 +9,7 @@ import IconMenu from 'material-ui/IconMenu'; import MenuItem from 'material-ui/MenuItem'; import MoreVertIcon from 'material-ui/svg-icons/navigation/more-vert'; -import { polyglot as polyglotPropTypes } from '../propTypes'; +import { polyglot as polyglotPropTypes } from '../../propTypes'; import { exportPublishedDataset } from '../../export'; import { toggleLogin as toggleLoginAction } from '../../user'; diff --git a/src/app/js/lib/Appbar/MenuSignedIn.js b/src/app/js/lib/Appbar/MenuSignedIn.js index 86f8799dc..83628fd90 100644 --- a/src/app/js/lib/Appbar/MenuSignedIn.js +++ b/src/app/js/lib/Appbar/MenuSignedIn.js @@ -10,7 +10,7 @@ import MenuItem from 'material-ui/MenuItem'; import MoreVertIcon from 'material-ui/svg-icons/navigation/more-vert'; import { Link } from 'react-router'; -import { polyglot as polyglotPropTypes } from '../propTypes'; +import { polyglot as polyglotPropTypes } from '../../propTypes'; import { exportPublishedDataset as exportPublishedDatasetAction } from '../../export'; const styles = { diff --git a/src/app/js/lib/Property.js b/src/app/js/lib/Property.js index ae8c5a6b8..f5fd0ee3e 100644 --- a/src/app/js/lib/Property.js +++ b/src/app/js/lib/Property.js @@ -3,11 +3,11 @@ import { connect } from 'react-redux'; import compose from 'recompose/compose'; import translate from 'redux-polyglot/translate'; -import { property as propertyPropTypes } from './propTypes'; import { getResourceUnvalidatedFields, getResourceContributorsByField, } from '../resource'; +import { property as propertyPropTypes } from '../propTypes'; const styles = { container: unValidated => ({ diff --git a/src/app/js/lib/PropertyEdition.js b/src/app/js/lib/PropertyEdition.js index 86288e3c9..505364654 100644 --- a/src/app/js/lib/PropertyEdition.js +++ b/src/app/js/lib/PropertyEdition.js @@ -2,7 +2,7 @@ import React from 'react'; import TextField from 'material-ui/TextField'; import withHandlers from 'recompose/withHandlers'; -import { property as propertyPropTypes } from './propTypes'; +import { property as propertyPropTypes } from '../propTypes'; const styles = { container: { diff --git a/src/app/js/lib/fetchByUri.js b/src/app/js/lib/fetchByUri.js new file mode 100644 index 000000000..19847cc6b --- /dev/null +++ b/src/app/js/lib/fetchByUri.js @@ -0,0 +1,17 @@ +import fetch from './fetch'; + +export default (uri, token) => + fetch({ + url: `/api/ark?uri=${uri}`, + credentials: 'include', + headers: { + Accept: 'application/json', + Authorization: `Bearer ${token}`, + 'Content-Type': 'application/json', + }, + }).then(({ response, error }) => { + if (error) { + throw error; + } + return response; + }); diff --git a/src/app/js/lib/propTypes.js b/src/app/js/propTypes.js similarity index 86% rename from src/app/js/lib/propTypes.js rename to src/app/js/propTypes.js index 53d17fc7f..24f13fdfa 100644 --- a/src/app/js/lib/propTypes.js +++ b/src/app/js/propTypes.js @@ -8,6 +8,12 @@ export const polyglot = PropTypes.shape({ tm: PropTypes.func.isRequired, }); +export const field = PropTypes.shape({ + name: PropTypes.string.isRequired, + label: PropTypes.string.isRequired, + scheme: PropTypes.string, +}); + export const property = PropTypes.shape({ name: PropTypes.string.isRequired, value: PropTypes.any.isRequired, diff --git a/src/app/js/publication/NoDataset.js b/src/app/js/publication/NoDataset.js index 2c0422e32..5c43ab17b 100644 --- a/src/app/js/publication/NoDataset.js +++ b/src/app/js/publication/NoDataset.js @@ -1,7 +1,7 @@ import React from 'react'; import translate from 'redux-polyglot/translate'; import { CardText } from 'material-ui/Card'; -import { polyglot as polyglotPropTypes } from '../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../propTypes'; import Card from '../lib/Card'; const NoDatasetComponent = ({ p: polyglot }) => ( diff --git a/src/app/js/publication/Published.js b/src/app/js/publication/Published.js index 09057eee3..9325e631d 100644 --- a/src/app/js/publication/Published.js +++ b/src/app/js/publication/Published.js @@ -3,7 +3,7 @@ import translate from 'redux-polyglot/translate'; import classnames from 'classnames'; import { CardText } from 'material-ui/Card'; -import { polyglot as polyglotPropTypes } from '../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../propTypes'; import Card from '../lib/Card'; const PublishedComponent = ({ p: polyglot, ...props }) => ( diff --git a/src/app/js/resource/Detail.js b/src/app/js/resource/Detail.js index f34ba8b14..a37edd7a1 100644 --- a/src/app/js/resource/Detail.js +++ b/src/app/js/resource/Detail.js @@ -10,7 +10,7 @@ import { getResourceLastVersion, } from './'; import Card from '../lib/Card'; -import { polyglot as polyglotPropTypes } from '../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../propTypes'; import { isLoggedIn } from '../user'; import DetailProperties from './DetailProperties'; diff --git a/src/app/js/resource/EditDetail.js b/src/app/js/resource/EditDetail.js index f6f2e203e..67d7c422a 100644 --- a/src/app/js/resource/EditDetail.js +++ b/src/app/js/resource/EditDetail.js @@ -18,7 +18,7 @@ import Card from '../lib/Card'; import FormTextField from '../lib/FormTextField'; import Alert from '../lib/Alert'; import ButtonWithStatus from '../lib/ButtonWithStatus'; -import { polyglot as polyglotPropTypes } from '../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../propTypes'; const validate = (values) => { const errors = Object.keys(values).reduce((currentErrors, field) => { diff --git a/src/app/js/resource/HideDetail.js b/src/app/js/resource/HideDetail.js index 7a1fedc87..e209f8bcf 100644 --- a/src/app/js/resource/HideDetail.js +++ b/src/app/js/resource/HideDetail.js @@ -13,13 +13,13 @@ import { isSaving, HIDE_RESOURCE_FORM_NAME, } from './'; -import { getCollectionFields } from '../publication'; + import Card from '../lib/Card'; import FormTextField from '../lib/FormTextField'; import Alert from '../lib/Alert'; import ButtonWithStatus from '../lib/ButtonWithStatus'; -import { polyglot as polyglotPropTypes } from '../lib/propTypes'; import DetailProperties from './DetailProperties'; +import { polyglot as polyglotPropTypes } from '../propTypes'; export const HideDetailComponent = ({ resource, saving, error, handleSubmit, p: polyglot }) => ( diff --git a/src/app/js/resource/RemovedDetail.js b/src/app/js/resource/RemovedDetail.js index 6ccc91b40..760e8eb32 100644 --- a/src/app/js/resource/RemovedDetail.js +++ b/src/app/js/resource/RemovedDetail.js @@ -9,7 +9,7 @@ import { getRemovedData, } from './'; import Card from '../lib/Card'; -import { polyglot as polyglotPropTypes } from '../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../propTypes'; const styles = { container: { diff --git a/src/app/js/resource/Resource.js b/src/app/js/resource/Resource.js index 5a17b2889..ead750cc6 100644 --- a/src/app/js/resource/Resource.js +++ b/src/app/js/resource/Resource.js @@ -20,7 +20,7 @@ import EditDetail from './EditDetail'; import HideDetail from './HideDetail'; import RemovedDetail from './RemovedDetail'; import AddFieldDetail from './AddFieldDetail'; -import { polyglot as polyglotPropTypes } from '../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../propTypes'; import DatasetCharacteristics from '../characteristic/DatasetCharacteristics'; import Loading from '../lib/Loading'; diff --git a/src/app/js/resource/index.js b/src/app/js/resource/index.js index 460e3e19f..9698528e3 100644 --- a/src/app/js/resource/index.js +++ b/src/app/js/resource/index.js @@ -141,8 +141,7 @@ export const getAddFieldToResourceRequest = (state, data) => ({ body: JSON.stringify(data), }); -export const getResourceLastVersion = (state) => { - const resource = state.resource.resource; +export const getResourceLastVersion = (state, resource = state.resource.resource) => { const { versions, uri } = resource; if (!versions) { return null; diff --git a/src/app/js/user/Login.js b/src/app/js/user/Login.js index ae4482acb..1a7b1e548 100644 --- a/src/app/js/user/Login.js +++ b/src/app/js/user/Login.js @@ -6,7 +6,7 @@ import translate from 'redux-polyglot/translate'; import { submit as submitAction, isSubmitting } from 'redux-form'; import { Card, CardActions, CardHeader, CardText } from 'material-ui/Card'; -import { polyglot as polyglotPropTypes } from '../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../propTypes'; import { login as loginAction, toggleLogin as toggleLoginAction, LOGIN_FORM_NAME } from './'; import LoginForm from './LoginForm'; import ButtonWithStatus from '../lib/ButtonWithStatus'; diff --git a/src/app/js/user/LoginDialog.js b/src/app/js/user/LoginDialog.js index 207c826f0..03c065628 100644 --- a/src/app/js/user/LoginDialog.js +++ b/src/app/js/user/LoginDialog.js @@ -8,7 +8,7 @@ import Dialog from 'material-ui/Dialog'; import FlatButton from 'material-ui/FlatButton'; import { submit as submitAction, isSubmitting } from 'redux-form'; -import { polyglot as polyglotPropTypes } from '../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../propTypes'; import { login as loginAction, toggleLogin as toggleLoginAction, LOGIN_FORM_NAME } from './'; import LoginForm from './LoginForm'; import ButtonWithStatus from '../lib/ButtonWithStatus'; diff --git a/src/app/js/user/LoginForm.js b/src/app/js/user/LoginForm.js index 3b2892835..b6e445dee 100644 --- a/src/app/js/user/LoginForm.js +++ b/src/app/js/user/LoginForm.js @@ -4,7 +4,7 @@ import translate from 'redux-polyglot/translate'; import { Field, reduxForm, propTypes as reduxFormPropTypes } from 'redux-form'; import FormTextField from '../lib/FormTextField'; -import { polyglot as polyglotPropTypes } from '../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../propTypes'; import { LOGIN_FORM_NAME } from './'; import Alert from '../lib/Alert'; From a0267d1efbede376a0a9f1a4271cafbdf249120d Mon Sep 17 00:00:00 2001 From: djhi Date: Thu, 16 Feb 2017 12:30:10 +0100 Subject: [PATCH 3/5] fix tests --- src/app/js/lib/SchemeAutoComplete.js | 2 +- src/app/js/resource/AddFieldDetail.js | 2 +- src/app/js/resource/ContributionField.js | 2 +- src/app/js/resource/Contributor.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/js/lib/SchemeAutoComplete.js b/src/app/js/lib/SchemeAutoComplete.js index a718898aa..a22989b85 100644 --- a/src/app/js/lib/SchemeAutoComplete.js +++ b/src/app/js/lib/SchemeAutoComplete.js @@ -5,7 +5,7 @@ import translate from 'redux-polyglot/translate'; import { Field } from 'redux-form'; import MenuItem from 'material-ui/MenuItem'; -import { polyglot as polyglotPropTypes } from './propTypes'; +import { polyglot as polyglotPropTypes } from '../propTypes'; import FormAutoCompleteField from './FormAutoCompleteField'; import { diff --git a/src/app/js/resource/AddFieldDetail.js b/src/app/js/resource/AddFieldDetail.js index 721f8b214..0d20cb7e2 100644 --- a/src/app/js/resource/AddFieldDetail.js +++ b/src/app/js/resource/AddFieldDetail.js @@ -20,7 +20,7 @@ import { import Card from '../lib/Card'; import Alert from '../lib/Alert'; import ButtonWithStatus from '../lib/ButtonWithStatus'; -import { polyglot as polyglotPropTypes } from '../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../propTypes'; import SelectFieldToAdd from './SelectFieldToAdd'; import { isLoggedIn as getIsLoggedIn } from '../user'; import DetailProperties from './DetailProperties'; diff --git a/src/app/js/resource/ContributionField.js b/src/app/js/resource/ContributionField.js index 84ca1dbd6..57e6bcd60 100644 --- a/src/app/js/resource/ContributionField.js +++ b/src/app/js/resource/ContributionField.js @@ -11,7 +11,7 @@ import { getDocumentFields, } from '../publication'; import FormTextField from '../lib/FormTextField'; -import { polyglot as polyglotPropTypes } from '../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../propTypes'; import FormSelectField from '../lib/FormSelectField'; const required = value => (value ? undefined : 'Required'); diff --git a/src/app/js/resource/Contributor.js b/src/app/js/resource/Contributor.js index 8bd53218f..07215fcb5 100644 --- a/src/app/js/resource/Contributor.js +++ b/src/app/js/resource/Contributor.js @@ -4,7 +4,7 @@ import { Field } from 'redux-form'; import { CardText } from 'material-ui/Card'; import FormTextField from '../lib/FormTextField'; -import { polyglot as polyglotPropTypes } from '../lib/propTypes'; +import { polyglot as polyglotPropTypes } from '../propTypes'; const required = value => (value ? undefined : 'Required'); const validMail = value => From 3a6835ea4059c7af6bc79a5b3706e6d7607ccadb Mon Sep 17 00:00:00 2001 From: djhi Date: Thu, 16 Feb 2017 14:30:05 +0100 Subject: [PATCH 4/5] review --- src/app/js/formats/Format.js | 2 +- src/app/js/formats/FormatEdition.js | 2 +- src/app/js/formats/uri/{component.js => Component.js} | 6 +++--- .../uri/{editionComponent.js => EditionComponent.js} | 0 src/app/js/formats/uri/index.js | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) rename src/app/js/formats/uri/{component.js => Component.js} (88%) rename src/app/js/formats/uri/{editionComponent.js => EditionComponent.js} (100%) diff --git a/src/app/js/formats/Format.js b/src/app/js/formats/Format.js index ca3bec47d..04ee5a2c2 100644 --- a/src/app/js/formats/Format.js +++ b/src/app/js/formats/Format.js @@ -14,7 +14,7 @@ const Format = ({ field, fields, linkedResource, rawLinkedResource, resource }) if (field.format && field.format.name) { switch (field.format.name) { case 'uri': - Component = uri.component; + Component = uri.Component; break; default: diff --git a/src/app/js/formats/FormatEdition.js b/src/app/js/formats/FormatEdition.js index a5c398f04..f89255f37 100644 --- a/src/app/js/formats/FormatEdition.js +++ b/src/app/js/formats/FormatEdition.js @@ -57,7 +57,7 @@ class FormatEdition extends Component { switch (name) { case 'uri': - EditionComponent = uri.editionComponent; + EditionComponent = uri.EditionComponent; break; default: diff --git a/src/app/js/formats/uri/component.js b/src/app/js/formats/uri/Component.js similarity index 88% rename from src/app/js/formats/uri/component.js rename to src/app/js/formats/uri/Component.js index 71ba558b8..ae6d07a84 100644 --- a/src/app/js/formats/uri/component.js +++ b/src/app/js/formats/uri/Component.js @@ -2,7 +2,7 @@ import React, { PropTypes } from 'react'; import { Link } from 'react-router'; import { field as fieldPropTypes } from '../../propTypes'; -const UriComponent = ({ linkedResource, resource, field }) => { +const UriView = ({ linkedResource, resource, field }) => { const uri = resource[field.name]; let label = resource[field.name]; @@ -28,10 +28,10 @@ const UriComponent = ({ linkedResource, resource, field }) => { return {label}; }; -UriComponent.propTypes = { +UriView.propTypes = { field: fieldPropTypes.isRequired, linkedResource: PropTypes.object.isRequired, // eslint-disable-line resource: PropTypes.object.isRequired, // eslint-disable-line }; -export default UriComponent; +export default UriView; diff --git a/src/app/js/formats/uri/editionComponent.js b/src/app/js/formats/uri/EditionComponent.js similarity index 100% rename from src/app/js/formats/uri/editionComponent.js rename to src/app/js/formats/uri/EditionComponent.js diff --git a/src/app/js/formats/uri/index.js b/src/app/js/formats/uri/index.js index 191d03f80..126f659c9 100644 --- a/src/app/js/formats/uri/index.js +++ b/src/app/js/formats/uri/index.js @@ -1,8 +1,8 @@ -import component from './component'; -import editionComponent from './editionComponent'; +import Component from './Component'; +import EditionComponent from './EditionComponent'; export default { format: 'uri', - component, - editionComponent, + Component, + EditionComponent, }; From 4faae7695b83aaa0009a3234826293a23bc5826a Mon Sep 17 00:00:00 2001 From: djhi Date: Thu, 16 Feb 2017 15:15:01 +0100 Subject: [PATCH 5/5] e2e stability --- src/app/e2e/admin/publication.js | 2 -- src/app/e2e/admin/resources.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/app/e2e/admin/publication.js b/src/app/e2e/admin/publication.js index e49fde529..051e2c9ac 100644 --- a/src/app/e2e/admin/publication.js +++ b/src/app/e2e/admin/publication.js @@ -198,8 +198,6 @@ describe('Admin', () => { const headersText = await Promise.all(headers.map(h => h.getText())); expect(headersText).toEqual(['uri', 'stronger', 'name']); - await driver.sleep(5000); - const rows = await Promise.all([1, 2, 3, 4].map(index => Promise.all([ driver diff --git a/src/app/e2e/admin/resources.js b/src/app/e2e/admin/resources.js index e51839909..905c2b41b 100644 --- a/src/app/e2e/admin/resources.js +++ b/src/app/e2e/admin/resources.js @@ -55,7 +55,7 @@ describe('Admin', () => { it('should remove a resource which has been restored', async () => { const buttons = await driver.findElements(By.css('.btn-restore-resource')); - await buttons[0].click(); + await driver.wait(elementIsClicked(buttons[0]), DEFAULT_WAIT_TIMEOUT); await driver.sleep(500); const trs = await driver.findElements(By.css('.removed_resources table tbody tr'));