Skip to content

Commit

Permalink
Merge pull request #60 from Inist-CNRS/format
Browse files Browse the repository at this point in the history
[RFR] Formats
  • Loading branch information
ThieryMichel authored Feb 16, 2017
2 parents fee2af7 + 4faae76 commit 5527989
Show file tree
Hide file tree
Showing 56 changed files with 616 additions and 63 deletions.
16 changes: 16 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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({}); \
"
2 changes: 0 additions & 2 deletions src/app/e2e/admin/publication.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/app/e2e/admin/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
2 changes: 1 addition & 1 deletion src/app/js/admin/Admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion src/app/js/admin/fields/FieldForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -15,6 +15,7 @@ import {
saveField,
} from './';

import Format from '../../formats/FormatEdition';
import Alert from '../../lib/Alert';
import TransformerList from './TransformerList';

Expand Down Expand Up @@ -69,6 +70,12 @@ export const FieldFormComponent = ({
</Field>
<SchemeAutoComplete name="scheme" />
{ isContribution ? null : <FieldArray name="transformers" component={TransformerList} /> }
{ isContribution ? null : <Field
name="format"
component={Format}
label={polyglot.t('format')}
fullWidth
/>}
</form>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/app/js/admin/fields/TransformerArgListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => (
Expand Down
2 changes: 1 addition & 1 deletion src/app/js/admin/fields/TransformerList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => (
Expand Down
2 changes: 1 addition & 1 deletion src/app/js/admin/fields/TransformerListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/app/js/admin/parsing/ParsingExcerptAddColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => (
<TableRowColumn>
Expand Down
2 changes: 1 addition & 1 deletion src/app/js/admin/parsing/ParsingResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/app/js/admin/parsing/ParsingSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/app/js/admin/publicationPreview/PublicationExcerpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion src/app/js/admin/publicationPreview/PublicationPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => (
Expand Down
2 changes: 1 addition & 1 deletion src/app/js/admin/publish/Publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/app/js/admin/removedResources/RemovedResourceList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/app/js/admin/validation/Validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion src/app/js/admin/validation/ValidationField.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion src/app/js/characteristic/DatasetCharacteristicsEdition.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Card from '../lib/Card';
import {
property as propertyPropTypes,
polyglot as polyglotPropTypes,
} from '../lib/propTypes';
} from '../propTypes';

import {
getNewCharacteristics,
Expand Down
2 changes: 1 addition & 1 deletion src/app/js/characteristic/DatasetCharacteristicsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 9 additions & 11 deletions src/app/js/dataset/Dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -13,12 +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 { polyglot as polyglotPropTypes } from '../lib/propTypes';

import { polyglot as polyglotPropTypes } from '../propTypes';
import { loadDatasetPage as loadDatasetPageAction } from './';
import { getCollectionFields } from '../publication';

Expand Down Expand Up @@ -56,14 +56,12 @@ export class DatasetComponent extends Component {
<TableBody displayRowCheckbox={false}>
{dataset.map(data => (
<TableRow>
{columns.map(({ name }) => (
<TableRowColumn className={`dataset-${name}`}>
{name === 'uri' ?
<Link to={`/resource?uri=${data[name]}`}>{data[name]}</Link>
:
data[name]
}
</TableRowColumn>
{columns.map(column => (
<DatasetColumn
column={column}
columns={columns}
resource={data}
/>
))}
</TableRow>
))}
Expand Down
44 changes: 33 additions & 11 deletions src/app/js/dataset/Dataset.spec.js
Original file line number Diff line number Diff line change
@@ -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('<Dataset />', () => {
const columns = [
Expand Down Expand Up @@ -65,13 +63,37 @@ describe('<Dataset />', () => {
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', () => {
Expand Down
10 changes: 10 additions & 0 deletions src/app/js/dataset/DatasetColumn.js
Original file line number Diff line number Diff line change
@@ -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);
62 changes: 62 additions & 0 deletions src/app/js/dataset/DefaultColumn.js
Original file line number Diff line number Diff line change
@@ -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 (
<TableRowColumn className={`dataset-${column.name}`}>
<Format
field={column}
fields={columns}
linkedResource={linkedResource}
resource={resource}
/>
</TableRowColumn>
);
}
}

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);

Loading

0 comments on commit 5527989

Please sign in to comment.