Skip to content

Commit

Permalink
Merge pull request #110 from EmmanuelDemey/master
Browse files Browse the repository at this point in the history
maxOccurs=unbounded
  • Loading branch information
alicela authored Aug 4, 2020
2 parents 1e64b88 + 96c24e7 commit b9bca34
Show file tree
Hide file tree
Showing 32 changed files with 1,225 additions and 355 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ cypress/screenshots

coverage
build

*.mp4
6 changes: 3 additions & 3 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
"redux-thunk": "2.3.0"
},
"devDependencies": {
"axe-core": "3.5.3",
"axe-core": "3.5.5",
"coveralls": "3.0.3",
"cross-env": "6.0.3",
"cypress": "4.7.0",
"cross-env": "7.0.2",
"cypress": "4.11.0",
"cypress-axe": "0.8.1",
"lcov-result-merger": "^3.1.0",
"node-sass": "4.14.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { Provider } from 'react-redux';
import configureStore from 'redux-mock-store';

const mockStore = configureStore([]);
const store = mockStore({});
const store = mockStore({
app: {
secondLang: true,
},
});

const correspondence = {
id: '1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('collection-visualization-controls', () => {
render(
<CollectionVisualizationControls
id="id"
isValidated="false"
isValidated={false}
handleValidation={() => console.log('validate')}
permission={{ authType: '', roles: [''] }}
/>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import React, { Component } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import { Pagination } from '@inseefr/wilco';
import D from 'js/i18n';

class SearchConceptsByLabel extends Component {
render() {
const { searchLabel, handleSearch, hitEls } = this.props;
return (
<div>
<input
value={searchLabel}
onChange={e => handleSearch(e.target.value)}
type="text"
placeholder={D.searchLabelPlaceholder}
className="form-control"
/>
<Pagination itemEls={hitEls} itemsPerPage="10" />
</div>
);
}
}
const SearchConceptsByLabel = ({ searchLabel, handleSearch, hitEls }) => {
return (
<div>
<input
value={searchLabel}
onChange={e => handleSearch(e.target.value)}
type="text"
placeholder={D.searchLabelPlaceholder}
className="form-control"
/>
<Pagination itemEls={hitEls} itemsPerPage="10" />
</div>
);
};

SearchConceptsByLabel.propTypes = {
searchLabel: PropTypes.string.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('concept-edition-creation-search-concepts-by-label', () => {
render(
<SearchConceptsByLabel
searchLabel="label"
hitEls={[<div>Element</div>]}
hitEls={[]}
handleSearch={() => console.log('save')}
/>,
{ wrapper: MemoryRouter }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class OperationsIndicatorEdition extends Component {
<div className="row">
<div className="form-group col-md-12">
<label htmlFor="contributor" className="w-100">
{D1.operationsContributorTitle}
{D1.creatorTitle}
<SelectRmes
placeholder=""
unclearable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function OperationsIndicatorVisualization(props) {
))}
</ul>
}
title={D1.operationsContributorTitle}
title={D1.creatorTitle}
lang={langs.lg1}
alone={true}
allowEmpty={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export default function HelpInformation({ msd, codesLists, organisations }) {
<dd>{msd.masLabelLg2}</dd>
<dt>{D.helpPresentational}:</dt>
<dd>{msd.isPresentational.toString()}</dd>
{msd.maxOccurs && (
<>
<dt>{D.helpMaxOccurs}:</dt>
<dd>{msd.maxOccurs}</dd>
</>
)}
<dt>{D.helpRange}:</dt>
<dd>
{msd.rangeType === CODE_LIST && codesLists[msd.codeList]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import HelpInformation from './';
describe('HelpInformation', () => {
it('should return null if the masLabelLg1 is undefined', () => {
const { container } = render(<HelpInformation msd={{}} />);
expect(container).toBeEmpty();
expect(container).toBeEmptyDOMElement();
});
});
4 changes: 2 additions & 2 deletions app/src/js/applications/operations/msd/outline/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ jest.mock('js/applications/operations/msd/utils');
const metadataStructureOpened = {
idMas: '1',
masLabelLg1: 'masLabelLg1',
children: { '1': { children: [] } },
children: { '1': { idMas: '2', children: [] } },
};

const metadataStructureClosed = {
idMas: '2',
masLabelLg1: 'masLabelLg1',
children: { '1': { children: [] } },
children: { '1': { idMas: '1', children: [] } },
};

describe('Outline', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import PropTypes from 'prop-types';
import D from 'js/i18n';
import Field, {
DocumentField,
} from 'js/applications/operations/msd/pages/sims-creation/sims-field';
import Field from 'js/applications/operations/msd/pages/sims-creation/sims-field';
import { flattenTree } from 'js/utils/msd';
import SimsDocumentField from 'js/applications/operations/msd/pages/sims-creation/sims-document-field';

import {
Loading,
CancelButton,
Expand Down Expand Up @@ -41,6 +41,7 @@ class SimsCreation extends React.Component {
super(props);

const { metadataStructure, sims = {} } = this.props;

const flattenStructure = flattenTree(metadataStructure);

this.state = {
Expand Down Expand Up @@ -180,6 +181,7 @@ class SimsCreation extends React.Component {
lang={lg1}
alone={!hasLabelLg2(msd) || !secondLang}
organisationsOptions={organisationsOptions}
unbounded={msd.maxOccurs === 'unbounded'}
/>
)}
{!msd.isPresentational && hasLabelLg2(msd) && secondLang && (
Expand All @@ -196,7 +198,7 @@ class SimsCreation extends React.Component {
)}

{msd.rangeType === RICH_TEXT && (
<DocumentField
<SimsDocumentField
msd={msd}
currentSection={sims[msd.idMas]}
handleChange={handleChange}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React, { useCallback } from 'react';
import { isLink, isDocument } from 'js/applications/operations/document/utils';
import DocumentsBloc from '../../documents/documents-bloc';
import PropTypes from 'prop-types';

export const SimsDocumentField = ({ handleChange, msd, currentSection }) => {
const handleDeleteDocument = useCallback(
uri => {
const objects = currentSection.documents || [];
handleChange({
id: msd.idMas,
override: {
documents: objects.filter(doc => doc.uri !== uri),
},
});
},
[handleChange, currentSection.documents, msd.idMas]
);

const handleAddDocument = useCallback(
newObject => {
const objects = currentSection.documents || [];
handleChange({
id: msd.idMas,
override: {
documents: [...objects, newObject],
},
});
},
[handleChange, msd.idMas, currentSection.documents]
);

return (
<div className="bauhaus-document-field">
<DocumentsBloc
documents={(currentSection.documents || []).filter(isDocument)}
localPrefix={'Lg1'}
editMode={true}
deleteHandler={handleDeleteDocument}
addHandler={handleAddDocument}
objectType="documents"
/>
<DocumentsBloc
documents={(currentSection.documents || []).filter(isLink)}
localPrefix={'Lg1'}
editMode={true}
deleteHandler={handleDeleteDocument}
addHandler={handleAddDocument}
objectType="links"
/>
</div>
);
};

SimsDocumentField.propTypes = {
msd: PropTypes.object.isRequired,
currentSection: PropTypes.object,
handleChange: PropTypes.func,
};

export default SimsDocumentField;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { PureComponent, useCallback } from 'react';
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import D from 'js/i18n';
import { rangeType } from 'js/utils/msd/';
Expand All @@ -8,83 +8,45 @@ import { EditorMarkdownToolbar, ArrayUtils } from 'bauhaus-utilities';
import { Editor } from 'react-draft-wysiwyg';

import { Note, getLang, Select } from '@inseefr/wilco';
import { isLink, isDocument } from 'js/applications/operations/document/utils';
import './sims-field.scss';
import DocumentsBloc from '../../documents/documents-bloc';

const { RICH_TEXT, TEXT, DATE, CODE_LIST, ORGANIZATION } = rangeType;

export const DocumentField = ({ handleChange, msd, currentSection }) => {
const handleDeleteDocument = useCallback(
uri => {
console.log('handle delete');
const objects = currentSection.documents || [];
console.log({
id: msd.idMas,
override: {
documents: objects.filter(doc => doc.uri !== uri),
},
});
handleChange({
id: msd.idMas,
override: {
documents: objects.filter(doc => doc.uri !== uri),
},
});
},
[handleChange, currentSection.documents, msd.idMas]
);

const handleAddDocument = useCallback(
newObject => {
console.log('handle add');
const SimsCodeListSelect = props => {
let value;
let onChange;

const objects = currentSection.documents || [];
console.log({
id: msd.idMas,
override: {
documents: [...objects, newObject],
},
});
handleChange({
id: msd.idMas,
override: {
documents: [...objects, newObject],
},
});
},
[handleChange, msd.idMas, currentSection.documents]
);
if (!props.multi) {
value = props.options.find(
({ value }) => value === props.currentSection.value
);
onChange = props.onChange;
} else {
const currentSectionValue = Array.isArray(props.currentSection.value)
? props.currentSection.value
: [props.currentSection.value];

value = props.options.filter(({ value }) =>
currentSectionValue.includes(value)
);
onChange = values => {
props.onChange((values || []).map(({ value }) => value));
};
}

return (
<div className="bauhaus-document-field">
<DocumentsBloc
documents={(currentSection.documents || []).filter(isDocument)}
localPrefix={'Lg1'}
editMode={true}
deleteHandler={handleDeleteDocument}
addHandler={handleAddDocument}
objectType="documents"
/>
<DocumentsBloc
documents={(currentSection.documents || []).filter(isLink)}
localPrefix={'Lg1'}
editMode={true}
deleteHandler={handleDeleteDocument}
addHandler={handleAddDocument}
objectType="links"
/>
</div>
<Select
placeholder=""
aria-label={props['aria-label']}
className="form-control"
value={value}
options={props.options}
onChange={onChange}
multi={props.multi}
/>
);
};

DocumentField.propTypes = {
msd: PropTypes.object.isRequired,
currentSection: PropTypes.object,
codesLists: PropTypes.object.isRequired,
handleChange: PropTypes.func,
};

class Field extends PureComponent {
static propTypes = {
msd: PropTypes.object.isRequired,
Expand Down Expand Up @@ -119,6 +81,7 @@ class Field extends PureComponent {
lang,
alone,
organisationsOptions = [],
unbounded,
} = this.props;
const codesList = this.props.codesLists[msd.codeList] || {};
const codes = codesList.codes || [];
Expand Down Expand Up @@ -195,15 +158,12 @@ class Field extends PureComponent {
)}

{msd.rangeType === CODE_LIST && codesList && (
<Select
placeholder=""
<SimsCodeListSelect
aria-label={codesList.codeListLabelLg1}
className="form-control"
value={codesListOptions.find(
({ value }) => value === currentSection.value
)}
currentSection={currentSection}
options={codesListOptions}
onChange={this.handleCodeListInput}
multi={unbounded}
/>
)}
</span>
Expand Down
Loading

0 comments on commit b9bca34

Please sign in to comment.